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