Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/AlgorithmServiceNodeView.cs @ 11463

Last change on this file since 11463 was 11463, checked in by swagner, 10 years ago

#2205: Worked on optimization networks

File size: 5.2 KB
Line 
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
22using HeuristicLab.Core.Views;
23using HeuristicLab.MainForm;
24using HeuristicLab.PluginInfrastructure;
25using System;
26using System.Windows.Forms;
27
28namespace HeuristicLab.Optimization.Networks.Views {
29  [View("AlgorithmServiceNode View")]
30  [Content(typeof(AlgorithmServiceNode), true)]
31  [Content(typeof(IAlgorithmServiceNode), false)]
32  public partial class AlgorithmServiceNodeView : EntityView {
33    protected TypeSelectorDialog typeSelectorDialog;
34
35    public new IAlgorithmServiceNode Content {
36      get { return (IAlgorithmServiceNode)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public AlgorithmServiceNodeView() {
41      InitializeComponent();
42    }
43
44    protected override void Dispose(bool disposing) {
45      if (disposing) {
46        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
47        if (components != null) components.Dispose();
48      }
49      base.Dispose(disposing);
50    }
51
52    protected override void DeregisterContentEvents() {
53      Content.TemplateChanged -= Content_TemplateChanged;
54      base.DeregisterContentEvents();
55    }
56    protected override void RegisterContentEvents() {
57      base.RegisterContentEvents();
58      Content.TemplateChanged += Content_TemplateChanged;
59    }
60
61    protected override void OnContentChanged() {
62      base.OnContentChanged();
63      if (Content == null) {
64        portCollectionView.Content = null;
65        templateViewHost.Content = null;
66        runCollectionView.Content = null;
67      } else {
68        portCollectionView.Content = Content.Ports;
69        templateViewHost.ViewType = null;
70        templateViewHost.Content = Content.Template;
71        runCollectionView.Content = Content.Runs;
72      }
73    }
74
75    protected override void SetEnabledStateOfControls() {
76      base.SetEnabledStateOfControls();
77      portCollectionView.Enabled = Content != null && !ReadOnly;
78      setTemplateButton.Enabled = Content != null && !ReadOnly;
79      clearTemplateButton.Enabled = Content != null && Content.Template != null && !ReadOnly;
80      templatePanel.Enabled = Content != null;
81      runCollectionView.Enabled = Content != null && !ReadOnly;
82    }
83
84    protected virtual void Content_TemplateChanged(object sender, System.EventArgs e) {
85      if (InvokeRequired)
86        Invoke(new EventHandler(Content_TemplateChanged), sender, e);
87      else {
88        clearTemplateButton.Enabled = Content.Template != null && !ReadOnly;
89        templateViewHost.ViewType = null;
90        templateViewHost.Content = Content.Template;
91      }
92    }
93
94    protected virtual void setTemplateButton_Click(object sender, EventArgs e) {
95      if (typeSelectorDialog == null) {
96        typeSelectorDialog = new TypeSelectorDialog();
97        typeSelectorDialog.Caption = "Select Algorithm Template";
98        typeSelectorDialog.TypeSelector.Configure(typeof(IAlgorithm), false, true);
99      }
100      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
101        try {
102          Content.Template = (IAlgorithm)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
103        }
104        catch (Exception ex) {
105          ErrorHandling.ShowErrorDialog(this, ex);
106        }
107      }
108    }
109    protected virtual void clearTemplateButton_Click(object sender, EventArgs e) {
110      Content.Template = null;
111    }
112    protected virtual void templatePanel_DragEnterOver(object sender, DragEventArgs e) {
113      e.Effect = DragDropEffects.None;
114      if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) is IAlgorithm)) {
115        if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link;  // ALT key
116        else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move;  // SHIFT key
117        else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
118        else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
119        else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
120      }
121    }
122    protected virtual void templatePanel_DragDrop(object sender, DragEventArgs e) {
123      if (e.Effect != DragDropEffects.None) {
124        IAlgorithm alg = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as IAlgorithm;
125        if (e.Effect.HasFlag(DragDropEffects.Copy)) alg = (IAlgorithm)alg.Clone();
126        Content.Template = alg;
127      }
128    }
129  }
130}
Note: See TracBrowser for help on using the repository browser.