source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/TreeView/HiveJobItemTreeView.cs @ 6382

Last change on this file since 6382 was 6382, checked in by cneumuel, 8 years ago

#1233

  • added missing files
File size: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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;
23using System.Collections.Generic;
24using System.Windows.Forms;
25using HeuristicLab.Clients.Hive.Jobs;
26using HeuristicLab.Clients.Hive.Views.ExperimentManager.TreeView;
27using HeuristicLab.Core;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.Optimization;
31
32namespace HeuristicLab.Clients.Hive.Views.ExperimentManager {
33  [View("HiveJob ItemTreeView")]
34  [Content(typeof(ItemCollection<HiveJob>), IsDefaultView = false)]
35  public partial class HiveJobItemTreeView : ItemTreeView<HiveJob> {
36    public new ItemCollection<HiveJob> Content {
37      get { return (ItemCollection<HiveJob>)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public HiveJobItemTreeView() {
42      InitializeComponent();
43    }
44
45    #region Register Content Events
46    protected override void DeregisterContentEvents() {
47      // TODO: Deregister your event handlers on the Content here
48      base.DeregisterContentEvents();
49    }
50    protected override void RegisterContentEvents() {
51      base.RegisterContentEvents();
52      // TODO: Register your event handlers on the Content here
53    }
54    #endregion
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      if (Content == null) {
59        // TODO: Put code here when content is null
60      } else {
61        // TODO: Put code here when content has been changed and is not null
62      }
63    }
64
65    protected override void SetEnabledStateOfControls() {
66      base.SetEnabledStateOfControls();
67      // TODO: Put code here to enable or disable controls based on whether the Content is/not null or the view is ReadOnly
68    }
69
70    #region Event Handlers
71    // TODO: Put event handlers here
72    #endregion
73
74    #region Child Control Events
75    protected override void addButton_Click(object sender, EventArgs e) {
76      IOptimizer optimizer = CreateItem<IOptimizer>();
77      if (optimizer != null) {
78        if (treeView.SelectedNode == null) {
79          Content.Add(new OptimizerHiveJob(optimizer));
80        } else {
81          var experiment = ((HiveJob)treeView.SelectedNode.Tag).ItemJob.Item as Experiment;
82          if (experiment != null) {
83            experiment.Optimizers.Add(optimizer);
84          }
85        }
86      }
87    }
88
89    protected override void removeButton_Click(object sender, EventArgs e) {
90      if (treeView.SelectedNode != null) {
91        var selectedItem = (HiveJob)treeView.SelectedNode.Tag;
92        var parentItem = GetParentItem(selectedItem);
93        if (parentItem == null) {
94          Content.Remove((HiveJob)treeView.SelectedNode.Tag);
95        } else {
96          var experiment = parentItem.ItemJob.Item as Experiment;
97          if (experiment != null) {
98            experiment.Optimizers.Remove(((OptimizerJob)selectedItem.ItemJob).Item);
99          }
100        }       
101      }
102    }
103    #endregion
104
105    protected override ICollection<IItemTreeNodeAction<HiveJob>> GetTreeNodeItemActions(HiveJob selectedItem) {
106      var actions = base.GetTreeNodeItemActions(selectedItem);
107      if (selectedItem != null) {
108        if (selectedItem.ItemJob.Item is Experiment) {
109
110        }
111        actions.Add(new DeleteJobTreeNodeAction(Content));
112      }
113     
114      return actions;
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.