- Timestamp:
- 01/29/10 01:44:57 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/ItemCollectionView.cs
r2708 r2713 30 30 using HeuristicLab.Common; 31 31 using HeuristicLab.MainForm; 32 using HeuristicLab.MainForm.WindowsForms; 32 33 33 34 namespace 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; } 38 39 } 39 40 … … 47 48 } 48 49 49 protected override void Deregister ObjectEvents() {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.Deregister ObjectEvents();54 } 55 protected override void Register ObjectEvents() {56 base.Register ObjectEvents();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 On ObjectChanged() {63 base.On ObjectChanged();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(); 64 65 Caption = "Item Collection"; 65 66 while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]); 66 67 itemsListView.Enabled = false; 67 68 detailsGroupBox.Enabled = false; 68 viewHost. Object = null;69 viewHost.Content = null; 69 70 addButton.Enabled = false; 70 71 sortAscendingButton.Enabled = false; … … 72 73 removeButton.Enabled = false; 73 74 74 if ( ItemCollection!= null) {75 Caption += " (" + ItemCollection.GetType().Name + ")";75 if (Content != null) { 76 Caption += " (" + Content.GetType().Name + ")"; 76 77 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) 79 80 AddListViewItem(CreateListViewItem(item)); 80 81 sortAscendingButton.Enabled = itemsListView.Items.Count > 0; … … 130 131 #region ListView Events 131 132 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; 133 134 if (itemsListView.SelectedItems.Count == 1) { 134 135 T item = (T)itemsListView.SelectedItems[0].Tag; 135 viewHost. Object = item;136 viewHost.Content = item; 136 137 detailsGroupBox.Enabled = true; 137 138 } else { 138 viewHost. Object = null;139 viewHost.Content = null; 139 140 detailsGroupBox.Enabled = false; 140 141 } … … 146 147 protected virtual void itemsListView_KeyDown(object sender, KeyEventArgs e) { 147 148 if (e.KeyCode == Keys.Delete) { 148 if ((itemsListView.SelectedItems.Count > 0) && ! ItemCollection.IsReadOnly) {149 if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly) { 149 150 foreach (ListViewItem item in itemsListView.SelectedItems) 150 ItemCollection.Remove((T)item.Tag);151 Content.Remove((T)item.Tag); 151 152 } 152 153 } … … 165 166 data.SetData("Type", item.GetType()); 166 167 data.SetData("Value", item); 167 if ( ItemCollection.IsReadOnly) {168 if (Content.IsReadOnly) { 168 169 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 169 170 } else { 170 171 DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 171 172 if ((result & DragDropEffects.Move) == DragDropEffects.Move) 172 ItemCollection.Remove(item);173 Content.Remove(item); 173 174 } 174 175 } … … 176 177 e.Effect = DragDropEffects.None; 177 178 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))) { 179 180 if ((e.KeyState & 8) == 8) e.Effect = DragDropEffects.Copy; // CTRL key 180 181 else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key … … 188 189 T item = e.Data.GetData("Value") as T; 189 190 if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone(); 190 ItemCollection.Add(item);191 Content.Add(item); 191 192 } 192 193 } … … 197 198 T item = CreateItem(); 198 199 if (item != null) 199 ItemCollection.Add(item);200 Content.Add(item); 200 201 } 201 202 protected virtual void sortAscendingButton_Click(object sender, EventArgs e) { … … 208 209 if (itemsListView.SelectedItems.Count > 0) { 209 210 foreach (ListViewItem item in itemsListView.SelectedItems) 210 ItemCollection.Remove((T)item.Tag);211 Content.Remove((T)item.Tag); 211 212 itemsListView.SelectedItems.Clear(); 212 213 } … … 214 215 #endregion 215 216 216 #region ItemCollectionEvents217 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); 220 221 else 221 222 foreach (T item in e.Items) 222 223 AddListViewItem(CreateListViewItem(item)); 223 224 } 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); 227 228 else { 228 229 foreach (T item in e.Items) { … … 234 235 } 235 236 } 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); 239 240 else { 240 241 foreach (T item in e.OldItems) {
Note: See TracChangeset
for help on using the changeset viewer.