Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Clients.Access.Views/3.3/UserViews/LightweightUserGroupSelectionView.cs @ 10653

Last change on this file since 10653 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

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