Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3611 was 3595, checked in by gkronber, 15 years ago

Changed CheckedItemCollectionView and CheckedItemListView to extend from ItemCollectionView and ItemListView. #992 (CheckedItemList and CheckedItemCollection is necessary)

File size: 3.4 KB
Line 
1#region License Information
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;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Collections;
31using HeuristicLab.MainForm;
32
33namespace HeuristicLab.Core.Views {
34  [View("CheckedItemCollection View")]
35  [Content(typeof(ICheckedItemCollection<>), false)]
36  [Content(typeof(CheckedItemCollection<>), true)]
37  public partial class CheckedItemCollectionView<T> : ItemCollectionView<T> where T : class, IItem {
38    public new ICheckedItemCollection<T> Content {
39      get { return (ICheckedItemCollection<T>)base.Content; }
40      set { base.Content = value; }
41    }
42   
43    public CheckedItemCollectionView()
44      : base() {
45      InitializeComponent();
46    }
47
48    protected override void RegisterContentEvents() {
49      Content.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged);
50      base.RegisterContentEvents();
51    }
52
53    protected override void DeregisterContentEvents() {
54      Content.CheckedItemsChanged -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged);
55      base.DeregisterContentEvents();
56    }
57
58    protected override void OnContentChanged() {
59      Caption = "Checked Item Collection";
60      base.OnContentChanged();
61    }
62
63    protected override ListViewItem CreateListViewItem(T item) {
64      ListViewItem listViewItem = base.CreateListViewItem(item);
65      listViewItem.Checked = Content.ItemChecked(item);
66      return listViewItem;
67    }
68
69    #region ListView Events
70    protected virtual void itemsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
71      var checkedItem = (T)e.Item.Tag;
72      if (Content.ItemChecked(checkedItem) != e.Item.Checked) {
73        Content.SetItemCheckedState(checkedItem, e.Item.Checked);
74      }
75    }
76    #endregion
77
78    #region Content Events
79    protected virtual void Content_CheckedItemsChanged(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<T> e) {
80      if (InvokeRequired)
81        Invoke(new CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged), sender, e);
82      else {
83        foreach (T item in e.Items) {
84          foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
85            if (listViewItem.Checked != Content.ItemChecked(item))
86              listViewItem.Checked = Content.ItemChecked(item);
87          }
88        }
89      }
90    }     
91    #endregion
92  }
93}
Note: See TracBrowser for help on using the repository browser.