Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs @ 14721

Last change on this file since 14721 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 23.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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
392      try {
393        RunCollection.UpdateOfRunsInProgress = true;
394        RunCollection.Modify();
395      } finally {
396        ReadOnly = false;
397        RunCollection.UpdateOfRunsInProgress = false;
398      }
399    }
400    #endregion
401
402    #region Content Events
403    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
404      if (suppressUpdates) return;
405      if (InvokeRequired)
406        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
407      else {
408        foreach (IRun item in e.Items)
409          AddListViewItem(CreateListViewItem(item));
410
411        AdjustListViewColumnSizes();
412        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
413        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
414        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
415      }
416    }
417    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
418      if (suppressUpdates) return;
419      if (InvokeRequired)
420        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
421      else {
422        foreach (IRun item in e.Items) {
423          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
424          ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
425          if (listViewItem != null) RemoveListViewItem(listViewItem);
426        }
427        RebuildImageList();
428        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
429        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
430        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
431      }
432    }
433    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
434      if (suppressUpdates) return;
435      if (InvokeRequired)
436        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
437      else {
438        foreach (IRun item in e.OldItems) {
439          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
440          ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
441          if (listViewItem != null) RemoveListViewItem(listViewItem);
442        }
443        RebuildImageList();
444        foreach (IRun item in e.Items)
445          AddListViewItem(CreateListViewItem(item));
446
447        AdjustListViewColumnSizes();
448        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
449        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
450        runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
451      }
452    }
453    private void RunCollection_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
454      if (InvokeRequired) Invoke((Action<object, EventArgs>)RunCollection_UpdateOfRunsInProgressChanged, sender, e);
455      else {
456        suppressUpdates = RunCollection.UpdateOfRunsInProgress;
457        if (!suppressUpdates) {
458          foreach (IRun item in Content) {
459            //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
460            ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
461            if (listViewItem != null) RemoveListViewItem(listViewItem);
462          }
463          RebuildImageList();
464          foreach (IRun item in Content)
465            AddListViewItem(CreateListViewItem(item));
466
467          AdjustListViewColumnSizes();
468          analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
469          clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
470          runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
471        }
472      }
473    }
474    #endregion
475
476    #region Item Events
477    private void Item_ItemImageChanged(object sender, EventArgs e) {
478      if (suppressUpdates) return;
479      if (InvokeRequired)
480        Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
481      else {
482        IRun item = (IRun)sender;
483        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
484          UpdateListViewItemImage(listViewItem);
485      }
486    }
487    private void Item_ToStringChanged(object sender, EventArgs e) {
488      if (suppressUpdates) return;
489      if (InvokeRequired)
490        Invoke(new EventHandler(Item_ToStringChanged), sender, e);
491      else {
492        IRun item = (IRun)sender;
493        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
494          UpdateListViewItemText(listViewItem);
495        AdjustListViewColumnSizes();
496      }
497    }
498    private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) {
499      if (suppressUpdates) return;
500      if (InvokeRequired)
501        Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e);
502      else {
503        IRun run = (IRun)sender;
504        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
505          UpdateRun(run);
506      }
507    }
508
509    private void UpdateRun(IRun run) {
510      foreach (ListViewItem listViewItem in GetListViewItemsForItem(run)) {
511        if (run.Visible) {
512          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
513          listViewItem.ForeColor = run.Color;
514        } else {
515          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
516          listViewItem.ForeColor = Color.LightGray;
517        }
518      }
519    }
520    #endregion
521
522    #region Helpers
523    private void AdjustListViewColumnSizes() {
524      if (itemsListView.Items.Count > 0) {
525        for (int i = 0; i < itemsListView.Columns.Count; i++) {
526          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
527        }
528      }
529    }
530    private void RebuildImageList() {
531      itemsListView.SmallImageList.Images.Clear();
532      foreach (ListViewItem listViewItem in itemsListView.Items) {
533        IRun item = listViewItem.Tag as IRun;
534        itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage);
535        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
536      }
537    }
538    #endregion
539  }
540}
Note: See TracBrowser for help on using the repository browser.