Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1648

  • fixed user query ws methods
  • improved user view
File size: 3.3 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.Windows.Forms;
25using HeuristicLab.Core;
26using HeuristicLab.MainForm;
27using HeuristicLab.MainForm.WindowsForms;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Clients.Access.Views {
31  [View("RefreshableLightweightUser View")]
32  [Content(typeof(AccessClient), false)]
33  public partial class RefreshableLightweightUserView : RefreshableView {
34    public RefreshableLightweightUserView() {
35      InitializeComponent();
36    }
37
38    //set an action like a webservice call to retrieve the users which should be marked as checked           
39    public Func<List<Guid>> FetchSelectedUsers { get; set; }
40    private List<Guid> selectedUsers;
41
42    protected override void RefreshData() {
43      Action completeRefreshAction = new Action(delegate {
44        selectedUsers = FetchSelectedUsers();
45        Content.Refresh();
46      });
47
48      Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
49    }
50
51    protected override void Content_Refreshing(object sender, EventArgs e) {
52      base.Content_Refreshing(sender, e);
53      lightweightUserView.Content = null;
54    }
55
56    protected override void Content_Refreshed(object sender, EventArgs e) {
57      base.Content_Refreshed(sender, e);
58
59      var checkedUsers = new CheckedItemList<LightweightUser>(Content.Users);
60      checkedUsers.ForEach(u => {
61        int idx = checkedUsers.IndexOf(u);
62        checkedUsers.SetItemCheckedState(idx, selectedUsers.Contains(u.Id));
63      });
64      lightweightUserView.Content = checkedUsers.AsReadOnly();
65    }
66
67    protected override void SetEnabledStateOfControls() {
68      base.SetEnabledStateOfControls();
69      refreshButton.Enabled = FetchSelectedUsers != null;
70    }
71
72    public ICheckedItemList<LightweightUser> GetCheckedUsers() {
73      return (lightweightUserView.Content == null) ? null : lightweightUserView.Content;
74    }
75
76    public event EventHandler SelectedUsersChanged;
77    protected virtual void OnSelectedUsersChanged() {
78      if (InvokeRequired)
79        Invoke((MethodInvoker)OnSelectedUsersChanged);
80      else {
81        EventHandler handler = SelectedUsersChanged;
82        if (handler != null)
83          handler(this, EventArgs.Empty);
84      }
85    }
86
87    private void lightweightUserView_SelectedUsersChanged(object sender, EventArgs e) {
88      OnSelectedUsersChanged();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.