#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System.Collections.Generic;
using System.Windows.Forms;
using HeuristicLab.Core;
using HeuristicLab.Core.Views;
using HeuristicLab.MainForm;
namespace HeuristicLab.Optimization.BubbleChart {
[View("RecursiveDataItem View")]
[Content(typeof(RecursiveDataItem), false)]
public partial class RecursiveDataItemView : NamedItemView {
public new RecursiveDataItem Content {
get { return (RecursiveDataItem)base.Content; }
set { base.Content = value; }
}
public RecursiveDataItemView() {
InitializeComponent();
}
protected override void OnContentChanged() {
base.OnContentChanged();
listView.Items.Clear();
treeView.Nodes.Clear();
viewHost.Content = null;
if (Content != null) {
foreach (var data in Content.Data) {
listView.Items.Add(CreateListViewItem(data));
}
for (int i = 0; i < listView.Columns.Count; i++)
listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
foreach (var dataItem in Content.Children) {
treeView.Nodes.Add(CreateTreeNode(dataItem));
}
treeView.ExpandAll();
}
}
protected override void SetEnabledStateOfControls() {
base.SetEnabledStateOfControls();
}
private ListViewItem CreateListViewItem(KeyValuePair data) {
return new ListViewItem(new[] { data.Key, data.Value != null ? data.Value.ToString() : "-" }) {
Tag = data.Value
};
}
private TreeNode CreateTreeNode(RecursiveDataItem dataItem) {
var node = new TreeNode(dataItem.Name) {
Tag = dataItem
};
foreach (var child in dataItem.Children) {
node.Nodes.Add(CreateTreeNode(child));
}
return node;
}
private void listView_SelectedIndexChanged(object sender, System.EventArgs e) {
if (listView.SelectedItems.Count == 1) {
var item = (IItem)listView.SelectedItems[0].Tag;
viewHost.Content = item;
} else {
viewHost.Content = null;
}
}
private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
var dataItem = (RecursiveDataItem)e.Node.Tag;
viewHost.Content = dataItem;
}
}
}