Changeset 2948


Ignore:
Timestamp:
03/06/10 03:30:37 (12 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • implemented reviewers' comments on version r2917.
Location:
trunk/sources
Files:
4 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/VariableView.cs

    r2917 r2948  
    9494        dataTypeTextBox.Text = Content.Value == null ? "-" : Content.Value.GetType().GetPrettyName();
    9595        dataTypeTextBox.Enabled = Content.Value != null;
    96         setValueButton.Enabled = Content.Value == null;
     96        setValueButton.Enabled = true;
    9797        clearValueButton.Enabled = Content.Value != null;
    9898        valueGroupBox.Enabled = true;
     
    107107        dataTypeTextBox.Text = Content.Value == null ? "-" : Content.Value.GetType().GetPrettyName();
    108108        dataTypeTextBox.Enabled = Content.Value != null;
    109         setValueButton.Enabled = Content.Value == null;
    110109        clearValueButton.Enabled = Content.Value != null;
    111110        viewHost.Content = Content.Value;
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ConstrainedValueParameterView.cs

    r2924 r2948  
    2121
    2222using System;
    23 using System.Linq;
     23using System.Collections.Generic;
    2424using HeuristicLab.Collections;
    2525using HeuristicLab.Core;
     
    3232  /// </summary>
    3333  [View("ConstrainedValueParameter View")]
     34  [Content(typeof(OptionalConstrainedValueParameter<>), true)]
    3435  [Content(typeof(ConstrainedValueParameter<>), true)]
    3536  public partial class ConstrainedValueParameterView<T> : ParameterView where T : class, IItem {
     37    private List<T> valueComboBoxItems;
     38
    3639    /// <summary>
    3740    /// Gets or sets the variable to represent visually.
     
    3942    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    4043    /// No own data storage present.</remarks>
    41     public new ConstrainedValueParameter<T> Content {
    42       get { return (ConstrainedValueParameter<T>)base.Content; }
     44    public new OptionalConstrainedValueParameter<T> Content {
     45      get { return (OptionalConstrainedValueParameter<T>)base.Content; }
    4346      set { base.Content = value; }
    4447    }
     
    5053      InitializeComponent();
    5154      Caption = "ConstrainedValueParameter";
     55      valueComboBoxItems = new List<T>();
    5256    }
    5357    /// <summary>
     
    5660    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    5761    /// <param name="variable">The variable to represent visually.</param>
    58     public ConstrainedValueParameterView(ConstrainedValueParameter<T> content)
     62    public ConstrainedValueParameterView(OptionalConstrainedValueParameter<T> content)
    5963      : this() {
    6064      Content = content;
     
    102106    private void FillValueComboBox() {
    103107      valueComboBox.SelectedIndexChanged -= new EventHandler(valueComboBox_SelectedIndexChanged);
    104       valueComboBox.DataSource = null;
     108      valueComboBoxItems.Clear();
     109      valueComboBox.Items.Clear();
     110      if (!(Content is ConstrainedValueParameter<T>)) {
     111        valueComboBoxItems.Add(null);
     112        valueComboBox.Items.Add("-");
     113      }
    105114      if (Content != null) {
    106         valueComboBox.DataSource = Content.ValidValues.ToList();
     115        foreach (T item in Content.ValidValues) {
     116          valueComboBoxItems.Add(item);
     117          valueComboBox.Items.Add(item.ToString());
     118        }
    107119        valueComboBox.Enabled = valueComboBox.Items.Count > 0;
    108         valueComboBox.SelectedItem = Content.Value;
     120        valueComboBox.SelectedIndex = valueComboBoxItems.IndexOf(Content.Value);
    109121      }
    110122      valueComboBox.SelectedIndexChanged += new EventHandler(valueComboBox_SelectedIndexChanged);
     
    116128        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    117129      else {
    118         valueComboBox.SelectedItem = Content.Value;
     130        valueComboBox.SelectedIndex = valueComboBoxItems.IndexOf(Content.Value);
    119131        viewHost.Content = Content.Value;
    120132      }
     
    141153
    142154    private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    143       Content.Value = (T)valueComboBox.SelectedItem;
     155      Content.Value = valueComboBoxItems[valueComboBox.SelectedIndex];
    144156    }
    145157  }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r2924 r2948  
    9292      <DependentUpon>ConstrainedValueParameterView.cs</DependentUpon>
    9393    </Compile>
    94     <Compile Include="OptionalConstrainedValueParameterView.cs">
    95       <SubType>UserControl</SubType>
    96     </Compile>
    97     <Compile Include="OptionalConstrainedValueParameterView.Designer.cs">
    98       <DependentUpon>OptionalConstrainedValueParameterView.cs</DependentUpon>
    99     </Compile>
    100     <Compile Include="OptionalValueParameterView.cs">
    101       <SubType>UserControl</SubType>
    102     </Compile>
    103     <Compile Include="OptionalValueParameterView.Designer.cs">
    104       <DependentUpon>OptionalValueParameterView.cs</DependentUpon>
    105     </Compile>
    10694    <Compile Include="ValueLookupParameterView.cs">
    10795      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.cs

    r2917 r2948  
    9797        actualNameTextBox.Text = Content.ActualName;
    9898        actualNameTextBox.Enabled = true;
    99         setValueButton.Enabled = Content.Value == null;
     99        setValueButton.Enabled = true;
    100100        clearValueButton.Enabled = Content.Value != null;
    101101        valueGroupBox.Enabled = true;
     
    114114        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    115115      else {
    116         setValueButton.Enabled = Content.Value == null;
    117116        clearValueButton.Enabled = Content.Value != null;
    118117        viewHost.Content = Content.Value;
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.Designer.cs

    r2924 r2948  
    3333    protected override void Dispose(bool disposing) {
    3434      if (disposing) {
     35        if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    3536        if (components != null) components.Dispose();
    3637      }
     
    4849      this.valuePanel = new System.Windows.Forms.Panel();
    4950      this.viewHost = new HeuristicLab.Core.Views.ViewHost();
     51      this.clearValueButton = new System.Windows.Forms.Button();
     52      this.setValueButton = new System.Windows.Forms.Button();
    5053      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5154      this.valueGroupBox.SuspendLayout();
    5255      this.valuePanel.SuspendLayout();
    5356      this.SuspendLayout();
    54       //
    55       // dataTypeLabel
    56       //
    57       this.dataTypeLabel.Location = new System.Drawing.Point(3, 55);
    5857      //
    5958      // dataTypeTextBox
     
    8079                  | System.Windows.Forms.AnchorStyles.Right)));
    8180      this.valueGroupBox.Controls.Add(this.valuePanel);
     81      this.valueGroupBox.Controls.Add(this.clearValueButton);
     82      this.valueGroupBox.Controls.Add(this.setValueButton);
    8283      this.valueGroupBox.Location = new System.Drawing.Point(0, 78);
    8384      this.valueGroupBox.Name = "valueGroupBox";
     
    9495                  | System.Windows.Forms.AnchorStyles.Right)));
    9596      this.valuePanel.Controls.Add(this.viewHost);
    96       this.valuePanel.Location = new System.Drawing.Point(6, 19);
     97      this.valuePanel.Location = new System.Drawing.Point(6, 49);
    9798      this.valuePanel.Name = "valuePanel";
    98       this.valuePanel.Size = new System.Drawing.Size(374, 212);
     99      this.valuePanel.Size = new System.Drawing.Size(374, 182);
    99100      this.valuePanel.TabIndex = 0;
    100101      this.valuePanel.DragOver += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragEnterOver);
     
    108109      this.viewHost.Location = new System.Drawing.Point(0, 0);
    109110      this.viewHost.Name = "viewHost";
    110       this.viewHost.Size = new System.Drawing.Size(374, 212);
     111      this.viewHost.Size = new System.Drawing.Size(374, 182);
    111112      this.viewHost.TabIndex = 0;
    112113      this.viewHost.ViewType = null;
     114      //
     115      // clearValueButton
     116      //
     117      this.clearValueButton.Enabled = false;
     118      this.clearValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
     119      this.clearValueButton.Location = new System.Drawing.Point(36, 19);
     120      this.clearValueButton.Name = "clearValueButton";
     121      this.clearValueButton.Size = new System.Drawing.Size(24, 24);
     122      this.clearValueButton.TabIndex = 1;
     123      this.toolTip.SetToolTip(this.clearValueButton, "Clear Value");
     124      this.clearValueButton.UseVisualStyleBackColor = true;
     125      this.clearValueButton.Click += new System.EventHandler(this.setValueButton_Click);
     126      //
     127      // setValueButton
     128      //
     129      this.setValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
     130      this.setValueButton.Location = new System.Drawing.Point(6, 19);
     131      this.setValueButton.Name = "setValueButton";
     132      this.setValueButton.Size = new System.Drawing.Size(24, 24);
     133      this.setValueButton.TabIndex = 0;
     134      this.toolTip.SetToolTip(this.setValueButton, "Set Value");
     135      this.setValueButton.UseVisualStyleBackColor = true;
     136      this.setValueButton.Click += new System.EventHandler(this.changeValueButton_Click);
    113137      //
    114138      // ValueParameterView
     
    139163    protected System.Windows.Forms.Panel valuePanel;
    140164    protected HeuristicLab.Core.Views.ViewHost viewHost;
     165    protected System.Windows.Forms.Button setValueButton;
     166    protected System.Windows.Forms.Button clearValueButton;
    141167  }
    142168}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r2917 r2948  
    3131  /// </summary>
    3232  [View("ValueParameter View")]
     33  [Content(typeof(OptionalValueParameter<>), true)]
    3334  [Content(typeof(ValueParameter<>), true)]
     35  [Content(typeof(IValueParameter<>), false)]
    3436  public partial class ValueParameterView<T> : ParameterView where T : class, IItem {
     37    protected TypeSelectorDialog typeSelectorDialog;
     38
    3539    /// <summary>
    3640    /// Gets or sets the variable to represent visually.
     
    3842    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    3943    /// No own data storage present.</remarks>
    40     public new ValueParameter<T> Content {
    41       get { return (ValueParameter<T>)base.Content; }
     44    public new IValueParameter<T> Content {
     45      get { return (IValueParameter<T>)base.Content; }
    4246      set { base.Content = value; }
    4347    }
     
    5559    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    5660    /// <param name="variable">The variable to represent visually.</param>
    57     public ValueParameterView(ValueParameter<T> content)
     61    public ValueParameterView(IValueParameter<T> content)
    5862      : this() {
    5963      Content = content;
     
    8286      if (Content == null) {
    8387        Caption = "ValueParameter";
     88        setValueButton.Enabled = false;
     89        clearValueButton.Visible = true;
     90        clearValueButton.Enabled = false;
    8491        viewHost.Content = null;
    8592        valueGroupBox.Enabled = false;
    8693      } else {
    8794        Caption = Content.Name + " (" + Content.GetType().Name + ")";
     95        setValueButton.Enabled = true;
     96        clearValueButton.Visible = !(Content is ValueParameter<T>);
     97        clearValueButton.Enabled = Content.Value != null;
    8898        valueGroupBox.Enabled = true;
    8999        viewHost.Content = Content.Value;
     
    95105        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    96106      else {
     107        clearValueButton.Enabled = Content.Value != null;
    97108        viewHost.Content = Content.Value;
    98109      }
    99110    }
    100111
     112    protected virtual void changeValueButton_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, false);
     117      }
     118      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
     119        Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     120    }
     121    protected virtual void setValueButton_Click(object sender, EventArgs e) {
     122      Content.Value = null;
     123    }
    101124    protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
    102125      e.Effect = DragDropEffects.None;
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueParameter.cs

    r2947 r2948  
    3535      get { return base.Value; }
    3636      set {
    37         if (value == null) throw new ArgumentNullException();
     37        if ((value == null) && (Value != null)) throw new ArgumentNullException();
    3838        base.Value = value;
    3939      }
    4040    }
    4141
    42     private ValueParameter() : base() { }
     42    public ValueParameter() : base() { }
     43    public ValueParameter(string name) : base(name) { }
    4344    public ValueParameter(string name, T value) : base(name, value) { }
     45    public ValueParameter(string name, string description) : base(name, description) { }
    4446    public ValueParameter(string name, string description, T value) : base(name, description, value) { }
    45 
    46     public override IDeepCloneable Clone(Cloner cloner) {
    47       ValueParameter<T> clone = new ValueParameter<T>(Name, Description, Value);
    48       cloner.RegisterClonedObject(this, clone);
    49       clone.Value = (T)cloner.Clone(Value);
    50       return clone;
    51     }
    5247  }
    5348}
Note: See TracChangeset for help on using the changeset viewer.