[8042] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9456] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8042] | 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 |
|
---|
[8141] | 40 | protected override void RegisterContentEvents() {
|
---|
| 41 | base.RegisterContentEvents();
|
---|
| 42 | Access.AccessClient.Instance.Refreshing += new EventHandler(Content_Refreshing);
|
---|
| 43 | refreshableLightweightUserView.StorableStateChanged += new EventHandler(refreshableLightweightUserView_StorableStateChanged);
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | protected override void DeregisterContentEvents() {
|
---|
| 47 | Access.AccessClient.Instance.Refreshing -= new EventHandler(Content_Refreshing);
|
---|
| 48 | refreshableLightweightUserView.StorableStateChanged -= new EventHandler(refreshableLightweightUserView_StorableStateChanged);
|
---|
| 49 | base.DeregisterContentEvents();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[8042] | 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 |
|
---|
[8141] | 65 | refreshableLightweightUserView.Content = Content.Id != Guid.Empty ? Access.AccessClient.Instance : null;
|
---|
| 66 | refreshableLightweightUserView.FetchSelectedUsers = Content.Id != Guid.Empty ? new Func<List<Guid>>(delegate { return AccessAdministrationClient.CallAccessService<List<Guid>>(s => s.GetUserGroupIdsOfGroup(Content.Id)); }) : null;
|
---|
[8042] | 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private void groupNameTextBox_TextChanged(object sender, System.EventArgs e) {
|
---|
[10106] | 71 | if (Content != null && Content.Name != this.groupNameTextBox.Text)
|
---|
[8042] | 72 | Content.Name = this.groupNameTextBox.Text;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | private void storeButton_Click(object sender, EventArgs e) {
|
---|
| 76 | Action storeAction = new Action(delegate {
|
---|
| 77 | foreach (var ug in refreshableLightweightUserView.GetAddedUsers()) {
|
---|
| 78 | AccessAdministrationClient.CallAccessService(s => s.AddUserGroupBaseToGroup(ug, Content));
|
---|
| 79 | }
|
---|
| 80 | });
|
---|
| 81 |
|
---|
| 82 | Action deleteAction = new Action(delegate {
|
---|
| 83 | foreach (var ug in refreshableLightweightUserView.GetDeletedUsers()) {
|
---|
| 84 | AccessAdministrationClient.CallAccessService(s => s.RemoveUserGroupBaseFromGroup(ug, Content));
|
---|
| 85 | }
|
---|
| 86 | });
|
---|
| 87 |
|
---|
| 88 | AccessAdministrationClient.Instance.ExecuteActionAsync(storeAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
|
---|
| 89 | AccessAdministrationClient.Instance.ExecuteActionAsync(deleteAction, PluginInfrastructure.ErrorHandling.ShowErrorDialog);
|
---|
| 90 | }
|
---|
[8141] | 91 |
|
---|
| 92 | private void Content_Refreshing(object sender, EventArgs e) {
|
---|
| 93 | storeButton.Enabled = false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | private void refreshableLightweightUserView_StorableStateChanged(object sender, EventArgs e) {
|
---|
| 97 | storeButton.Enabled = true;
|
---|
| 98 | }
|
---|
[8042] | 99 | }
|
---|
| 100 | }
|
---|