Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2645_ContextAlgorithms/HeuristicLab.Clients.Access.Views/3.3/UserViews/LightweightUserInformationView.cs @ 17511

Last change on this file since 17511 was 15583, checked in by swagner, 7 years ago

#2640: Updated year of copyrights in license headers

File size: 4.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 System.Windows.Forms;
24using HeuristicLab.MainForm;
25using HeuristicLab.MainForm.WindowsForms;
26
27namespace HeuristicLab.Clients.Access.Views {
28  [View("RefreshableLightweightUserInformation View")]
29  [Content(typeof(LightweightUser), true)]
30  public partial class LightweightUserInformationView : AsynchronousContentView {
31    public new LightweightUser Content {
32      get { return (LightweightUser)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public LightweightUserInformationView() {
37      InitializeComponent();
38    }
39
40    protected override void OnContentChanged() {
41      base.OnContentChanged();
42      rolesListView.Items.Clear();
43      groupsListView.Items.Clear();
44      rolesListView.SmallImageList.Images.Clear();
45      groupsListView.SmallImageList.Images.Clear();
46
47      if (Content == null) {
48        userNameTextBox.Clear();
49        fullNameTextBox.Clear();
50        emailTextBox.Clear();
51      } else {
52        userNameTextBox.Text = Content.UserName;
53        fullNameTextBox.Text = Content.FullName;
54        emailTextBox.Text = Content.EMail;
55
56        foreach (Role r in Content.Roles)
57          rolesListView.Items.Add(CreateListViewRoleItem(r));
58
59        foreach (UserGroup g in Content.Groups)
60          groupsListView.Items.Add(CreateListViewGroupItem(g));
61
62        rolesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
63        groupsListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
64      }
65    }
66
67    private void changePasswordButton_Click(object sender, System.EventArgs e) {
68      using (ChangePasswordDialog dialog = new ChangePasswordDialog()) {
69        dialog.ShowDialog(this);
70      }
71    }
72
73    private ListViewItem CreateListViewRoleItem(Role item) {
74      ListViewItem listViewItem = new ListViewItem();
75
76      listViewItem.Text = item.ToString();
77      rolesListView.SmallImageList.Images.Add(item.ItemImage);
78      listViewItem.ImageIndex = rolesListView.SmallImageList.Images.Count - 1;
79      listViewItem.Tag = item;
80
81      return listViewItem;
82    }
83
84    private ListViewItem CreateListViewGroupItem(UserGroup item) {
85      ListViewItem listViewItem = new ListViewItem();
86
87      listViewItem.Text = item.ToString();
88      groupsListView.SmallImageList.Images.Add(item.ItemImage);
89      listViewItem.ImageIndex = rolesListView.SmallImageList.Images.Count - 1;
90      listViewItem.Tag = item;
91
92      return listViewItem;
93    }
94
95    private void fullNameTextBox_TextChanged(object sender, System.EventArgs e) {
96      if (UserInformation.Instance.User.FullName != fullNameTextBox.Text) {
97        UserInformation.Instance.User.FullName = fullNameTextBox.Text;
98        OnUserInformationChanged();
99      }
100    }
101
102    private void emailTextBox_TextChanged(object sender, System.EventArgs e) {
103      if (UserInformation.Instance.User.EMail != emailTextBox.Text) {
104        UserInformation.Instance.User.EMail = emailTextBox.Text;
105        OnUserInformationChanged();
106      }
107    }
108
109    #region Events
110    public event EventHandler UserInformationChanged;
111    private void OnUserInformationChanged() {
112      EventHandler handler = UserInformationChanged;
113      if (handler != null) handler(this, EventArgs.Empty);
114    }
115    #endregion
116  }
117}
Note: See TracBrowser for help on using the repository browser.