source: branches/HiveProjectManagement/HeuristicLab.Clients.Access.Administration/3.3/Views/UserGroupView.cs @ 15567

Last change on this file since 15567 was 15567, checked in by jzenisek, 5 years ago

#2839 worked on views for project and resource administration

File size: 4.2 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26
27namespace 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    }
75
76    private void groupNameTextBox_TextChanged(object sender, EventArgs e) {
77      if (Content != null && Content.Name != groupNameTextBox.Text)
78        Content.Name = groupNameTextBox.Text;
79    }
80
81    private void storeButton_Click(object sender, EventArgs e) {
82      Action storeAction = new Action(delegate {
83        foreach (var ug in refreshableLightweightUserView.GetAddedUsers()) {
84          AccessAdministrationClient.CallAccessService(s => s.AddUserGroupBaseToGroup(ug, Content));
85        }
86      });
87
88      Action deleteAction = new Action(delegate {
89        foreach (var ug in refreshableLightweightUserView.GetDeletedUsers()) {
90          AccessAdministrationClient.CallAccessService(s => s.RemoveUserGroupBaseFromGroup(ug, Content));
91        }
92      });
93
94      AccessAdministrationClient.Instance.ExecuteActionAsync(storeAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
95      AccessAdministrationClient.Instance.ExecuteActionAsync(deleteAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
96    }
97
98    private void Content_Refreshing(object sender, EventArgs e) {
99      storeButton.Enabled = false;
100    }
101
102    private void refreshableLightweightUserView_StorableStateChanged(object sender, EventArgs e) {
103      storeButton.Enabled = true;
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.