Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/29/10 01:44:57 (15 years ago)
Author:
swagner
Message:

Adapted HL 3.3 plugins according to changes in MainForm (#857)

File:
1 edited

Legend:

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

    r2708 r2713  
    3030using HeuristicLab.Common;
    3131using HeuristicLab.MainForm;
     32using HeuristicLab.MainForm.WindowsForms;
    3233
    3334namespace HeuristicLab.Core.Views {
    34   public partial class ItemCollectionView<T> : ObjectView where T : class, IItem {
    35     public IObservableCollection<T> ItemCollection {
    36       get { return (IObservableCollection<T>)Object; }
    37       set { base.Object = value; }
     35  public partial class ItemCollectionView<T> : ContentView where T : class, IItem {
     36    public new IObservableCollection<T> Content {
     37      get { return (IObservableCollection<T>)base.Content; }
     38      set { base.Content = value; }
    3839    }
    3940
     
    4748    }
    4849
    49     protected override void DeregisterObjectEvents() {
    50       ItemCollection.ItemsAdded -= new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsAdded);
    51       ItemCollection.ItemsRemoved -= new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsRemoved);
    52       ItemCollection.CollectionReset -= new CollectionItemsChangedEventHandler<T>(ItemCollection_CollectionReset);
    53       base.DeregisterObjectEvents();
    54     }
    55     protected override void RegisterObjectEvents() {
    56       base.RegisterObjectEvents();
    57       ItemCollection.ItemsAdded += new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsAdded);
    58       ItemCollection.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsRemoved);
    59       ItemCollection.CollectionReset += new CollectionItemsChangedEventHandler<T>(ItemCollection_CollectionReset);
    60     }
    61 
    62     protected override void OnObjectChanged() {
    63       base.OnObjectChanged();
     50    protected override void DeregisterContentEvents() {
     51      Content.ItemsAdded -= new CollectionItemsChangedEventHandler<T>(Content_ItemsAdded);
     52      Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<T>(Content_ItemsRemoved);
     53      Content.CollectionReset -= new CollectionItemsChangedEventHandler<T>(Content_CollectionReset);
     54      base.DeregisterContentEvents();
     55    }
     56    protected override void RegisterContentEvents() {
     57      base.RegisterContentEvents();
     58      Content.ItemsAdded += new CollectionItemsChangedEventHandler<T>(Content_ItemsAdded);
     59      Content.ItemsRemoved += new CollectionItemsChangedEventHandler<T>(Content_ItemsRemoved);
     60      Content.CollectionReset += new CollectionItemsChangedEventHandler<T>(Content_CollectionReset);
     61    }
     62
     63    protected override void OnContentChanged() {
     64      base.OnContentChanged();
    6465      Caption = "Item Collection";
    6566      while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
    6667      itemsListView.Enabled = false;
    6768      detailsGroupBox.Enabled = false;
    68       viewHost.Object = null;
     69      viewHost.Content = null;
    6970      addButton.Enabled = false;
    7071      sortAscendingButton.Enabled = false;
     
    7273      removeButton.Enabled = false;
    7374
    74       if (ItemCollection != null) {
    75         Caption += " (" + ItemCollection.GetType().Name + ")";
     75      if (Content != null) {
     76        Caption += " (" + Content.GetType().Name + ")";
    7677        itemsListView.Enabled = true;
    77         addButton.Enabled = !ItemCollection.IsReadOnly;
    78         foreach (T item in ItemCollection)
     78        addButton.Enabled = !Content.IsReadOnly;
     79        foreach (T item in Content)
    7980          AddListViewItem(CreateListViewItem(item));
    8081        sortAscendingButton.Enabled = itemsListView.Items.Count > 0;
     
    130131    #region ListView Events
    131132    protected virtual void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
    132       removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && !ItemCollection.IsReadOnly;
     133      removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && !Content.IsReadOnly;
    133134      if (itemsListView.SelectedItems.Count == 1) {
    134135        T item = (T)itemsListView.SelectedItems[0].Tag;
    135         viewHost.Object = item;
     136        viewHost.Content = item;
    136137        detailsGroupBox.Enabled = true;
    137138      } else {
    138         viewHost.Object = null;
     139        viewHost.Content = null;
    139140        detailsGroupBox.Enabled = false;
    140141      }
     
    146147    protected virtual void itemsListView_KeyDown(object sender, KeyEventArgs e) {
    147148      if (e.KeyCode == Keys.Delete) {
    148         if ((itemsListView.SelectedItems.Count > 0) && !ItemCollection.IsReadOnly) {
     149        if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly) {
    149150          foreach (ListViewItem item in itemsListView.SelectedItems)
    150             ItemCollection.Remove((T)item.Tag);
     151            Content.Remove((T)item.Tag);
    151152        }
    152153      }
     
    165166      data.SetData("Type", item.GetType());
    166167      data.SetData("Value", item);
    167       if (ItemCollection.IsReadOnly) {
     168      if (Content.IsReadOnly) {
    168169        DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    169170      } else {
    170171        DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    171172        if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    172           ItemCollection.Remove(item);
     173          Content.Remove(item);
    173174      }
    174175    }
     
    176177      e.Effect = DragDropEffects.None;
    177178      Type type = e.Data.GetData("Type") as Type;
    178       if ((!ItemCollection.IsReadOnly) && (type != null) && (typeof(T).IsAssignableFrom(type))) {
     179      if ((!Content.IsReadOnly) && (type != null) && (typeof(T).IsAssignableFrom(type))) {
    179180        if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy;  // CTRL key
    180181        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
     
    188189        T item = e.Data.GetData("Value") as T;
    189190        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    190         ItemCollection.Add(item);
     191        Content.Add(item);
    191192      }
    192193    }
     
    197198      T item = CreateItem();
    198199      if (item != null)
    199         ItemCollection.Add(item);
     200        Content.Add(item);
    200201    }
    201202    protected virtual void sortAscendingButton_Click(object sender, EventArgs e) {
     
    208209      if (itemsListView.SelectedItems.Count > 0) {
    209210        foreach (ListViewItem item in itemsListView.SelectedItems)
    210           ItemCollection.Remove((T)item.Tag);
     211          Content.Remove((T)item.Tag);
    211212        itemsListView.SelectedItems.Clear();
    212213      }
     
    214215    #endregion
    215216
    216     #region ItemCollection Events
    217     protected virtual void ItemCollection_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {
    218       if (InvokeRequired)
    219         Invoke(new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsAdded), sender, e);
     217    #region Content Events
     218    protected virtual void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<T> e) {
     219      if (InvokeRequired)
     220        Invoke(new CollectionItemsChangedEventHandler<T>(Content_ItemsAdded), sender, e);
    220221      else
    221222        foreach (T item in e.Items)
    222223          AddListViewItem(CreateListViewItem(item));
    223224    }
    224     protected virtual void ItemCollection_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) {
    225       if (InvokeRequired)
    226         Invoke(new CollectionItemsChangedEventHandler<T>(ItemCollection_ItemsRemoved), sender, e);
     225    protected virtual void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<T> e) {
     226      if (InvokeRequired)
     227        Invoke(new CollectionItemsChangedEventHandler<T>(Content_ItemsRemoved), sender, e);
    227228      else {
    228229        foreach (T item in e.Items) {
     
    234235      }
    235236    }
    236     protected virtual void ItemCollection_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) {
    237       if (InvokeRequired)
    238         Invoke(new CollectionItemsChangedEventHandler<T>(ItemCollection_CollectionReset), sender, e);
     237    protected virtual void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<T> e) {
     238      if (InvokeRequired)
     239        Invoke(new CollectionItemsChangedEventHandler<T>(Content_CollectionReset), sender, e);
    239240      else {
    240241        foreach (T item in e.OldItems) {
Note: See TracChangeset for help on using the changeset viewer.