[8042] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8042] | 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
|
---|
| 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 | SetEnabledStateOfControls();
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | private List<Guid> selectedUsers;
|
---|
| 52 |
|
---|
| 53 | protected override void OnContentChanged() {
|
---|
| 54 | base.OnContentChanged();
|
---|
| 55 |
|
---|
| 56 | selectedUsers = null;
|
---|
| 57 | lightweightUserView.Content = null;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void RefreshData() {
|
---|
| 61 | Action completeRefreshAction = new Action(delegate {
|
---|
| 62 | selectedUsers = FetchSelectedUsers();
|
---|
| 63 | Content.Refresh();
|
---|
| 64 | });
|
---|
| 65 |
|
---|
| 66 | Content.ExecuteActionAsync(completeRefreshAction, new Action<Exception>((Exception ex) => ErrorHandling.ShowErrorDialog(this, "Refresh failed.", ex)));
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void Content_Refreshing(object sender, EventArgs e) {
|
---|
| 70 | base.Content_Refreshing(sender, e);
|
---|
| 71 | lightweightUserView.Content = null;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | protected override void Content_Refreshed(object sender, EventArgs e) {
|
---|
| 75 | base.Content_Refreshed(sender, e);
|
---|
| 76 |
|
---|
[9063] | 77 | if (Content.UsersAndGroups != null) {
|
---|
| 78 | lightweightUserView.Content = new ItemList<UserGroupBase>(Content.UsersAndGroups.Where(x => selectedUsers.Contains(x.Id)));
|
---|
| 79 | if (lightweightUserView.Content != null) OnStorableStateChanged();
|
---|
| 80 | }
|
---|
[8042] | 81 | }
|
---|
| 82 |
|
---|
| 83 | protected override void SetEnabledStateOfControls() {
|
---|
| 84 | base.SetEnabledStateOfControls();
|
---|
| 85 | refreshButton.Enabled = FetchSelectedUsers != null && Content != null;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | public IItemList<UserGroupBase> GetDeletedUsers() {
|
---|
| 89 | if (lightweightUserView.Content == null) {
|
---|
| 90 | return null;
|
---|
| 91 | } else {
|
---|
| 92 | var deletedIds = selectedUsers.Where(x => lightweightUserView.Content.Count(y => y.Id == x) == 0);
|
---|
| 93 | List<UserGroupBase> deletedUGs = Content.UsersAndGroups.Where(x => deletedIds.Contains(x.Id)).ToList();
|
---|
| 94 | return new ItemList<UserGroupBase>(deletedUGs);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | public IItemList<UserGroupBase> GetCheckedUsers() {
|
---|
| 99 | return (lightweightUserView.Content == null) ? null : lightweightUserView.Content;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | public IItemList<UserGroupBase> GetAddedUsers() {
|
---|
| 103 | return (lightweightUserView.Content == null) ? null : new ItemList<UserGroupBase>(lightweightUserView.Content.Where(x => !selectedUsers.Contains(x.Id)));
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | public event EventHandler SelectedUsersChanged;
|
---|
| 107 | protected virtual void OnSelectedUsersChanged() {
|
---|
| 108 | if (InvokeRequired)
|
---|
| 109 | Invoke((MethodInvoker)OnSelectedUsersChanged);
|
---|
| 110 | else {
|
---|
| 111 | EventHandler handler = SelectedUsersChanged;
|
---|
| 112 | if (handler != null)
|
---|
| 113 | handler(this, EventArgs.Empty);
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[8141] | 117 | public event EventHandler StorableStateChanged;
|
---|
| 118 | protected virtual void OnStorableStateChanged() {
|
---|
| 119 | if (InvokeRequired)
|
---|
| 120 | Invoke((MethodInvoker)OnStorableStateChanged);
|
---|
| 121 | else {
|
---|
| 122 | EventHandler handler = StorableStateChanged;
|
---|
| 123 | if (handler != null)
|
---|
| 124 | handler(this, EventArgs.Empty);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[8042] | 128 | private void lightweightUserView_SelectedUsersChanged(object sender, EventArgs e) {
|
---|
| 129 | OnSelectedUsersChanged();
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | }
|
---|