[2796] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12012] | 3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2796] | 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;
|
---|
[5768] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
[2655] | 26 | using System.Windows.Forms;
|
---|
[5783] | 27 | using HeuristicLab.Collections;
|
---|
[2655] | 28 | using HeuristicLab.MainForm;
|
---|
[13014] | 29 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[2655] | 30 |
|
---|
| 31 | namespace HeuristicLab.Core.Views {
|
---|
[2917] | 32 | [View("ParameterCollection View")]
|
---|
[2655] | 33 | [Content(typeof(ParameterCollection), true)]
|
---|
[3393] | 34 | [Content(typeof(IKeyedItemCollection<string, IParameter>), false)]
|
---|
[2655] | 35 | public partial class ParameterCollectionView : NamedItemCollectionView<IParameter> {
|
---|
[2676] | 36 | protected CreateParameterDialog createParameterDialog;
|
---|
[5783] | 37 |
|
---|
[5901] | 38 | protected bool allowEditingOfHiddenParameters;
|
---|
| 39 | public virtual bool AllowEditingOfHiddenParameters {
|
---|
| 40 | get { return allowEditingOfHiddenParameters; }
|
---|
| 41 | set {
|
---|
| 42 | if (value != allowEditingOfHiddenParameters) {
|
---|
| 43 | allowEditingOfHiddenParameters = value;
|
---|
| 44 | SetEnabledStateOfControls();
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[2655] | 49 | public ParameterCollectionView() {
|
---|
| 50 | InitializeComponent();
|
---|
[2924] | 51 | itemsGroupBox.Text = "Parameters";
|
---|
[5901] | 52 | allowEditingOfHiddenParameters = true;
|
---|
[2655] | 53 | }
|
---|
| 54 |
|
---|
[5237] | 55 | protected override void Dispose(bool disposing) {
|
---|
| 56 | if (disposing) {
|
---|
| 57 | if (createParameterDialog != null) createParameterDialog.Dispose();
|
---|
| 58 | if (components != null) components.Dispose();
|
---|
| 59 | }
|
---|
| 60 | base.Dispose(disposing);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[5768] | 63 | protected override void DeregisterItemEvents(IParameter item) {
|
---|
| 64 | item.HiddenChanged -= new EventHandler(Item_HiddenChanged);
|
---|
| 65 | base.DeregisterItemEvents(item);
|
---|
| 66 | }
|
---|
| 67 | protected override void RegisterItemEvents(IParameter item) {
|
---|
| 68 | base.RegisterItemEvents(item);
|
---|
| 69 | item.HiddenChanged += new EventHandler(Item_HiddenChanged);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[5783] | 72 | protected override void OnContentChanged() {
|
---|
| 73 | base.OnContentChanged();
|
---|
| 74 | if ((Content == null) || !Content.Any(x => x.Hidden))
|
---|
| 75 | showHiddenParametersCheckBox.Checked = false;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | protected override void SetEnabledStateOfControls() {
|
---|
| 79 | base.SetEnabledStateOfControls();
|
---|
| 80 | showHiddenParametersCheckBox.Enabled = (Content != null) && Content.Any(x => x.Hidden);
|
---|
[5901] | 81 | viewHost.ReadOnly = ReadOnly || ((viewHost.Content is IParameter) && (((IParameter)viewHost.Content).Hidden) && !AllowEditingOfHiddenParameters);
|
---|
[5783] | 82 | }
|
---|
| 83 |
|
---|
[2655] | 84 | protected override IParameter CreateItem() {
|
---|
| 85 | if (createParameterDialog == null) createParameterDialog = new CreateParameterDialog();
|
---|
| 86 |
|
---|
| 87 | if (createParameterDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 88 | IParameter param = createParameterDialog.Parameter;
|
---|
[3407] | 89 | if ((param != null) && Content.ContainsKey(param.Name))
|
---|
[2655] | 90 | param = (IParameter)Activator.CreateInstance(param.GetType(), GetUniqueName(param.Name), param.Description);
|
---|
| 91 | return param;
|
---|
[3407] | 92 | }
|
---|
| 93 | return null;
|
---|
[2655] | 94 | }
|
---|
[5768] | 95 |
|
---|
[5783] | 96 | protected override ListViewItem CreateListViewItem(IParameter item) {
|
---|
| 97 | ListViewItem listViewItem = base.CreateListViewItem(item);
|
---|
| 98 | if ((item != null) && item.Hidden) {
|
---|
[5768] | 99 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 100 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 101 | }
|
---|
[5783] | 102 | return listViewItem;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | protected override void AddListViewItem(ListViewItem listViewItem) {
|
---|
[5768] | 106 | base.AddListViewItem(listViewItem);
|
---|
[5783] | 107 | IParameter parameter = listViewItem.Tag as IParameter;
|
---|
| 108 | if ((parameter != null) && parameter.Hidden && !showHiddenParametersCheckBox.Checked) {
|
---|
| 109 | itemsListView.Items.Remove(listViewItem);
|
---|
| 110 | RebuildImageList();
|
---|
| 111 | }
|
---|
[5768] | 112 | }
|
---|
| 113 |
|
---|
| 114 | protected virtual void UpdateParameterVisibility(IParameter parameter) {
|
---|
[5783] | 115 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 116 | if (parameter.Hidden) {
|
---|
| 117 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 118 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 119 | if (!showHiddenParametersCheckBox.Checked)
|
---|
| 120 | itemsListView.Items.Remove(listViewItem);
|
---|
[5768] | 121 | } else {
|
---|
[5783] | 122 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
|
---|
| 123 | listViewItem.ForeColor = itemsListView.ForeColor;
|
---|
| 124 | if (!showHiddenParametersCheckBox.Checked)
|
---|
| 125 | itemsListView.Items.Add(listViewItem);
|
---|
[5768] | 126 | }
|
---|
| 127 | }
|
---|
[5783] | 128 | RebuildImageList();
|
---|
[5768] | 129 | AdjustListViewColumnSizes();
|
---|
[5783] | 130 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 131 | showHiddenParametersCheckBox.Enabled = (Content != null) && Content.Any(x => x.Hidden);
|
---|
[5768] | 132 | }
|
---|
| 133 |
|
---|
| 134 | #region Control Events
|
---|
| 135 | protected virtual void showHiddenParametersCheckBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
[5783] | 136 | if (Content != null) {
|
---|
| 137 | foreach (IParameter parameter in itemListViewItemMapping.Keys.Where(x => x.Hidden).OrderBy(x => x.ToString())) {
|
---|
| 138 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 139 | if (showHiddenParametersCheckBox.Checked)
|
---|
| 140 | itemsListView.Items.Add(listViewItem);
|
---|
| 141 | else
|
---|
| 142 | itemsListView.Items.Remove(listViewItem);
|
---|
| 143 | }
|
---|
[5768] | 144 | }
|
---|
| 145 | RebuildImageList();
|
---|
[5783] | 146 | AdjustListViewColumnSizes();
|
---|
[5768] | 147 | }
|
---|
| 148 | }
|
---|
[5901] | 149 | protected override void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 150 | base.itemsListView_SelectedIndexChanged(sender, e);
|
---|
| 151 | SetEnabledStateOfControls();
|
---|
| 152 | }
|
---|
| 153 | protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
| 154 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 155 | IParameter item = itemsListView.SelectedItems[0].Tag as IParameter;
|
---|
| 156 | if (item != null) {
|
---|
[13014] | 157 | Control c = this;
|
---|
| 158 | BreadcrumbViewHost bcvh;
|
---|
| 159 |
|
---|
| 160 | do {
|
---|
| 161 | c = c.Parent;
|
---|
| 162 | bcvh = c as BreadcrumbViewHost;
|
---|
| 163 | } while ((bcvh == null || !bcvh.EnableBreadcrumbs) && c != null);
|
---|
| 164 |
|
---|
| 165 | if (bcvh != null) {
|
---|
| 166 | bcvh.AddBreadcrumbs(bcvh.Content);
|
---|
| 167 | bcvh.AddBreadcrumbs(item);
|
---|
| 168 | bcvh.Content = item;
|
---|
| 169 | bcvh.ReadOnly = ReadOnly || (item.Hidden && !AllowEditingOfHiddenParameters);
|
---|
| 170 | bcvh.Locked = Locked;
|
---|
| 171 | } else {
|
---|
| 172 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
| 173 | if (view != null) {
|
---|
| 174 | view.ReadOnly = ReadOnly || (item.Hidden && !AllowEditingOfHiddenParameters);
|
---|
| 175 | view.Locked = Locked;
|
---|
| 176 | }
|
---|
[5901] | 177 | }
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
[5768] | 181 | protected virtual void itemsListViewContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
[5783] | 182 | showHideParametersToolStripMenuItem.Text = "Show/Hide Parameters";
|
---|
| 183 | showHideParametersToolStripMenuItem.Enabled = false;
|
---|
[5929] | 184 | if (itemsListView.SelectedItems.Count == 0) {
|
---|
| 185 | e.Cancel = true;
|
---|
| 186 | } else if (!ReadOnly && !Locked && AllowEditingOfHiddenParameters) {
|
---|
[5768] | 187 | List<IParameter> parameters = new List<IParameter>();
|
---|
| 188 | foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
|
---|
| 189 | IParameter parameter = listViewItem.Tag as IParameter;
|
---|
| 190 | if (parameter != null) parameters.Add(parameter);
|
---|
| 191 | }
|
---|
[5929] | 192 | showHideParametersToolStripMenuItem.Enabled = parameters.Count > 0;
|
---|
[5768] | 193 | if (parameters.Count == 1) showHideParametersToolStripMenuItem.Text = parameters[0].Hidden ? "Show Parameter" : "Hide Parameter";
|
---|
[5929] | 194 | else if ((parameters.Count > 1) && parameters.All(x => x.Hidden == parameters[0].Hidden)) showHideParametersToolStripMenuItem.Text = parameters[0].Hidden ? "Show Parameters" : "Hide Parameters";
|
---|
[5768] | 195 | showHideParametersToolStripMenuItem.Tag = parameters;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 | protected virtual void showHideParametersToolStripMenuItem_Click(object sender, System.EventArgs e) {
|
---|
| 199 | foreach (IParameter parameter in (IEnumerable<IParameter>)showHideParametersToolStripMenuItem.Tag)
|
---|
| 200 | parameter.Hidden = !parameter.Hidden;
|
---|
| 201 | }
|
---|
[5901] | 202 | protected override void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 203 | base.showDetailsCheckBox_CheckedChanged(sender, e);
|
---|
| 204 | SetEnabledStateOfControls();
|
---|
| 205 | }
|
---|
[5768] | 206 | #endregion
|
---|
| 207 |
|
---|
[5783] | 208 | #region Content Events
|
---|
| 209 | protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 210 | if (InvokeRequired)
|
---|
| 211 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_ItemsAdded), sender, e);
|
---|
| 212 | else {
|
---|
| 213 | base.Content_ItemsAdded(sender, e);
|
---|
| 214 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 215 | }
|
---|
| 216 | }
|
---|
| 217 | protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 218 | if (InvokeRequired)
|
---|
| 219 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_ItemsRemoved), sender, e);
|
---|
| 220 | else {
|
---|
| 221 | base.Content_ItemsRemoved(sender, e);
|
---|
| 222 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 223 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | protected override void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 227 | if (InvokeRequired)
|
---|
| 228 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_CollectionReset), sender, e);
|
---|
| 229 | else {
|
---|
| 230 | base.Content_CollectionReset(sender, e);
|
---|
| 231 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 232 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 | #endregion
|
---|
| 236 |
|
---|
[5768] | 237 | #region Item Events
|
---|
| 238 | protected virtual void Item_HiddenChanged(object sender, EventArgs e) {
|
---|
| 239 | if (InvokeRequired)
|
---|
| 240 | Invoke(new EventHandler(Item_HiddenChanged), sender, e);
|
---|
| 241 | else
|
---|
| 242 | UpdateParameterVisibility((IParameter)sender);
|
---|
| 243 | }
|
---|
| 244 | #endregion
|
---|
[5783] | 245 |
|
---|
| 246 | #region Helpers
|
---|
| 247 | protected override void RebuildImageList() {
|
---|
| 248 | base.RebuildImageList();
|
---|
| 249 | if (!showHiddenParametersCheckBox.Checked) {
|
---|
| 250 | // update image of hidden list view items
|
---|
| 251 | foreach (IParameter parameter in itemListViewItemMapping.Keys.Where(x => x.Hidden)) {
|
---|
| 252 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 253 | itemsListView.SmallImageList.Images.Add(parameter.ItemImage);
|
---|
| 254 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 | #endregion
|
---|
[2655] | 260 | }
|
---|
| 261 | }
|
---|