Free cookie consent management tool by TermsFeed Policy Generator

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

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

Operator architecture refactoring (#95)

  • implemented reviewers' comments
  • added additional plugins HeuristicLab.Evolutionary, HeuristicLab.Permutation, HeuristicLab.Selection, and HeuristicLab.Routing.TSP
File size: 3.3 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.Collections.Generic;
24using System.ComponentModel;
25using System.Data;
26using System.Drawing;
27using System.Text;
28using System.Linq;
29using System.Windows.Forms;
30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Core;
32
33namespace HeuristicLab.Core.Views {
34  public partial class CreateParameterDialog : Form {
35    protected TypeSelectorDialog typeSelectorDialog;
36
37    public IParameter Parameter {
38      get {
39        try {
40          Type type = parameterTypeSelector.SelectedType;
41          if (type.ContainsGenericParameters) {
42            type = type.MakeGenericType((Type)dataTypeTextBox.Tag);
43          }
44          return (IParameter)Activator.CreateInstance(type, nameTextBox.Text, descriptionTextBox.Text);
45        }
46        catch (Exception ex) {
47          Auxiliary.ShowErrorMessageBox(ex);
48        }
49        return null;
50      }
51    }
52
53    /// <summary>
54    /// Initializes a new instance of <see cref="AddVariableInfoDialog"/>.
55    /// </summary>
56    public CreateParameterDialog() {
57      InitializeComponent();
58    }
59
60    protected virtual void setDataTypeButton_Click(object sender, EventArgs e) {
61      if (typeSelectorDialog == null) {
62        typeSelectorDialog = new TypeSelectorDialog();
63        typeSelectorDialog.Caption = "Select Data Type";
64        typeSelectorDialog.TypeSelector.Configure(typeof(IItem), true, true);
65      }
66
67      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
68        dataTypeTextBox.Text = typeSelectorDialog.TypeSelector.SelectedType.FullName;
69        dataTypeTextBox.Tag = typeSelectorDialog.TypeSelector.SelectedType;
70      }
71      okButton.Enabled = dataTypeTextBox.Tag != null;
72    }
73
74    protected virtual void CreateParameterDialog_Load(object sender, EventArgs e) {
75      parameterTypeSelector.Configure(typeof(IParameter), false, true);
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}
Note: See TracBrowser for help on using the repository browser.