Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/CheckedItemCollectionView.cs @ 4857

Last change on this file since 4857 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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