Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3838 was 3788, checked in by mkommend, 14 years ago

corrected behavior of CheckedItemCollectionViews (ticket #893)

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