[2746] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[2790] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2746] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Windows.Forms;
|
---|
| 26 | using HeuristicLab.Collections;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[3758] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[2746] | 30 |
|
---|
| 31 | namespace HeuristicLab.Core.Views {
|
---|
| 32 | /// <summary>
|
---|
| 33 | /// The visual representation of all variables in a specified scope.
|
---|
| 34 | /// </summary>
|
---|
[2917] | 35 | [View("ItemArray View")]
|
---|
[2746] | 36 | [Content(typeof(ItemArray<>), true)]
|
---|
[3393] | 37 | [Content(typeof(IItemArray<>), false)]
|
---|
[3483] | 38 | public partial class ItemArrayView<T> : ItemView where T : class, IItem {
|
---|
[3407] | 39 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
| 40 |
|
---|
[2746] | 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>
|
---|
[3393] | 46 | public new IItemArray<T> Content {
|
---|
| 47 | get { return (IItemArray<T>)base.Content; }
|
---|
[2746] | 48 | set { base.Content = value; }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public ListView ItemsListView {
|
---|
| 52 | get { return itemsListView; }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /// <summary>
|
---|
| 56 | /// Initializes a new instance of <see cref="VariablesScopeView"/> with caption "Variables Scope View".
|
---|
| 57 | /// </summary>
|
---|
| 58 | public ItemArrayView() {
|
---|
| 59 | 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>
|
---|
| 66 | protected override void DeregisterContentEvents() {
|
---|
| 67 | Content.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced);
|
---|
| 68 | Content.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
|
---|
| 69 | Content.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
|
---|
[5070] | 70 | foreach (T item in Content) {
|
---|
| 71 | item.ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
|
---|
| 72 | item.ToStringChanged -= new EventHandler(Item_ToStringChanged);
|
---|
| 73 | }
|
---|
[2746] | 74 | base.DeregisterContentEvents();
|
---|
| 75 | }
|
---|
| 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>
|
---|
| 81 | protected override void RegisterContentEvents() {
|
---|
| 82 | base.RegisterContentEvents();
|
---|
| 83 | Content.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced);
|
---|
| 84 | Content.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved);
|
---|
| 85 | Content.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | protected override void OnContentChanged() {
|
---|
| 89 | base.OnContentChanged();
|
---|
[3775] | 90 |
|
---|
| 91 | int selectedIndex = -1;
|
---|
| 92 | if (itemsListView.SelectedItems.Count == 1) selectedIndex = itemsListView.SelectedIndices[0];
|
---|
| 93 |
|
---|
[2746] | 94 | while (itemsListView.Items.Count > 0) RemoveListViewItem(itemsListView.Items[0]);
|
---|
| 95 | viewHost.Content = null;
|
---|
| 96 | if (Content != null) {
|
---|
| 97 | Caption += " (" + Content.GetType().Name + ")";
|
---|
| 98 | foreach (T item in Content)
|
---|
| 99 | AddListViewItem(CreateListViewItem(item));
|
---|
[4240] | 100 | AdjustListViewColumnSizes();
|
---|
[3775] | 101 | if ((selectedIndex != -1) && (selectedIndex < itemsListView.Items.Count))
|
---|
| 102 | itemsListView.Items[selectedIndex].Selected = true;
|
---|
[2746] | 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[3904] | 106 | protected override void SetEnabledStateOfControls() {
|
---|
| 107 | base.SetEnabledStateOfControls();
|
---|
[3362] | 108 | if (Content == null) {
|
---|
| 109 | addButton.Enabled = false;
|
---|
| 110 | moveUpButton.Enabled = false;
|
---|
| 111 | moveDownButton.Enabled = false;
|
---|
| 112 | removeButton.Enabled = false;
|
---|
| 113 | itemsListView.Enabled = false;
|
---|
| 114 | detailsGroupBox.Enabled = false;
|
---|
| 115 | } else {
|
---|
| 116 | addButton.Enabled = itemsListView.SelectedItems.Count > 0 &&
|
---|
[3435] | 117 | !Content.IsReadOnly && !ReadOnly;
|
---|
[3362] | 118 | moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
|
---|
| 119 | itemsListView.SelectedIndices[0] != 0 &&
|
---|
[3435] | 120 | !Content.IsReadOnly && !ReadOnly;
|
---|
[3362] | 121 | moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
|
---|
| 122 | itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 &&
|
---|
[3435] | 123 | !Content.IsReadOnly && !ReadOnly;
|
---|
[3362] | 124 | removeButton.Enabled = itemsListView.SelectedItems.Count > 0 &&
|
---|
[3435] | 125 | !Content.IsReadOnly && !ReadOnly;
|
---|
[3362] | 126 | itemsListView.Enabled = true;
|
---|
[4099] | 127 | detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
|
---|
[3362] | 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[2746] | 131 | protected virtual T CreateItem() {
|
---|
[3407] | 132 | if (typeSelectorDialog == null) {
|
---|
| 133 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
| 134 | typeSelectorDialog.Caption = "Select Item";
|
---|
| 135 | typeSelectorDialog.TypeSelector.Caption = "Available Items";
|
---|
[3588] | 136 | typeSelectorDialog.TypeSelector.Configure(typeof(T), false, true);
|
---|
[2746] | 137 | }
|
---|
[3407] | 138 |
|
---|
| 139 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 140 | try {
|
---|
| 141 | return (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
[5070] | 142 | } catch (Exception ex) {
|
---|
[3758] | 143 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
[3407] | 144 | }
|
---|
[2746] | 145 | }
|
---|
[3407] | 146 | return null;
|
---|
[2746] | 147 | }
|
---|
| 148 | protected virtual ListViewItem CreateListViewItem(T item) {
|
---|
[3341] | 149 | 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;
|
---|
| 155 | return listViewItem;
|
---|
[2746] | 156 | }
|
---|
| 157 | protected virtual void AddListViewItem(ListViewItem listViewItem) {
|
---|
| 158 | itemsListView.Items.Add(listViewItem);
|
---|
[3341] | 159 | if (listViewItem.Tag != null) {
|
---|
| 160 | ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
|
---|
[2932] | 161 | ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
|
---|
[3341] | 162 | }
|
---|
[2746] | 163 | }
|
---|
| 164 | protected virtual void InsertListViewItem(int index, ListViewItem listViewItem) {
|
---|
| 165 | itemsListView.Items.Insert(index, listViewItem);
|
---|
[3341] | 166 | if (listViewItem.Tag != null) {
|
---|
| 167 | ((T)listViewItem.Tag).ItemImageChanged += new EventHandler(Item_ItemImageChanged);
|
---|
[2932] | 168 | ((T)listViewItem.Tag).ToStringChanged += new EventHandler(Item_ToStringChanged);
|
---|
[3341] | 169 | }
|
---|
[2746] | 170 | }
|
---|
| 171 | protected virtual void RemoveListViewItem(ListViewItem listViewItem) {
|
---|
[3341] | 172 | if (listViewItem.Tag != null) {
|
---|
| 173 | ((T)listViewItem.Tag).ItemImageChanged -= new EventHandler(Item_ItemImageChanged);
|
---|
[2932] | 174 | ((T)listViewItem.Tag).ToStringChanged -= new EventHandler(Item_ToStringChanged);
|
---|
[3341] | 175 | }
|
---|
[2746] | 176 | listViewItem.Remove();
|
---|
[3341] | 177 | foreach (ListViewItem other in itemsListView.Items)
|
---|
| 178 | if (other.ImageIndex > listViewItem.ImageIndex) other.ImageIndex--;
|
---|
| 179 | itemsListView.SmallImageList.Images.RemoveAt(listViewItem.ImageIndex);
|
---|
[2746] | 180 | }
|
---|
[3341] | 181 | protected virtual void UpdateListViewItemImage(ListViewItem listViewItem) {
|
---|
[2746] | 182 | T item = listViewItem.Tag as T;
|
---|
[3341] | 183 | int i = listViewItem.ImageIndex;
|
---|
| 184 | listViewItem.ImageList.Images[i] = item == null ? HeuristicLab.Common.Resources.VS2008ImageLibrary.Nothing : item.ItemImage;
|
---|
| 185 | listViewItem.ImageIndex = -1;
|
---|
| 186 | listViewItem.ImageIndex = i;
|
---|
| 187 | }
|
---|
| 188 | protected virtual void UpdateListViewItemText(ListViewItem listViewItem) {
|
---|
| 189 | T item = listViewItem.Tag as T;
|
---|
[2746] | 190 | listViewItem.Text = item == null ? "null" : item.ToString();
|
---|
| 191 | listViewItem.ToolTipText = item == null ? string.Empty : item.ItemName + ": " + item.ItemDescription;
|
---|
| 192 | }
|
---|
| 193 |
|
---|
[3362] | 194 | #region ListView Events
|
---|
[2746] | 195 | protected virtual void itemsListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[3456] | 196 | addButton.Enabled = itemsListView.SelectedItems.Count > 0 && (Content != null) && !Content.IsReadOnly && !ReadOnly;
|
---|
[2746] | 197 | moveUpButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
|
---|
| 198 | itemsListView.SelectedIndices[0] != 0 &&
|
---|
[3456] | 199 | (Content != null) && !Content.IsReadOnly && !ReadOnly;
|
---|
[2746] | 200 | moveDownButton.Enabled = itemsListView.SelectedItems.Count == 1 &&
|
---|
| 201 | itemsListView.SelectedIndices[0] != itemsListView.Items.Count - 1 &&
|
---|
[3456] | 202 | (Content != null) && !Content.IsReadOnly && !ReadOnly;
|
---|
| 203 | removeButton.Enabled = itemsListView.SelectedItems.Count > 0 && (Content != null) && !Content.IsReadOnly && !ReadOnly;
|
---|
[3829] | 204 | AdjustListViewColumnSizes();
|
---|
[2746] | 205 |
|
---|
[4096] | 206 | if (showDetailsCheckBox.Checked) {
|
---|
| 207 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 208 | T item = itemsListView.SelectedItems[0].Tag as T;
|
---|
| 209 | detailsGroupBox.Enabled = true;
|
---|
| 210 | viewHost.Content = item;
|
---|
| 211 | } else {
|
---|
| 212 | viewHost.Content = null;
|
---|
| 213 | detailsGroupBox.Enabled = false;
|
---|
| 214 | }
|
---|
[2746] | 215 | }
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | protected virtual void itemsListView_KeyDown(object sender, KeyEventArgs e) {
|
---|
| 219 | if (e.KeyCode == Keys.Delete) {
|
---|
[3435] | 220 | if ((itemsListView.SelectedItems.Count > 0) && !Content.IsReadOnly && !ReadOnly) {
|
---|
[2746] | 221 | foreach (ListViewItem item in itemsListView.SelectedItems)
|
---|
| 222 | Content[item.Index] = null;
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | protected virtual void itemsListView_DoubleClick(object sender, EventArgs e) {
|
---|
| 228 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 229 | T item = itemsListView.SelectedItems[0].Tag as T;
|
---|
| 230 | if (item != null) {
|
---|
[3557] | 231 | IContentView view = MainFormManager.MainForm.ShowContent(item);
|
---|
[3416] | 232 | if (view != null) {
|
---|
| 233 | view.ReadOnly = ReadOnly;
|
---|
[3423] | 234 | view.Locked = Locked;
|
---|
[3416] | 235 | }
|
---|
[2746] | 236 | }
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
| 239 |
|
---|
| 240 | protected virtual void itemsListView_ItemDrag(object sender, ItemDragEventArgs e) {
|
---|
[3432] | 241 | if (!Locked) {
|
---|
| 242 | ListViewItem listViewItem = (ListViewItem)e.Item;
|
---|
| 243 | T item = listViewItem.Tag as T;
|
---|
| 244 | if (item != null) {
|
---|
| 245 | DataObject data = new DataObject();
|
---|
| 246 | data.SetData("Type", item.GetType());
|
---|
| 247 | data.SetData("Value", item);
|
---|
[3435] | 248 | if (Content.IsReadOnly || ReadOnly) {
|
---|
[3432] | 249 | DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
|
---|
| 250 | } else {
|
---|
| 251 | DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
|
---|
| 252 | if ((result & DragDropEffects.Move) == DragDropEffects.Move)
|
---|
| 253 | Content[listViewItem.Index] = null;
|
---|
| 254 | }
|
---|
[2746] | 255 | }
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 | protected virtual void itemsListView_DragEnterOver(object sender, DragEventArgs e) {
|
---|
| 259 | e.Effect = DragDropEffects.None;
|
---|
| 260 | Type type = e.Data.GetData("Type") as Type;
|
---|
[3435] | 261 | if (!Content.IsReadOnly && !ReadOnly && (type != null) && (typeof(T).IsAssignableFrom(type))) {
|
---|
[2746] | 262 | Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
|
---|
| 263 | ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
|
---|
| 264 | if (listViewItem != null) {
|
---|
[3694] | 265 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
[2746] | 266 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
| 267 | else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
|
---|
| 268 | else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
|
---|
[3526] | 269 | else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
|
---|
[2746] | 270 | }
|
---|
| 271 | }
|
---|
| 272 | }
|
---|
| 273 | protected virtual void itemsListView_DragDrop(object sender, DragEventArgs e) {
|
---|
| 274 | if (e.Effect != DragDropEffects.None) {
|
---|
| 275 | T item = e.Data.GetData("Value") as T;
|
---|
| 276 | if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
|
---|
| 277 |
|
---|
| 278 | Point p = itemsListView.PointToClient(new Point(e.X, e.Y));
|
---|
| 279 | ListViewItem listViewItem = itemsListView.GetItemAt(p.X, p.Y);
|
---|
| 280 | Content[listViewItem.Index] = item;
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
| 283 | #endregion
|
---|
| 284 |
|
---|
| 285 | #region Button Events
|
---|
[3341] | 286 | protected virtual void addButton_Click(object sender, EventArgs e) {
|
---|
| 287 | if (itemsListView.SelectedItems.Count > 0) {
|
---|
| 288 | T item = CreateItem();
|
---|
| 289 | if (item != null) {
|
---|
| 290 | foreach (ListViewItem listViewItem in itemsListView.SelectedItems)
|
---|
| 291 | Content[listViewItem.Index] = item;
|
---|
| 292 | }
|
---|
| 293 | }
|
---|
| 294 | }
|
---|
[2746] | 295 | protected virtual void moveUpButton_Click(object sender, EventArgs e) {
|
---|
| 296 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 297 | int index = itemsListView.SelectedIndices[0];
|
---|
| 298 | T item = Content[index - 1];
|
---|
| 299 | Content[index - 1] = Content[index];
|
---|
| 300 | itemsListView.Items[index].Selected = false;
|
---|
| 301 | itemsListView.Items[index - 1].Selected = true;
|
---|
| 302 | Content[index] = item;
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 | protected virtual void moveDownButton_Click(object sender, EventArgs e) {
|
---|
| 306 | if (itemsListView.SelectedItems.Count == 1) {
|
---|
| 307 | int index = itemsListView.SelectedIndices[0];
|
---|
| 308 | T item = Content[index + 1];
|
---|
| 309 | Content[index + 1] = Content[index];
|
---|
| 310 | itemsListView.Items[index].Selected = false;
|
---|
| 311 | itemsListView.Items[index + 1].Selected = true;
|
---|
| 312 | Content[index] = item;
|
---|
| 313 | }
|
---|
| 314 | }
|
---|
[3341] | 315 | protected virtual void removeButton_Click(object sender, EventArgs e) {
|
---|
| 316 | if (itemsListView.SelectedItems.Count > 0) {
|
---|
| 317 | foreach (ListViewItem item in itemsListView.SelectedItems)
|
---|
| 318 | Content[item.Index] = null;
|
---|
| 319 | }
|
---|
| 320 | }
|
---|
[2746] | 321 | #endregion
|
---|
| 322 |
|
---|
[4096] | 323 | #region CheckBox Events
|
---|
| 324 | protected virtual void showDetailsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 325 | if (showDetailsCheckBox.Checked) {
|
---|
| 326 | splitContainer.Panel2Collapsed = false;
|
---|
| 327 | detailsGroupBox.Enabled = itemsListView.SelectedItems.Count == 1;
|
---|
| 328 | viewHost.Content = itemsListView.SelectedItems.Count == 1 ? (T)itemsListView.SelectedItems[0].Tag : null;
|
---|
| 329 | } else {
|
---|
| 330 | splitContainer.Panel2Collapsed = true;
|
---|
| 331 | viewHost.Content = null;
|
---|
| 332 | }
|
---|
| 333 | }
|
---|
| 334 | #endregion
|
---|
| 335 |
|
---|
[2746] | 336 | #region Content Events
|
---|
| 337 | protected virtual void Content_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
|
---|
| 338 | if (InvokeRequired)
|
---|
| 339 | Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsReplaced), sender, e);
|
---|
| 340 | else {
|
---|
| 341 | int[] selected = new int[itemsListView.SelectedIndices.Count];
|
---|
| 342 | itemsListView.SelectedIndices.CopyTo(selected, 0);
|
---|
| 343 |
|
---|
| 344 | List<ListViewItem> listViewItems = new List<ListViewItem>();
|
---|
| 345 | foreach (IndexedItem<T> item in e.OldItems)
|
---|
| 346 | listViewItems.Add(itemsListView.Items[item.Index]);
|
---|
| 347 | foreach (ListViewItem listViewItem in listViewItems)
|
---|
| 348 | RemoveListViewItem(listViewItem);
|
---|
| 349 |
|
---|
| 350 | foreach (IndexedItem<T> item in e.Items)
|
---|
| 351 | InsertListViewItem(item.Index, CreateListViewItem(item.Value));
|
---|
[4240] | 352 | AdjustListViewColumnSizes();
|
---|
[2746] | 353 |
|
---|
| 354 | for (int i = 0; i < selected.Length; i++)
|
---|
| 355 | itemsListView.Items[selected[i]].Selected = true;
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | protected virtual void Content_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
|
---|
| 359 | if (InvokeRequired)
|
---|
| 360 | Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_ItemsMoved), sender, e);
|
---|
| 361 | else {
|
---|
| 362 | foreach (IndexedItem<T> item in e.Items) {
|
---|
| 363 | ListViewItem listViewItem = itemsListView.Items[item.Index];
|
---|
| 364 | listViewItem.Tag = item.Value;
|
---|
[3341] | 365 | UpdateListViewItemImage(listViewItem);
|
---|
| 366 | UpdateListViewItemText(listViewItem);
|
---|
[2746] | 367 | }
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 | protected virtual void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
|
---|
| 371 | if (InvokeRequired)
|
---|
| 372 | Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CollectionReset), sender, e);
|
---|
| 373 | else {
|
---|
| 374 | List<ListViewItem> listViewItems = new List<ListViewItem>();
|
---|
| 375 | foreach (IndexedItem<T> item in e.OldItems)
|
---|
| 376 | listViewItems.Add(itemsListView.Items[item.Index]);
|
---|
| 377 | foreach (ListViewItem listViewItem in listViewItems)
|
---|
| 378 | RemoveListViewItem(listViewItem);
|
---|
| 379 |
|
---|
| 380 | foreach (IndexedItem<T> item in e.Items)
|
---|
| 381 | InsertListViewItem(item.Index, CreateListViewItem(item.Value));
|
---|
[4240] | 382 | AdjustListViewColumnSizes();
|
---|
[2746] | 383 | }
|
---|
| 384 | }
|
---|
| 385 | #endregion
|
---|
| 386 |
|
---|
| 387 | #region Item Events
|
---|
[3341] | 388 | protected virtual void Item_ItemImageChanged(object sender, EventArgs e) {
|
---|
| 389 | if (InvokeRequired)
|
---|
| 390 | Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
|
---|
| 391 | else {
|
---|
| 392 | T item = (T)sender;
|
---|
| 393 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 394 | if (((T)listViewItem.Tag) == item)
|
---|
| 395 | UpdateListViewItemImage(listViewItem);
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
[2932] | 399 | protected virtual void Item_ToStringChanged(object sender, EventArgs e) {
|
---|
[2746] | 400 | if (InvokeRequired)
|
---|
[2932] | 401 | Invoke(new EventHandler(Item_ToStringChanged), sender, e);
|
---|
[2746] | 402 | else {
|
---|
| 403 | T item = (T)sender;
|
---|
| 404 | foreach (ListViewItem listViewItem in itemsListView.Items) {
|
---|
| 405 | if (((T)listViewItem.Tag) == item)
|
---|
[3341] | 406 | UpdateListViewItemText(listViewItem);
|
---|
[2746] | 407 | }
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | #endregion
|
---|
[3362] | 411 |
|
---|
| 412 | #region Helpers
|
---|
| 413 | protected virtual void AdjustListViewColumnSizes() {
|
---|
| 414 | if (itemsListView.Items.Count > 0) {
|
---|
| 415 | for (int i = 0; i < itemsListView.Columns.Count; i++)
|
---|
| 416 | itemsListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
| 417 | }
|
---|
| 418 | }
|
---|
| 419 | #endregion
|
---|
[2746] | 420 | }
|
---|
| 421 | }
|
---|