Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2522_RefactorPluginInfrastructure/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserGroupListView.cs @ 17869

Last change on this file since 17869 was 15973, checked in by gkronber, 6 years ago

#2522: merged trunk changes from r13402:15972 to branch resolving conflicts where necessary

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 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 HeuristicLab.MainForm;
24
25namespace HeuristicLab.Clients.Access.Administration {
26  public partial class RefreshableUserGroupListView : RefreshableView {
27    public RefreshableUserGroupListView() {
28      InitializeComponent();
29    }
30
31    protected override void RefreshData() {
32      Content.RefreshUserGroupsAsync((ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
33    }
34
35    protected override void Content_Refreshing(object sender, EventArgs e) {
36      if (InvokeRequired) {
37        Invoke(new EventHandler(Content_Refreshing), sender, e);
38      } else {
39        base.Content_Refreshing(sender, e);
40        userGroupListView.Enabled = false;
41        storeButton.Enabled = false;
42        if (Content.Groups != null) {
43          Content.Groups.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
44        }
45      }
46    }
47
48    protected override void Content_Refreshed(object sender, EventArgs e) {
49      if (InvokeRequired) {
50        Invoke(new EventHandler(Content_Refreshed), sender, e);
51      } else {
52        base.Content_Refreshed(sender, e);
53        userGroupListView.Enabled = true;
54        userGroupListView.Content = Content.Groups;
55        if (Content.Groups != null) {
56          storeButton.Enabled = true;
57          Content.Groups.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
58        }
59      }
60    }
61
62    void Groups_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<UserGroup>> e) {
63      foreach (var u in e.Items) {
64        Content.DeleteUserGroupAsync(u.Value, (ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
65      }
66    }
67
68    protected override void DeregisterContentEvents() {
69      if (Content.Groups != null) {
70        Content.Groups.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<UserGroup>>(Groups_ItemsRemoved);
71      }
72      base.DeregisterContentEvents();
73    }
74
75    private void storeButton_Click(object sender, EventArgs e) {
76      Content.StoreUserGroupsAsync((ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.