Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RefactorPluginInfrastructure-2522/HeuristicLab.Clients.Access.Administration/3.3/Views/RefreshableUserListView.cs @ 13401

Last change on this file since 13401 was 13338, checked in by gkronber, 9 years ago

#2522:

  • moved UI components out of HeuristicLab.PluginInfrastructure -> HeuristicLab.PluginInfrastructure.UI
  • moved ErrorDialog to HeuristicLab.MainForm.WindowsForms
  • moved ErrorHandling (for building an error message string) to HeuristicLab.Common
  • Changed exception handlers in Views to use MainForm.ShowError()
  • Changed usages for ErrorDialog in non-UI components to throw exceptions instead.
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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 RefreshableUserListView : RefreshableView {
27    public RefreshableUserListView() {
28      InitializeComponent();
29    }
30
31    protected override void RefreshData() {
32      Content.RefreshUsersAsync((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        userListView.Enabled = false;
41        storeButton.Enabled = false;
42        if (Content.Users != null) {
43          Content.Users.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_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        userListView.Enabled = true;
54        userListView.Content = Content.Users;
55        if (Content.Users != null) {
56          storeButton.Enabled = true;
57          Content.Users.ItemsRemoved += new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_ItemsRemoved);
58        }
59      }
60    }
61
62    protected override void DeregisterContentEvents() {
63      if (Content.Users != null) {
64        Content.Users.ItemsRemoved -= new Collections.CollectionItemsChangedEventHandler<Collections.IndexedItem<User>>(Users_ItemsRemoved);
65      }
66      base.DeregisterContentEvents();
67    }
68
69    void Users_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<Collections.IndexedItem<User>> e) {
70      foreach (var u in e.Items) {
71        if (u.Value.Id != Guid.Empty) {
72          Content.DeleteUserAsync(u.Value, (ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
73        }
74      }
75    }
76
77    private void storeButton_Click(object sender, EventArgs e) {
78      Content.StoreUsersAsync((ex) => MainFormManager.MainForm.ShowError(ex.Message, ex));
79    }
80  }
81}
Note: See TracBrowser for help on using the repository browser.