[3260] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11594] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3260] | 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 |
|
---|
[4068] | 22 | using System;
|
---|
[5744] | 23 | using System.Collections;
|
---|
[4068] | 24 | using System.Collections.Generic;
|
---|
[11594] | 25 | using System.ComponentModel;
|
---|
[4068] | 26 | using System.Drawing;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Windows.Forms;
|
---|
[3274] | 29 | using HeuristicLab.Collections;
|
---|
[6527] | 30 | using HeuristicLab.Common;
|
---|
[3393] | 31 | using HeuristicLab.Core;
|
---|
[3260] | 32 | using HeuristicLab.Core.Views;
|
---|
| 33 | using HeuristicLab.MainForm;
|
---|
[3277] | 34 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[3260] | 35 |
|
---|
| 36 | namespace HeuristicLab.Optimization.Views {
|
---|
| 37 | [View("RunCollection View")]
|
---|
| 38 | [Content(typeof(RunCollection), true)]
|
---|
[3393] | 39 | [Content(typeof(IItemCollection<IRun>), false)]
|
---|
[4883] | 40 | public sealed partial class RunCollectionView : ItemView {
|
---|
[5237] | 41 | private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping;
|
---|
[5744] | 42 | private bool validDragOperation;
|
---|
[4883] | 43 |
|
---|
[3393] | 44 | public new IItemCollection<IRun> Content {
|
---|
| 45 | get { return (IItemCollection<IRun>)base.Content; }
|
---|
[3277] | 46 | set { base.Content = value; }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[3614] | 49 | public RunCollection RunCollection {
|
---|
| 50 | get { return Content as RunCollection; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[3277] | 53 | public ListView ItemsListView {
|
---|
| 54 | get { return itemsListView; }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[3260] | 57 | public RunCollectionView() {
|
---|
| 58 | InitializeComponent();
|
---|
[3505] | 59 | itemsGroupBox.Text = "Runs";
|
---|
[5237] | 60 | itemListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>();
|
---|
[6693] | 61 | runCollectionModifiersListView.Evaluator = EvaluateModifications;
|
---|
[3260] | 62 | }
|
---|
[3277] | 63 |
|
---|
| 64 | protected override void DeregisterContentEvents() {
|
---|
[3280] | 65 | Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 66 | Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 67 | Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[5237] | 68 | foreach (IRun run in itemListViewItemMapping.Keys) {
|
---|
| 69 | DeregisterItemEvents(run);
|
---|
| 70 | }
|
---|
[3277] | 71 | base.DeregisterContentEvents();
|
---|
[3260] | 72 | }
|
---|
[3277] | 73 | protected override void RegisterContentEvents() {
|
---|
| 74 | base.RegisterContentEvents();
|
---|
[3280] | 75 | Content.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 76 | Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 77 | Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[3277] | 78 | }
|
---|
[5237] | 79 | private void DeregisterItemEvents(IRun item) {
|
---|
| 80 | item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
|
---|
| 81 | item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
|
---|
[11594] | 82 | item.PropertyChanged -= Item_PropertyChanged;
|
---|
[3449] | 83 | }
|
---|
[5237] | 84 | private void RegisterItemEvents(IRun item) {
|
---|
| 85 | item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
|
---|
| 86 | item.ToStringChanged += new EventHandler(Item_ToStringChanged);
|
---|
[11594] | 87 | item.PropertyChanged += Item_PropertyChanged;
|
---|
[3449] | 88 | }
|
---|
[3277] | 89 |
|
---|
[3507] | 90 | protected override void OnInitialized(EventArgs e) {
|
---|
| 91 | base.OnInitialized(e);
|
---|
| 92 | var viewTypes = MainFormManager.GetViewTypes(typeof(RunCollection), true);
|
---|
| 93 | foreach (Type viewType in viewTypes.OrderBy(x => ViewAttribute.GetViewName(x))) {
|
---|
| 94 | if ((viewType != typeof(ItemCollectionView<IRun>)) && (viewType != typeof(ViewHost))) {
|
---|
| 95 | ToolStripMenuItem menuItem = new ToolStripMenuItem();
|
---|
| 96 | menuItem.Text = ViewAttribute.GetViewName(viewType);
|
---|
| 97 | menuItem.Tag = viewType;
|
---|
| 98 | menuItem.Click += new EventHandler(menuItem_Click);
|
---|
| 99 | analyzeRunsToolStripDropDownButton.DropDownItems.Add(menuItem);
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[3277] | 104 | protected override void OnContentChanged() {
|
---|
| 105 | base.OnContentChanged();
|
---|
[3775] | 106 |
|
---|
| 107 | string selectedName = null;
|
---|
| 108 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null))
|
---|
| 109 | selectedName = ((IRun)itemsListView.SelectedItems[0].Tag).Name;
|
---|
| 110 |
|
---|
[5237] | 111 | itemsListView.Items.Clear();
|
---|
| 112 | itemListViewItemMapping.Clear();
|
---|
| 113 | RebuildImageList();
|
---|
[3277] | 114 | viewHost.Content = null;
|
---|
| 115 |
|
---|
| 116 | if (Content != null) {
|
---|
[3614] | 117 | if (RunCollection != null) {
|
---|
[3709] | 118 | if (!tabControl.TabPages.Contains(constraintPage))
|
---|
| 119 | tabControl.TabPages.Add(constraintPage);
|
---|
[3614] | 120 | runCollectionConstraintCollectionView.Content = RunCollection.Constraints;
|
---|
| 121 | runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
|
---|
[6693] | 122 | if (!tabControl.TabPages.Contains(modifiersPage))
|
---|
| 123 | tabControl.TabPages.Add(modifiersPage);
|
---|
| 124 | runCollectionModifiersListView.Content = RunCollection.Modifiers;
|
---|
[3614] | 125 | }
|
---|
| 126 | foreach (IRun item in Content) {
|
---|
[3775] | 127 | ListViewItem listViewItem = CreateListViewItem(item);
|
---|
| 128 | AddListViewItem(listViewItem);
|
---|
| 129 | if ((selectedName != null) && item.Name.Equals(selectedName))
|
---|
| 130 | listViewItem.Selected = true;
|
---|
[3614] | 131 | }
|
---|
[4200] | 132 | AdjustListViewColumnSizes();
|
---|
[3709] | 133 | } else {
|
---|
| 134 | runCollectionConstraintCollectionView.Content = null;
|
---|
| 135 | if (tabControl.TabPages.Contains(constraintPage))
|
---|
| 136 | tabControl.TabPages.Remove(constraintPage);
|
---|
[6693] | 137 | if (tabControl.TabPages.Contains(modifiersPage))
|
---|
| 138 | tabControl.TabPages.Remove(modifiersPage);
|
---|
[3277] | 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[3904] | 142 | protected override void SetEnabledStateOfControls() {
|
---|
| 143 | base.SetEnabledStateOfControls();
|
---|
[3350] | 144 | if (Content == null) {
|
---|
[3507] | 145 | analyzeRunsToolStripDropDownButton.Enabled = false;
|
---|
[3614] | 146 | runCollectionConstraintCollectionView.ReadOnly = true;
|
---|
[3350] | 147 | itemsListView.Enabled = false;
|
---|
| 148 | detailsGroupBox.Enabled = false;
|
---|
| 149 | viewHost.Enabled = false;
|
---|
| 150 | removeButton.Enabled = false;
|
---|
[3716] | 151 | clearButton.Enabled = false;
|
---|
[3350] | 152 | } else {
|
---|
[3507] | 153 | analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
|
---|
[3614] | 154 | runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
|
---|
[3350] | 155 | itemsListView.Enabled = true;
|
---|
[4099] | 156 | detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
|
---|
[3435] | 157 | removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && !Content.IsReadOnly && !ReadOnly;
|
---|
[3716] | 158 | clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
|
---|
[3350] | 159 | viewHost.Enabled = true;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[4883] | 163 | private ListViewItem CreateListViewItem(IRun item) {
|
---|
[3277] | 164 | ListViewItem listViewItem = new ListViewItem();
|
---|
[5237] | 165 | if (item == null) {
|
---|
| 166 | listViewItem.Text = "null";
|
---|
[5287] | 167 | itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
|
---|
[5237] | 168 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 169 | } else {
|
---|
| 170 | listViewItem.Text = item.ToString();
|
---|
| 171 | listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
|
---|
| 172 | itemsListView.SmallImageList.Images.Add(item.ItemImage);
|
---|
| 173 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
| 174 | listViewItem.Tag = item;
|
---|
[4200] | 175 |
|
---|
[5237] | 176 | if (item.Visible) {
|
---|
| 177 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
|
---|
| 178 | listViewItem.ForeColor = item.Color;
|
---|
| 179 | } else {
|
---|
| 180 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 181 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 182 | }
|
---|
[4200] | 183 | }
|
---|
[3277] | 184 | return listViewItem;
|
---|
| 185 | }
|
---|
[4883] | 186 | private void AddListViewItem(ListViewItem listViewItem) {
|
---|
[5371] | 187 | if (listViewItem == null) throw new ArgumentNullException();
|
---|
[3277] | 188 | itemsListView.Items.Add(listViewItem);
|
---|
[4883] | 189 | IRun run = listViewItem.Tag as IRun;
|
---|
| 190 | if (run != null) {
|
---|
[5237] | 191 | if (!itemListViewItemMapping.ContainsKey(run)) {
|
---|
| 192 | itemListViewItemMapping.Add(run, new List<ListViewItem>());
|
---|
| 193 | RegisterItemEvents(run);
|
---|
| 194 | }
|
---|
| 195 | itemListViewItemMapping[run].Add(listViewItem);
|
---|
[4883] | 196 | }
|
---|
[3277] | 197 | }
|
---|
[4883] | 198 | private void RemoveListViewItem(ListViewItem listViewItem) {
|
---|
[5371] | 199 | if (listViewItem == null) throw new ArgumentNullException();
|
---|
[4883] | 200 | IRun run = listViewItem.Tag as IRun;
|
---|
| 201 | if (run != null) {
|
---|
[5237] | 202 | itemListViewItemMapping[run].Remove(listViewItem);
|
---|
| 203 | if (itemListViewItemMapping[run].Count == 0) {
|
---|
| 204 | DeregisterItemEvents(run);
|
---|
| 205 | itemListViewItemMapping.Remove(run);
|
---|
[4883] | 206 | }
|
---|
| 207 | }
|
---|
[3277] | 208 | listViewItem.Remove();
|
---|
| 209 | }
|
---|
[4883] | 210 | private void UpdateListViewItemImage(ListViewItem listViewItem) {
|
---|
[5371] | 211 | if (listViewItem == null) throw new ArgumentNullException();
|
---|
[5237] | 212 | IRun item = listViewItem.Tag as IRun;
|
---|
[3341] | 213 | int i = listViewItem.ImageIndex;
|
---|
[5839] | 214 | itemsListView.SmallImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage;
|
---|
[3341] | 215 | listViewItem.ImageIndex = -1;
|
---|
| 216 | listViewItem.ImageIndex = i;
|
---|
| 217 | }
|
---|
[4883] | 218 | private void UpdateListViewItemText(ListViewItem listViewItem) {
|
---|
[5371] | 219 | if (listViewItem == null) throw new ArgumentNullException();
|
---|
[5237] | 220 | IRun item = listViewItem.Tag as IRun;
|
---|
| 221 | listViewItem.Text = item == null ? "null" : item.ToString();
|
---|
| 222 | listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
|
---|
[3277] | 223 | }
|
---|
[5237] | 224 | private IEnumerable<ListViewItem> GetListViewItemsForItem(IRun item) {
|
---|
| 225 | if (item == null) {
|
---|
| 226 | List<ListViewItem> listViewItems = new List<ListViewItem>();
|
---|
| 227 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 228 | if (listViewItem.Tag == null) listViewItems.Add(listViewItem);
|
---|
| 229 | }
|
---|
| 230 | return listViewItems;
|
---|
| 231 | } else {
|
---|
[5302] | 232 | List<ListViewItem> listViewItems = null;
|
---|
| 233 | itemListViewItemMapping.TryGetValue(item, out listViewItems);
|
---|
| 234 | return listViewItems == null ? Enumerable.Empty<ListViewItem>() : listViewItems;
|
---|
[5237] | 235 | }
|
---|
[3277] | 236 | }
|
---|
| 237 |
|
---|
| 238 | #region ListView Events
|
---|
[4883] | 239 | private void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[11591] | 240 | removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && (Content != null) && !Content.IsReadOnly && !ReadOnly;
|
---|
[7065] | 241 | // for performance reason (multiple selection fires this handler for every selected item)
|
---|
| 242 | if (itemsListView.SelectedIndices.Count <= 1)
|
---|
| 243 | AdjustListViewColumnSizes();
|
---|
[11591] | 244 | if (showDetailsCheckBox.Checked) {
|
---|
| 245 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 246 | IRun item = (IRun)itemsListView.SelectedItems[0].Tag;
|
---|
| 247 | detailsGroupBox.Enabled = true;
|
---|
| 248 | viewHost.Content = item;
|
---|
[4096] | 249 | } else {
|
---|
[11591] | 250 | viewHost.Content = null;
|
---|
| 251 | detailsGroupBox.Enabled = false;
|
---|
[4096] | 252 | }
|
---|
[3277] | 253 | }
|
---|
| 254 | }
|
---|
[4883] | 255 | private void itemsListView_KeyDown(object sender, KeyEventArgs e) {
|
---|
[3277] | 256 | if (e.KeyCode == Keys.Delete) {
|
---|
[3435] | 257 | if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
|
---|
[9613] | 258 | if (RunCollection != null) {
|
---|
| 259 | RunCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(i => (IRun)i.Tag));
|
---|
| 260 | } else {
|
---|
| 261 | foreach (ListViewItem item in itemsListView.SelectedItems)
|
---|
| 262 | Content.Remove((IRun)item.Tag);
|
---|
| 263 | }
|
---|
[3277] | 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
[4883] | 267 | private void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
[3277] | 268 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
[11591] | 269 | IRun item = itemsListView.SelectedItems[0].Tag as IRun;
|
---|
| 270 | if (item != null) {
|
---|
| 271 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
| 272 | if (view != null) {
|
---|
| 273 | view.ReadOnly = ReadOnly;
|
---|
| 274 | view.Locked = Locked;
|
---|
| 275 | }
|
---|
[10103] | 276 | }
|
---|
[3277] | 277 | }
|
---|
| 278 | }
|
---|
[4883] | 279 | private void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 280 | if (!Locked) {
|
---|
[5702] | 281 | List<IRun> items = new List<IRun>();
|
---|
| 282 | foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
|
---|
| 283 | IRun item = listViewItem.Tag as IRun;
|
---|
| 284 | if (item != null) items.Add(item);
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 | if (items.Count > 0) {
|
---|
[5237] | 288 | DataObject data = new DataObject();
|
---|
[5837] | 289 | if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
|
---|
| 290 | else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
|
---|
[5237] | 291 | if (Content.IsReadOnly || ReadOnly) {
|
---|
| 292 | DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
|
---|
| 293 | } else {
|
---|
| 294 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
|
---|
[5744] | 295 | if (result.HasFlag(DragDropEffects.Move)) {
|
---|
[5702] | 296 | foreach (IRun item in items) Content.Remove(item);
|
---|
| 297 | }
|
---|
[5237] | 298 | }
|
---|
[3432] | 299 | }
|
---|
[3277] | 300 | }
|
---|
| 301 | }
|
---|
[5744] | 302 | private void itemsListView_DragEnter(object sender, DragEventArgs e) {
|
---|
| 303 | validDragOperation = false;
|
---|
[5837] | 304 | if (!Content.IsReadOnly && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun)) {
|
---|
[5744] | 305 | validDragOperation = true;
|
---|
[5837] | 306 | } else if (!Content.IsReadOnly && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
|
---|
[5744] | 307 | validDragOperation = true;
|
---|
[5837] | 308 | IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
[5744] | 309 | foreach (object item in items)
|
---|
| 310 | validDragOperation = validDragOperation && (item is IRun);
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | private void itemsListView_DragOver(object sender, DragEventArgs e) {
|
---|
[3277] | 314 | e.Effect = DragDropEffects.None;
|
---|
[5744] | 315 | if (validDragOperation) {
|
---|
[3694] | 316 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
[3277] | 317 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
[5744] | 318 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
| 319 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
|
---|
| 320 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
|
---|
[3277] | 321 | }
|
---|
| 322 | }
|
---|
[4883] | 323 | private void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
[3277] | 324 | if (e.Effect != DragDropEffects.None) {
|
---|
[5837] | 325 | if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IRun) {
|
---|
| 326 | IRun item = (IRun)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
|
---|
[5744] | 327 | Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (IRun)item.Clone() : item);
|
---|
[5837] | 328 | } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
|
---|
| 329 | IEnumerable<IRun> items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<IRun>();
|
---|
[6527] | 330 | if (e.Effect.HasFlag(DragDropEffects.Copy)) {
|
---|
| 331 | Cloner cloner = new Cloner();
|
---|
| 332 | items = items.Select(x => cloner.Clone(x));
|
---|
| 333 | }
|
---|
[7065] | 334 | if (RunCollection != null) {
|
---|
| 335 | RunCollection.AddRange(items);
|
---|
| 336 | } else { // the content is an IItemCollection<IRun>
|
---|
| 337 | foreach (IRun item in items)
|
---|
| 338 | Content.Add(item);
|
---|
| 339 | }
|
---|
[5702] | 340 | }
|
---|
[3277] | 341 | }
|
---|
| 342 | }
|
---|
| 343 | #endregion
|
---|
| 344 |
|
---|
| 345 | #region Button Events
|
---|
[4883] | 346 | private void menuItem_Click(object sender, EventArgs e) {
|
---|
[3507] | 347 | ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
|
---|
[3796] | 348 | Type viewType = (Type)menuItem.Tag;
|
---|
| 349 | IContentView view = MainFormManager.MainForm.ShowContent(Content, viewType);
|
---|
[3507] | 350 | if (view != null) {
|
---|
| 351 | view.Locked = Locked;
|
---|
| 352 | view.ReadOnly = ReadOnly;
|
---|
| 353 | }
|
---|
| 354 | }
|
---|
[4883] | 355 | private void removeButton_Click(object sender, EventArgs e) {
|
---|
[3277] | 356 | if (itemsListView.SelectedItems.Count > 0) {
|
---|
[9613] | 357 | if (RunCollection != null) {
|
---|
| 358 | RunCollection.RemoveRange(itemsListView.SelectedItems.Cast<ListViewItem>().Select(i => (IRun)i.Tag));
|
---|
| 359 | } else {
|
---|
| 360 | foreach (ListViewItem item in itemsListView.SelectedItems)
|
---|
| 361 | Content.Remove((IRun)item.Tag);
|
---|
| 362 | }
|
---|
[3277] | 363 | itemsListView.SelectedItems.Clear();
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
[4883] | 366 | private void clearButton_Click(object sender, EventArgs e) {
|
---|
[3716] | 367 | Content.Clear();
|
---|
| 368 | }
|
---|
[3277] | 369 | #endregion
|
---|
| 370 |
|
---|
[6693] | 371 | #region Control Events
|
---|
[4883] | 372 | private void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[4096] | 373 | if (showDetailsCheckBox.Checked) {
|
---|
| 374 | splitContainer.Panel2Collapsed = false;
|
---|
| 375 | detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
|
---|
| 376 | viewHost.Content = itemsListView.SelectedItems.Count == 1 ? (IRun)itemsListView.SelectedItems[0].Tag : null;
|
---|
| 377 | } else {
|
---|
| 378 | splitContainer.Panel2Collapsed = true;
|
---|
| 379 | viewHost.Content = null;
|
---|
| 380 | }
|
---|
| 381 | }
|
---|
[6693] | 382 | private void EvaluateModifications() {
|
---|
| 383 | if (RunCollection == null)
|
---|
| 384 | return;
|
---|
| 385 | ReadOnly = true;
|
---|
| 386 | try {
|
---|
| 387 | RunCollection.Modify();
|
---|
[11594] | 388 | } finally {
|
---|
[6693] | 389 | ReadOnly = false;
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
[4096] | 392 | #endregion
|
---|
| 393 |
|
---|
[3277] | 394 | #region Content Events
|
---|
[4883] | 395 | private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3277] | 396 | if (InvokeRequired)
|
---|
[3280] | 397 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
|
---|
[3449] | 398 | else {
|
---|
[4200] | 399 | foreach (IRun item in e.Items)
|
---|
[3277] | 400 | AddListViewItem(CreateListViewItem(item));
|
---|
[4200] | 401 |
|
---|
| 402 | AdjustListViewColumnSizes();
|
---|
[3507] | 403 | analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
|
---|
[3716] | 404 | clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
|
---|
[3614] | 405 | runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
|
---|
[3449] | 406 | }
|
---|
[3277] | 407 | }
|
---|
[4883] | 408 | private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3277] | 409 | if (InvokeRequired)
|
---|
[3280] | 410 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
|
---|
[3277] | 411 | else {
|
---|
[3280] | 412 | foreach (IRun item in e.Items) {
|
---|
[4203] | 413 | //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
|
---|
[4883] | 414 | ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
|
---|
| 415 | if (listViewItem != null) RemoveListViewItem(listViewItem);
|
---|
[3277] | 416 | }
|
---|
[5237] | 417 | RebuildImageList();
|
---|
[3507] | 418 | analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
|
---|
[3716] | 419 | clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
|
---|
[3614] | 420 | runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
|
---|
[3277] | 421 | }
|
---|
| 422 | }
|
---|
[4883] | 423 | private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3277] | 424 | if (InvokeRequired)
|
---|
[3280] | 425 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
|
---|
[3277] | 426 | else {
|
---|
[3280] | 427 | foreach (IRun item in e.OldItems) {
|
---|
[5237] | 428 | //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
|
---|
[4883] | 429 | ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
|
---|
| 430 | if (listViewItem != null) RemoveListViewItem(listViewItem);
|
---|
[3277] | 431 | }
|
---|
[5237] | 432 | RebuildImageList();
|
---|
[4200] | 433 | foreach (IRun item in e.Items)
|
---|
[3277] | 434 | AddListViewItem(CreateListViewItem(item));
|
---|
[4200] | 435 |
|
---|
| 436 | AdjustListViewColumnSizes();
|
---|
[3507] | 437 | analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
|
---|
[3716] | 438 | clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
|
---|
[3614] | 439 | runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
|
---|
[3277] | 440 | }
|
---|
| 441 | }
|
---|
| 442 | #endregion
|
---|
| 443 |
|
---|
| 444 | #region Item Events
|
---|
[4883] | 445 | private void Item_ItemImageChanged(object sender, EventArgs e) {
|
---|
[3341] | 446 | if (InvokeRequired)
|
---|
| 447 | Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
|
---|
| 448 | else {
|
---|
| 449 | IRun item = (IRun)sender;
|
---|
| 450 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
|
---|
| 451 | UpdateListViewItemImage(listViewItem);
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
[4883] | 454 | private void Item_ToStringChanged(object sender, EventArgs e) {
|
---|
[3277] | 455 | if (InvokeRequired)
|
---|
| 456 | Invoke(new EventHandler(Item_ToStringChanged), sender, e);
|
---|
| 457 | else {
|
---|
[3280] | 458 | IRun item = (IRun)sender;
|
---|
[3277] | 459 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
|
---|
[3341] | 460 | UpdateListViewItemText(listViewItem);
|
---|
[3829] | 461 | AdjustListViewColumnSizes();
|
---|
[3277] | 462 | }
|
---|
| 463 | }
|
---|
[11594] | 464 | private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
[3632] | 465 | if (InvokeRequired)
|
---|
[11594] | 466 | this.Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e);
|
---|
[3632] | 467 | else {
|
---|
| 468 | IRun run = (IRun)sender;
|
---|
[11594] | 469 | if (e.PropertyName == "Color" || e.PropertyName == "Visible")
|
---|
| 470 | UpdateRun(run);
|
---|
[3632] | 471 | }
|
---|
[3614] | 472 | }
|
---|
| 473 |
|
---|
[4883] | 474 | private void UpdateRun(IRun run) {
|
---|
[3507] | 475 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(run)) {
|
---|
| 476 | if (run.Visible) {
|
---|
| 477 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
|
---|
| 478 | listViewItem.ForeColor = run.Color;
|
---|
| 479 | } else {
|
---|
| 480 | listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
|
---|
| 481 | listViewItem.ForeColor = Color.LightGray;
|
---|
| 482 | }
|
---|
| 483 | }
|
---|
| 484 | }
|
---|
[3277] | 485 | #endregion
|
---|
[3716] | 486 |
|
---|
[3829] | 487 | #region Helpers
|
---|
[4883] | 488 | private void AdjustListViewColumnSizes() {
|
---|
[3829] | 489 | if (itemsListView.Items.Count > 0) {
|
---|
| 490 | for (int i = 0; i < itemsListView.Columns.Count; i++) {
|
---|
| 491 | itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
| 492 | }
|
---|
| 493 | }
|
---|
| 494 | }
|
---|
[5237] | 495 | private void RebuildImageList() {
|
---|
| 496 | itemsListView.SmallImageList.Images.Clear();
|
---|
[5239] | 497 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 498 | IRun item = listViewItem.Tag as IRun;
|
---|
[5287] | 499 | itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage);
|
---|
[5239] | 500 | listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
|
---|
[5237] | 501 | }
|
---|
| 502 | }
|
---|
[3829] | 503 | #endregion
|
---|
[3260] | 504 | }
|
---|
| 505 | }
|
---|