[7555] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 29 | using HeuristicLab.PluginInfrastructure;
|
---|
| 30 |
|
---|
| 31 | namespace 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
|
---|
[7639] | 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 |
|
---|
[7555] | 50 | private List<Guid> selectedUsers;
|
---|
| 51 |
|
---|
[7639] | 52 | protected override void OnContentChanged() {
|
---|
| 53 | base.OnContentChanged();
|
---|
| 54 |
|
---|
| 55 | selectedUsers = null;
|
---|
| 56 | lightweightUserView.Content = null;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[7555] | 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 |
|
---|
[7639] | 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 |
|
---|
[7555] | 94 | public IItemList<UserGroupBase> GetCheckedUsers() {
|
---|
[7640] | 95 | return (lightweightUserView.Content == null) ? null : lightweightUserView.Content;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public IItemList<UserGroupBase> GetAddedUsers() {
|
---|
[7639] | 99 | return (lightweightUserView.Content == null) ? null : new ItemList<UserGroupBase>(lightweightUserView.Content.Where(x => !selectedUsers.Contains(x.Id)));
|
---|
[7555] | 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 | }
|
---|