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