[12379] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2015 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.Collections.Generic;
|
---|
| 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Core.Views;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Optimization.BubbleChart {
|
---|
| 29 | [View("RecursiveDataItem View")]
|
---|
[12880] | 30 | [Content(typeof(RecursiveDataItem), false)]
|
---|
[12379] | 31 | public partial class RecursiveDataItemView : NamedItemView {
|
---|
| 32 |
|
---|
| 33 | public new RecursiveDataItem Content {
|
---|
| 34 | get { return (RecursiveDataItem)base.Content; }
|
---|
| 35 | set { base.Content = value; }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public RecursiveDataItemView() {
|
---|
| 39 | InitializeComponent();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | protected override void OnContentChanged() {
|
---|
[12381] | 43 | base.OnContentChanged();
|
---|
| 44 |
|
---|
| 45 | listView.Items.Clear();
|
---|
| 46 | treeView.Nodes.Clear();
|
---|
[12379] | 47 | viewHost.Content = null;
|
---|
| 48 |
|
---|
| 49 | if (Content != null) {
|
---|
| 50 | foreach (var data in Content.Data) {
|
---|
| 51 | listView.Items.Add(CreateListViewItem(data));
|
---|
| 52 | }
|
---|
[12381] | 53 | for (int i = 0; i < listView.Columns.Count; i++)
|
---|
| 54 | listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
[12388] | 55 |
|
---|
[12381] | 56 | foreach (var dataItem in Content.Children) {
|
---|
| 57 | treeView.Nodes.Add(CreateTreeNode(dataItem));
|
---|
| 58 | }
|
---|
[12388] | 59 | treeView.ExpandAll();
|
---|
[12379] | 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | protected override void SetEnabledStateOfControls() {
|
---|
| 64 | base.SetEnabledStateOfControls();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | private ListViewItem CreateListViewItem(KeyValuePair<string, IItem> data) {
|
---|
[12381] | 68 | return new ListViewItem(new[] { data.Key, data.Value != null ? data.Value.ToString() : "-" }) {
|
---|
[12379] | 69 | Tag = data.Value
|
---|
| 70 | };
|
---|
| 71 | }
|
---|
[12381] | 72 | private TreeNode CreateTreeNode(RecursiveDataItem dataItem) {
|
---|
| 73 | var node = new TreeNode(dataItem.Name) {
|
---|
| 74 | Tag = dataItem
|
---|
| 75 | };
|
---|
| 76 | foreach (var child in dataItem.Children) {
|
---|
| 77 | node.Nodes.Add(CreateTreeNode(child));
|
---|
| 78 | }
|
---|
| 79 | return node;
|
---|
| 80 | }
|
---|
[12379] | 81 |
|
---|
| 82 | private void listView_SelectedIndexChanged(object sender, System.EventArgs e) {
|
---|
| 83 | if (listView.SelectedItems.Count == 1) {
|
---|
| 84 | var item = (IItem)listView.SelectedItems[0].Tag;
|
---|
| 85 | viewHost.Content = item;
|
---|
| 86 | } else {
|
---|
| 87 | viewHost.Content = null;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[12381] | 90 | private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
|
---|
| 91 | var dataItem = (RecursiveDataItem)e.Node.Tag;
|
---|
| 92 | viewHost.Content = dataItem;
|
---|
| 93 | }
|
---|
[12379] | 94 | }
|
---|
| 95 | }
|
---|