1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2014 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 HeuristicLab.Collections;
|
---|
23 | using HeuristicLab.Core.Views;
|
---|
24 | using HeuristicLab.MainForm;
|
---|
25 | using System.Windows.Forms;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Core.Networks.Views {
|
---|
28 | [View("MessageValueCollection View")]
|
---|
29 | [Content(typeof(MessageValueCollection), true)]
|
---|
30 | [Content(typeof(IKeyedItemCollection<string, IMessageValue>), false)]
|
---|
31 | public partial class MessageValueCollectionView : ItemCollectionView<IMessageValue> {
|
---|
32 | public new IKeyedItemCollection<string, IMessageValue> Content {
|
---|
33 | get { return (IKeyedItemCollection<string, IMessageValue>)base.Content; }
|
---|
34 | set { base.Content = value; }
|
---|
35 | }
|
---|
36 |
|
---|
37 | public MessageValueCollectionView() {
|
---|
38 | InitializeComponent();
|
---|
39 | itemsGroupBox.Text = "Message Values";
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override void DeregisterContentEvents() {
|
---|
43 | Content.ItemsReplaced -= new CollectionItemsChangedEventHandler<IMessageValue>(Content_ItemsReplaced);
|
---|
44 | base.DeregisterContentEvents();
|
---|
45 | }
|
---|
46 | protected override void RegisterContentEvents() {
|
---|
47 | base.RegisterContentEvents();
|
---|
48 | Content.ItemsReplaced += new CollectionItemsChangedEventHandler<IMessageValue>(Content_ItemsReplaced);
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected override void OnContentChanged() {
|
---|
52 | string selectedName = null;
|
---|
53 | if ((itemsListView.SelectedItems.Count == 1) && (itemsListView.SelectedItems[0].Tag != null &&
|
---|
54 | itemsListView.SelectedItems[0].Tag is IMessageValue))
|
---|
55 | selectedName = ((IMessageValue)itemsListView.SelectedItems[0].Tag).Name;
|
---|
56 | base.OnContentChanged();
|
---|
57 | if (selectedName != null) {
|
---|
58 | foreach (ListViewItem item in itemsListView.Items) {
|
---|
59 | if ((item.Tag != null) && (((IMessageValue)item.Tag).Name.Equals(selectedName)))
|
---|
60 | item.Selected = true;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | #region Content Events
|
---|
66 | protected virtual void Content_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IMessageValue> e) {
|
---|
67 | if (InvokeRequired)
|
---|
68 | Invoke(new CollectionItemsChangedEventHandler<IMessageValue>(Content_ItemsReplaced), sender, e);
|
---|
69 | else {
|
---|
70 | foreach (IMessageValue value in e.Items) {
|
---|
71 | foreach (ListViewItem listViewItem in GetListViewItemsForItem(value))
|
---|
72 | UpdateListViewItemText(listViewItem);
|
---|
73 | }
|
---|
74 | AdjustListViewColumnSizes();
|
---|
75 | }
|
---|
76 | }
|
---|
77 | #endregion
|
---|
78 | }
|
---|
79 | }
|
---|