Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs @ 15303

Last change on this file since 15303 was 14793, checked in by mkommend, 8 years ago

#2758: Improved performance of RunCollectionView and added runs counter.

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