Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5237


Ignore:
Timestamp:
01/08/11 01:47:47 (14 years ago)
Author:
swagner
Message:

#1324:

  • Added performance optimization in all other item collection views
  • Checked and refactored item event registration/deregistration
  • Enabled null items in item collection views
  • Moved non-default Dispose methods from designer files into user files
Location:
trunk/sources
Files:
40 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.Designer.cs

    r3764 r5237  
    2020#endregion
    2121
    22 using System;
    23 using System.Windows.Forms;
    2422
    2523namespace HeuristicLab.Core.Views {
     
    2927    /// </summary>
    3028    private System.ComponentModel.IContainer components = null;
    31 
    32     /// <summary>
    33     /// Clean up any resources being used.
    34     /// </summary>
    35     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    36     protected override void Dispose(bool disposing) {
    37       if (disposing) {
    38         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    39         foreach (ListViewItem item in listView.Items) {
    40           ((T)item.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    41           ((T)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
    42         }
    43         if (components != null) components.Dispose();
    44       }
    45       base.Dispose(disposing);
    46     }
    4729
    4830    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/Clipboard.cs

    r4500 r5237  
    3434  public sealed partial class Clipboard<T> : HeuristicLab.MainForm.WindowsForms.Sidebar where T : class, IItem {
    3535    private TypeSelectorDialog typeSelectorDialog;
    36     private Dictionary<T, ListViewItem> itemListViewItemTable;
     36    private Dictionary<T, ListViewItem> itemListViewItemMapping;
    3737
    3838    private string itemsPath;
     
    6262      ItemsPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
    6363                  Path.DirectorySeparatorChar + "HeuristicLab" + Path.DirectorySeparatorChar + "Clipboard";
    64       itemListViewItemTable = new Dictionary<T, ListViewItem>();
     64      itemListViewItemMapping = new Dictionary<T, ListViewItem>();
    6565    }
    6666    public Clipboard(string itemsPath) {
    6767      InitializeComponent();
    6868      ItemsPath = itemsPath;
    69       itemListViewItemTable = new Dictionary<T, ListViewItem>();
     69      itemListViewItemMapping = new Dictionary<T, ListViewItem>();
     70    }
     71
     72    protected override void Dispose(bool disposing) {
     73      if (disposing) {
     74        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     75        foreach (T item in itemListViewItemMapping.Keys) {
     76          item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
     77          item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     78        }
     79        if (components != null) components.Dispose();
     80      }
     81      base.Dispose(disposing);
    7082    }
    7183
     
    91103        Invoke(new Action<T>(AddItem), item);
    92104      else {
    93         if (!itemListViewItemTable.ContainsKey(item)) {
     105        if (item == null) throw new ArgumentNullException("item", "Cannot add null item to clipboard.");
     106        if (!itemListViewItemMapping.ContainsKey(item)) {
    94107          ListViewItem listViewItem = new ListViewItem(item.ToString());
    95108          listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     
    98111          listViewItem.Tag = item;
    99112          listView.Items.Add(listViewItem);
    100           itemListViewItemTable.Add(item, listViewItem);
     113          itemListViewItemMapping.Add(item, listViewItem);
    101114          item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    102115          item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     
    111124        Invoke(new Action<T>(RemoveItem), item);
    112125      else {
    113         if (itemListViewItemTable.ContainsKey(item)) {
     126        if (itemListViewItemMapping.ContainsKey(item)) {
    114127          item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    115128          item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
    116           ListViewItem listViewItem = itemListViewItemTable[item];
     129          ListViewItem listViewItem = itemListViewItemMapping[item];
    117130          listViewItem.Remove();
    118           foreach (ListViewItem other in listView.Items)
    119             if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
    120           listView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
    121           itemListViewItemTable.Remove(item);
     131          itemListViewItemMapping.Remove(item);
    122132          sortAscendingButton.Enabled = sortDescendingButton.Enabled = listView.Items.Count > 1;
    123133        }
     
    178188
    179189      int i = 0;
    180       T[] items = GetStorableItems(itemListViewItemTable.Keys);
     190      T[] items = GetStorableItems(itemListViewItemMapping.Keys);
    181191
    182192      foreach (T item in items) {
     
    243253          foreach (ListViewItem item in listView.SelectedItems)
    244254            RemoveItem((T)item.Tag);
     255          RebuildImageList();
    245256        }
    246257      }
     
    271282      } else {
    272283        DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    273         if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     284        if ((result & DragDropEffects.Move) == DragDropEffects.Move) {
    274285          RemoveItem(item);
     286          RebuildImageList();
     287        }
    275288      }
    276289    }
     
    281294      if (!ReadOnly && (type != null) && (item != null)) {
    282295        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
    283         else if (((e.KeyState & 4) == 4) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Move;  // SHIFT key
     296        else if (((e.KeyState & 4) == 4) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Move;  // SHIFT key
    284297        else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
    285         else if (((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Move;
    286         else if (((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) && !itemListViewItemTable.ContainsKey(item)) e.Effect = DragDropEffects.Link;
     298        else if (((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Move;
     299        else if (((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) && !itemListViewItemMapping.ContainsKey(item)) e.Effect = DragDropEffects.Link;
    287300      }
    288301    }
     
    291304        T item = e.Data.GetData("Value") as T;
    292305        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    293         AddItem(item);
     306        try {
     307          AddItem(item);
     308        }
     309        catch (Exception ex) {
     310          ErrorHandling.ShowErrorDialog(this, ex);
     311        }
    294312      }
    295313    }
     
    326344        foreach (ListViewItem item in listView.SelectedItems)
    327345          RemoveItem((T)item.Tag);
     346        RebuildImageList();
    328347      }
    329348    }
    330349    private void saveButton_Click(object sender, EventArgs e) {
    331       IEnumerable<T> items = itemListViewItemTable.Keys.Except(GetStorableItems(itemListViewItemTable.Keys));
     350      IEnumerable<T> items = itemListViewItemMapping.Keys.Except(GetStorableItems(itemListViewItemMapping.Keys));
    332351      if (items.Any()) {
    333352        string itemNames = string.Join(Environment.NewLine, items.Select(item => item.ToString()).ToArray());
     
    345364      else {
    346365        T item = (T)sender;
    347         ListViewItem listViewItem = itemListViewItemTable[item];
     366        ListViewItem listViewItem = itemListViewItemMapping[item];
    348367        int i = listViewItem.ImageIndex;
    349368        listViewItem.ImageList.Images[i] = item.ItemImage;
     
    357376      else {
    358377        T item = (T)sender;
    359         itemListViewItemTable[item].Text = item.ToString();
     378        itemListViewItemMapping[item].Text = item.ToString();
    360379        listView.Sort();
    361380        AdjustListViewColumnSizes();
     
    371390      }
    372391    }
     392    private void RebuildImageList() {
     393      listView.SmallImageList.Images.Clear();
     394      foreach (ListViewItem item in listView.Items) {
     395        listView.SmallImageList.Images.Add(((T)item.Tag).ItemImage);
     396        item.ImageIndex = listView.SmallImageList.Images.Count - 1;
     397      }
     398    }
    373399    #endregion
    374400  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.Designer.cs

    r4096 r5237  
    2929    /// </summary>
    3030    private System.ComponentModel.IContainer components = null;
    31 
    32     /// <summary>
    33     /// Clean up any resources being used.
    34     /// </summary>
    35     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    36     protected override void Dispose(bool disposing) {
    37       if (disposing) {
    38         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    39         foreach (ListViewItem listViewItem in itemsListView.Items) {
    40           T item = listViewItem.Tag as T;
    41           if (item != null) item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    42           if (item != null) item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
    43         }
    44         if (components != null) components.Dispose();
    45       }
    46       base.Dispose(disposing);
    47     }
    4831
    4932    #region Windows Form Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemArrayView.cs

    r5070 r5237  
    3030
    3131namespace HeuristicLab.Core.Views {
    32   /// <summary>
    33   /// The visual representation of all variables in a specified scope.
    34   /// </summary>
    3532  [View("ItemArray View")]
    3633  [Content(typeof(ItemArray<>), true)]
    3734  [Content(typeof(IItemArray<>), false)]
    3835  public partial class ItemArrayView<T> : ItemView where T : class, IItem {
     36    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3937    protected TypeSelectorDialog typeSelectorDialog;
    4038
    41     /// <summary>
    42     /// Gets or sets the scope whose variables to represent visually.
    43     /// </summary>
    44     /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    45     /// No won data storage present.</remarks>
    4639    public new IItemArray<T> Content {
    4740      get { return (IItemArray<T>)base.Content; }
     
    5346    }
    5447
    55     /// <summary>
    56     /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
    57     /// </summary>
    5848    public ItemArrayView() {
    5949      InitializeComponent();
    60     }
    61 
    62     /// <summary>
    63     /// Removes the eventhandlers from the underlying <see cref="IScope"/>.
    64     /// </summary>
    65     /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
     50      itemListViewItemMapping = new Dictionary<T, List<ListViewItem>>();
     51    }
     52
     53    protected override void Dispose(bool disposing) {
     54      if (disposing) {
     55        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     56        if (components != null) components.Dispose();
     57      }
     58      base.Dispose(disposing);
     59    }
     60
    6661    protected override void DeregisterContentEvents() {
    6762      Content.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced);
    6863      Content.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
    6964      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
    70       foreach (T item in Content) {
    71         item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    72         item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     65      foreach (T item in itemListViewItemMapping.Keys) {
     66        DeregisterItemEvents(item);
    7367      }
    7468      base.DeregisterContentEvents();
    7569    }
    76 
    77     /// <summary>
    78     /// Adds eventhandlers to the underlying <see cref="IScope"/>.
    79     /// </summary>
    80     /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    8170    protected override void RegisterContentEvents() {
    8271      base.RegisterContentEvents();
     
    8574      Content.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
    8675    }
     76    protected virtual void DeregisterItemEvents(T item) {
     77      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
     78      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     79    }
     80    protected virtual void RegisterItemEvents(T item) {
     81      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
     82      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     83    }
    8784
    8885    protected override void OnContentChanged() {
     
    9289      if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
    9390
    94       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
     91      itemsListView.Items.Clear();
     92      itemListViewItemMapping.Clear();
     93      RebuildImageList();
    9594      viewHost.Content = null;
    9695      if (Content != null) {
     
    140139        try {
    141140          return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    142         } catch (Exception ex) {
     141        }
     142        catch (Exception ex) {
    143143          ErrorHandling.ShowErrorDialog(this, ex);
    144144        }
     
    148148    protected virtual ListViewItem CreateListViewItem(T item) {
    149149      ListViewItem listViewItem = new ListViewItem();
    150       listViewItem.Text = item == null ? "null" : item.ToString();
    151       listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
    152       itemsListView.SmallImageList.Images.Add(item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage);
    153       listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    154       listViewItem.Tag = item;
     150      if (item == null) {
     151        listViewItem.Text = "null";
     152        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing);
     153        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     154      } else {
     155        listViewItem.Text = item.ToString();
     156        listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     157        itemsListView.SmallImageList.Images.Add(item.ItemImage);
     158        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     159        listViewItem.Tag = item;
     160      }
    155161      return listViewItem;
    156162    }
    157163    protected virtual void AddListViewItem(ListViewItem listViewItem) {
     164      T item = (listViewItem.Tag as T);
    158165      itemsListView.Items.Add(listViewItem);
    159       if (listViewItem.Tag != null) {
    160         ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    161         ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
     166      if (item != null) {
     167        if (!itemListViewItemMapping.ContainsKey(item)) {
     168          RegisterItemEvents(item);
     169          itemListViewItemMapping.Add(item, new List<ListViewItem>());
     170        }
     171        itemListViewItemMapping[item].Add(listViewItem);
    162172      }
    163173    }
    164174    protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) {
     175      T item = (listViewItem.Tag as T);
    165176      itemsListView.Items.Insert(index, listViewItem);
    166       if (listViewItem.Tag != null) {
    167         ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    168         ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
     177      if (item != null) {
     178        if (!itemListViewItemMapping.ContainsKey(item)) {
     179          RegisterItemEvents(item);
     180          itemListViewItemMapping.Add(item, new List<ListViewItem>());
     181        }
     182        itemListViewItemMapping[item].Add(listViewItem);
    169183      }
    170184    }
    171185    protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
    172       if (listViewItem.Tag != null) {
    173         ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    174         ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
     186      T item = (listViewItem.Tag as T);
     187      if (item != null) {
     188        itemListViewItemMapping[item].Remove(listViewItem);
     189        if (itemListViewItemMapping[item].Count == 0) {
     190          itemListViewItemMapping.Remove(item);
     191          DeregisterItemEvents(item);
     192        }
    175193      }
    176194      listViewItem.Remove();
    177       foreach (ListViewItem other in itemsListView.Items)
    178         if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
    179       itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
    180195    }
    181196    protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) {
     
    190205      listViewItem.Text = item == null ? "null" : item.ToString();
    191206      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
     207    }
     208    protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
     209      return itemListViewItemMapping[item];
    192210    }
    193211
     
    347365        foreach (ListViewItem listViewItem in listViewItems)
    348366          RemoveListViewItem(listViewItem);
     367        RebuildImageList();
    349368
    350369        foreach (IndexedItem<T> item in e.Items)
     
    377396        foreach (ListViewItem listViewItem in listViewItems)
    378397          RemoveListViewItem(listViewItem);
     398        RebuildImageList();
    379399
    380400        foreach (IndexedItem<T> item in e.Items)
     
    391411      else {
    392412        T item = (T)sender;
    393         foreach (ListViewItem listViewItem in itemsListView.Items) {
    394           if (((T)listViewItem.Tag) == item)
    395             UpdateListViewItemImage(listViewItem);
    396         }
     413        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
     414          UpdateListViewItemImage(listViewItem);
    397415      }
    398416    }
     
    402420      else {
    403421        T item = (T)sender;
    404         foreach (ListViewItem listViewItem in itemsListView.Items) {
    405           if (((T)listViewItem.Tag) == item)
    406             UpdateListViewItemText(listViewItem);
    407         }
     422        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
     423          UpdateListViewItemText(listViewItem);
    408424      }
    409425    }
     
    417433      }
    418434    }
     435    private void RebuildImageList() {
     436      itemsListView.SmallImageList.Images.Clear();
     437      foreach (ListViewItem item in itemsListView.Items) {
     438        itemsListView.SmallImageList.Images.Add(((T)item.Tag).ItemImage);
     439        item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     440      }
     441    }
    419442    #endregion
    420443  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.Designer.cs

    r4096 r5237  
    2020#endregion
    2121
    22 using System;
    2322using System.Windows.Forms;
    2423
     
    2928    /// </summary>
    3029    private System.ComponentModel.IContainer components = null;
    31 
    32     /// <summary>
    33     /// Clean up any resources being used.
    34     /// </summary>
    35     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    36     protected override void Dispose(bool disposing) {
    37       if (disposing) {
    38         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    39         foreach (ListViewItem item in itemsListView.Items) {
    40           ((T)item.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    41           ((T)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
    42         }
    43         if (components != null) components.Dispose();
    44       }
    45       base.Dispose(disposing);
    46     }
    4730
    4831    #region Windows Form Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs

    r5068 r5237  
    3434  [Content(typeof(IItemCollection<>), false)]
    3535  public partial class ItemCollectionView<T> : ItemView where T : class, IItem {
    36     private Dictionary<T, List<ListViewItem>> listViewItemMapping;
     36    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3737    protected TypeSelectorDialog typeSelectorDialog;
    3838
     
    4848    public ItemCollectionView() {
    4949      InitializeComponent();
    50       listViewItemMapping = new Dictionary<T, List<ListViewItem>>();
     50      itemListViewItemMapping = new Dictionary<T, List<ListViewItem>>();
     51    }
     52
     53    protected override void Dispose(bool disposing) {
     54      if (disposing) {
     55        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     56        if (components != null) components.Dispose();
     57      }
     58      base.Dispose(disposing);
    5159    }
    5260
     
    5563      Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<T>(Content_ItemsRemoved);
    5664      Content.CollectionReset -= new CollectionItemsChangedEventHandler<T>(Content_CollectionReset);
    57       foreach (T item in listViewItemMapping.Keys) {
    58         item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    59         item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     65      foreach (T item in itemListViewItemMapping.Keys) {
     66        DeregisterItemEvents(item);
    6067      }
    6168      base.DeregisterContentEvents();
     
    6774      Content.CollectionReset += new CollectionItemsChangedEventHandler<T>(Content_CollectionReset);
    6875    }
     76    protected virtual void DeregisterItemEvents(T item) {
     77      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
     78      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     79    }
     80    protected virtual void RegisterItemEvents(T item) {
     81      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
     82      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     83    }
    6984
    7085    protected override void OnContentChanged() {
    7186      base.OnContentChanged();
    72       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
     87      itemsListView.Items.Clear();
     88      itemListViewItemMapping.Clear();
    7389      RebuildImageList();
    7490      viewHost.Content = null;
     
    112128        try {
    113129          return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    114         } catch (Exception ex) {
     130        }
     131        catch (Exception ex) {
    115132          ErrorHandling.ShowErrorDialog(this, ex);
    116133        }
     
    120137    protected virtual ListViewItem CreateListViewItem(T item) {
    121138      ListViewItem listViewItem = new ListViewItem();
    122       listViewItem.Text = item.ToString();
    123       listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
    124       listViewItem.Tag = item;
    125       itemsListView.SmallImageList.Images.Add(item.ItemImage);
    126       listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     139      if (item == null) {
     140        listViewItem.Text = "null";
     141        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing);
     142        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     143      } else {
     144        listViewItem.Text = item.ToString();
     145        listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     146        itemsListView.SmallImageList.Images.Add(item.ItemImage);
     147        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     148        listViewItem.Tag = item;
     149      }
    127150      return listViewItem;
    128151    }
     
    130153      T item = (listViewItem.Tag as T);
    131154      itemsListView.Items.Add(listViewItem);
    132       if (!listViewItemMapping.ContainsKey(item)) {
    133         item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    134         item.ToStringChanged += new EventHandler(Item_ToStringChanged);
    135         listViewItemMapping.Add(item, new List<ListViewItem>());
    136       }
    137       listViewItemMapping[item].Add(listViewItem);
     155      if (item != null) {
     156        if (!itemListViewItemMapping.ContainsKey(item)) {
     157          RegisterItemEvents(item);
     158          itemListViewItemMapping.Add(item, new List<ListViewItem>());
     159        }
     160        itemListViewItemMapping[item].Add(listViewItem);
     161      }
    138162      sortAscendingButton.Enabled = itemsListView.Items.Count > 1;
    139163      sortDescendingButton.Enabled = itemsListView.Items.Count > 1;
     
    141165    protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
    142166      T item = (listViewItem.Tag as T);
    143       listViewItemMapping[item].Remove(listViewItem);
    144       if (listViewItemMapping[item].Count == 0) {
    145         listViewItemMapping.Remove(item);
    146         item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    147         item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     167      if (item != null) {
     168        itemListViewItemMapping[item].Remove(listViewItem);
     169        if (itemListViewItemMapping[item].Count == 0) {
     170          itemListViewItemMapping.Remove(item);
     171          DeregisterItemEvents(item);
     172        }
    148173      }
    149174      listViewItem.Remove();
     
    152177    }
    153178    protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) {
     179      T item = listViewItem.Tag as T;
    154180      int i = listViewItem.ImageIndex;
    155       listViewItem.ImageList.Images[i] = ((T)listViewItem.Tag).ItemImage;
     181      listViewItem.ImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage;
    156182      listViewItem.ImageIndex = -1;
    157183      listViewItem.ImageIndex = i;
    158184    }
    159185    protected virtual void UpdateListViewItemText(ListViewItem listViewItem) {
    160       if (!listViewItem.Text.Equals(listViewItem.Tag.ToString()))
    161         listViewItem.Text = listViewItem.Tag.ToString();
     186      T item = listViewItem.Tag as T;
     187      listViewItem.Text = item == null ? "null" : item.ToString();
     188      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
    162189    }
    163190    protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
    164       return listViewItemMapping[item];
     191      if (item == null) {
     192        List<ListViewItem> listViewItems = new List<ListViewItem>();
     193        foreach (ListViewItem listViewItem in itemsListView.Items) {
     194          if (listViewItem.Tag == null) listViewItems.Add(listViewItem);
     195        }
     196        return listViewItems;
     197      } else {
     198        return itemListViewItemMapping[item];
     199      }
    165200    }
    166201
     
    190225    protected virtual void itemsListView_DoubleClick(object sender, EventArgs e) {
    191226      if (itemsListView.SelectedItems.Count == 1) {
    192         T item = (T)itemsListView.SelectedItems[0].Tag;
    193         IContentView view = MainFormManager.MainForm.ShowContent(item);
    194         if (view != null) {
    195           view.ReadOnly = ReadOnly;
    196           view.Locked = Locked;
     227        T item = itemsListView.SelectedItems[0].Tag as T;
     228        if (item != null) {
     229          IContentView view = MainFormManager.MainForm.ShowContent(item);
     230          if (view != null) {
     231            view.ReadOnly = ReadOnly;
     232            view.Locked = Locked;
     233          }
    197234        }
    198235      }
     
    201238      if (!Locked) {
    202239        ListViewItem listViewItem = (ListViewItem)e.Item;
    203         T item = (T)listViewItem.Tag;
    204         DataObject data = new DataObject();
    205         data.SetData("Type", item.GetType());
    206         data.SetData("Value", item);
    207         if (Content.IsReadOnly || ReadOnly) {
    208           DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    209         } else {
    210           DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    211           if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    212             Content.Remove(item);
     240        T item = listViewItem.Tag as T;
     241        if (item != null) {
     242          DataObject data = new DataObject();
     243          data.SetData("Type", item.GetType());
     244          data.SetData("Value", item);
     245          if (Content.IsReadOnly || ReadOnly) {
     246            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     247          } else {
     248            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     249            if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     250              Content.Remove(item);
     251          }
    213252        }
    214253      }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.Designer.cs

    r4096 r5237  
    2929    /// </summary>
    3030    private System.ComponentModel.IContainer components = null;
    31 
    32     /// <summary>
    33     /// Clean up any resources being used.
    34     /// </summary>
    35     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    36     protected override void Dispose(bool disposing) {
    37       if (disposing) {
    38         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    39         foreach (ListViewItem item in itemsListView.Items) {
    40           ((T)item.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    41           ((T)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
    42         }
    43         if (components != null) components.Dispose();
    44       }
    45       base.Dispose(disposing);
    46     }
    4731
    4832    #region Windows Form Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemListView.cs

    r5070 r5237  
    3030
    3131namespace HeuristicLab.Core.Views {
    32   /// <summary>
    33   /// The visual representation of all variables in a specified scope.
    34   /// </summary>
    3532  [View("ItemList View")]
    3633  [Content(typeof(ItemList<>), true)]
    3734  [Content(typeof(IItemList<>), false)]
    3835  public partial class ItemListView<T> : ItemView where T : class, IItem {
     36    protected Dictionary<T, List<ListViewItem>> itemListViewItemMapping;
    3937    protected TypeSelectorDialog typeSelectorDialog;
    4038
    41     /// <summary>
    42     /// Gets or sets the scope whose variables to represent visually.
    43     /// </summary>
    44     /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    45     /// No won data storage present.</remarks>
    4639    public new IItemList<T> Content {
    4740      get { return (IItemList<T>)base.Content; }
     
    5346    }
    5447
    55     /// <summary>
    56     /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
    57     /// </summary>
    5848    public ItemListView() {
    5949      InitializeComponent();
    60     }
    61 
    62     /// <summary>
    63     /// Removes the eventhandlers from the underlying <see cref="IScope"/>.
    64     /// </summary>
    65     /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
     50      itemListViewItemMapping = new Dictionary<T, List<ListViewItem>>();
     51    }
     52
     53    protected override void Dispose(bool disposing) {
     54      if (disposing) {
     55        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     56        if (components != null) components.Dispose();
     57      }
     58      base.Dispose(disposing);
     59    }
     60
    6661    protected override void DeregisterContentEvents() {
    6762      Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsAdded);
     
    7065      Content.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
    7166      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
    72       foreach (T item in Content) {
    73         item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    74         item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     67      foreach (T item in itemListViewItemMapping.Keys) {
     68        DeregisterItemEvents(item);
    7569      }
    7670      base.DeregisterContentEvents();
    7771    }
    78 
    79     /// <summary>
    80     /// Adds eventhandlers to the underlying <see cref="IScope"/>.
    81     /// </summary>
    82     /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    8372    protected override void RegisterContentEvents() {
    8473      base.RegisterContentEvents();
     
    8978      Content.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
    9079    }
     80    protected virtual void DeregisterItemEvents(T item) {
     81      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
     82      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     83    }
     84    protected virtual void RegisterItemEvents(T item) {
     85      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
     86      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     87    }
    9188
    9289    protected override void OnContentChanged() {
     
    9693      if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
    9794
    98       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
     95      itemsListView.Items.Clear();
     96      itemListViewItemMapping.Clear();
     97      RebuildImageList();
    9998      viewHost.Content = null;
    10099      if (Content != null) {
     
    143142        try {
    144143          return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    145         } catch (Exception ex) {
     144        }
     145        catch (Exception ex) {
    146146          ErrorHandling.ShowErrorDialog(this, ex);
    147147        }
     
    151151    protected virtual ListViewItem CreateListViewItem(T item) {
    152152      ListViewItem listViewItem = new ListViewItem();
    153       listViewItem.Text = item.ToString();
    154       listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
    155       listViewItem.Tag = item;
    156       itemsListView.SmallImageList.Images.Add(item.ItemImage);
    157       listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     153      if (item == null) {
     154        listViewItem.Text = "null";
     155        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing);
     156        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     157      } else {
     158        listViewItem.Text = item.ToString();
     159        listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     160        itemsListView.SmallImageList.Images.Add(item.ItemImage);
     161        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     162        listViewItem.Tag = item;
     163      }
    158164      return listViewItem;
    159165    }
    160166    protected virtual void AddListViewItem(ListViewItem listViewItem) {
     167      T item = (listViewItem.Tag as T);
    161168      itemsListView.Items.Add(listViewItem);
    162       ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    163       ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
     169      if (item != null) {
     170        if (!itemListViewItemMapping.ContainsKey(item)) {
     171          RegisterItemEvents(item);
     172          itemListViewItemMapping.Add(item, new List<ListViewItem>());
     173        }
     174        itemListViewItemMapping[item].Add(listViewItem);
     175      }
    164176    }
    165177    protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) {
     178      T item = (listViewItem.Tag as T);
    166179      itemsListView.Items.Insert(index, listViewItem);
    167       ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    168       ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
     180      if (item != null) {
     181        if (!itemListViewItemMapping.ContainsKey(item)) {
     182          RegisterItemEvents(item);
     183          itemListViewItemMapping.Add(item, new List<ListViewItem>());
     184        }
     185        itemListViewItemMapping[item].Add(listViewItem);
     186      }
    169187    }
    170188    protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
    171       ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    172       ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
     189      T item = (listViewItem.Tag as T);
     190      if (item != null) {
     191        itemListViewItemMapping[item].Remove(listViewItem);
     192        if (itemListViewItemMapping[item].Count == 0) {
     193          itemListViewItemMapping.Remove(item);
     194          DeregisterItemEvents(item);
     195        }
     196      }
    173197      listViewItem.Remove();
    174       foreach (ListViewItem other in itemsListView.Items)
    175         if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
    176       itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
    177198    }
    178199    protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) {
     200      T item = listViewItem.Tag as T;
    179201      int i = listViewItem.ImageIndex;
    180       listViewItem.ImageList.Images[i] = ((T)listViewItem.Tag).ItemImage;
     202      listViewItem.ImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage;
    181203      listViewItem.ImageIndex = -1;
    182204      listViewItem.ImageIndex = i;
    183205    }
    184206    protected virtual void UpdateListViewItemText(ListViewItem listViewItem) {
    185       if (!listViewItem.Text.Equals(listViewItem.Tag.ToString()))
    186         listViewItem.Text = listViewItem.Tag.ToString();
     207      T item = listViewItem.Tag as T;
     208      listViewItem.Text = item == null ? "null" : item.ToString();
     209      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
     210    }
     211    protected virtual IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
     212      return itemListViewItemMapping[item];
    187213    }
    188214
     
    222248    protected virtual void itemsListView_DoubleClick(object sender, EventArgs e) {
    223249      if (itemsListView.SelectedItems.Count == 1) {
    224         T item = (T)itemsListView.SelectedItems[0].Tag;
    225         IContentView view = MainFormManager.MainForm.ShowContent(item);
    226         if (view != null) {
    227           view.ReadOnly = ReadOnly;
    228           view.Locked = Locked;
     250        T item = itemsListView.SelectedItems[0].Tag as T;
     251        if (item != null) {
     252          IContentView view = MainFormManager.MainForm.ShowContent(item);
     253          if (view != null) {
     254            view.ReadOnly = ReadOnly;
     255            view.Locked = Locked;
     256          }
    229257        }
    230258      }
     
    234262      if (!Locked) {
    235263        ListViewItem listViewItem = (ListViewItem)e.Item;
    236         T item = (T)listViewItem.Tag;
    237         DataObject data = new DataObject();
    238         data.SetData("Type", item.GetType());
    239         data.SetData("Value", item);
    240         if (Content.IsReadOnly || ReadOnly) {
    241           DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    242         } else {
    243           DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    244           if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    245             Content.RemoveAt(listViewItem.Index);
     264        T item = listViewItem.Tag as T;
     265        if (item != null) {
     266          DataObject data = new DataObject();
     267          data.SetData("Type", item.GetType());
     268          data.SetData("Value", item);
     269          if (Content.IsReadOnly || ReadOnly) {
     270            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     271          } else {
     272            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     273            if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     274              Content.RemoveAt(listViewItem.Index);
     275          }
    246276        }
    247277      }
     
    337367        foreach (ListViewItem listViewItem in listViewItems)
    338368          RemoveListViewItem(listViewItem);
     369        RebuildImageList();
    339370      }
    340371    }
     
    351382        foreach (ListViewItem listViewItem in listViewItems)
    352383          RemoveListViewItem(listViewItem);
     384        RebuildImageList();
    353385
    354386        foreach (IndexedItem<T> item in e.Items)
     
    381413        foreach (ListViewItem listViewItem in listViewItems)
    382414          RemoveListViewItem(listViewItem);
     415        RebuildImageList();
    383416
    384417        foreach (IndexedItem<T> item in e.Items)
     
    395428      else {
    396429        T item = (T)sender;
    397         foreach (ListViewItem listViewItem in itemsListView.Items) {
    398           if (((T)listViewItem.Tag) == item)
    399             UpdateListViewItemImage(listViewItem);
    400         }
     430        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
     431          UpdateListViewItemImage(listViewItem);
    401432      }
    402433    }
     
    406437      else {
    407438        T item = (T)sender;
    408         foreach (ListViewItem listViewItem in itemsListView.Items) {
    409           if (((T)listViewItem.Tag) == item)
    410             UpdateListViewItemText(listViewItem);
    411         }
     439        foreach (ListViewItem listViewItem in GetListViewItemsForItem(item))
     440          UpdateListViewItemText(listViewItem);
    412441      }
    413442    }
     
    421450      }
    422451    }
     452    private void RebuildImageList() {
     453      itemsListView.SmallImageList.Images.Clear();
     454      foreach (ListViewItem item in itemsListView.Items) {
     455        itemsListView.SmallImageList.Images.Add(((T)item.Tag).ItemImage);
     456        item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     457      }
     458    }
    423459    #endregion
    424460  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/ItemSetView.cs

    r4068 r5237  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Windows.Forms;
    2423using HeuristicLab.MainForm;
     
    3433    }
    3534
    36     private Dictionary<T, ListViewItem> listViewItemDictionary;
    37     protected Dictionary<T, ListViewItem> ListViewItemDictionary {
    38       get { return listViewItemDictionary; }
    39     }
    40 
    4135    public ItemSetView() {
    42       listViewItemDictionary = new Dictionary<T, ListViewItem>();
    4336      InitializeComponent();
    44     }
    45 
    46     protected override void OnContentChanged() {
    47       base.OnContentChanged();
    48       if (Content != null)
    49         Caption += " (" + Content.GetType().Name + ")";
    50     }
    51 
    52     protected override void AddListViewItem(ListViewItem listViewItem) {
    53       ListViewItemDictionary.Add((T)listViewItem.Tag, listViewItem);
    54       base.AddListViewItem(listViewItem);
    55     }
    56     protected override void RemoveListViewItem(ListViewItem listViewItem) {
    57       base.RemoveListViewItem(listViewItem);
    58       ListViewItemDictionary.Remove((T)listViewItem.Tag);
    59     }
    60     protected override IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
    61       return new ListViewItem[] { listViewItemDictionary[item] };
    6237    }
    6338  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/NamedItemCollectionView.cs

    r4715 r5237  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Windows.Forms;
    2423using HeuristicLab.Collections;
     
    3433    }
    3534
    36     private Dictionary<T, ListViewItem> listViewItemDictionary;
    37     protected Dictionary<T, ListViewItem> ListViewItemDictionary {
    38       get { return listViewItemDictionary; }
    39     }
    40 
    4135    public NamedItemCollectionView() {
    42       listViewItemDictionary = new Dictionary<T, ListViewItem>();
    4336      InitializeComponent();
    4437    }
     
    7568    protected override ListViewItem CreateListViewItem(T item) {
    7669      ListViewItem listViewItem = base.CreateListViewItem(item);
    77       listViewItem.ToolTipText = string.IsNullOrEmpty(item.Description) ? item.ItemName : item.ItemName + ": " + item.Description;
     70      if ((item != null) && !string.IsNullOrEmpty(item.Description)) {
     71        listViewItem.ToolTipText = item.ItemName + ": " + item.Description;
     72      }
    7873      return listViewItem;
    79     }
    80     protected override void AddListViewItem(ListViewItem listViewItem) {
    81       ListViewItemDictionary.Add((T)listViewItem.Tag, listViewItem);
    82       base.AddListViewItem(listViewItem);
    83     }
    84     protected override void RemoveListViewItem(ListViewItem listViewItem) {
    85       base.RemoveListViewItem(listViewItem);
    86       ListViewItemDictionary.Remove((T)listViewItem.Tag);
    87     }
    88     protected override IEnumerable<ListViewItem> GetListViewItemsForItem(T item) {
    89       ListViewItem listViewItem = null;
    90       listViewItemDictionary.TryGetValue(item, out listViewItem);
    91       if (listViewItem != null) return new ListViewItem[] { listViewItem };
    92       else return new ListViewItem[0];
    9374    }
    9475
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorTreeView.Designer.cs

    r2949 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (graphTreeView.Nodes.Count > 0) {
    36           RemoveTreeNode(graphTreeView.Nodes[0]);
    37           graphTreeView.Nodes.Clear();
    38         }
    39         if (components != null) components.Dispose();
    40       }
    41       base.Dispose(disposing);
    42     }
    4328
    4429    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/OperatorTreeView.cs

    r5224 r5237  
    3030
    3131namespace HeuristicLab.Core.Views {
    32   /// <summary>
    33   /// The visual representation of an <see cref="OperatorGraph"/>.
    34   /// </summary>
    3532  [View("Operator View (Successors)")]
    3633  [Content(typeof(IOperator), false)]
     
    4037    private Dictionary<IKeyedItemCollection<string, IParameter>, IOperator> parametersOperatorTable;
    4138
    42     /// <summary>
    43     /// Gets or sets the operator graph to represent visually.
    44     /// </summary>
    45     /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    46     /// No own data storage present.</remarks>
    4739    public new IOperator Content {
    4840      get { return (IOperator)base.Content; }
     
    6153    }
    6254
    63     /// <summary>
    64     /// Initializes a new instance of <see cref="OperatorGraphView"/> with caption "Operator Graph".
    65     /// </summary>
    6655    public OperatorTreeView() {
    6756      InitializeComponent();
     
    7261    }
    7362
    74     /// <summary>
    75     /// Updates all controls with the latest data of the model.
    76     /// </summary>
    77     /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
     63    protected override void Dispose(bool disposing) {
     64      if (disposing) {
     65        if (graphTreeView.Nodes.Count > 0) {
     66          RemoveTreeNode(graphTreeView.Nodes[0]);
     67          graphTreeView.Nodes.Clear();
     68        }
     69        if (components != null) components.Dispose();
     70      }
     71      base.Dispose(disposing);
     72    }
     73
    7874    protected override void OnContentChanged() {
    7975      base.OnContentChanged();
  • trunk/sources/HeuristicLab.Core.Views/3.3/ParameterCollectionView.Designer.cs

    r3742 r5237  
    2727    private System.ComponentModel.IContainer components = null;
    2828
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (createParameterDialog != null) createParameterDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    40 
    4129    #region Component Designer generated code
    4230
  • trunk/sources/HeuristicLab.Core.Views/3.3/ParameterCollectionView.cs

    r4068 r5237  
    3838    }
    3939
     40    protected override void Dispose(bool disposing) {
     41      if (disposing) {
     42        if (createParameterDialog != null) createParameterDialog.Dispose();
     43        if (components != null) components.Dispose();
     44      }
     45      base.Dispose(disposing);
     46    }
     47
    4048    protected override IParameter CreateItem() {
    4149      if (createParameterDialog == null) createParameterDialog = new CreateParameterDialog();
  • trunk/sources/HeuristicLab.Core.Views/3.3/ScopeView.Designer.cs

    r4477 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (scopesTreeView.Nodes.Count > 0) {
    36           ClearTreeNode(scopesTreeView.Nodes[0]);
    37         }
    38         if (components != null) components.Dispose();
    39       }
    40       base.Dispose(disposing);
    41     }
    4228
    4329    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/ScopeView.cs

    r4477 r5237  
    5757    }
    5858
     59    /// <summary>
     60    /// Clean up any resources being used.
     61    /// </summary>
     62    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     63    protected override void Dispose(bool disposing) {
     64      if (disposing) {
     65        if (scopesTreeView.Nodes.Count > 0) {
     66          ClearTreeNode(scopesTreeView.Nodes[0]);
     67        }
     68        if (components != null) components.Dispose();
     69      }
     70      base.Dispose(disposing);
     71    }
     72
    5973    /// <summary>
    6074    /// Updates all controls with the latest data of the model.
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.Designer.cs

    r4867 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/TypeSelector.cs

    r4867 r5237  
    7474      currentSearchString = string.Empty;
    7575      selectedType = null;
     76    }
     77
     78    protected override void Dispose(bool disposing) {
     79      if (disposing) {
     80        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     81        if (components != null) components.Dispose();
     82      }
     83      base.Dispose(disposing);
    7684    }
    7785
  • trunk/sources/HeuristicLab.Core.Views/3.3/ValueParameterCollectionView.Designer.cs

    r3742 r5237  
    2727    private System.ComponentModel.IContainer components = null;
    2828
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (createParameterDialog != null) createParameterDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    40 
    4129    #region Component Designer generated code
    4230
  • trunk/sources/HeuristicLab.Core.Views/3.3/ValueParameterCollectionView.cs

    r4068 r5237  
    3838    }
    3939
     40    protected override void Dispose(bool disposing) {
     41      if (disposing) {
     42        if (createParameterDialog != null) createParameterDialog.Dispose();
     43        if (components != null) components.Dispose();
     44      }
     45      base.Dispose(disposing);
     46    }
     47
    4048    protected override IValueParameter CreateItem() {
    4149      if (createParameterDialog == null) {
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableView.Designer.cs

    r4477 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableView.cs

    r4477 r5237  
    5151    public VariableView() {
    5252      InitializeComponent();
     53    }
     54
     55    /// <summary>
     56    /// Clean up any resources being used.
     57    /// </summary>
     58    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     59    protected override void Dispose(bool disposing) {
     60      if (disposing) {
     61        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     62        if (components != null) components.Dispose();
     63      }
     64      base.Dispose(disposing);
    5365    }
    5466
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DockForm.Designer.cs

    r3732 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (View != null)
    35         View.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
    36       if (disposing && (components != null)) {
    37         components.Dispose();
    38       }
    39       base.Dispose(disposing);
    40     }
    4128
    4229    #region Windows Form Designer generated code
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DockForm.cs

    r4068 r5237  
    7373      }
    7474    }
     75
     76    protected override void Dispose(bool disposing) {
     77      if (View != null)
     78        View.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
     79      if (disposing && (components != null)) {
     80        components.Dispose();
     81      }
     82      base.Dispose(disposing);
     83    }
     84
    7585    private IView view;
    7686    public IView View {
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DocumentForm.Designer.cs

    r3732 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (view != null)
    35         view.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
    36       if (disposing && (components != null)) {
    37         components.Dispose();
    38       }
    39       base.Dispose(disposing);
    40     }
    4128
    4229    #region Windows Form Designer generated code
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/DocumentForm.cs

    r4068 r5237  
    5050    }
    5151
     52    protected override void Dispose(bool disposing) {
     53      if (view != null)
     54        view.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
     55      if (disposing && (components != null)) {
     56        components.Dispose();
     57      }
     58      base.Dispose(disposing);
     59    }
     60
    5261    private void UpdateText() {
    5362      if (InvokeRequired)
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForm.cs

    r4234 r5237  
    430430    private void ToolStripItemClicked(object sender, EventArgs e) {
    431431      System.Windows.Forms.ToolStripItem item = (System.Windows.Forms.ToolStripItem)sender;
    432       ((IActionUserInterfaceItem)item.Tag).Execute();
     432      try {
     433        ((IActionUserInterfaceItem)item.Tag).Execute();
     434      }
     435      catch (Exception ex) {
     436        ErrorHandling.ShowErrorDialog((Control)MainFormManager.MainForm, ex);
     437      }
    433438    }
    434439    #endregion
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.Designer.cs

    r4522 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (problemTypeSelectorDialog != null) problemTypeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/AlgorithmView.cs

    r4540 r5237  
    4949    public AlgorithmView() {
    5050      InitializeComponent();
     51    }
     52
     53    protected override void Dispose(bool disposing) {
     54      if (disposing) {
     55        if (problemTypeSelectorDialog != null) problemTypeSelectorDialog.Dispose();
     56        if (components != null) components.Dispose();
     57      }
     58      base.Dispose(disposing);
    5159    }
    5260
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.Designer.cs

    r4522 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (algorithmTypeSelectorDialog != null) algorithmTypeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/BatchRunView.cs

    r4540 r5237  
    4747    public BatchRunView() {
    4848      InitializeComponent();
     49    }
     50
     51    protected override void Dispose(bool disposing) {
     52      if (disposing) {
     53        if (algorithmTypeSelectorDialog != null) algorithmTypeSelectorDialog.Dispose();
     54        if (components != null) components.Dispose();
     55      }
     56      base.Dispose(disposing);
    4957    }
    5058
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionConstraintCollectionView.cs

    r4162 r5237  
    2323using System.Drawing;
    2424using System.Windows.Forms;
    25 using HeuristicLab.Collections;
    2625using HeuristicLab.Core;
    2726using HeuristicLab.Core.Views;
     
    6059    protected override ListViewItem CreateListViewItem(IRunCollectionConstraint item) {
    6160      ListViewItem listViewItem = base.CreateListViewItem(item);
    62       if (item.Active)
    63         listViewItem.Font = new Font(listViewItem.Font, FontStyle.Bold);
    64       else
    65         listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
     61      if (item != null) {
     62        listViewItem.Font = item.Active ? new Font(listViewItem.Font, FontStyle.Bold) : new Font(listViewItem.Font, FontStyle.Regular);
     63      }
    6664      return listViewItem;
    6765    }
    6866
    69     protected override void RegisterContentEvents() {
    70       base.RegisterContentEvents();
    71       foreach (IRunCollectionConstraint constraint in Content)
    72         RegisterConstraintEvents(constraint);
     67    protected override void DeregisterItemEvents(IRunCollectionConstraint item) {
     68      item.ActiveChanged -= new EventHandler(Item_ActiveChanged);
     69      base.DeregisterItemEvents(item);
    7370    }
    74     protected override void DeregisterContentEvents() {
    75       base.DeregisterContentEvents();
    76       foreach (IRunCollectionConstraint constraint in Content)
    77         DeregisterConstraintEvents(constraint);
    78     }
    79     protected override void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
    80       base.Content_ItemsAdded(sender, e);
    81       foreach (IRunCollectionConstraint constraint in e.Items)
    82         RegisterConstraintEvents(constraint);
    83 
    84     }
    85     protected override void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
    86       base.Content_ItemsRemoved(sender, e);
    87       foreach (IRunCollectionConstraint constraint in e.Items)
    88         DeregisterConstraintEvents(constraint);
    89     }
    90     protected override void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRunCollectionConstraint> e) {
    91       base.Content_CollectionReset(sender, e);
    92       foreach (IRunCollectionConstraint constraint in e.OldItems)
    93         RegisterConstraintEvents(constraint);
    94       foreach (IRunCollectionConstraint constraint in e.Items)
    95         DeregisterConstraintEvents(constraint);
     71    protected override void RegisterItemEvents(IRunCollectionConstraint item) {
     72      base.RegisterItemEvents(item);
     73      item.ActiveChanged += new EventHandler(Item_ActiveChanged);
    9674    }
    9775
    98     protected virtual void RegisterConstraintEvents(IRunCollectionConstraint constraint) {
    99       constraint.ActiveChanged += new EventHandler(constraint_ActiveChanged);
    100     }
    101     protected virtual void DeregisterConstraintEvents(IRunCollectionConstraint constraint) {
    102       constraint.ActiveChanged -= new EventHandler(constraint_ActiveChanged);
    103     }
    104     protected virtual void constraint_ActiveChanged(object sender, EventArgs e) {
     76    protected virtual void Item_ActiveChanged(object sender, EventArgs e) {
    10577      IRunCollectionConstraint constraint = (IRunCollectionConstraint)sender;
    10678      foreach (ListViewItem listViewItem in GetListViewItemsForItem(constraint)) {
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.Designer.cs

    r4883 r5237  
    2020#endregion
    2121
    22 using System;
    2322using System.Windows.Forms;
    2423
     
    3635    protected override void Dispose(bool disposing) {
    3736      if (disposing) {
    38         foreach (ListViewItem item in itemsListView.Items) {
    39           ((IRun)item.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    40           ((IRun)item.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
    41         }
    4237        if (components != null) components.Dispose();
    4338      }
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionView.cs

    r4883 r5237  
    3636  [Content(typeof(IItemCollection<IRun>), false)]
    3737  public sealed partial class RunCollectionView : ItemView {
    38     private Dictionary<IRun, List<ListViewItem>> runListViewItemMapping;
     38    private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping;
    3939
    4040    public new IItemCollection<IRun> Content {
     
    5454      InitializeComponent();
    5555      itemsGroupBox.Text = "Runs";
    56       runListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>();
     56      itemListViewItemMapping = new Dictionary<IRun, List<ListViewItem>>();
    5757    }
    5858
     
    6161      Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    6262      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    63       DeregisterRunEvents(Content);
     63      foreach (IRun run in itemListViewItemMapping.Keys) {
     64        DeregisterItemEvents(run);
     65      }
    6466      base.DeregisterContentEvents();
    6567    }
     
    6971      Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    7072      Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    71       RegisterRunEvents(Content);
    72     }
    73     private void RegisterRunEvents(IEnumerable<IRun> runs) {
    74       foreach (IRun run in runs)
    75         run.Changed += new EventHandler(Run_Changed);
    76     }
    77     private void DeregisterRunEvents(IEnumerable<IRun> runs) {
    78       foreach (IRun run in runs)
    79         run.Changed -= new EventHandler(Run_Changed);
     73    }
     74    private void DeregisterItemEvents(IRun item) {
     75      item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
     76      item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     77      item.Changed -= new EventHandler(Item_Changed);
     78    }
     79    private void RegisterItemEvents(IRun item) {
     80      item.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
     81      item.ToStringChanged += new EventHandler(Item_ToStringChanged);
     82      item.Changed += new EventHandler(Item_Changed);
    8083    }
    8184
     
    101104        selectedName = ((IRun)itemsListView.SelectedItems[0].Tag).Name;
    102105
    103       while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
     106      itemsListView.Items.Clear();
     107      itemListViewItemMapping.Clear();
     108      RebuildImageList();
    104109      viewHost.Content = null;
    105110
     
    148153    private ListViewItem CreateListViewItem(IRun item) {
    149154      ListViewItem listViewItem = new ListViewItem();
    150       listViewItem.Text = item.ToString();
    151       listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
    152       itemsListView.SmallImageList.Images.Add(item.ItemImage);
    153       listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    154       listViewItem.Tag = item;
    155 
    156       if (item.Visible) {
    157         listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
    158         listViewItem.ForeColor = item.Color;
     155      if (item == null) {
     156        listViewItem.Text = "null";
     157        itemsListView.SmallImageList.Images.Add(HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing);
     158        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
    159159      } else {
    160         listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
    161         listViewItem.ForeColor = Color.LightGray;
     160        listViewItem.Text = item.ToString();
     161        listViewItem.ToolTipText = item.ItemName + ": " + item.ItemDescription;
     162        itemsListView.SmallImageList.Images.Add(item.ItemImage);
     163        listViewItem.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     164        listViewItem.Tag = item;
     165
     166        if (item.Visible) {
     167          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Regular);
     168          listViewItem.ForeColor = item.Color;
     169        } else {
     170          listViewItem.Font = new Font(listViewItem.Font, FontStyle.Italic);
     171          listViewItem.ForeColor = Color.LightGray;
     172        }
    162173      }
    163174      return listViewItem;
     
    167178      IRun run = listViewItem.Tag as IRun;
    168179      if (run != null) {
    169         if (!runListViewItemMapping.ContainsKey(run))
    170           runListViewItemMapping.Add(run, new List<ListViewItem>());
    171         runListViewItemMapping[run].Add(listViewItem);
    172         run.ItemImageChanged += new EventHandler(Item_ItemImageChanged);
    173         run.ToStringChanged += new EventHandler(Item_ToStringChanged);
     180        if (!itemListViewItemMapping.ContainsKey(run)) {
     181          itemListViewItemMapping.Add(run, new List<ListViewItem>());
     182          RegisterItemEvents(run);
     183        }
     184        itemListViewItemMapping[run].Add(listViewItem);
    174185      }
    175186    }
     
    177188      IRun run = listViewItem.Tag as IRun;
    178189      if (run != null) {
    179         runListViewItemMapping[run].Remove(listViewItem);
    180         if (runListViewItemMapping[run].Count == 0) {
    181           runListViewItemMapping.Remove(run);
    182           run.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
    183           run.ToStringChanged -= new EventHandler(Item_ToStringChanged);
     190        itemListViewItemMapping[run].Remove(listViewItem);
     191        if (itemListViewItemMapping[run].Count == 0) {
     192          DeregisterItemEvents(run);
     193          itemListViewItemMapping.Remove(run);
    184194        }
    185195      }
    186196      listViewItem.Remove();
    187       foreach (ListViewItem other in itemsListView.Items)
    188         if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
    189       itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
    190197    }
    191198    private void UpdateListViewItemImage(ListViewItem listViewItem) {
     199      IRun item = listViewItem.Tag as IRun;
    192200      int i = listViewItem.ImageIndex;
    193       listViewItem.ImageList.Images[i] = ((IRun)listViewItem.Tag).ItemImage;
     201      listViewItem.ImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage;
    194202      listViewItem.ImageIndex = -1;
    195203      listViewItem.ImageIndex = i;
    196204    }
    197205    private void UpdateListViewItemText(ListViewItem listViewItem) {
    198       if (!listViewItem.Text.Equals(listViewItem.Tag.ToString()))
    199         listViewItem.Text = listViewItem.Tag.ToString();
    200     }
    201     private IEnumerable<ListViewItem> GetListViewItemsForItem(IRun run) {
    202       return runListViewItemMapping[run];
     206      IRun item = listViewItem.Tag as IRun;
     207      listViewItem.Text = item == null ? "null" : item.ToString();
     208      listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
     209    }
     210    private IEnumerable<ListViewItem> GetListViewItemsForItem(IRun item) {
     211      if (item == null) {
     212        List<ListViewItem> listViewItems = new List<ListViewItem>();
     213        foreach (ListViewItem listViewItem in itemsListView.Items) {
     214          if (listViewItem.Tag == null) listViewItems.Add(listViewItem);
     215        }
     216        return listViewItems;
     217      } else {
     218        return itemListViewItemMapping[item];
     219      }
    203220    }
    204221
     
    228245    private void itemsListView_DoubleClick(object sender, EventArgs e) {
    229246      if (itemsListView.SelectedItems.Count == 1) {
    230         IRun item = (IRun)itemsListView.SelectedItems[0].Tag;
    231         IContentView view = MainFormManager.MainForm.ShowContent(item);
    232         if (view != null) {
    233           view.ReadOnly = ReadOnly;
    234           view.Locked = Locked;
     247        IRun item = itemsListView.SelectedItems[0].Tag as IRun;
     248        if (item != null) {
     249          IContentView view = MainFormManager.MainForm.ShowContent(item);
     250          if (view != null) {
     251            view.ReadOnly = ReadOnly;
     252            view.Locked = Locked;
     253          }
    235254        }
    236255      }
     
    239258      if (!Locked) {
    240259        ListViewItem listViewItem = (ListViewItem)e.Item;
    241         IRun item = (IRun)listViewItem.Tag;
    242         DataObject data = new DataObject();
    243         data.SetData("Type", item.GetType());
    244         data.SetData("Value", item);
    245         if (Content.IsReadOnly || ReadOnly) {
    246           DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    247         } else {
    248           DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    249           if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    250             Content.Remove(item);
     260        IRun item = listViewItem.Tag as IRun;
     261        if (item != null) {
     262          DataObject data = new DataObject();
     263          data.SetData("Type", item.GetType());
     264          data.SetData("Value", item);
     265          if (Content.IsReadOnly || ReadOnly) {
     266            DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     267          } else {
     268            DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     269            if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     270              Content.Remove(item);
     271          }
    251272        }
    252273      }
     
    312333        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
    313334      else {
    314         RegisterRunEvents(e.Items);
    315335        foreach (IRun item in e.Items)
    316336          AddListViewItem(CreateListViewItem(item));
     
    326346        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
    327347      else {
    328         DeregisterRunEvents(e.Items);
    329348        foreach (IRun item in e.Items) {
    330349          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
     
    332351          if (listViewItem != null) RemoveListViewItem(listViewItem);
    333352        }
     353        RebuildImageList();
    334354        analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
    335355        clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
     
    341361        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
    342362      else {
    343         DeregisterRunEvents(e.OldItems);
    344363        foreach (IRun item in e.OldItems) {
     364          //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
    345365          ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
    346366          if (listViewItem != null) RemoveListViewItem(listViewItem);
    347367        }
    348         RegisterRunEvents(e.Items);
     368        RebuildImageList();
    349369        foreach (IRun item in e.Items)
    350370          AddListViewItem(CreateListViewItem(item));
     
    378398      }
    379399    }
    380     private void Run_Changed(object sender, EventArgs e) {
    381       if (InvokeRequired)
    382         this.Invoke(new EventHandler(Run_Changed), sender, e);
     400    private void Item_Changed(object sender, EventArgs e) {
     401      if (InvokeRequired)
     402        this.Invoke(new EventHandler(Item_Changed), sender, e);
    383403      else {
    384404        IRun run = (IRun)sender;
     
    408428      }
    409429    }
     430    private void RebuildImageList() {
     431      itemsListView.SmallImageList.Images.Clear();
     432      foreach (ListViewItem item in itemsListView.Items) {
     433        itemsListView.SmallImageList.Images.Add(((IRun)item.Tag).ItemImage);
     434        item.ImageIndex = itemsListView.SmallImageList.Images.Count - 1;
     435      }
     436    }
    410437    #endregion
    411438  }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.Designer.cs

    r4522 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.cs

    r4522 r5237  
    5353    public ValueLookupParameterView() {
    5454      InitializeComponent();
     55    }
     56
     57    /// <summary>
     58    /// Clean up any resources being used.
     59    /// </summary>
     60    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     61    protected override void Dispose(bool disposing) {
     62      if (disposing) {
     63        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     64        if (components != null) components.Dispose();
     65      }
     66      base.Dispose(disposing);
    5567    }
    5668
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.Designer.cs

    r4522 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
     
    120108      this.valueViewHost.Size = new System.Drawing.Size(374, 182);
    121109      this.valueViewHost.TabIndex = 3;
    122       this.valueViewHost.ViewType = null;   
     110      this.valueViewHost.ViewType = null;
    123111      //
    124112      // clearValueButton
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r4522 r5237  
    5454    public ValueParameterView() {
    5555      InitializeComponent();
     56    }
     57
     58    /// <summary>
     59    /// Clean up any resources being used.
     60    /// </summary>
     61    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
     62    protected override void Dispose(bool disposing) {
     63      if (disposing) {
     64        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
     65        if (components != null) components.Dispose();
     66      }
     67      base.Dispose(disposing);
    5668    }
    5769
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TravelingSalesmanProblemView.Designer.cs

    r3764 r5237  
    2626    /// </summary>
    2727    private System.ComponentModel.IContainer components = null;
    28 
    29     /// <summary>
    30     /// Clean up any resources being used.
    31     /// </summary>
    32     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    33     protected override void Dispose(bool disposing) {
    34       if (disposing) {
    35         if (tsplibImportDialog != null) tsplibImportDialog.Dispose();
    36         if (components != null) components.Dispose();
    37       }
    38       base.Dispose(disposing);
    39     }
    4028
    4129    #region Component Designer generated code
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman.Views/3.3/TravelingSalesmanProblemView.cs

    r4513 r5237  
    4646    public TravelingSalesmanProblemView() {
    4747      InitializeComponent();
     48    }
     49
     50    protected override void Dispose(bool disposing) {
     51      if (disposing) {
     52        if (tsplibImportDialog != null) tsplibImportDialog.Dispose();
     53        if (components != null) components.Dispose();
     54      }
     55      base.Dispose(disposing);
    4856    }
    4957
Note: See TracChangeset for help on using the changeset viewer.