Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2839_HiveProjectManagement/HeuristicLab.Clients.Access.Views/3.3/UserViews/LightweightUserInformationView.cs @ 17369

Last change on this file since 17369 was 16057, checked in by jkarder, 6 years ago

#2839:

File size: 4.5 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    protected override void SetEnabledStateOfControls() {
68      base.SetEnabledStateOfControls();
69      bool enabled = Content != null && !Locked;
70      //userNameTextBox.ReadOnly = !enabled;
71      fullNameTextBox.ReadOnly = !enabled;
72      emailTextBox.ReadOnly = !enabled;
73      //rolesListView.Enabled = enabled;
74      //groupsListView.Enabled = enabled;
75      changePasswordButton.Enabled = enabled;
76    }
77
78    private void changePasswordButton_Click(object sender, System.EventArgs e) {
79      using (ChangePasswordDialog dialog = new ChangePasswordDialog()) {
80        dialog.ShowDialog(this);
81      }
82    }
83
84    private ListViewItem CreateListViewRoleItem(Role item) {
85      ListViewItem listViewItem = new ListViewItem();
86
87      listViewItem.Text = item.ToString();
88      rolesListView.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 ListViewItem CreateListViewGroupItem(UserGroup item) {
96      ListViewItem listViewItem = new ListViewItem();
97
98      listViewItem.Text = item.ToString();
99      groupsListView.SmallImageList.Images.Add(item.ItemImage);
100      listViewItem.ImageIndex = rolesListView.SmallImageList.Images.Count - 1;
101      listViewItem.Tag = item;
102
103      return listViewItem;
104    }
105
106    private void fullNameTextBox_TextChanged(object sender, System.EventArgs e) {
107      if (UserInformation.Instance.User.FullName != fullNameTextBox.Text) {
108        UserInformation.Instance.User.FullName = fullNameTextBox.Text;
109        OnUserInformationChanged();
110      }
111    }
112
113    private void emailTextBox_TextChanged(object sender, System.EventArgs e) {
114      if (UserInformation.Instance.User.EMail != emailTextBox.Text) {
115        UserInformation.Instance.User.EMail = emailTextBox.Text;
116        OnUserInformationChanged();
117      }
118    }
119
120    #region Events
121    public event EventHandler UserInformationChanged;
122    private void OnUserInformationChanged() {
123      EventHandler handler = UserInformationChanged;
124      if (handler != null) handler(this, EventArgs.Empty);
125    }
126    #endregion
127  }
128}
Note: See TracBrowser for help on using the repository browser.