Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3758 was 3758, checked in by swagner, 14 years ago

Implemented ErrorDialog and OperatorExecutionException (#1007)

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