Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1648 switched user controls to a CheckedItemListView

File size: 3.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.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
39    //set an action like a webservice call to retrieve the users which should be marked as checked       
40    //TODO: disable refresh button if not set
41    public Func<List<Guid>> FetchSelectedUsers { get; set; }
42    private List<Guid> selectedUsers;
43
44    protected override void RefreshData() {
45      Action completeRefreshAction = new Action(delegate {
46        selectedUsers = FetchSelectedUsers();
47        Content.Refresh();
48      });
49
50      Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
51    }
52
53    protected override void Content_Refreshing(object sender, EventArgs e) {
54      base.Content_Refreshing(sender, e);
55      lightweightUserView.Content = null;
56    }
57
58    protected override void Content_Refreshed(object sender, EventArgs e) {
59      base.Content_Refreshed(sender, e);
60
61      var checkedUsers = new CheckedItemList<LightweightUser>(Content.Users);
62      checkedUsers.ForEach(u => {
63        int idx = checkedUsers.IndexOf(u);
64        checkedUsers.SetItemCheckedState(idx, selectedUsers.Contains(u.Id));
65      });
66      lightweightUserView.Content = checkedUsers;
67    }
68
69    public ICheckedItemList<LightweightUser> GetCheckedUsers() {
70      if (lightweightUserView.Content == null)
71        return null;
72      else
73        return 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.