Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.CEDMA.Core/3.3/ConsoleEditor.cs @ 2273

Last change on this file since 2273 was 2273, checked in by gkronber, 15 years ago

Added functionality to open any database file to CEDMA console. #712

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Windows.Forms;
28using System.ServiceModel;
29using HeuristicLab.PluginInfrastructure;
30using System.Drawing;
31
32namespace HeuristicLab.CEDMA.Core {
33  class ConsoleEditor : EditorBase {
34    private ComboBox viewComboBox;
35    private Button resultsButton;
36    private Button openButton;
37    private Console console;
38
39    public ConsoleEditor(Console console) {
40      InitializeComponent();
41      this.console = console;
42      resultsButton.Enabled = false;
43      viewComboBox.Enabled = false;
44      PopulateViewComboBox();
45    }
46
47    #region autogenerated code
48    private void InitializeComponent() {
49      this.viewComboBox = new System.Windows.Forms.ComboBox();
50      this.resultsButton = new System.Windows.Forms.Button();
51      this.openButton = new System.Windows.Forms.Button();
52      this.SuspendLayout();
53      //
54      // viewComboBox
55      //
56      this.viewComboBox.FormattingEnabled = true;
57      this.viewComboBox.Location = new System.Drawing.Point(0, 29);
58      this.viewComboBox.Name = "viewComboBox";
59      this.viewComboBox.Size = new System.Drawing.Size(121, 21);
60      this.viewComboBox.TabIndex = 7;
61      //
62      // resultsButton
63      //
64      this.resultsButton.Location = new System.Drawing.Point(127, 27);
65      this.resultsButton.Name = "resultsButton";
66      this.resultsButton.Size = new System.Drawing.Size(86, 23);
67      this.resultsButton.TabIndex = 6;
68      this.resultsButton.Text = "Show results";
69      this.resultsButton.UseVisualStyleBackColor = true;
70      this.resultsButton.Click += new System.EventHandler(this.resultsButton_Click);
71      //
72      // openButton
73      //
74      this.openButton.Location = new System.Drawing.Point(4, 0);
75      this.openButton.Name = "openButton";
76      this.openButton.Size = new System.Drawing.Size(75, 23);
77      this.openButton.TabIndex = 8;
78      this.openButton.Text = "Open...";
79      this.openButton.UseVisualStyleBackColor = true;
80      this.openButton.Click += new System.EventHandler(this.openButton_Click);
81      //
82      // ConsoleEditor
83      //
84      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
85      this.Controls.Add(this.openButton);
86      this.Controls.Add(this.viewComboBox);
87      this.Controls.Add(this.resultsButton);
88      this.Name = "ConsoleEditor";
89      this.Size = new System.Drawing.Size(224, 112);
90      this.ResumeLayout(false);
91
92    }
93
94    #endregion
95
96    private void PopulateViewComboBox() {
97      DiscoveryService service = new DiscoveryService();
98      IResultsViewFactory[] factories = service.GetInstances<IResultsViewFactory>();
99      viewComboBox.DataSource = factories;
100      viewComboBox.ValueMember = "Name";
101    }
102
103
104    private void resultsButton_Click(object sender, EventArgs e) {
105      IResultsViewFactory factory = (IResultsViewFactory)viewComboBox.SelectedItem;
106      IControl control = factory.CreateView(console.Results);
107      PluginManager.ControlManager.ShowControl(control);
108    }
109
110    private void openButton_Click(object sender, EventArgs e) {
111      OpenFileDialog dialog = new OpenFileDialog();
112      DialogResult result = dialog.ShowDialog();
113      if (result == DialogResult.OK) {
114        viewComboBox.Enabled = true;
115        resultsButton.Enabled = true;
116        console.Database = dialog.FileName;
117      }
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.