Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.SimOpt/SimOptProblemInjectorView.cs @ 583

Last change on this file since 583 was 583, checked in by abeham, 16 years ago

Adding communication framework to branch 3.1 (ticket #278)

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9
10using HeuristicLab.PluginInfrastructure;
11using HeuristicLab.Core;
12using HeuristicLab.Data;
13
14namespace HeuristicLab.SimOpt {
15  public partial class SimOptProblemInjectorView : ViewBase {
16    public SimOptProblemInjector SimOptProblemInjector {
17      get { return (SimOptProblemInjector)base.Item; }
18      set { base.Item = value; }
19    }
20
21    public SimOptProblemInjectorView() {
22      InitializeComponent();
23      UpdateDataTypeTreeView();
24    }
25
26    public SimOptProblemInjectorView(SimOptProblemInjector simOptProblemInjector)
27      : this() {
28      SimOptProblemInjector = simOptProblemInjector;
29    }
30
31    protected override void UpdateControls() {
32      base.UpdateControls();
33      if (SimOptProblemInjector == null) {
34        geneNameStringDataView.Enabled = false;
35        geneNameStringDataView.StringData = null;
36        objectParameterDataView.Enabled = false;
37        objectParameterDataView.ConstrainedItemList = null;
38        maximizationBoolDataView.Enabled = false;
39        maximizationBoolDataView.BoolData = null;
40      } else {
41        objectParameterDataView.ConstrainedItemList = SimOptProblemInjector.Parameters;
42        objectParameterDataView.Enabled = true;
43        geneNameStringDataView.StringData = SimOptProblemInjector.GeneName;
44        geneNameStringDataView.Enabled = true;
45        maximizationBoolDataView.BoolData = SimOptProblemInjector.Maximization;
46        maximizationBoolDataView.Enabled = true;
47      }
48    }
49
50    private void UpdateDataTypeTreeView() {
51      dataTypeTreeView.Nodes.Clear();
52      DiscoveryService discoveryService = new DiscoveryService();
53      foreach (PluginInfo plugin in discoveryService.Plugins) {
54        TreeNode pluginNode = new TreeNode(plugin.Name);
55        pluginNode.Tag = null;
56
57        Type[] types = discoveryService.GetTypes(typeof(IObjectData), plugin);
58        foreach (Type type in types) {
59          if (!type.IsAbstract) {
60            TreeNode itemNode = new TreeNode();
61            itemNode.Text = type.Name;
62            itemNode.Tag = type;
63            pluginNode.Nodes.Add(itemNode);
64          }
65        }
66        if (pluginNode.Nodes.Count > 0) {
67          dataTypeTreeView.Nodes.Add(pluginNode);
68        }
69      }
70      if (dataTypeTreeView.Nodes.Count == 0) {
71        dataTypeTreeView.Enabled = false;
72        dataTypeTreeView.Nodes.Add(new TreeNode("No item types available"));
73      }
74    }
75
76    private void dataTypeTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
77      DoDragDrop(e.Item, DragDropEffects.Copy);
78    }
79
80    private void objectParameterDataView_DragDrop(object sender, DragEventArgs e) {
81      TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));
82      IVariable var = new Variable();
83      var.Name = "Unnamed";
84      var.Value = (IItem)Activator.CreateInstance((Type)node.Tag);
85      ICollection<IConstraint> tmp;
86      objectParameterDataView.ConstrainedItemList.TryAdd(var, out tmp);
87    }
88
89    private void objectParameterDataView_DragEnter(object sender, DragEventArgs e) {
90      e.Effect = DragDropEffects.Copy | DragDropEffects.Move;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.