Changeset 2756


Ignore:
Timestamp:
02/05/10 05:23:56 (11 years ago)
Author:
swagner
Message:

Operator architecture refactoring (#95)

  • worked on parameters and operators
Location:
trunk/sources
Files:
7 added
1 deleted
12 edited
8 moved

Legend:

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

    r2727 r2756  
    3838  [Content(typeof(IOperator), false)]
    3939  public sealed partial class OperatorTreeView : ItemView {
    40     private Dictionary<IOperatorParameter, List<TreeNode>> operatorParameterNodeTable;
     40    private Dictionary<IValueParameter<IOperator>, List<TreeNode>> opParamNodeTable;
    4141    private Dictionary<IOperator, List<TreeNode>> operatorNodeTable;
    4242    private Dictionary<IObservableKeyedCollection<string, IParameter>, IOperator> parametersOperatorTable;
     
    5858      InitializeComponent();
    5959      graphTreeView.Sorted = true;
    60       operatorParameterNodeTable = new Dictionary<IOperatorParameter, List<TreeNode>>();
     60      opParamNodeTable = new Dictionary<IValueParameter<IOperator>, List<TreeNode>>();
    6161      operatorNodeTable = new Dictionary<IOperator, List<TreeNode>>();
    6262      parametersOperatorTable = new Dictionary<IObservableKeyedCollection<string, IParameter>, IOperator>();
     
    9494
    9595    #region TreeNode Management
    96     private TreeNode CreateTreeNode(IOperatorParameter operatorParameter) {
     96    private TreeNode CreateTreeNode(IValueParameter<IOperator> opParam) {
    9797      TreeNode node = new TreeNode();
    98       node.Text = operatorParameter.Name + ": ";
    99       SetOperatorParameterTag(node, operatorParameter);
    100 
    101       if (!operatorParameterNodeTable.ContainsKey(operatorParameter)) {
    102         operatorParameterNodeTable.Add(operatorParameter, new List<TreeNode>());
    103         operatorParameter.ValueChanged += new EventHandler(operatorParameter_ValueChanged);
    104       }
    105       operatorParameterNodeTable[operatorParameter].Add(node);
    106 
    107       IOperator op = operatorParameter.Value;
     98      node.Text = opParam.Name + ": ";
     99      SetOperatorParameterTag(node, opParam);
     100
     101      if (!opParamNodeTable.ContainsKey(opParam)) {
     102        opParamNodeTable.Add(opParam, new List<TreeNode>());
     103        opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
     104      }
     105      opParamNodeTable[opParam].Add(node);
     106
     107      IOperator op = opParam.Value;
    108108      if (op == null)
    109109        node.Text += "-";
     
    139139
    140140      foreach (IParameter param in op.Parameters) {
    141         if (param is IOperatorParameter)
     141        if (param is IValueParameter<IOperator>)
    142142          node.Nodes.Add(new TreeNode());
    143143      }
     
    167167      ClearTreeNode(node);
    168168
    169       IOperatorParameter opParam = GetOperatorParameterTag(node);
     169      IValueParameter<IOperator> opParam = GetOperatorParameterTag(node);
    170170      if (opParam != null) {
    171         operatorParameterNodeTable[opParam].Remove(node);
    172         if (operatorParameterNodeTable[opParam].Count == 0) {
    173           opParam.ValueChanged -= new EventHandler(operatorParameter_ValueChanged);
    174           operatorParameterNodeTable.Remove(opParam);
     171        opParamNodeTable[opParam].Remove(node);
     172        if (opParamNodeTable[opParam].Count == 0) {
     173          opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
     174          opParamNodeTable.Remove(opParam);
    175175        }
    176176      }
     
    180180    private void AddParameterNodes(IOperator op, IEnumerable<IParameter> parameters) {
    181181      foreach (IParameter param in parameters) {
    182         IOperatorParameter opParam = param as IOperatorParameter;
     182        IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    183183        if (opParam != null) {
    184184          foreach (TreeNode node in operatorNodeTable[op])
     
    189189    private void RemoveParameterNodes(IEnumerable<IParameter> parameters) {
    190190      foreach (IParameter param in parameters) {
    191         IOperatorParameter opParam = param as IOperatorParameter;
     191        IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    192192        if (opParam != null) {
    193           while (operatorParameterNodeTable.ContainsKey(opParam))
    194             RemoveTreeNode(operatorParameterNodeTable[opParam][0]);
     193          while (opParamNodeTable.ContainsKey(opParam))
     194            RemoveTreeNode(opParamNodeTable[opParam][0]);
    195195        }
    196196      }
     
    199199
    200200    #region Parameter and Operator Events
    201     private void operatorParameter_ValueChanged(object sender, EventArgs e) {
    202       if (InvokeRequired)
    203         Invoke(new EventHandler(operatorParameter_ValueChanged), sender, e);
    204       else {
    205         IOperatorParameter opParam = (IOperatorParameter)sender;
    206         foreach (TreeNode node in operatorParameterNodeTable[opParam].ToArray())
     201    private void opParam_ValueChanged(object sender, EventArgs e) {
     202      if (InvokeRequired)
     203        Invoke(new EventHandler(opParam_ValueChanged), sender, e);
     204      else {
     205        IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
     206        foreach (TreeNode node in opParamNodeTable[opParam].ToArray())
    207207          ClearTreeNode(node);
    208         foreach (TreeNode node in operatorParameterNodeTable[opParam]) {
     208        foreach (TreeNode node in opParamNodeTable[opParam]) {
    209209          node.Text = opParam.Name + ": ";
    210210          if (opParam.Value == null)
     
    221221        IOperator op = (IOperator)sender;
    222222        foreach (TreeNode node in operatorNodeTable[op]) {
    223           IOperatorParameter opParam = GetOperatorParameterTag(node);
     223          IValueParameter<IOperator> opParam = GetOperatorParameterTag(node);
    224224          if (opParam == null)
    225225            node.Text = op.Name + " (" + op.ItemName + ")";
     
    287287        IOperator op = GetOperatorTag(node);
    288288        foreach (IParameter param in op.Parameters) {
    289           IOperatorParameter opParam = param as IOperatorParameter;
     289          IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    290290          if (opParam != null) node.Nodes.Add(CreateTreeNode(opParam));
    291291        }
     
    299299    private void graphTreeView_KeyDown(object sender, KeyEventArgs e) {
    300300      if ((e.KeyCode == Keys.Delete) && (graphTreeView.SelectedNode != null)) {
    301         IOperatorParameter opParam = GetOperatorParameterTag(graphTreeView.SelectedNode);
     301        IValueParameter<IOperator> opParam = GetOperatorParameterTag(graphTreeView.SelectedNode);
    302302        if (opParam != null) opParam.Value = null;
    303303      }
     
    324324    private void graphTreeView_ItemDrag(object sender, ItemDragEventArgs e) {
    325325      TreeNode node = (TreeNode)e.Item;
    326       IOperatorParameter opParam = GetOperatorParameterTag(node);
     326      IValueParameter<IOperator> opParam = GetOperatorParameterTag(node);
    327327      IOperator op = GetOperatorTag(node);
    328328      DataObject data = new DataObject();
     
    357357        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) op = (IOperator)op.Clone();
    358358        TreeNode node = graphTreeView.GetNodeAt(graphTreeView.PointToClient(new Point(e.X, e.Y)));
    359         IOperatorParameter opParam = GetOperatorParameterTag(node);
     359        IValueParameter<IOperator> opParam = GetOperatorParameterTag(node);
    360360        opParam.Value = op;
    361361      }
     
    389389    }
    390390
    391     private IOperatorParameter GetOperatorParameterTag(TreeNode node) {
     391    private IValueParameter<IOperator> GetOperatorParameterTag(TreeNode node) {
    392392      if (node.Tag != null)
    393         return ((Tuple<IOperatorParameter, IOperator>)node.Tag).Item1;
     393        return ((Tuple<IValueParameter<IOperator>, IOperator>)node.Tag).Item1;
    394394      else
    395395        return null;
    396396    }
    397     private void SetOperatorParameterTag(TreeNode node, IOperatorParameter operatorParameter) {
     397    private void SetOperatorParameterTag(TreeNode node, IValueParameter<IOperator> opParam) {
    398398      if (node.Tag == null)
    399         node.Tag = new Tuple<IOperatorParameter, IOperator>(operatorParameter, null);
    400       else
    401         ((Tuple<IOperatorParameter, IOperator>)node.Tag).Item1 = operatorParameter;
     399        node.Tag = new Tuple<IValueParameter<IOperator>, IOperator>(opParam, null);
     400      else
     401        ((Tuple<IValueParameter<IOperator>, IOperator>)node.Tag).Item1 = opParam;
    402402    }
    403403    private IOperator GetOperatorTag(TreeNode node) {
    404404      if (node.Tag != null)
    405         return ((Tuple<IOperatorParameter, IOperator>)node.Tag).Item2;
     405        return ((Tuple<IValueParameter<IOperator>, IOperator>)node.Tag).Item2;
    406406      else
    407407        return null;
     
    409409    private void SetOperatorTag(TreeNode node, IOperator op) {
    410410      if (node.Tag == null)
    411         node.Tag = new Tuple<IOperatorParameter, IOperator>(null, op);
    412       else
    413         ((Tuple<IOperatorParameter, IOperator>)node.Tag).Item2 = op;
     411        node.Tag = new Tuple<IValueParameter<IOperator>, IOperator>(null, op);
     412      else
     413        ((Tuple<IValueParameter<IOperator>, IOperator>)node.Tag).Item2 = op;
    414414    }
    415415    #endregion
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r2754 r2756  
    104104    <Compile Include="ChangedEventArgs.cs" />
    105105    <None Include="HeuristicLabCorePlugin.cs.frame" />
     106    <Compile Include="Interfaces\IValueLookupParameter.cs" />
     107    <Compile Include="Interfaces\IValueParameter.cs" />
     108    <Compile Include="Interfaces\ILookupParameter.cs" />
    106109    <Compile Include="ItemArray.cs" />
    107110    <Compile Include="DeepCloneable.cs" />
    108111    <Compile Include="Engine.cs" />
    109     <Compile Include="Interfaces\IOperatorParameter.cs" />
    110112    <Compile Include="Interfaces\IScope.cs" />
    111113    <Compile Include="Interfaces\IVariable.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs

    r2664 r2756  
    115115      var opParams = from o in Operators
    116116                     from p in o.Parameters
    117                      where p is IOperatorParameter
    118                      where (((IOperatorParameter)p).Value != null) && (((IOperatorParameter)p).Value == op)
    119                      select (IOperatorParameter)p;
    120       foreach (IOperatorParameter opParam in opParams)
     117                     where p is IValueParameter<IOperator>
     118                     where (((IValueParameter<IOperator>)p).Value != null) && (((IValueParameter<IOperator>)p).Value == op)
     119                     select (IValueParameter<IOperator>)p;
     120      foreach (IValueParameter<IOperator> opParam in opParams)
    121121        opParam.Value = null;
    122122    }
    123123    private void AddParameter(IParameter param) {
    124       IOperatorParameter opParam = param as IOperatorParameter;
     124      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    125125      if (opParam != null) {
    126126        RegisterOperatorParameterEvents(opParam);
     
    129129    }
    130130    private void RemoveParameter(IParameter param) {
    131       IOperatorParameter opParam = param as IOperatorParameter;
     131      IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    132132      if (opParam != null) {
    133133        DeregisterOperatorParameterEvents(opParam);
     
    163163      op.Parameters.CollectionReset -= new CollectionItemsChangedEventHandler<IParameter>(Parameters_CollectionReset);
    164164    }
    165     private void RegisterOperatorParameterEvents(IOperatorParameter opParam) {
     165    private void RegisterOperatorParameterEvents(IValueParameter<IOperator> opParam) {
    166166      opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    167167    }
    168     private void DeregisterOperatorParameterEvents(IOperatorParameter opParam) {
     168    private void DeregisterOperatorParameterEvents(IValueParameter<IOperator> opParam) {
    169169      opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
    170170    }
     
    207207    }
    208208    private void opParam_ValueChanged(object sender, EventArgs e) {
    209       IOperatorParameter opParam = (IOperatorParameter)sender;
     209      IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
    210210      if (opParam.Value != null) Operators.Add(opParam.Value);
    211211    }
  • trunk/sources/HeuristicLab.Operators.Views/3.3/HeuristicLab.Operators.Views-3.3.csproj

    r2754 r2756  
    5858    </Compile>
    5959    <None Include="HeuristicLabOperatorsViewsPlugin.cs.frame" />
     60    <Compile Include="MultipleSuccessorsOperatorView.cs">
     61      <SubType>UserControl</SubType>
     62    </Compile>
     63    <Compile Include="MultipleSuccessorsOperatorView.Designer.cs">
     64      <DependentUpon>MultipleSuccessorsOperatorView.cs</DependentUpon>
     65    </Compile>
    6066    <Compile Include="HeuristicLabOperatorsViewsPlugin.cs" />
    6167    <Compile Include="OperatorView.cs">
  • trunk/sources/HeuristicLab.Operators/3.3/Counter.cs

    r2740 r2756  
    3636  [Creatable("Test")]
    3737  public sealed class Counter : SingleSuccessorOperator {
    38     public ItemParameter<IntData> Value {
    39       get { return (ItemParameter<IntData>)Parameters["Value"]; }
     38    public LookupParameter<IntData> ValueParameter {
     39      get { return (LookupParameter<IntData>)Parameters["Value"]; }
    4040    }
    41     public ItemParameter<IntData> Increment {
    42       get { return (ItemParameter<IntData>)Parameters["Increment"]; }
     41    public ValueLookupParameter<IntData> IncrementParaneter {
     42      get { return (ValueLookupParameter<IntData>)Parameters["Increment"]; }
     43    }
     44    public IntData Increment {
     45      get { return IncrementParaneter.Value; }
     46      set { IncrementParaneter.Value = value; }
    4347    }
    4448
    4549    public Counter()
    4650      : base() {
    47       Parameters.Add(new ItemParameter<IntData>("Value", "The value which should be incremented."));
    48       Parameters.Add(new ItemParameter<IntData>("Increment", "The increment which is added to the value.", new IntData(1)));
     51      Parameters.Add(new LookupParameter<IntData>("Value", "The value which should be incremented."));
     52      Parameters.Add(new ValueLookupParameter<IntData>("Increment", "The increment which is added to the value.", new IntData(1)));
    4953    }
    5054
    5155    public override ExecutionContextCollection Apply() {
    52       IntData value = (IntData)Value.Value;
    53       IntData increment = (IntData)Increment.Value;
    54       value.Value += increment.Value;
     56      if (ValueParameter.ActualValue == null) ValueParameter.ActualValue = new IntData();
     57      ValueParameter.ActualValue.Value += IncrementParaneter.ActualValue.Value;
    5558      return base.Apply();
    5659    }
  • trunk/sources/HeuristicLab.Operators/3.3/MultipleSuccessorsOperator.cs

    r2740 r2756  
    3838  [EmptyStorableClass]
    3939  public abstract class MultipleSuccessorsOperator : Operator {
    40     protected IOperatorParameter[] SuccessorParameters {
     40    protected IValueParameter<IOperator>[] SuccessorParameters {
    4141      get {
    4242        return (from p in Parameters
    43                 where p is IOperatorParameter
     43                where p is IValueParameter<IOperator>
    4444                orderby p.Name ascending
    45                 select (IOperatorParameter)p).ToArray();
     45                select (IValueParameter<IOperator>)p).ToArray();
    4646      }
    4747    }
     
    5353          successors = new OperatorList();
    5454          var opParams = SuccessorParameters;
    55           foreach (IOperatorParameter opParam in opParams) {
     55          foreach (IValueParameter<IOperator> opParam in opParams) {
    5656            opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    5757            successors.Add(opParam.Value);
     
    7373    private void UpdateOperatorParameters() {
    7474      var opParams = SuccessorParameters;
    75       foreach (IOperatorParameter opParam in opParams) {
     75      foreach (IValueParameter<IOperator> opParam in opParams) {
    7676        opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
    7777        Parameters.Remove(opParam.Name);
    7878      }
    7979      for (int i = 0; i < Successors.Count; i++) {
    80         IOperatorParameter opParam = new OperatorParameter(i.ToString(), string.Empty, Successors[i]);
     80        IValueParameter<IOperator> opParam = new OperatorParameter(i.ToString(), string.Empty, Successors[i]);
    8181        opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
    8282        Parameters.Add(opParam);
     
    9292    private void successors_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
    9393      foreach (IndexedItem<IOperator> item in e.Items)
    94         ((IOperatorParameter)Parameters[item.Index.ToString()]).Value = item.Value;
     94        ((IValueParameter<IOperator>)Parameters[item.Index.ToString()]).Value = item.Value;
    9595    }
    9696    private void successors_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
    9797      foreach (IndexedItem<IOperator> item in e.Items)
    98         ((IOperatorParameter)Parameters[item.Index.ToString()]).Value = item.Value;
     98        ((IValueParameter<IOperator>)Parameters[item.Index.ToString()]).Value = item.Value;
    9999    }
    100100    private void successors_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<IOperator>> e) {
     
    102102    }
    103103    private void opParam_ValueChanged(object sender, EventArgs e) {
    104       IOperatorParameter opParam = (IOperatorParameter)sender;
     104      IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender;
    105105      int index = int.Parse(opParam.Name);
    106106      successors[index] = opParam.Value;
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/HeuristicLab.Parameters.Views-3.3.csproj

    r2754 r2756  
    5252  <ItemGroup>
    5353    <None Include="HeuristicLabParametersViewsPlugin.cs.frame" />
    54     <Compile Include="SubScopesItemParameterView.cs">
     54    <Compile Include="ValueLookupParameterView.cs">
    5555      <SubType>UserControl</SubType>
    5656    </Compile>
    57     <Compile Include="SubScopesItemParameterView.Designer.cs">
    58       <DependentUpon>SubScopesItemParameterView.cs</DependentUpon>
     57    <Compile Include="ValueLookupParameterView.Designer.cs">
     58      <DependentUpon>ValueLookupParameterView.cs</DependentUpon>
    5959    </Compile>
    60     <Compile Include="OperatorParameterView.cs">
     60    <Compile Include="LookupParameterView.cs">
    6161      <SubType>UserControl</SubType>
    6262    </Compile>
    63     <Compile Include="OperatorParameterView.Designer.cs">
    64       <DependentUpon>OperatorParameterView.cs</DependentUpon>
     63    <Compile Include="LookupParameterView.Designer.cs">
     64      <DependentUpon>LookupParameterView.cs</DependentUpon>
    6565    </Compile>
    6666    <Compile Include="HeuristicLabParametersViewsPlugin.cs" />
    67     <Compile Include="ItemParameterView.cs">
    68       <SubType>UserControl</SubType>
    69     </Compile>
    70     <Compile Include="ItemParameterView.Designer.cs">
    71       <DependentUpon>ItemParameterView.cs</DependentUpon>
    72     </Compile>
    7367    <Compile Include="ParameterView.cs">
    7468      <SubType>UserControl</SubType>
     
    7872    </Compile>
    7973    <Compile Include="Properties\AssemblyInfo.cs" />
     74    <Compile Include="ValueParameterView.cs">
     75      <SubType>UserControl</SubType>
     76    </Compile>
     77    <Compile Include="ValueParameterView.Designer.cs">
     78      <DependentUpon>ValueParameterView.cs</DependentUpon>
     79    </Compile>
    8080  </ItemGroup>
    8181  <ItemGroup>
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/LookupParameterView.Designer.cs

    r2754 r2756  
    2121
    2222namespace HeuristicLab.Parameters.Views {
    23   partial class SubScopesItemParameterView<T> {
     23  partial class LookupParameterView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    3333    protected override void Dispose(bool disposing) {
    3434      if (disposing) {
    35         if (typeSelectorDialog != null) typeSelectorDialog.Dispose();
    3635        if (components != null) components.Dispose();
    3736      }
     
    4645    /// </summary>
    4746    private void InitializeComponent() {
    48       this.components = new System.ComponentModel.Container();
    4947      this.actualNameTextBox = new System.Windows.Forms.TextBox();
    5048      this.actualNameLabel = new System.Windows.Forms.Label();
    51       this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5249      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5350      this.SuspendLayout();
     
    10198      this.actualNameLabel.Text = "&Actual Name:";
    10299      //
    103       // SubScopesItemParameterView
     100      // LookupParameterView
    104101      //
    105102      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     
    107104      this.Controls.Add(this.actualNameTextBox);
    108105      this.Controls.Add(this.actualNameLabel);
    109       this.Name = "SubScopesItemParameterView";
     106      this.Name = "LookupParameterView";
    110107      this.Size = new System.Drawing.Size(386, 143);
    111108      this.Controls.SetChildIndex(this.descriptionTextBox, 0);
     
    127124    protected System.Windows.Forms.TextBox actualNameTextBox;
    128125    protected System.Windows.Forms.Label actualNameLabel;
    129     protected System.Windows.Forms.ToolTip toolTip;
    130126  }
    131127}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/LookupParameterView.cs

    r2754 r2756  
    3535  /// The visual representation of a <see cref="Parameter"/>.
    3636  /// </summary>
    37   [Content(typeof(SubScopesItemParameter<>), true)]
    38   public partial class SubScopesItemParameterView<T> : ParameterView where T : class, IItem {
    39     protected TypeSelectorDialog typeSelectorDialog;
    40 
     37  [Content(typeof(LookupParameter<>), true)]
     38  [Content(typeof(SubScopesLookupParameter<>), true)]
     39  [Content(typeof(ILookupParameter<>), false)]
     40  public partial class LookupParameterView<T> : ParameterView where T : class, IItem {
    4141    /// <summary>
    4242    /// Gets or sets the variable to represent visually.
     
    4444    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    4545    /// No own data storage present.</remarks>
    46     public new SubScopesItemParameter<T> Content {
    47       get { return (SubScopesItemParameter<T>)base.Content; }
     46    public new ILookupParameter<T> Content {
     47      get { return (ILookupParameter<T>)base.Content; }
    4848      set { base.Content = value; }
    4949    }
     
    5252    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
    5353    /// </summary>
    54     public SubScopesItemParameterView() {
     54    public LookupParameterView() {
    5555      InitializeComponent();
    56       Caption = "SubScopesItemParameter";
     56      Caption = "LookupParameter";
    5757    }
    5858    /// <summary>
     
    6161    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    6262    /// <param name="variable">The variable to represent visually.</param>
    63     public SubScopesItemParameterView(SubScopesItemParameter<T> content)
     63    public LookupParameterView(ILookupParameter<T> content)
    6464      : this() {
    6565      Content = content;
     
    8787      base.OnContentChanged();
    8888      if (Content == null) {
    89         Caption = "SubScopesItemParameter";
     89        Caption = "LookupParameter";
    9090        actualNameTextBox.Text = "-";
    9191        actualNameTextBox.Enabled = false;
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.Designer.cs

    r2754 r2756  
    2121
    2222namespace HeuristicLab.Parameters.Views {
    23   partial class ItemParameterView<T> {
     23  partial class ValueLookupParameterView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4747    private void InitializeComponent() {
    4848      this.components = new System.ComponentModel.Container();
    49       this.localValueGroupBox = new System.Windows.Forms.GroupBox();
    50       this.localValuePanel = new System.Windows.Forms.Panel();
     49      this.valueGroupBox = new System.Windows.Forms.GroupBox();
     50      this.valuePanel = new System.Windows.Forms.Panel();
    5151      this.viewHost = new HeuristicLab.Core.Views.ViewHost();
    52       this.clearLocalValueButton = new System.Windows.Forms.Button();
    53       this.setLocalValueButton = new System.Windows.Forms.Button();
     52      this.clearValueButton = new System.Windows.Forms.Button();
     53      this.setValueButton = new System.Windows.Forms.Button();
     54      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5455      this.actualNameTextBox = new System.Windows.Forms.TextBox();
    5556      this.actualNameLabel = new System.Windows.Forms.Label();
    56       this.toolTip = new System.Windows.Forms.ToolTip(this.components);
    5757      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    58       this.localValueGroupBox.SuspendLayout();
    59       this.localValuePanel.SuspendLayout();
     58      this.valueGroupBox.SuspendLayout();
     59      this.valuePanel.SuspendLayout();
    6060      this.SuspendLayout();
    6161      //
     
    8989      this.descriptionTextBox.TabIndex = 5;
    9090      //
    91       // localValueGroupBox
    92       //
    93       this.localValueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     91      // valueGroupBox
     92      //
     93      this.valueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    9494                  | System.Windows.Forms.AnchorStyles.Left)
    9595                  | System.Windows.Forms.AnchorStyles.Right)));
    96       this.localValueGroupBox.Controls.Add(this.localValuePanel);
    97       this.localValueGroupBox.Controls.Add(this.clearLocalValueButton);
    98       this.localValueGroupBox.Controls.Add(this.setLocalValueButton);
    99       this.localValueGroupBox.Location = new System.Drawing.Point(0, 146);
    100       this.localValueGroupBox.Name = "localValueGroupBox";
    101       this.localValueGroupBox.Size = new System.Drawing.Size(386, 169);
    102       this.localValueGroupBox.TabIndex = 10;
    103       this.localValueGroupBox.TabStop = false;
    104       this.localValueGroupBox.Text = "Local &Value:";
    105       //
    106       // localValuePanel
    107       //
    108       this.localValuePanel.AllowDrop = true;
    109       this.localValuePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     96      this.valueGroupBox.Controls.Add(this.valuePanel);
     97      this.valueGroupBox.Controls.Add(this.clearValueButton);
     98      this.valueGroupBox.Controls.Add(this.setValueButton);
     99      this.valueGroupBox.Location = new System.Drawing.Point(0, 146);
     100      this.valueGroupBox.Name = "valueGroupBox";
     101      this.valueGroupBox.Size = new System.Drawing.Size(386, 169);
     102      this.valueGroupBox.TabIndex = 8;
     103      this.valueGroupBox.TabStop = false;
     104      this.valueGroupBox.Text = "&Value:";
     105      //
     106      // valuePanel
     107      //
     108      this.valuePanel.AllowDrop = true;
     109      this.valuePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    110110                  | System.Windows.Forms.AnchorStyles.Left)
    111111                  | System.Windows.Forms.AnchorStyles.Right)));
    112       this.localValuePanel.Controls.Add(this.viewHost);
    113       this.localValuePanel.Location = new System.Drawing.Point(6, 48);
    114       this.localValuePanel.Name = "localValuePanel";
    115       this.localValuePanel.Size = new System.Drawing.Size(374, 115);
    116       this.localValuePanel.TabIndex = 0;
    117       this.localValuePanel.DragOver += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragEnterOver);
    118       this.localValuePanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragDrop);
    119       this.localValuePanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.localValuePanel_DragEnterOver);
     112      this.valuePanel.Controls.Add(this.viewHost);
     113      this.valuePanel.Location = new System.Drawing.Point(6, 48);
     114      this.valuePanel.Name = "valuePanel";
     115      this.valuePanel.Size = new System.Drawing.Size(374, 115);
     116      this.valuePanel.TabIndex = 0;
     117      this.valuePanel.DragOver += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragEnterOver);
     118      this.valuePanel.DragDrop += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragDrop);
     119      this.valuePanel.DragEnter += new System.Windows.Forms.DragEventHandler(this.valuePanel_DragEnterOver);
    120120      //
    121121      // viewHost
     
    128128      this.viewHost.TabIndex = 0;
    129129      //
    130       // clearLocalValueButton
    131       //
    132       this.clearLocalValueButton.Enabled = false;
    133       this.clearLocalValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
    134       this.clearLocalValueButton.Location = new System.Drawing.Point(35, 19);
    135       this.clearLocalValueButton.Name = "clearLocalValueButton";
    136       this.clearLocalValueButton.Size = new System.Drawing.Size(23, 23);
    137       this.clearLocalValueButton.TabIndex = 9;
    138       this.toolTip.SetToolTip(this.clearLocalValueButton, "Clear Value");
    139       this.clearLocalValueButton.UseVisualStyleBackColor = true;
    140       this.clearLocalValueButton.Click += new System.EventHandler(this.clearLocalValueButton_Click);
    141       //
    142       // setLocalValueButton
    143       //
    144       this.setLocalValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
    145       this.setLocalValueButton.Location = new System.Drawing.Point(6, 19);
    146       this.setLocalValueButton.Name = "setLocalValueButton";
    147       this.setLocalValueButton.Size = new System.Drawing.Size(23, 23);
    148       this.setLocalValueButton.TabIndex = 8;
    149       this.toolTip.SetToolTip(this.setLocalValueButton, "Set Value");
    150       this.setLocalValueButton.UseVisualStyleBackColor = true;
    151       this.setLocalValueButton.Click += new System.EventHandler(this.setLocalValueButton_Click);
     130      // clearValueButton
     131      //
     132      this.clearValueButton.Enabled = false;
     133      this.clearValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Remove;
     134      this.clearValueButton.Location = new System.Drawing.Point(35, 19);
     135      this.clearValueButton.Name = "clearValueButton";
     136      this.clearValueButton.Size = new System.Drawing.Size(23, 23);
     137      this.clearValueButton.TabIndex = 1;
     138      this.toolTip.SetToolTip(this.clearValueButton, "Clear Value");
     139      this.clearValueButton.UseVisualStyleBackColor = true;
     140      this.clearValueButton.Click += new System.EventHandler(this.clearValueButton_Click);
     141      //
     142      // setValueButton
     143      //
     144      this.setValueButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Add;
     145      this.setValueButton.Location = new System.Drawing.Point(6, 19);
     146      this.setValueButton.Name = "setValueButton";
     147      this.setValueButton.Size = new System.Drawing.Size(23, 23);
     148      this.setValueButton.TabIndex = 0;
     149      this.toolTip.SetToolTip(this.setValueButton, "Set Value");
     150      this.setValueButton.UseVisualStyleBackColor = true;
     151      this.setValueButton.Click += new System.EventHandler(this.setValueButton_Click);
    152152      //
    153153      // actualNameTextBox
     
    170170      this.actualNameLabel.Text = "&Actual Name:";
    171171      //
    172       // ItemParameterView
     172      // ValueLookupParameterView
    173173      //
    174174      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    175175      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    176       this.Controls.Add(this.localValueGroupBox);
    177176      this.Controls.Add(this.actualNameTextBox);
    178177      this.Controls.Add(this.actualNameLabel);
    179       this.Name = "ItemParameterView";
     178      this.Controls.Add(this.valueGroupBox);
     179      this.Name = "ValueLookupParameterView";
    180180      this.Size = new System.Drawing.Size(386, 315);
    181181      this.Controls.SetChildIndex(this.descriptionTextBox, 0);
    182182      this.Controls.SetChildIndex(this.descriptionLabel, 0);
    183183      this.Controls.SetChildIndex(this.dataTypeTextBox, 0);
    184       this.Controls.SetChildIndex(this.actualNameLabel, 0);
    185184      this.Controls.SetChildIndex(this.dataTypeLabel, 0);
    186185      this.Controls.SetChildIndex(this.nameTextBox, 0);
     186      this.Controls.SetChildIndex(this.nameLabel, 0);
     187      this.Controls.SetChildIndex(this.valueGroupBox, 0);
     188      this.Controls.SetChildIndex(this.actualNameLabel, 0);
    187189      this.Controls.SetChildIndex(this.actualNameTextBox, 0);
    188       this.Controls.SetChildIndex(this.nameLabel, 0);
    189       this.Controls.SetChildIndex(this.localValueGroupBox, 0);
    190190      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    191       this.localValueGroupBox.ResumeLayout(false);
    192       this.localValuePanel.ResumeLayout(false);
     191      this.valueGroupBox.ResumeLayout(false);
     192      this.valuePanel.ResumeLayout(false);
    193193      this.ResumeLayout(false);
    194194      this.PerformLayout();
     
    198198    #endregion
    199199
    200     protected System.Windows.Forms.GroupBox localValueGroupBox;
     200    protected System.Windows.Forms.GroupBox valueGroupBox;
     201    protected System.Windows.Forms.Panel valuePanel;
     202    protected HeuristicLab.Core.Views.ViewHost viewHost;
     203    protected System.Windows.Forms.Button setValueButton;
     204    protected System.Windows.Forms.ToolTip toolTip;
     205    protected System.Windows.Forms.Button clearValueButton;
    201206    protected System.Windows.Forms.TextBox actualNameTextBox;
    202207    protected System.Windows.Forms.Label actualNameLabel;
    203     protected System.Windows.Forms.Panel localValuePanel;
    204     protected HeuristicLab.Core.Views.ViewHost viewHost;
    205     protected System.Windows.Forms.Button setLocalValueButton;
    206     protected System.Windows.Forms.ToolTip toolTip;
    207     protected System.Windows.Forms.Button clearLocalValueButton;
    208208  }
    209209}
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueLookupParameterView.cs

    r2754 r2756  
    3535  /// The visual representation of a <see cref="Parameter"/>.
    3636  /// </summary>
    37   [Content(typeof(ItemParameter<>), true)]
    38   public partial class ItemParameterView<T> : ParameterView where T : class, IItem {
     37  [Content(typeof(ValueLookupParameter<>), true)]
     38  [Content(typeof(IValueLookupParameter<>), false)]
     39  public partial class ValueLookupParameterView<T> : ParameterView where T : class, IItem {
    3940    protected TypeSelectorDialog typeSelectorDialog;
    4041
     
    4445    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    4546    /// No own data storage present.</remarks>
    46     public new ItemParameter<T> Content {
    47       get { return (ItemParameter<T>)base.Content; }
     47    public new IValueLookupParameter<T> Content {
     48      get { return (IValueLookupParameter<T>)base.Content; }
    4849      set { base.Content = value; }
    4950    }
     
    5253    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
    5354    /// </summary>
    54     public ItemParameterView() {
     55    public ValueLookupParameterView() {
    5556      InitializeComponent();
    56       Caption = "ItemParameter";
     57      Caption = "ValueLookupParameter";
    5758    }
    5859    /// <summary>
     
    6162    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    6263    /// <param name="variable">The variable to represent visually.</param>
    63     public ItemParameterView(ItemParameter<T> content)
     64    public ValueLookupParameterView(IValueLookupParameter<T> content)
    6465      : this() {
    6566      Content = content;
     
    7273    protected override void DeregisterContentEvents() {
    7374      Content.ActualNameChanged -= new EventHandler(Content_ActualNameChanged);
    74       Content.LocalValueChanged -= new EventHandler(Content_LocalValueChanged);
     75      Content.ValueChanged -= new EventHandler(Content_ValueChanged);
    7576      base.DeregisterContentEvents();
    7677    }
     
    8384      base.RegisterContentEvents();
    8485      Content.ActualNameChanged += new EventHandler(Content_ActualNameChanged);
    85       Content.LocalValueChanged += new EventHandler(Content_LocalValueChanged);
     86      Content.ValueChanged += new EventHandler(Content_ValueChanged);
    8687    }
    8788
     
    8990      base.OnContentChanged();
    9091      if (Content == null) {
    91         Caption = "ItemParameter";
     92        Caption = "ValueLookupParameter";
    9293        actualNameTextBox.Text = "-";
    9394        actualNameTextBox.Enabled = false;
    94         setLocalValueButton.Enabled = false;
    95         clearLocalValueButton.Enabled = false;
    96         localValueGroupBox.Enabled = false;
     95        setValueButton.Enabled = false;
     96        clearValueButton.Enabled = false;
     97        valueGroupBox.Enabled = false;
    9798        viewHost.Content = null;
    9899      } else {
    99100        Caption = Content.Name + " (" + Content.GetType().Name + ")";
    100101        actualNameTextBox.Text = Content.ActualName;
    101         actualNameTextBox.Enabled = Content.LocalValue == null;
    102         setLocalValueButton.Enabled = Content.LocalValue == null;
    103         clearLocalValueButton.Enabled = Content.LocalValue != null;
    104         localValueGroupBox.Enabled = true;
    105         viewHost.Content = Content.LocalValue;
     102        actualNameTextBox.Enabled = true;
     103        setValueButton.Enabled = Content.Value == null;
     104        clearValueButton.Enabled = Content.Value != null;
     105        valueGroupBox.Enabled = true;
     106        viewHost.Content = Content.Value;
    106107      }
    107108    }
     
    113114        actualNameTextBox.Text = Content.ActualName;
    114115    }
    115     protected virtual void Content_LocalValueChanged(object sender, EventArgs e) {
     116    protected virtual void Content_ValueChanged(object sender, EventArgs e) {
    116117      if (InvokeRequired)
    117         Invoke(new EventHandler(Content_LocalValueChanged), sender, e);
     118        Invoke(new EventHandler(Content_ValueChanged), sender, e);
    118119      else {
    119         actualNameTextBox.Enabled = Content.LocalValue == null;
    120         setLocalValueButton.Enabled = Content.LocalValue == null;
    121         clearLocalValueButton.Enabled = Content.LocalValue != null;
    122         viewHost.Content = Content.LocalValue;
     120        setValueButton.Enabled = Content.Value == null;
     121        clearValueButton.Enabled = Content.Value != null;
     122        viewHost.Content = Content.Value;
    123123      }
    124124    }
     
    127127      Content.ActualName = actualNameTextBox.Text;
    128128    }
    129     protected virtual void setLocalValueButton_Click(object sender, EventArgs e) {
     129    protected virtual void setValueButton_Click(object sender, EventArgs e) {
    130130      if (typeSelectorDialog == null) {
    131131        typeSelectorDialog = new TypeSelectorDialog();
    132         typeSelectorDialog.Caption = "Select Local Value Type";
     132        typeSelectorDialog.Caption = "Select Value";
     133        typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
    133134      }
    134       typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
    135135      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
    136         Content.LocalValue = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     136        Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    137137    }
    138     protected virtual void clearLocalValueButton_Click(object sender, EventArgs e) {
    139       Content.LocalValue = null;
     138    protected virtual void clearValueButton_Click(object sender, EventArgs e) {
     139      Content.Value = null;
    140140    }
    141     protected virtual void localValuePanel_DragEnterOver(object sender, DragEventArgs e) {
     141    protected virtual void valuePanel_DragEnterOver(object sender, DragEventArgs e) {
    142142      e.Effect = DragDropEffects.None;
    143143      Type type = e.Data.GetData("Type") as Type;
     
    150150      }
    151151    }
    152     protected virtual void localValuePanel_DragDrop(object sender, DragEventArgs e) {
     152    protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
    153153      if (e.Effect != DragDropEffects.None) {
    154         T item = e.Data.GetData("Value") as T;
    155         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (T)item.Clone();
    156         Content.LocalValue = item;
     154        T value = e.Data.GetData("Value") as T;
     155        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) value = (T)value.Clone();
     156        Content.Value = value;
    157157      }
    158158    }
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.Designer.cs

    r2754 r2756  
    2121
    2222namespace HeuristicLab.Parameters.Views {
    23   partial class OperatorParameterView {
     23  partial class ValueParameterView<T> {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    5858      this.SuspendLayout();
    5959      //
    60       // dataTypeLabel
    61       //
    62       this.dataTypeLabel.TabIndex = 6;
    63       //
    6460      // dataTypeTextBox
    6561      //
    6662      this.dataTypeTextBox.Location = new System.Drawing.Point(80, 94);
    6763      this.dataTypeTextBox.Size = new System.Drawing.Size(306, 20);
    68       this.dataTypeTextBox.TabIndex = 7;
    6964      //
    7065      // nameTextBox
     
    7570      this.nameTextBox.Size = new System.Drawing.Size(306, 20);
    7671      //
    77       // descriptionLabel
    78       //
    79       this.descriptionLabel.TabIndex = 4;
    80       //
    8172      // descriptionTextBox
    8273      //
    8374      this.descriptionTextBox.Location = new System.Drawing.Point(80, 26);
    8475      this.descriptionTextBox.Size = new System.Drawing.Size(306, 62);
    85       this.descriptionTextBox.TabIndex = 5;
    8676      //
    8777      // valueGroupBox
     
    9686      this.valueGroupBox.Name = "valueGroupBox";
    9787      this.valueGroupBox.Size = new System.Drawing.Size(386, 195);
    98       this.valueGroupBox.TabIndex = 10;
     88      this.valueGroupBox.TabIndex = 6;
    9989      this.valueGroupBox.TabStop = false;
    10090      this.valueGroupBox.Text = "&Value:";
     
    131121      this.clearValueButton.Name = "clearValueButton";
    132122      this.clearValueButton.Size = new System.Drawing.Size(23, 23);
    133       this.clearValueButton.TabIndex = 9;
     123      this.clearValueButton.TabIndex = 1;
    134124      this.toolTip.SetToolTip(this.clearValueButton, "Clear Value");
    135125      this.clearValueButton.UseVisualStyleBackColor = true;
     
    142132      this.setValueButton.Name = "setValueButton";
    143133      this.setValueButton.Size = new System.Drawing.Size(23, 23);
    144       this.setValueButton.TabIndex = 8;
     134      this.setValueButton.TabIndex = 0;
    145135      this.toolTip.SetToolTip(this.setValueButton, "Set Value");
    146136      this.setValueButton.UseVisualStyleBackColor = true;
    147137      this.setValueButton.Click += new System.EventHandler(this.setValueButton_Click);
    148138      //
    149       // OperatorParameterView
     139      // ValueParameterView
    150140      //
    151141      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    152142      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    153143      this.Controls.Add(this.valueGroupBox);
    154       this.Name = "OperatorParameterView";
     144      this.Name = "ValueParameterView";
    155145      this.Size = new System.Drawing.Size(386, 315);
    156146      this.Controls.SetChildIndex(this.descriptionTextBox, 0);
  • trunk/sources/HeuristicLab.Parameters.Views/3.3/ValueParameterView.cs

    r2754 r2756  
    3535  /// The visual representation of a <see cref="Parameter"/>.
    3636  /// </summary>
    37   [Content(typeof(OperatorParameter), true)]
    38   [Content(typeof(IOperatorParameter), false)]
    39   public partial class OperatorParameterView : ParameterView {
     37  [Content(typeof(ValueParameter<>), true)]
     38  [Content(typeof(IValueParameter<>), false)]
     39  public partial class ValueParameterView<T> : ParameterView where T : class, IItem {
    4040    protected TypeSelectorDialog typeSelectorDialog;
    4141
     
    4545    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
    4646    /// No own data storage present.</remarks>
    47     public new IOperatorParameter Content {
    48       get { return (IOperatorParameter)base.Content; }
     47    public new IValueParameter<T> Content {
     48      get { return (IValueParameter<T>)base.Content; }
    4949      set { base.Content = value; }
    5050    }
     
    5353    /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
    5454    /// </summary>
    55     public OperatorParameterView() {
     55    public ValueParameterView() {
    5656      InitializeComponent();
    57       Caption = "OperatorParameter";
     57      Caption = "ValueParameter";
    5858    }
    5959    /// <summary>
     
    6262    /// <remarks>Calls <see cref="VariableView()"/>.</remarks>
    6363    /// <param name="variable">The variable to represent visually.</param>
    64     public OperatorParameterView(IOperatorParameter content)
     64    public ValueParameterView(IValueParameter<T> content)
    6565      : this() {
    6666      Content = content;
     
    8888      base.OnContentChanged();
    8989      if (Content == null) {
    90         Caption = "OperatorParameter";
     90        Caption = "ValueParameter";
    9191        setValueButton.Enabled = false;
    9292        clearValueButton.Enabled = false;
     
    115115      if (typeSelectorDialog == null) {
    116116        typeSelectorDialog = new TypeSelectorDialog();
    117         typeSelectorDialog.Caption = "Select Operator";
     117        typeSelectorDialog.Caption = "Select Value";
    118118        typeSelectorDialog.TypeSelector.Configure(Content.DataType, false, false);
    119119      }
    120120      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK)
    121         Content.Value = (IOperator)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     121        Content.Value = (T)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
    122122    }
    123123    protected virtual void clearValueButton_Click(object sender, EventArgs e) {
     
    137137    protected virtual void valuePanel_DragDrop(object sender, DragEventArgs e) {
    138138      if (e.Effect != DragDropEffects.None) {
    139         IOperator value = e.Data.GetData("Value") as IOperator;
    140         if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) value = (IOperator)value.Clone();
     139        T value = e.Data.GetData("Value") as T;
     140        if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) value = (T)value.Clone();
    141141        Content.Value = value;
    142142      }
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLab.Parameters-3.3.csproj

    r2754 r2756  
    5050  <ItemGroup>
    5151    <None Include="HeuristicLabParametersPlugin.cs.frame" />
    52     <Compile Include="SubScopesItemParameter.cs" />
     52    <Compile Include="LookupParameter.cs" />
     53    <Compile Include="SubScopesLookupParameter.cs" />
     54    <Compile Include="ValueLookupParameter.cs" />
     55    <Compile Include="ValueParameter.cs" />
    5356    <Compile Include="ScopeParameter.cs" />
    5457    <Compile Include="HeuristicLabParametersPlugin.cs" />
    55     <Compile Include="ItemParameter.cs" />
    5658    <Compile Include="OperatorParameter.cs" />
    5759    <Compile Include="Parameter.cs" />
     
    6668      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
    6769      <Name>HeuristicLab.Collections-3.3</Name>
     70    </ProjectReference>
     71    <ProjectReference Include="..\..\HeuristicLab.Common\3.2\HeuristicLab.Common-3.2.csproj">
     72      <Project>{1FC004FC-59AF-4249-B1B6-FF25873A20E4}</Project>
     73      <Name>HeuristicLab.Common-3.2</Name>
    6874    </ProjectReference>
    6975    <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj">
  • trunk/sources/HeuristicLab.Parameters/3.3/HeuristicLabParametersPlugin.cs.frame

    r2754 r2756  
    3232  [PluginFile("HeuristicLab.Parameters-3.3.dll", PluginFileType.Assembly)]
    3333  [PluginDependency("HeuristicLab.Collections", "3.3")]
     34  [PluginDependency("HeuristicLab.Common", "3.2")]
    3435  [PluginDependency("HeuristicLab.Core", "3.3")]
    3536  [PluginDependency("HeuristicLab.Persistence", "3.3")]
  • trunk/sources/HeuristicLab.Parameters/3.3/OperatorParameter.cs

    r2740 r2756  
    3232  /// </summary>
    3333  [Item("OperatorParameter", "A parameter which represents an operator.")]
     34  [EmptyStorableClass]
    3435  [Creatable("Test")]
    35   public class OperatorParameter : Parameter, IOperatorParameter {
    36     private IOperator value;
    37     [Storable]
    38     public IOperator Value {
    39       get { return this.value; }
    40       set {
    41         if (value != this.value) {
    42           if (this.value != null) this.value.Changed -= new ChangedEventHandler(Value_Changed);
    43           this.value = value;
    44           if (this.value != null) this.value.Changed += new ChangedEventHandler(Value_Changed);
    45           OnValueChanged();
    46         }
    47       }
     36  public class OperatorParameter : ValueParameter<IOperator> {
     37    public OperatorParameter()
     38      : base("Anonymous") {
    4839    }
    49 
    50     public OperatorParameter()
    51       : base("Anonymous", null, typeof(IOperator)) {
     40    public OperatorParameter(string name)
     41      : base(name) {
     42    }
     43    public OperatorParameter(string name, IOperator value)
     44      : base(name, value) {
     45      Value = value;
    5246    }
    5347    public OperatorParameter(string name, string description)
    54       : base(name, description, typeof(IOperator)) {
     48      : base(name, description) {
    5549    }
    5650    public OperatorParameter(string name, string description, IOperator value)
    57       : base(name, description, typeof(IOperator)) {
     51      : base(name, description, value) {
    5852      Value = value;
    59     }
    60 
    61     public override IDeepCloneable Clone(Cloner cloner) {
    62       OperatorParameter clone = (OperatorParameter)base.Clone(cloner);
    63       clone.Value = (IOperator)cloner.Clone(value);
    64       return clone;
    65     }
    66 
    67     public override string ToString() {
    68       return string.Format("{0}: {1} ({2})", Name, Value != null ? Value.ToString() : "null", DataType.Name);
    69     }
    70 
    71     public event EventHandler ValueChanged;
    72     private void OnValueChanged() {
    73       if (ValueChanged != null)
    74         ValueChanged(this, new EventArgs());
    75       OnChanged();
    76     }
    77     private void Value_Changed(object sender, ChangedEventArgs e) {
    78       OnChanged(e);
    7953    }
    8054  }
  • trunk/sources/HeuristicLab.Parameters/3.3/Parameter.cs

    r2740 r2756  
    5656      dataType = typeof(IItem);
    5757    }
     58    protected Parameter(string name, Type dataType)
     59      : base(name) {
     60      if (dataType == null) throw new ArgumentNullException();
     61      this.dataType = dataType;
     62    }
    5863    protected Parameter(string name, string description, Type dataType)
    5964      : base(name, description) {
  • trunk/sources/HeuristicLab.Parameters/3.3/ScopeParameter.cs

    r2740 r2756  
    4040
    4141    public ScopeParameter()
    42       : base("Anonymous", null, typeof(IScope)) {
     42      : base("Anonymous", typeof(IScope)) {
     43    }
     44    public ScopeParameter(string name)
     45      : base(name, typeof(IScope)) {
    4346    }
    4447    public ScopeParameter(string name, string description)
  • trunk/sources/HeuristicLab.Parameters/3.3/SubScopesLookupParameter.cs

    r2754 r2756  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3132  /// A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.
    3233  /// </summary>
    33   [Item("SubScopesItemParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]
    34   public class SubScopesItemParameter<T> : Parameter where T : class, IItem {
     34  [Item("SubScopesLookupParameter<T>", "A generic parameter representing instances of type T which are collected from the sub-scopes of the current scope.")]
     35  public class SubScopesLookupParameter<T> : Parameter, ILookupParameter<T> where T : class, IItem {
    3536    [Storable]
    3637    private string actualName;
     
    4647    }
    4748
    48     public T[] Values {
    49       get { return GetValues(); }
    50       set { SetValues(value); }
     49    public T[] ActualValues {
     50      get { return GetActualValues(); }
     51      set { SetActualValues(value); }
    5152    }
    5253
    53     public SubScopesItemParameter()
    54       : base("Anonymous", null, typeof(T)) {
     54    public SubScopesLookupParameter()
     55      : base("Anonymous", typeof(T)) {
    5556      actualName = Name;
    5657    }
    57     public SubScopesItemParameter(string name, string description)
     58    public SubScopesLookupParameter(string name)
     59      : base(name, typeof(T)) {
     60      actualName = Name;
     61    }
     62    public SubScopesLookupParameter(string name, string description)
    5863      : base(name, description, typeof(T)) {
    5964      actualName = Name;
     
    6166
    6267    public override IDeepCloneable Clone(Cloner cloner) {
    63       SubScopesItemParameter<T> clone = (SubScopesItemParameter<T>)base.Clone(cloner);
     68      SubScopesLookupParameter<T> clone = (SubScopesLookupParameter<T>)base.Clone(cloner);
    6469      clone.actualName = actualName;
    6570      return clone;
     
    7075    }
    7176
    72     protected string GetActualName() {
    73       string name = Name;
    74       ExecutionContext current = ExecutionContext;
    75       while (current != null) {
    76         if (current.Operator.Parameters.ContainsKey(name))
    77           name = ((SubScopesItemParameter<T>)current.Operator.Parameters[name]).ActualName;
    78         current = current.Parent;
     77    protected virtual T[] GetActualValues() {
     78      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
     79      IScope scope = ExecutionContext.Scope;
     80      T[] values = new T[scope.SubScopes.Count];
     81      IVariable var;
     82      T value;
     83
     84      for (int i = 0; i < values.Length; i++) {
     85        scope.SubScopes[i].Variables.TryGetValue(name, out var);
     86        if (var != null) {
     87          value = var.Value as T;
     88          if (value == null)
     89            throw new InvalidOperationException(
     90              string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     91                            name,
     92                            typeof(T).GetPrettyName())
     93            );
     94          values[i] = value;
     95        }
    7996      }
    80       return name;
     97      return values;
    8198    }
    82     protected virtual T[] GetValues() {
    83       string name = GetActualName();
    84       IScope scope = ExecutionContext.Scope;
    85       T[] value = new T[scope.SubScopes.Count];
    86       IVariable var;
    87 
    88       for (int i = 0; i < value.Length; i++) {
    89         scope.SubScopes[i].Variables.TryGetValue(name, out var);
    90         if (var != null) value[i] = (T)var.Value;
    91       }
    92       return value;
    93     }
    94     protected virtual void SetValues(T[] values) {
    95       string name = GetActualName();
     99    protected virtual void SetActualValues(T[] values) {
     100      string name = LookupParameter<T>.TranslateName(Name, ExecutionContext);
    96101      IScope scope = ExecutionContext.Scope;
    97102      IVariable var;
  • trunk/sources/HeuristicLab.Parameters/3.3/ValueLookupParameter.cs

    r2754 r2756  
    2424using System.Text;
    2525using System.Xml;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    2930namespace HeuristicLab.Parameters {
    3031  /// <summary>
    31   /// A generic parameter which represents an instance of type T.
     32  /// A parameter whose value is either defined it the parameter itself or is retrieved from the scope.
    3233  /// </summary>
    33   [Item("ItemParameter<T>", "A generic parameter which represents an instance of type T.")]
    34   public class ItemParameter<T> : Parameter where T : class, IItem {
     34  [Item("ValueLookupParameter<T>", "A parameter whose value is either defined it the parameter itself or is retrieved from the scope.")]
     35  public class ValueLookupParameter<T> : Parameter, IValueLookupParameter<T> where T : class, IItem {
    3536    [Storable]
    3637    private string actualName;
     
    4647    }
    4748
    48     private T localValue;
     49    private T value;
    4950    [Storable]
    50     public T LocalValue {
    51       get { return this.localValue; }
     51    public T Value {
     52      get { return this.value; }
    5253      set {
    53         if (value != this.localValue) {
    54           if ((value != null) && (!DataType.IsInstanceOfType(value))) throw new ArgumentException("Static value does not match data type of parameter");
    55           if (this.localValue != null) this.localValue.Changed -= new ChangedEventHandler(LocalValue_Changed);
    56           this.localValue = value;
    57           if (this.localValue != null) this.localValue.Changed += new ChangedEventHandler(LocalValue_Changed);
    58           OnLocalValueChanged();
     54        if (value != this.value) {
     55          if (this.value != null) this.value.Changed -= new ChangedEventHandler(Value_Changed);
     56          this.value = value;
     57          if (this.value != null) this.value.Changed += new ChangedEventHandler(Value_Changed);
     58          OnValueChanged();
    5959        }
    6060      }
    6161    }
    6262
    63     public T Value {
    64       get { return GetValue(); }
    65       set { SetValue(value); }
     63    public T ActualValue {
     64      get { return GetActualValue(); }
     65      set { SetActualValue(value); }
    6666    }
    6767
    68     public ItemParameter()
    69       : base("Anonymous", null, typeof(T)) {
     68    public ValueLookupParameter()
     69      : base("Anonymous", typeof(T)) {
    7070      actualName = Name;
    71       LocalValue = null;
    7271    }
    73     public ItemParameter(string name, string description)
     72    public ValueLookupParameter(string name)
     73      : base(name, typeof(T)) {
     74      actualName = Name;
     75    }
     76    public ValueLookupParameter(string name, T value)
     77      : base(name, typeof(T)) {
     78      actualName = Name;
     79      Value = value;
     80    }
     81    public ValueLookupParameter(string name, string description)
    7482      : base(name, description, typeof(T)) {
    7583      actualName = Name;
    76       LocalValue = null;
    7784    }
    78     public ItemParameter(string name, string description, T localValue)
     85    public ValueLookupParameter(string name, string description, T value)
    7986      : base(name, description, typeof(T)) {
    8087      actualName = Name;
    81       LocalValue = localValue;
     88      Value = value;
    8289    }
    8390
    8491    public override IDeepCloneable Clone(Cloner cloner) {
    85       ItemParameter<T> clone = (ItemParameter<T>)base.Clone(cloner);
     92      ValueLookupParameter<T> clone = (ValueLookupParameter<T>)base.Clone(cloner);
    8693      clone.actualName = actualName;
    87       clone.LocalValue = (T)cloner.Clone(localValue);
     94      clone.Value = (T)cloner.Clone(value);
    8895      return clone;
    8996    }
    9097
    9198    public override string ToString() {
    92       return string.Format("{0}: {1} ({2})", Name, LocalValue != null ? LocalValue.ToString() : ActualName, DataType.Name);
     99      return string.Format("{0}: {1} ({2})", Name, Value != null ? Value.ToString() : ActualName, DataType.Name);
    93100    }
    94101
    95     protected ItemParameter<T> GetParameter(out string name) {
    96       ItemParameter<T> param = this;
     102    private IValueParameter<T> GetParameter(out string name) {
     103      IValueParameter<T> valueParam = this;
     104      ILookupParameter<T> lookupParam = this;
    97105      ExecutionContext current = ExecutionContext;
    98       name = param.Name;
    99       while (param != null) {
    100         if (param.LocalValue != null) return param;
    101         name = param.ActualName;
     106
     107      name = Name;
     108      while ((valueParam != null) && (lookupParam != null)) {
     109        if ((valueParam != null) && (valueParam.Value != null)) return valueParam;
     110        if (lookupParam != null) name = lookupParam.ActualName;
     111
    102112        current = current.Parent;
    103113        while ((current != null) && !current.Operator.Parameters.ContainsKey(name))
    104114          current = current.Parent;
    105         if (current != null)
    106           param = (ItemParameter<T>)current.Operator.Parameters[actualName];
    107         else
    108           param = null;
     115
     116        if (current != null) {
     117          valueParam = current.Operator.Parameters[name] as IValueParameter<T>;
     118          lookupParam = current.Operator.Parameters[name] as ILookupParameter<T>;
     119          if ((valueParam == null) && (lookupParam == null))
     120            throw new InvalidOperationException(
     121              string.Format("Parameter look-up chain broken. Parameter \"{0}\" is not an \"{1}\" or an \"{2}\".",
     122                            name,
     123                            typeof(IValueParameter<T>).GetPrettyName(),
     124                            typeof(ILookupParameter<T>).GetPrettyName())
     125            );
     126        } else {
     127          valueParam = null;
     128          lookupParam = null;
     129        }
    109130      }
    110131      return null;
    111132    }
    112     protected IVariable GetVariable(string name) {
     133    private IVariable LookupVariable(string name) {
    113134      IScope scope = ExecutionContext.Scope;
    114135      while ((scope != null) && !scope.Variables.ContainsKey(name))
     
    116137      return scope != null ? scope.Variables[actualName] : null;
    117138    }
    118     protected virtual T GetValue() {
     139    protected virtual T GetActualValue() {
    119140      string name;
    120141      // try to get local value from context stack
    121       ItemParameter<T> param = GetParameter(out name);
     142      IValueParameter<T> param = GetParameter(out name);
    122143      if (param != null) return param.Value;
    123       else {
    124         // try to get variable from scope
    125         IVariable var = GetVariable(name);
    126         if (var != null) return (T)var.Value;
     144      else {  // try to get variable from scope
     145        IVariable var = LookupVariable(name);
     146        if (var != null) {
     147          T value = var.Value as T;
     148          if (value == null)
     149            throw new InvalidOperationException(
     150              string.Format("Type mismatch. Variable \"{0}\" does not contain a \"{1}\".",
     151                            name,
     152                            typeof(T).GetPrettyName())
     153            );
     154          return value;
     155        }
    127156      }
    128157      return null;
    129158    }
    130     protected virtual void SetValue(T value) {
     159    protected virtual void SetActualValue(T value) {
    131160      string name;
    132161      // try to get local value from context stack
    133       ItemParameter<T> param = GetParameter(out name);
     162      IValueParameter<T> param = GetParameter(out name);
    134163      if (param != null) param.Value = value;
    135       else {
    136         // try to get variable from scope
    137         IVariable var = GetVariable(name);
     164      else {  // try to get variable from scope
     165        IVariable var = LookupVariable(name);
    138166        if (var != null) var.Value = value;
    139167        else ExecutionContext.Scope.Variables.Add(new Variable(name, value));
     
    147175      OnChanged();
    148176    }
    149     public event EventHandler LocalValueChanged;
    150     private void OnLocalValueChanged() {
    151       if (LocalValueChanged != null)
    152         LocalValueChanged(this, new EventArgs());
     177    public event EventHandler ValueChanged;
     178    private void OnValueChanged() {
     179      if (ValueChanged != null)
     180        ValueChanged(this, new EventArgs());
    153181      OnChanged();
    154182    }
    155     private void LocalValue_Changed(object sender, ChangedEventArgs e) {
     183    private void Value_Changed(object sender, ChangedEventArgs e) {
    156184      OnChanged(e);
    157185    }
Note: See TracChangeset for help on using the changeset viewer.