Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Breadcrumbs/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs @ 10879

Last change on this file since 10879 was 10103, checked in by jkarder, 11 years ago

#2116:

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