Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7426 was 7426, checked in by ascheibe, 12 years ago

#1648 worked on user and group selection views

File size: 3.1 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    public Func<List<Guid>> FetchSelectedUsers { get; set; }
41    private List<Guid> selectedUsers;
42
43    protected override void RefreshData() {
44      Action completeRefreshAction = new Action(delegate {
45        selectedUsers = FetchSelectedUsers();
46        Content.Refresh();
47      });
48
49      Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
50    }
51
52    protected override void Content_Refreshing(object sender, EventArgs e) {
53      base.Content_Refreshing(sender, e);
54      lightweightUserView.Content = null;
55    }
56
57    protected override void Content_Refreshed(object sender, EventArgs e) {
58      base.Content_Refreshed(sender, e);
59
60      lightweightUserView.Content = new ItemList<UserGroupBase>(Content.UsersAndGroups.Where(x => selectedUsers.Contains(x.Id)));
61    }
62
63    protected override void SetEnabledStateOfControls() {
64      base.SetEnabledStateOfControls();
65      refreshButton.Enabled = FetchSelectedUsers != null;
66    }
67
68    public IItemList<UserGroupBase> GetCheckedUsers() {
69      return (lightweightUserView.Content == null) ? null : lightweightUserView.Content;
70    }
71
72    public event EventHandler SelectedUsersChanged;
73    protected virtual void OnSelectedUsersChanged() {
74      if (InvokeRequired)
75        Invoke((MethodInvoker)OnSelectedUsersChanged);
76      else {
77        EventHandler handler = SelectedUsersChanged;
78        if (handler != null)
79          handler(this, EventArgs.Empty);
80      }
81    }
82
83    private void lightweightUserView_SelectedUsersChanged(object sender, EventArgs e) {
84      OnSelectedUsersChanged();
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.