[2655] | 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 |
|
---|
| 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 {
|
---|
[2676] | 35 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
[2655] | 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 |
|
---|
[2676] | 60 | protected virtual void setDataTypeButton_Click(object sender, EventArgs e) {
|
---|
[2655] | 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 |
|
---|
[2676] | 74 | protected virtual void CreateParameterDialog_Load(object sender, EventArgs e) {
|
---|
[2655] | 75 | parameterTypeSelector.Configure(typeof(IParameter), false, true);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[2676] | 78 | protected virtual void parameterTypeSelector_SelectedTypeChanged(object sender, EventArgs e) {
|
---|
[2655] | 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 | }
|
---|