Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core.Views/3.3/CreateParameterDialog.cs @ 3120

Last change on this file since 3120 was 2818, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

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