Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs @ 12820

Last change on this file since 12820 was 12692, checked in by abeham, 9 years ago

#2270:

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