[2796] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 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;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Core.Views {
|
---|
[2917] | 31 | [View("ParameterCollection View")]
|
---|
[2655] | 32 | [Content(typeof(ParameterCollection), true)]
|
---|
[3393] | 33 | [Content(typeof(IKeyedItemCollection<string, IParameter>), false)]
|
---|
[2655] | 34 | public partial class ParameterCollectionView : NamedItemCollectionView<IParameter> {
|
---|
[2676] | 35 | protected CreateParameterDialog createParameterDialog;
|
---|
[5783] | 36 |
|
---|
[2655] | 37 | public ParameterCollectionView() {
|
---|
| 38 | InitializeComponent();
|
---|
[2924] | 39 | itemsGroupBox.Text = "Parameters";
|
---|
[2655] | 40 | }
|
---|
| 41 |
|
---|
[5237] | 42 | protected override void Dispose(bool disposing) {
|
---|
| 43 | if (disposing) {
|
---|
| 44 | if (createParameterDialog != null) createParameterDialog.Dispose();
|
---|
| 45 | if (components != null) components.Dispose();
|
---|
| 46 | }
|
---|
| 47 | base.Dispose(disposing);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[5768] | 50 | protected override void DeregisterItemEvents(IParameter item) {
|
---|
| 51 | item.HiddenChanged -= new EventHandler(Item_HiddenChanged);
|
---|
| 52 | base.DeregisterItemEvents(item);
|
---|
| 53 | }
|
---|
| 54 | protected override void RegisterItemEvents(IParameter item) {
|
---|
| 55 | base.RegisterItemEvents(item);
|
---|
| 56 | item.HiddenChanged += new EventHandler(Item_HiddenChanged);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[5783] | 59 | protected override void OnContentChanged() {
|
---|
| 60 | base.OnContentChanged();
|
---|
| 61 | if ((Content == null) || !Content.Any(x => x.Hidden))
|
---|
| 62 | showHiddenParametersCheckBox.Checked = false;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | protected override void SetEnabledStateOfControls() {
|
---|
| 66 | base.SetEnabledStateOfControls();
|
---|
| 67 | showHiddenParametersCheckBox.Enabled = (Content != null) && Content.Any(x => x.Hidden);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[2655] | 70 | protected override IParameter CreateItem() {
|
---|
| 71 | if (createParameterDialog == null) createParameterDialog = new CreateParameterDialog();
|
---|
| 72 |
|
---|
| 73 | if (createParameterDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 74 | IParameter param = createParameterDialog.Parameter;
|
---|
[3407] | 75 | if ((param != null) && Content.ContainsKey(param.Name))
|
---|
[2655] | 76 | param = (IParameter)Activator.CreateInstance(param.GetType(), GetUniqueName(param.Name), param.Description);
|
---|
| 77 | return param;
|
---|
[3407] | 78 | }
|
---|
| 79 | return null;
|
---|
[2655] | 80 | }
|
---|
[5768] | 81 |
|
---|
[5783] | 82 | protected override ListViewItem CreateListViewItem(IParameter item) {
|
---|
| 83 | ListViewItem listViewItem = base.CreateListViewItem(item);
|
---|
| 84 | if ((item != null) && item.Hidden) {
|
---|
[5768] | 85 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 86 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 87 | }
|
---|
[5783] | 88 | return listViewItem;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | protected override void AddListViewItem(ListViewItem listViewItem) {
|
---|
[5768] | 92 | base.AddListViewItem(listViewItem);
|
---|
[5783] | 93 | IParameter parameter = listViewItem.Tag as IParameter;
|
---|
| 94 | if ((parameter != null) && parameter.Hidden && !showHiddenParametersCheckBox.Checked) {
|
---|
| 95 | itemsListView.Items.Remove(listViewItem);
|
---|
| 96 | RebuildImageList();
|
---|
| 97 | }
|
---|
[5768] | 98 | }
|
---|
| 99 |
|
---|
| 100 | protected virtual void UpdateParameterVisibility(IParameter parameter) {
|
---|
[5783] | 101 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 102 | if (parameter.Hidden) {
|
---|
| 103 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 104 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 105 | if (!showHiddenParametersCheckBox.Checked)
|
---|
| 106 | itemsListView.Items.Remove(listViewItem);
|
---|
[5768] | 107 | } else {
|
---|
[5783] | 108 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
|
---|
| 109 | listViewItem.ForeColor = itemsListView.ForeColor;
|
---|
| 110 | if (!showHiddenParametersCheckBox.Checked)
|
---|
| 111 | itemsListView.Items.Add(listViewItem);
|
---|
[5768] | 112 | }
|
---|
| 113 | }
|
---|
[5783] | 114 | RebuildImageList();
|
---|
[5768] | 115 | AdjustListViewColumnSizes();
|
---|
[5783] | 116 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 117 | showHiddenParametersCheckBox.Enabled = (Content != null) && Content.Any(x => x.Hidden);
|
---|
[5768] | 118 | }
|
---|
| 119 |
|
---|
| 120 | #region Control Events
|
---|
| 121 | protected virtual void showHiddenParametersCheckBox_CheckedChanged(object sender, System.EventArgs e) {
|
---|
[5783] | 122 | if (Content != null) {
|
---|
| 123 | foreach (IParameter parameter in itemListViewItemMapping.Keys.Where(x => x.Hidden).OrderBy(x => x.ToString())) {
|
---|
| 124 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 125 | if (showHiddenParametersCheckBox.Checked)
|
---|
| 126 | itemsListView.Items.Add(listViewItem);
|
---|
| 127 | else
|
---|
| 128 | itemsListView.Items.Remove(listViewItem);
|
---|
| 129 | }
|
---|
[5768] | 130 | }
|
---|
| 131 | RebuildImageList();
|
---|
[5783] | 132 | AdjustListViewColumnSizes();
|
---|
[5768] | 133 | }
|
---|
| 134 | }
|
---|
| 135 | protected virtual void itemsListViewContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
[5783] | 136 | showHideParametersToolStripMenuItem.Text = "Show/Hide Parameters";
|
---|
| 137 | showHideParametersToolStripMenuItem.Enabled = false;
|
---|
| 138 | if ((itemsListView.SelectedItems.Count > 0) && !ReadOnly && !Locked) {
|
---|
[5768] | 139 | List<IParameter> parameters = new List<IParameter>();
|
---|
| 140 | foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
|
---|
| 141 | IParameter parameter = listViewItem.Tag as IParameter;
|
---|
| 142 | if (parameter != null) parameters.Add(parameter);
|
---|
| 143 | }
|
---|
| 144 | showHideParametersToolStripMenuItem.Enabled = (parameters.Count > 0) && (parameters.All(x => x.Hidden == parameters[0].Hidden));
|
---|
| 145 | if (parameters.Count == 1) showHideParametersToolStripMenuItem.Text = parameters[0].Hidden ? "Show Parameter" : "Hide Parameter";
|
---|
| 146 | else showHideParametersToolStripMenuItem.Text = parameters[0].Hidden ? "Show Parameters" : "Hide Parameters";
|
---|
| 147 | showHideParametersToolStripMenuItem.Tag = parameters;
|
---|
| 148 | }
|
---|
| 149 | }
|
---|
| 150 | protected virtual void showHideParametersToolStripMenuItem_Click(object sender, System.EventArgs e) {
|
---|
| 151 | foreach (IParameter parameter in (IEnumerable<IParameter>)showHideParametersToolStripMenuItem.Tag)
|
---|
| 152 | parameter.Hidden = !parameter.Hidden;
|
---|
| 153 | }
|
---|
| 154 | #endregion
|
---|
| 155 |
|
---|
[5783] | 156 | #region Content Events
|
---|
| 157 | protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 158 | if (InvokeRequired)
|
---|
| 159 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_ItemsAdded), sender, e);
|
---|
| 160 | else {
|
---|
| 161 | base.Content_ItemsAdded(sender, e);
|
---|
| 162 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
| 165 | protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 166 | if (InvokeRequired)
|
---|
| 167 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_ItemsRemoved), sender, e);
|
---|
| 168 | else {
|
---|
| 169 | base.Content_ItemsRemoved(sender, e);
|
---|
| 170 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 171 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 | protected override void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
| 175 | if (InvokeRequired)
|
---|
| 176 | Invoke(new CollectionItemsChangedEventHandler<IParameter>(Content_CollectionReset), sender, e);
|
---|
| 177 | else {
|
---|
| 178 | base.Content_CollectionReset(sender, e);
|
---|
| 179 | if (!Content.Any(x => x.Hidden)) showHiddenParametersCheckBox.Checked = false;
|
---|
| 180 | showHiddenParametersCheckBox.Enabled = Content.Any(x => x.Hidden);
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | #endregion
|
---|
| 184 |
|
---|
[5768] | 185 | #region Item Events
|
---|
| 186 | protected virtual void Item_HiddenChanged(object sender, EventArgs e) {
|
---|
| 187 | if (InvokeRequired)
|
---|
| 188 | Invoke(new EventHandler(Item_HiddenChanged), sender, e);
|
---|
| 189 | else
|
---|
| 190 | UpdateParameterVisibility((IParameter)sender);
|
---|
| 191 | }
|
---|
| 192 | #endregion
|
---|
[5783] | 193 |
|
---|
| 194 | #region Helpers
|
---|
| 195 | protected override void RebuildImageList() {
|
---|
| 196 | base.RebuildImageList();
|
---|
| 197 | if (!showHiddenParametersCheckBox.Checked) {
|
---|
| 198 | // update image of hidden list view items
|
---|
| 199 | foreach (IParameter parameter in itemListViewItemMapping.Keys.Where(x => x.Hidden)) {
|
---|
| 200 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(parameter)) {
|
---|
| 201 | itemsListView.SmallImageList.Images.Add(parameter.ItemImage);
|
---|
| 202 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 203 | }
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 | #endregion
|
---|
[2655] | 208 | }
|
---|
| 209 | }
|
---|