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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Data;
|
---|
26 | using System.Drawing;
|
---|
27 | using System.Text;
|
---|
28 | using System.Linq;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.PluginInfrastructure;
|
---|
31 | using HeuristicLab.Core;
|
---|
32 |
|
---|
33 | namespace HeuristicLab.Core.Views {
|
---|
34 | public partial class CreateParameterDialog : Form {
|
---|
35 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
36 |
|
---|
37 | public TypeSelector ParameterTypeSelector {
|
---|
38 | get { return parameterTypeSelector; }
|
---|
39 | }
|
---|
40 | public IParameter Parameter {
|
---|
41 | get {
|
---|
42 | try {
|
---|
43 | Type type = parameterTypeSelector.SelectedType;
|
---|
44 | if (type.ContainsGenericParameters) {
|
---|
45 | type = type.MakeGenericType((Type)dataTypeTextBox.Tag);
|
---|
46 | }
|
---|
47 | return (IParameter)Activator.CreateInstance(type, nameTextBox.Text, descriptionTextBox.Text);
|
---|
48 | }
|
---|
49 | catch (Exception ex) {
|
---|
50 | Auxiliary.ShowErrorMessageBox(ex);
|
---|
51 | }
|
---|
52 | return null;
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /// <summary>
|
---|
57 | /// Initializes a new instance of <see cref="AddVariableInfoDialog"/>.
|
---|
58 | /// </summary>
|
---|
59 | public CreateParameterDialog() {
|
---|
60 | InitializeComponent();
|
---|
61 | parameterTypeSelector.Configure(typeof(IParameter), false, true);
|
---|
62 | }
|
---|
63 |
|
---|
64 | protected virtual void setDataTypeButton_Click(object sender, EventArgs e) {
|
---|
65 | if (typeSelectorDialog == null) {
|
---|
66 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
67 | typeSelectorDialog.Caption = "Select Data Type";
|
---|
68 | typeSelectorDialog.TypeSelector.Configure(typeof(IItem), true, true);
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
72 | dataTypeTextBox.Text = typeSelectorDialog.TypeSelector.SelectedType.FullName;
|
---|
73 | dataTypeTextBox.Tag = typeSelectorDialog.TypeSelector.SelectedType;
|
---|
74 | }
|
---|
75 | okButton.Enabled = dataTypeTextBox.Tag != null;
|
---|
76 | }
|
---|
77 |
|
---|
78 | protected virtual void parameterTypeSelector_SelectedTypeChanged(object sender, EventArgs e) {
|
---|
79 | dataTypeTextBox.Text = "-";
|
---|
80 | dataTypeTextBox.Tag = null;
|
---|
81 | dataTypeTextBox.Enabled = false;
|
---|
82 | setDataTypeButton.Enabled = false;
|
---|
83 | okButton.Enabled = false;
|
---|
84 |
|
---|
85 | if (parameterTypeSelector.SelectedType != null) {
|
---|
86 | if (parameterTypeSelector.SelectedType.ContainsGenericParameters) {
|
---|
87 | dataTypeTextBox.Enabled = true;
|
---|
88 | setDataTypeButton.Enabled = true;
|
---|
89 | } else {
|
---|
90 | okButton.Enabled = true;
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|