Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ClientUserManagement/HeuristicLab.Clients.Access.Views/3.3/UserViews/RefreshableLightweightUserView.cs @ 7846

Last change on this file since 7846 was 7640, checked in by ascheibe, 13 years ago

#1648 fixed a small okb compatibility problem

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Core;
27using HeuristicLab.MainForm;
28using HeuristicLab.MainForm.WindowsForms;
29using HeuristicLab.PluginInfrastructure;
30
31namespace HeuristicLab.Clients.Access.Views {
32  [View("RefreshableLightweightUser View")]
33  [Content(typeof(AccessClient), false)]
34  public partial class RefreshableLightweightUserView : RefreshableView {
35    public RefreshableLightweightUserView() {
36      InitializeComponent();
37    }
38
39    //set an action like a webservice call to retrieve the users which should be marked as checked           
40    private Func<List<Guid>> fetchSelectedUsers;
41    public Func<List<Guid>> FetchSelectedUsers {
42      get { return fetchSelectedUsers; }
43      set {
44        fetchSelectedUsers = value;
45        selectedUsers = null;
46        lightweightUserView.Content = null;
47      }
48    }
49
50    private List<Guid> selectedUsers;
51
52    protected override void OnContentChanged() {
53      base.OnContentChanged();
54
55      selectedUsers = null;
56      lightweightUserView.Content = null;
57    }
58
59    protected override void RefreshData() {
60      Action completeRefreshAction = new Action(delegate {
61        selectedUsers = FetchSelectedUsers();
62        Content.Refresh();
63      });
64
65      Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
66    }
67
68    protected override void Content_Refreshing(object sender, EventArgs e) {
69      base.Content_Refreshing(sender, e);
70      lightweightUserView.Content = null;
71    }
72
73    protected override void Content_Refreshed(object sender, EventArgs e) {
74      base.Content_Refreshed(sender, e);
75
76      lightweightUserView.Content = new ItemList<UserGroupBase>(Content.UsersAndGroups.Where(x => selectedUsers.Contains(x.Id)));
77    }
78
79    protected override void SetEnabledStateOfControls() {
80      base.SetEnabledStateOfControls();
81      refreshButton.Enabled = FetchSelectedUsers != null;
82    }
83
84    public IItemList<UserGroupBase> GetDeletedUsers() {
85      if (lightweightUserView.Content == null) {
86        return null;
87      } else {
88        var deletedIds = selectedUsers.Where(x => lightweightUserView.Content.Count(y => y.Id == x) == 0);
89        List<UserGroupBase> deletedUGs = Content.UsersAndGroups.Where(x => deletedIds.Contains(x.Id)).ToList();
90        return new ItemList<UserGroupBase>(deletedUGs);
91      }
92    }
93
94    public IItemList<UserGroupBase> GetCheckedUsers() {
95      return (lightweightUserView.Content == null) ? null : lightweightUserView.Content;
96    }
97
98    public IItemList<UserGroupBase> GetAddedUsers() {
99      return (lightweightUserView.Content == null) ? null : new ItemList<UserGroupBase>(lightweightUserView.Content.Where(x => !selectedUsers.Contains(x.Id)));
100    }
101
102    public event EventHandler SelectedUsersChanged;
103    protected virtual void OnSelectedUsersChanged() {
104      if (InvokeRequired)
105        Invoke((MethodInvoker)OnSelectedUsersChanged);
106      else {
107        EventHandler handler = SelectedUsersChanged;
108        if (handler != null)
109          handler(this, EventArgs.Empty);
110      }
111    }
112
113    private void lightweightUserView_SelectedUsersChanged(object sender, EventArgs e) {
114      OnSelectedUsersChanged();
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.