Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2522_RefactorPluginInfrastructure/HeuristicLab.Clients.Access.Views/3.3/UserViews/LightweightUserGroupSelectionView.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.9 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 System.Windows.Forms;
24using HeuristicLab.Core;
25using HeuristicLab.MainForm;
26using HeuristicLab.PluginInfrastructure;
27
28namespace HeuristicLab.Clients.Access.Views {
29  public sealed partial class LightweightUserGroupSelectionView : UserControl {
30    public LightweightUserGroupSelectionView() {
31      InitializeComponent();
32    }
33
34    public ItemList<UserGroupBase> GetSelectedItems() {
35      ItemList<UserGroupBase> result = new ItemList<UserGroupBase>();
36
37      foreach (var item in itemsListView.SelectedItems) {
38        UserGroupBase ugb = ((ListViewItem)item).Tag as UserGroupBase;
39        if (ugb != null) {
40          result.Add(ugb);
41        }
42      }
43      return result;
44    }
45
46    private void LightweightUserGroupSelectionView_Load(object sender, EventArgs e) {
47      if (!this.DesignMode && AccessClient.Instance.UsersAndGroups == null) {
48        AccessClient.Instance.Refreshing += new EventHandler(Instance_Refreshing);
49        AccessClient.Instance.Refreshed += new EventHandler(Instance_Refreshed);
50        AccessClient.Instance.RefreshAsync(new Action<Exception>((Exception ex) => MainFormManager.MainForm.ShowError("Refresh failed.", ex)));
51        AccessClient.Instance.Refreshing -= new EventHandler(Instance_Refreshing);
52        AccessClient.Instance.Refreshed -= new EventHandler(Instance_Refreshed);
53      }
54
55      if (AccessClient.Instance.UsersAndGroups != null) {
56        AccessClient.Instance.UsersAndGroups.ForEach(x => AddListViewItem(CreateListViewItem(x)));
57
58        foreach (ColumnHeader c in this.itemsListView.Columns) {
59          c.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
60        }
61      }
62    }
63
64    void Instance_Refreshed(object sender, EventArgs e) {
65      if (AccessClient.Instance.UsersAndGroups != null)
66        this.itemsListView.Enabled = true;
67    }
68
69    void Instance_Refreshing(object sender, EventArgs e) {
70      this.itemsListView.Enabled = false;
71    }
72
73    private ListViewItem CreateListViewItem(UserGroupBase item) {
74      ListViewItem listViewItem = new ListViewItem();
75
76      listViewItem.Text = item.ToString();
77      itemsListView.SmallImageList.Images.Add(item.ItemImage);
78      listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
79      listViewItem.Tag = item;
80      if (item is UserGroup) {
81        listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, item.ToString()));
82        listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, string.Empty));
83        listViewItem.Group = itemsListView.Groups[0];
84      } else if (item is LightweightUser) {
85        var lu = item as LightweightUser;
86        listViewItem.SubItems.Insert(0, new ListViewItem.ListViewSubItem(listViewItem, lu.UserName));
87        listViewItem.SubItems.Insert(1, new ListViewItem.ListViewSubItem(listViewItem, lu.FullName));
88        listViewItem.Group = itemsListView.Groups[1];
89      }
90
91      return listViewItem;
92    }
93
94    private void AddListViewItem(ListViewItem listViewItem) {
95      itemsListView.Items.Add(listViewItem);
96    }
97  }
98}
Note: See TracBrowser for help on using the repository browser.