Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Core.Views/3.3/CheckedItemCollectionView.cs @ 9584

Last change on this file since 9584 was 6760, checked in by epitzer, 13 years ago

#1530 integrate changes from trunk

File size: 3.9 KB
RevLine 
[3595]1#region License Information
[3558]2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3558]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
[6760]22using System.Drawing;
[3558]23using System.Windows.Forms;
24using HeuristicLab.Collections;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.Core.Views {
28  [View("CheckedItemCollection View")]
[3628]29  [Content(typeof(ICheckedItemCollection<>), true)]
[3558]30  [Content(typeof(CheckedItemCollection<>), true)]
[3595]31  public partial class CheckedItemCollectionView<T> : ItemCollectionView<T> where T : class, IItem {
[3558]32    public new ICheckedItemCollection<T> Content {
33      get { return (ICheckedItemCollection<T>)base.Content; }
34      set { base.Content = value; }
35    }
[4068]36
[3595]37    public CheckedItemCollectionView()
38      : base() {
39      InitializeComponent();
[3558]40    }
41
[3595]42    protected override void RegisterContentEvents() {
43      Content.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged);
44      base.RegisterContentEvents();
[3558]45    }
46
47    protected override void DeregisterContentEvents() {
[3595]48      Content.CheckedItemsChanged -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged);
[3558]49      base.DeregisterContentEvents();
50    }
51
[6760]52    private Color backupColor = Color.Empty;
[3904]53    protected override void SetEnabledStateOfControls() {
[6760]54      if (backupColor == Color.Empty) backupColor = base.itemsListView.BackColor;
[3904]55      base.SetEnabledStateOfControls();
[6760]56      if (ReadOnly || Locked)
57        base.itemsListView.BackColor = ListView.DefaultBackColor;
58      else
59        base.itemsListView.BackColor = backupColor;
[3558]60    }
61
[3595]62    protected override ListViewItem CreateListViewItem(T item) {
63      ListViewItem listViewItem = base.CreateListViewItem(item);
[3564]64      listViewItem.Checked = Content.ItemChecked(item);
[3558]65      return listViewItem;
66    }
67
68    #region ListView Events
[3788]69    private bool doubleClick;
[3738]70    protected virtual void itemsListView_ItemCheck(object sender, ItemCheckEventArgs e) {
[3788]71      if (doubleClick) {
72        e.NewValue = e.CurrentValue;
73        doubleClick = false;
74      } else {
75        var checkedItem = (T)itemsListView.Items[e.Index].Tag;
76        bool check = e.NewValue == CheckState.Checked;
77        if (Content.ItemChecked(checkedItem) != check) {
[6760]78          if (!ReadOnly && !Locked) Content.SetItemCheckedState(checkedItem, check);
79          else e.NewValue = e.CurrentValue;
[3788]80        }
[3564]81      }
[3558]82    }
[3788]83    protected void itemsListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
84      if (e.Clicks > 1)
85        doubleClick = true;
86    }
[3558]87    #endregion
88
89    #region Content Events
[3595]90    protected virtual void Content_CheckedItemsChanged(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<T> e) {
[3558]91      if (InvokeRequired)
[3595]92        Invoke(new CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged), sender, e);
[3558]93      else {
94        foreach (T item in e.Items) {
95          foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
[3562]96            if (listViewItem.Checked != Content.ItemChecked(item))
97              listViewItem.Checked = Content.ItemChecked(item);
[3558]98          }
99        }
100      }
[4068]101    }
[3558]102    #endregion
103  }
104}
Note: See TracBrowser for help on using the repository browser.