Free cookie consent management tool by TermsFeed Policy Generator

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

Operator architecture refactoring (#95)

  • implemented reviewers' comments on version r2917.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.