[12764] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12764] | 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;
|
---|
[14058] | 23 | using System.Windows.Forms;
|
---|
| 24 | using HeuristicLab.Common.Resources;
|
---|
[12764] | 25 | using HeuristicLab.Core;
|
---|
[14058] | 26 | using HeuristicLab.Core.Views;
|
---|
[12764] | 27 | using HeuristicLab.MainForm;
|
---|
| 28 | using HeuristicLab.Parameters.Views;
|
---|
[14058] | 29 | using HeuristicLab.PluginInfrastructure;
|
---|
[12764] | 30 |
|
---|
| 31 | namespace HeuristicLab.Optimization.Views {
|
---|
| 32 | [View("ResultParameter View")]
|
---|
| 33 | [Content(typeof(ResultParameter<>), true)]
|
---|
| 34 | [Content(typeof(IResultParameter<>), false)]
|
---|
[14058] | 35 | public partial class ResultParameterView<T> : LookupParameterView<T> where T : class, IItem {
|
---|
| 36 | protected TypeSelectorDialog typeSelectorDialog;
|
---|
[12764] | 37 |
|
---|
| 38 | public new IResultParameter<T> Content {
|
---|
| 39 | get { return (IResultParameter<T>)base.Content; }
|
---|
| 40 | set { base.Content = value; }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | public ResultParameterView() {
|
---|
| 44 | InitializeComponent();
|
---|
[14058] | 45 | setDefaultValueButton.Text = string.Empty;
|
---|
| 46 | setDefaultValueButton.Image = VSImageLibrary.Edit;
|
---|
| 47 | removeDefaultValueButton.Text = string.Empty;
|
---|
| 48 | removeDefaultValueButton.Image = VSImageLibrary.Remove;
|
---|
[14070] | 49 | actualNameLabel.Text = "Result Name:";
|
---|
| 50 | dataTypeLabel.Text = "Result Type:";
|
---|
[12764] | 51 | }
|
---|
| 52 |
|
---|
[14058] | 53 | /// <summary>
|
---|
| 54 | /// Clean up any resources being used.
|
---|
| 55 | /// </summary>
|
---|
| 56 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
---|
| 57 | protected override void Dispose(bool disposing) {
|
---|
| 58 | if (disposing) {
|
---|
| 59 | if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
|
---|
| 60 | if (components != null) components.Dispose();
|
---|
| 61 | }
|
---|
| 62 | base.Dispose(disposing);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[12764] | 65 | protected override void DeregisterContentEvents() {
|
---|
[14058] | 66 | Content.ResultCollectionNameChanged -= ContentOnResultCollectionNameChanged;
|
---|
| 67 | Content.DefaultValueChanged -= ContentOnDefaultValueChanged;
|
---|
[12764] | 68 | base.DeregisterContentEvents();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected override void RegisterContentEvents() {
|
---|
| 72 | base.RegisterContentEvents();
|
---|
[14058] | 73 | Content.ResultCollectionNameChanged += ContentOnResultCollectionNameChanged;
|
---|
| 74 | Content.DefaultValueChanged += ContentOnDefaultValueChanged;
|
---|
[12764] | 75 | }
|
---|
| 76 |
|
---|
| 77 | protected override void OnContentChanged() {
|
---|
| 78 | base.OnContentChanged();
|
---|
[14058] | 79 | if (Content == null) {
|
---|
| 80 | resultCollectionNameTextBox.Text = "-";
|
---|
| 81 | defaultValueViewHost.Content = null;
|
---|
| 82 | } else {
|
---|
| 83 | resultCollectionNameTextBox.Text = Content.ResultCollectionName;
|
---|
| 84 | defaultValueViewHost.Content = Content.DefaultValue;
|
---|
| 85 | }
|
---|
[12764] | 86 | }
|
---|
| 87 |
|
---|
| 88 | protected override void SetEnabledStateOfControls() {
|
---|
| 89 | base.SetEnabledStateOfControls();
|
---|
[14058] | 90 | resultCollectionNameTextBox.Enabled = Content != null;
|
---|
| 91 | resultCollectionNameTextBox.ReadOnly = ReadOnly;
|
---|
[14070] | 92 | setDefaultValueButton.Enabled = Content != null && !ReadOnly && !Locked;
|
---|
| 93 | removeDefaultValueButton.Enabled = Content != null && !ReadOnly && !Locked;
|
---|
[12764] | 94 | }
|
---|
| 95 |
|
---|
[14058] | 96 | private void ContentOnDefaultValueChanged(object sender, EventArgs e) {
|
---|
| 97 | if (InvokeRequired) Invoke((Action<object, EventArgs>)ContentOnDefaultValueChanged, sender, e);
|
---|
| 98 | else defaultValueViewHost.Content = Content.DefaultValue;
|
---|
[12764] | 99 | }
|
---|
| 100 |
|
---|
[14058] | 101 | private void ContentOnResultCollectionNameChanged(object sender, EventArgs e) {
|
---|
| 102 | if (InvokeRequired) Invoke((Action<object, EventArgs>)ContentOnResultCollectionNameChanged, sender, e);
|
---|
| 103 | else resultCollectionNameTextBox.Text = Content.ResultCollectionName;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[12764] | 106 | private void resultNameTextBox_Validated(object sender, EventArgs e) {
|
---|
[14058] | 107 | if (InvokeRequired) Invoke((Action<object, EventArgs>)resultNameTextBox_Validated, sender, e);
|
---|
| 108 | else Content.ResultCollectionName = resultCollectionNameTextBox.Text;
|
---|
[12764] | 109 | }
|
---|
[14058] | 110 |
|
---|
| 111 | private void setDefaultValueButton_Click(object sender, EventArgs e) {
|
---|
| 112 | if (typeSelectorDialog == null) {
|
---|
| 113 | typeSelectorDialog = new TypeSelectorDialog();
|
---|
| 114 | typeSelectorDialog.Caption = "Select Value";
|
---|
| 115 | typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, true);
|
---|
| 116 | }
|
---|
| 117 | if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 118 | try {
|
---|
| 119 | Content.DefaultValue = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
|
---|
| 120 | } catch (Exception ex) {
|
---|
| 121 | ErrorHandling.ShowErrorDialog(this, ex);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | private void removeDefaultValueButton_Click(object sender, EventArgs e) {
|
---|
| 127 | Content.DefaultValue = null;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | protected virtual void defaultValueGroupBox_DragEnterOver(object sender, DragEventArgs e) {
|
---|
| 131 | e.Effect = DragDropEffects.None;
|
---|
| 132 | if (!ReadOnly && (e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) != null) && Content.DataType.IsAssignableFrom(e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat).GetType())) {
|
---|
| 133 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
| 134 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
| 135 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Copy)) e.Effect = DragDropEffects.Copy;
|
---|
| 136 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Move)) e.Effect = DragDropEffects.Move;
|
---|
| 137 | else if (e.AllowedEffect.HasFlag(DragDropEffects.Link)) e.Effect = DragDropEffects.Link;
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | protected virtual void defaultValueGroupBox_DragDrop(object sender, DragEventArgs e) {
|
---|
| 141 | if (e.Effect != DragDropEffects.None) {
|
---|
| 142 | T value = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as T;
|
---|
| 143 | if (e.Effect.HasFlag(DragDropEffects.Copy)) value = (T)value.Clone();
|
---|
| 144 | Content.DefaultValue = value;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
[12764] | 147 | }
|
---|
| 148 | }
|
---|