Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Breadcrumbs/HeuristicLab.Core.Views/3.3/ItemListView.cs @ 10089

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

#2116:

  • added hotlinking functionality
  • added methods for outermost view host detection and manipulation
File size: 23.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Drawing;
26using System.Linq;
27using System.Windows.Forms;
28using HeuristicLab.Collections;
29using HeuristicLab.Common;
30using HeuristicLab.MainForm;
31using HeuristicLab.MainForm.WindowsForms;
32using HeuristicLab.PluginInfrastructure;
33
34namespace HeuristicLab.Core.Views {
35  [View("ItemList View")]
36  [Content(typeof(ItemList<>), true)]
37  [Content(typeof(IItemList<>), false)]
38  public partial class ItemListView<T> : ItemView where T : class, IItem {
39    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
40    protected TypeSelectorDialog typeSelectorDialog;
41    protected bool validDragOperation;
42
43    public new IItemList<T> Content {
44      get { return (IItemList<T>)base.Content; }
45      set { base.Content = value; }
46    }
47
48    public ListView ItemsListView {
49      get { return itemsListView; }
50    }
51
52    public ItemListView() {
53      InitializeComponent();
54      itemListViewItemMapping = new Dictionary<T, List<ListViewItem>>();
55    }
56
57    protected override void Dispose(bool disposing) {
58      if (disposing) {
59        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
60        if (components != null) components.Dispose();
61      }
62      base.Dispose(disposing);
63    }
64
65    protected override void DeregisterContentEvents() {
66      Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsAdded);
67      Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsRemoved);
68      Content.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced);
69      Content.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
70      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
71      foreach (T item in itemListViewItemMapping.Keys) {
72        DeregisterItemEvents(item);
73      }
74      base.DeregisterContentEvents();
75    }
76    protected override void RegisterContentEvents() {
77      base.RegisterContentEvents();
78      Content.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsAdded);
79      Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsRemoved);
80      Content.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced);
81      Content.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
82      Content.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
83    }
84    protected virtual void DeregisterItemEvents(T item) {
85      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
86      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
87    }
88    protected virtual void RegisterItemEvents(T item) {
89      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
90      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
91    }
92
93    protected override void OnContentChanged() {
94      base.OnContentChanged();
95
96      int selectedIndex = -1;
97      if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
98
99      itemsListView.Items.Clear();
100      itemListViewItemMapping.Clear();
101      RebuildImageList();
102      viewHost.Content = null;
103      if (Content != null) {
104        foreach (T item in Content)
105          AddListViewItem(CreateListViewItem(item));
106        AdjustListViewColumnSizes();
107        if ((selectedIndex != -1) && (selectedIndex < itemsListView.Items.Count))
108          itemsListView.Items[selectedIndex].Selected = true;
109      }
110      SetEnabledStateOfControls();
111    }
112
113    protected override void SetEnabledStateOfControls() {
114      base.SetEnabledStateOfControls();
115      if (Content == null) {
116        addButton.Enabled = false;
117        moveUpButton.Enabled = false;
118        moveDownButton.Enabled = false;
119        removeButton.Enabled = false;
120        itemsListView.Enabled = false;
121        detailsGroupBox.Enabled = false;
122      } else {
123        addButton.Enabled = !Content.IsReadOnly && !ReadOnly;
124        moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
125                               itemsListView.SelectedIndices[0] != 0 &&
126                               !Content.IsReadOnly && !ReadOnly;
127        moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
128                                 itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 &&
129                                 !Content.IsReadOnly && !ReadOnly;
130        removeButton.Enabled = itemsListView.SelectedItems.Count > 0 &&
131                               !Content.IsReadOnly && !ReadOnly;
132        itemsListView.Enabled = true;
133        detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
134      }
135    }
136
137    protected virtual T CreateItem() {
138      if (typeSelectorDialog == null) {
139        typeSelectorDialog = new TypeSelectorDialog();
140        typeSelectorDialog.Caption = "Select Item";
141        typeSelectorDialog.TypeSelector.Caption = "Available Items";
142        typeSelectorDialog.TypeSelector.Configure(typeof(T), false, true);
143      }
144
145      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
146        try {
147          return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
148        } catch (Exception ex) {
149          ErrorHandling.ShowErrorDialog(this, ex);
150        }
151      }
152      return null;
153    }
154    protected virtual ListViewItem CreateListViewItem(T item) {
155      ListViewItem listViewItem = new ListViewItem();
156      if (item == null) {
157        listViewItem.Text = "null";
158        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VSImageLibrary.Nothing);
159        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
160      } else {
161        listViewItem.Text = item.ToString();
162        listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
163        itemsListView.SmallImageList.Images.Add(item.ItemImage);
164        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
165        listViewItem.Tag = item;
166      }
167      return listViewItem;
168    }
169    protected virtual void AddListViewItem(ListViewItem listViewItem) {
170      if (listViewItem == null) throw new ArgumentNullException();
171      T item = (listViewItem.Tag as T);
172      itemsListView.Items.Add(listViewItem);
173      if (item != null) {
174        if (!itemListViewItemMapping.ContainsKey(item)) {
175          RegisterItemEvents(item);
176          itemListViewItemMapping.Add(item, new List<ListViewItem>());
177        }
178        itemListViewItemMapping[item].Add(listViewItem);
179      }
180    }
181    protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) {
182      if (listViewItem == null) throw new ArgumentNullException();
183      T item = (listViewItem.Tag as T);
184      itemsListView.Items.Insert(index, listViewItem);
185      if (item != null) {
186        if (!itemListViewItemMapping.ContainsKey(item)) {
187          RegisterItemEvents(item);
188          itemListViewItemMapping.Add(item, new List<ListViewItem>());
189        }
190        itemListViewItemMapping[item].Add(listViewItem);
191      }
192    }
193    protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
194      if (listViewItem == null) throw new ArgumentNullException();
195      T item = (listViewItem.Tag as T);
196      if (item != null) {
197        itemListViewItemMapping[item].Remove(listViewItem);
198        if (itemListViewItemMapping[item].Count == 0) {
199          itemListViewItemMapping.Remove(item);
200          DeregisterItemEvents(item);
201        }
202      }
203      listViewItem.Remove();
204    }
205    protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) {
206      if (listViewItem == null) throw new ArgumentNullException();
207      T item = listViewItem.Tag as T;
208      int i = listViewItem.ImageIndex;
209      itemsListView.SmallImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage;
210      listViewItem.ImageIndex = -1;
211      listViewItem.ImageIndex = i;
212    }
213    protected virtual void UpdateListViewItemText(ListViewItem listViewItem) {
214      if (listViewItem == null) throw new ArgumentNullException();
215      T item = listViewItem.Tag as T;
216      listViewItem.Text = item == null ? "null" : item.ToString();
217      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
218    }
219    protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
220      if (item == null) {
221        List<ListViewItem> listViewItems = new List<ListViewItem>();
222        foreach (ListViewItem listViewItem in itemsListView.Items) {
223          if (listViewItem.Tag == null) listViewItems.Add(listViewItem);
224        }
225        return listViewItems;
226      } else {
227        List<ListViewItem> listViewItems = null;
228        itemListViewItemMapping.TryGetValue(item, out listViewItems);
229        return listViewItems == null ? Enumerable.Empty<ListViewItem>() : listViewItems;
230      }
231    }
232
233    #region ListView Events
234    protected virtual void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
235      moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
236                             itemsListView.SelectedIndices[0] != 0 &&
237                             (Content != null) && !Content.IsReadOnly && !ReadOnly;
238      moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
239                               itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 &&
240                               (Content != null) && !Content.IsReadOnly && !ReadOnly;
241      removeButton.Enabled = itemsListView.SelectedItems.Count > 0 &&
242                             (Content != null) && !Content.IsReadOnly && !ReadOnly;
243      AdjustListViewColumnSizes();
244      if (itemsListView.SelectedItems.Count == 1) {
245        var item = (T)itemsListView.SelectedItems[0].Tag;
246        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
247        var outermostViewHost = mainForm.GetOutermostViewOfType<ViewHost>(this);
248        if (outermostViewHost != null && outermostViewHost.HotlinkingEnabled) {
249          var oldCrumbs = outermostViewHost.Breadcrumbs;
250          var newCrumbs = BuildBreadcrumbTrail();
251          mainForm.ShowContentInSpecificViewHost(item, outermostViewHost);
252          outermostViewHost.UpdateBreadcrumbTrail(oldCrumbs, newCrumbs.Concat(new[] { item }));
253          outermostViewHost.ActiveView.ReadOnly = ReadOnly;
254          outermostViewHost.ActiveView.Locked = Locked;
255        } else {
256          if (showDetailsCheckBox.Checked) {
257            detailsGroupBox.Enabled = true;
258            viewHost.Content = item;
259          } else {
260            viewHost.Content = null;
261            detailsGroupBox.Enabled = false;
262          }
263        }
264      }
265    }
266
267    protected virtual void itemsListView_KeyDown(object sender, KeyEventArgs e) {
268      if (e.KeyCode == Keys.Delete) {
269        if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
270          foreach (ListViewItem item in itemsListView.SelectedItems)
271            Content.RemoveAt(item.Index);
272        }
273      }
274    }
275
276    protected virtual void itemsListView_DoubleClick(object sender, EventArgs e) {
277      if (itemsListView.SelectedItems.Count == 1) {
278        var item = (T)itemsListView.SelectedItems[0].Tag;
279        var mainForm = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>();
280        var outermostViewHost = mainForm.GetOutermostViewOfType<ViewHost>(this);
281        var oldCrumbs = outermostViewHost.Breadcrumbs;
282        var newCrumbs = BuildBreadcrumbTrail();
283        mainForm.ShowContentInSpecificViewHost(item, outermostViewHost);
284        outermostViewHost.UpdateBreadcrumbTrail(oldCrumbs, newCrumbs.Concat(new[] { item }));
285        outermostViewHost.ActiveView.ReadOnly = ReadOnly;
286        outermostViewHost.ActiveView.Locked = Locked;
287      }
288    }
289
290    protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
291      if (!Locked) {
292        List<T> items = new List<T>();
293        foreach (ListViewItem listViewItem in itemsListView.SelectedItems) {
294          T item = listViewItem.Tag as T;
295          if (item != null) items.Add(item);
296        }
297
298        if (items.Count > 0) {
299          DataObject data = new DataObject();
300          if (items.Count == 1) data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items[0]);
301          else data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, items);
302          if (Content.IsReadOnly || ReadOnly) {
303            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
304          } else {
305            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
306            if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
307              foreach (ListViewItem listViewItem in itemsListView.SelectedItems.Cast<ListViewItem>().ToArray()) {
308                if (listViewItem.Tag != null) Content.RemoveAt(listViewItem.Index);
309              }
310            }
311          }
312        }
313      }
314    }
315    protected virtual void itemsListView_DragEnter(object sender, DragEventArgs e) {
316      validDragOperation = false;
317      if (!Content.IsReadOnly && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is T)) {
318        validDragOperation = true;
319      } else if (!Content.IsReadOnly && !ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable)) {
320        validDragOperation = true;
321        IEnumerable items = (IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
322        foreach (object item in items)
323          validDragOperation = validDragOperation && (item is T);
324      }
325    }
326    protected virtual void itemsListView_DragOver(object sender, DragEventArgs e) {
327      e.Effect = DragDropEffects.None;
328      if (validDragOperation) {
329        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
330        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
331        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
332        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
333        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
334      }
335    }
336    protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) {
337      if (e.Effect != DragDropEffects.None) {
338        Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
339        ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
340
341        if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is T) {
342          T item = (T)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
343          if (listViewItem != null) Content.Insert(listViewItem.Index, e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
344          else Content.Add(e.Effect.HasFlag(DragDropEffects.Copy) ? (T)item.Clone() : item);
345        } else if (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IEnumerable) {
346          IEnumerable<T> items = ((IEnumerable)e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat)).Cast<T>();
347          if (e.Effect.HasFlag(DragDropEffects.Copy)) {
348            Cloner cloner = new Cloner();
349            items = items.Select(x => cloner.Clone(x));
350          }
351          foreach (T item in items) {
352            if (listViewItem != null) Content.Insert(listViewItem.Index, item);
353            else Content.Add(item);
354          }
355        }
356      }
357    }
358    #endregion
359
360    #region Button Events
361    protected virtual void addButton_Click(object sender, EventArgs e) {
362      T item = CreateItem();
363      if (item != null)
364        Content.Add(item);
365    }
366    protected virtual void moveUpButton_Click(object sender, EventArgs e) {
367      if (itemsListView.SelectedItems.Count == 1) {
368        int index = itemsListView.SelectedIndices[0];
369        Content.Reverse(index - 1, 2);
370        itemsListView.Items[index].Selected = false;
371        itemsListView.Items[index - 1].Selected = true;
372      }
373    }
374    protected virtual void moveDownButton_Click(object sender, EventArgs e) {
375      if (itemsListView.SelectedItems.Count == 1) {
376        int index = itemsListView.SelectedIndices[0];
377        Content.Reverse(index, 2);
378        itemsListView.Items[index].Selected = false;
379        itemsListView.Items[index + 1].Selected = true;
380      }
381    }
382    protected virtual void removeButton_Click(object sender, EventArgs e) {
383      if (itemsListView.SelectedItems.Count > 0) {
384        foreach (ListViewItem item in itemsListView.SelectedItems)
385          Content.RemoveAt(item.Index);
386      }
387    }
388    #endregion
389
390    #region CheckBox Events
391    protected virtual void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
392      if (showDetailsCheckBox.Checked) {
393        splitContainer.Panel2Collapsed = false;
394        detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
395        viewHost.Content = itemsListView.SelectedItems.Count == 1 ? (T)itemsListView.SelectedItems[0].Tag : null;
396      } else {
397        splitContainer.Panel2Collapsed = true;
398        viewHost.Content = null;
399      }
400    }
401    #endregion
402
403    #region Content Events
404    protected virtual void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
405      if (InvokeRequired)
406        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsAdded), sender, e);
407      else {
408        foreach (IndexedItem<T> item in e.Items)
409          InsertListViewItem(item.Index, CreateListViewItem(item.Value));
410        AdjustListViewColumnSizes();
411      }
412    }
413    protected virtual void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
414      if (InvokeRequired)
415        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsRemoved), sender, e);
416      else {
417        List<ListViewItem> listViewItems = new List<ListViewItem>();
418        foreach (IndexedItem<T> item in e.Items)
419          listViewItems.Add(itemsListView.Items[item.Index]);
420        foreach (ListViewItem listViewItem in listViewItems)
421          RemoveListViewItem(listViewItem);
422        RebuildImageList();
423      }
424    }
425    protected virtual void Content_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
426      if (InvokeRequired)
427        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced), sender, e);
428      else {
429        int[] selected = new int[itemsListView.SelectedIndices.Count];
430        itemsListView.SelectedIndices.CopyTo(selected, 0);
431
432        List<ListViewItem> listViewItems = new List<ListViewItem>();
433        foreach (IndexedItem<T> item in e.OldItems)
434          listViewItems.Add(itemsListView.Items[item.Index]);
435        foreach (ListViewItem listViewItem in listViewItems)
436          RemoveListViewItem(listViewItem);
437        RebuildImageList();
438
439        foreach (IndexedItem<T> item in e.Items)
440          InsertListViewItem(item.Index, CreateListViewItem(item.Value));
441        AdjustListViewColumnSizes();
442
443        for (int i = 0; i < selected.Length; i++)
444          itemsListView.Items[selected[i]].Selected = true;
445      }
446    }
447    protected virtual void Content_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
448      if (InvokeRequired)
449        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved), sender, e);
450      else {
451        foreach (IndexedItem<T> item in e.Items) {
452          ListViewItem listViewItem = itemsListView.Items[item.Index];
453          if (listViewItem.Tag != null)
454            itemListViewItemMapping[(T)listViewItem.Tag].Remove(listViewItem);
455          listViewItem.Tag = item.Value;
456          if (listViewItem.Tag != null)
457            itemListViewItemMapping[item.Value].Add(listViewItem);
458          UpdateListViewItemImage(listViewItem);
459          UpdateListViewItemText(listViewItem);
460        }
461      }
462    }
463    protected virtual void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
464      if (InvokeRequired)
465        Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset), sender, e);
466      else {
467        List<ListViewItem> listViewItems = new List<ListViewItem>();
468        foreach (IndexedItem<T> item in e.OldItems)
469          listViewItems.Add(itemsListView.Items[item.Index]);
470        foreach (ListViewItem listViewItem in listViewItems)
471          RemoveListViewItem(listViewItem);
472        RebuildImageList();
473
474        foreach (IndexedItem<T> item in e.Items)
475          InsertListViewItem(item.Index, CreateListViewItem(item.Value));
476        AdjustListViewColumnSizes();
477      }
478    }
479    #endregion
480
481    #region Item Events
482    protected virtual void Item_ItemImageChanged(object sender, EventArgs e) {
483      if (InvokeRequired)
484        Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
485      else {
486        T item = (T)sender;
487        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
488          UpdateListViewItemImage(listViewItem);
489      }
490    }
491    protected virtual void Item_ToStringChanged(object sender, EventArgs e) {
492      if (InvokeRequired)
493        Invoke(new EventHandler(Item_ToStringChanged), sender, e);
494      else {
495        T item = (T)sender;
496        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
497          UpdateListViewItemText(listViewItem);
498        AdjustListViewColumnSizes();
499      }
500    }
501    #endregion
502
503    #region Helpers
504    protected virtual void AdjustListViewColumnSizes() {
505      if (itemsListView.Items.Count > 0) {
506        for (int i = 0; i < itemsListView.Columns.Count; i++)
507          itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
508      }
509    }
510    protected virtual void RebuildImageList() {
511      itemsListView.SmallImageList.Images.Clear();
512      foreach (ListViewItem listViewItem in itemsListView.Items) {
513        T item = listViewItem.Tag as T;
514        itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VSImageLibrary.Nothing : item.ItemImage);
515        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
516      }
517    }
518    protected virtual IEnumerable<IContent> BuildBreadcrumbTrail() {
519      var l = new LinkedList<IContent>();
520      for (var control = (Control)this; control != null; control = control.Parent) {
521        var vh = control as ViewHost;
522        if (vh != null && vh.Content != null)
523          l.AddFirst(vh.Content);
524      }
525      return l;
526    }
527    #endregion
528  }
529}
Note: See TracBrowser for help on using the repository browser.