Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/ItemTreeView.cs @ 5637

Last change on this file since 5637 was 5637, checked in by cneumuel, 12 years ago

#1233

  • added treeview for hive jobs in experiment manager
File size: 3.3 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.Windows.Forms;
23using HeuristicLab.Common;
24using HeuristicLab.Core.Views;
25using HeuristicLab.MainForm;
26using HeuristicLab.MainForm.WindowsForms;
27
28namespace HeuristicLab.Clients.Hive.Views {
29  [View("ItemTree View")]
30  [Content(typeof(IItemTree), IsDefaultView = false)]
31  public sealed partial class ItemTreeView : ItemView {
32    public new IItemTree Content {
33      get { return (IItemTree)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public ItemTreeView() {
38      InitializeComponent();
39    }
40
41    protected override void DeregisterContentEvents() {
42      // Deregister your event handlers here
43      base.DeregisterContentEvents();
44    }
45
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      // Register your event handlers here
49    }
50
51    #region Event Handlers (Content)
52    // Put event handlers of the content here
53    #endregion
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        // Add code when content has been changed and is null
59        treeView.Nodes.Clear();
60      } else {
61        // Add code when content has been changed and is not null
62        treeView.Nodes.Clear();
63        AddChildNodes(Content, treeView.Nodes);
64      }
65    }
66
67    private void AddChildNodes(IItemTree item, TreeNodeCollection nodes) {
68      var node = CreateTreeViewNode(item);
69      nodes.Add(node);
70      var childItems = item.GetChildNodes();
71      foreach (var childItem in childItems) {       
72        AddChildNodes(childItem, node.Nodes);
73      }
74    }
75
76    private TreeNode CreateTreeViewNode(IItemTree item) {
77      var node = new TreeNode(item.ToString());
78      node.Tag = item;
79      if (!treeView.ImageList.Images.ContainsKey(item.ItemImage.GetHashCode().ToString())) {
80        treeView.ImageList.Images.Add(item.ItemImage.GetHashCode().ToString(), item.ItemImage);
81      }
82      node.ImageKey = item.ItemImage.GetHashCode().ToString();
83      return node;
84    }
85
86    protected override void SetEnabledStateOfControls() {
87      base.SetEnabledStateOfControls();
88      // Enable or disable controls based on whether the content is null or the view is set readonly
89    }
90
91    #region Event Handlers (child controls)
92    // Put event handlers of child controls here.
93    private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
94      viewHost.Content = (IContent)treeView.SelectedNode.Tag;
95    }
96    #endregion
97
98
99  }
100}
Note: See TracBrowser for help on using the repository browser.