1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using HeuristicLab.Core.Views;
|
---|
25 | using HeuristicLab.MainForm;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Clients.Access.Administration {
|
---|
28 | [View("UserGroup View")]
|
---|
29 | [Content(typeof(UserGroup), true)]
|
---|
30 | public partial class UserGroupView : ItemView {
|
---|
31 | public new UserGroup Content {
|
---|
32 | get { return (UserGroup)base.Content; }
|
---|
33 | set { base.Content = value; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public UserGroupView() {
|
---|
37 | InitializeComponent();
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected override void RegisterContentEvents() {
|
---|
41 | base.RegisterContentEvents();
|
---|
42 | AccessClient.Instance.Refreshing += new EventHandler(Content_Refreshing);
|
---|
43 | refreshableLightweightUserView.StorableStateChanged += new EventHandler(refreshableLightweightUserView_StorableStateChanged);
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected override void DeregisterContentEvents() {
|
---|
47 | AccessClient.Instance.Refreshing -= new EventHandler(Content_Refreshing);
|
---|
48 | refreshableLightweightUserView.StorableStateChanged -= new EventHandler(refreshableLightweightUserView_StorableStateChanged);
|
---|
49 | base.DeregisterContentEvents();
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected override void OnContentChanged() {
|
---|
53 | base.OnContentChanged();
|
---|
54 |
|
---|
55 | if (Content == null) {
|
---|
56 | groupNameTextBox.Clear();
|
---|
57 | idTextBox.Clear();
|
---|
58 |
|
---|
59 | refreshableLightweightUserView.Content = null;
|
---|
60 | refreshableLightweightUserView.FetchSelectedUsers = null;
|
---|
61 | } else {
|
---|
62 | groupNameTextBox.Text = Content.Name;
|
---|
63 | idTextBox.Text = Content.Id.ToString();
|
---|
64 |
|
---|
65 | refreshableLightweightUserView.Content = Content.Id != Guid.Empty ? AccessClient.Instance : null;
|
---|
66 | refreshableLightweightUserView.FetchSelectedUsers = Content.Id != Guid.Empty ? new Func<List<Guid>>(delegate { return AccessAdministrationClient.CallAccessService(s => s.GetUserGroupIdsOfGroup(Content.Id)); }) : null;
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected override void SetEnabledStateOfControls() {
|
---|
71 | base.SetEnabledStateOfControls();
|
---|
72 | bool enabled = Content != null && !Locked;
|
---|
73 | groupNameTextBox.ReadOnly = !enabled;
|
---|
74 | idTextBox.ReadOnly = !enabled;
|
---|
75 | storeButton.Enabled = enabled;
|
---|
76 | //refreshableLightweightUserView.Enabled = enabled;
|
---|
77 | refreshableLightweightUserView.Locked = !enabled;
|
---|
78 | //refreshableLightweightUserView.ReadOnly = !enabled;
|
---|
79 | }
|
---|
80 |
|
---|
81 | private void groupNameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
82 | if (Content != null && Content.Name != groupNameTextBox.Text)
|
---|
83 | Content.Name = groupNameTextBox.Text;
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void storeButton_Click(object sender, EventArgs e) {
|
---|
87 | Action storeAction = new Action(delegate {
|
---|
88 | foreach (var ug in refreshableLightweightUserView.GetAddedUsers()) {
|
---|
89 | AccessAdministrationClient.CallAccessService(s => s.AddUserGroupBaseToGroup(ug, Content));
|
---|
90 | }
|
---|
91 | });
|
---|
92 |
|
---|
93 | Action deleteAction = new Action(delegate {
|
---|
94 | foreach (var ug in refreshableLightweightUserView.GetDeletedUsers()) {
|
---|
95 | AccessAdministrationClient.CallAccessService(s => s.RemoveUserGroupBaseFromGroup(ug, Content));
|
---|
96 | }
|
---|
97 | });
|
---|
98 |
|
---|
99 | AccessAdministrationClient.Instance.ExecuteActionAsync(storeAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
|
---|
100 | AccessAdministrationClient.Instance.ExecuteActionAsync(deleteAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
|
---|
101 | }
|
---|
102 |
|
---|
103 | private void Content_Refreshing(object sender, EventArgs e) {
|
---|
104 | if (!Locked) storeButton.Enabled = false;
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void refreshableLightweightUserView_StorableStateChanged(object sender, EventArgs e) {
|
---|
108 | if (!Locked) storeButton.Enabled = true;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|