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