Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2522_RefactorPluginInfrastructure/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableRoleListView.cs @ 15973

Last change on this file since 15973 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.0 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 RefreshableRoleListView : RefreshableView {
27    public RefreshableRoleListView() {
28      InitializeComponent();
29    }
30
31    protected override void RefreshData() {
32      Content.RefreshRolesAsync((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        roleListView.Enabled = false;
41        storeButton.Enabled = false;
42        if (Content.Roles != null) {
43          Content.Roles.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Role>>(Roles_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        roleListView.Enabled = true;
54        roleListView.Content = Content.Roles;
55        if (Content.Roles != null) {
56          storeButton.Enabled = true;
57          Content.Roles.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Role>>(Roles_ItemsRemoved);
58        }
59      }
60    }
61
62    protected override void DeregisterContentEvents() {
63      if (Content.Roles != null) {
64        Content.Roles.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<Role>>(Roles_ItemsRemoved);
65      }
66      base.DeregisterContentEvents();
67    }
68
69    void Roles_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<Role>> e) {
70      foreach (var u in e.Items) {
71        Content.DeleteRoleAsync(u.Value, (ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
72      }
73    }
74
75    private void storeButton_Click(object sender, EventArgs e) {
76      Content.StoreRolesAsync((ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.