Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs @ 13042

Last change on this file since 13042 was 13014, checked in by jkarder, 9 years ago

#2116: added new breadcrumb navigation prototype

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