[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[3595] | 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
[3558] | 27 | using System.Linq;
|
---|
[3595] | 28 | using System.Text;
|
---|
[3558] | 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Collections;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Core.Views {
|
---|
| 34 | [View("CheckedItemCollection View")]
|
---|
[3564] | 35 | [Content(typeof(ICheckedItemCollection<>), false)]
|
---|
[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() {
|
---|
[3595] | 59 | Caption = "Checked Item Collection";
|
---|
[3558] | 60 | base.OnContentChanged();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[3595] | 63 | protected override ListViewItem CreateListViewItem(T item) {
|
---|
| 64 | ListViewItem listViewItem = base.CreateListViewItem(item);
|
---|
[3564] | 65 | listViewItem.Checked = Content.ItemChecked(item);
|
---|
[3558] | 66 | return listViewItem;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | #region ListView Events
|
---|
[3595] | 70 | protected virtual void itemsListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
|
---|
[3564] | 71 | var checkedItem = (T)e.Item.Tag;
|
---|
| 72 | if (Content.ItemChecked(checkedItem) != e.Item.Checked) {
|
---|
| 73 | Content.SetItemCheckedState(checkedItem, e.Item.Checked);
|
---|
| 74 | }
|
---|
[3558] | 75 | }
|
---|
| 76 | #endregion
|
---|
| 77 |
|
---|
| 78 | #region Content Events
|
---|
[3595] | 79 | protected virtual void Content_CheckedItemsChanged(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<T> e) {
|
---|
[3558] | 80 | if (InvokeRequired)
|
---|
[3595] | 81 | Invoke(new CollectionItemsChangedEventHandler<T>(Content_CheckedItemsChanged), sender, e);
|
---|
[3558] | 82 | else {
|
---|
| 83 | foreach (T item in e.Items) {
|
---|
| 84 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(item)) {
|
---|
[3562] | 85 | if (listViewItem.Checked != Content.ItemChecked(item))
|
---|
| 86 | listViewItem.Checked = Content.ItemChecked(item);
|
---|
[3558] | 87 | }
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[3595] | 90 | }
|
---|
[3558] | 91 | #endregion
|
---|
| 92 | }
|
---|
| 93 | }
|
---|