Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators/3.3/CombinedOperatorView.cs @ 2664

Last change on this file since 2664 was 2546, checked in by swagner, 15 years ago

Continued work on Optimizer and on adapting all views to the new MainForm concept (#770)

File size: 5.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Text;
28using System.Windows.Forms;
29using HeuristicLab.Core;
30using HeuristicLab.Core.Views;
31using HeuristicLab.MainForm;
32
33namespace HeuristicLab.Operators {
34  /// <summary>
35  /// The visual representation of a <see cref="CombinedOperator"/>.
36  /// </summary>
37  [Content(typeof(CombinedOperator), true)]
38  public partial class CombinedOperatorView : ItemViewBase {
39    /// <summary>
40    /// Gets or sets the combined operator to display.
41    /// </summary>
42    /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
43    /// No own data storage present.</remarks>
44    public CombinedOperator CombinedOperator {
45      get { return (CombinedOperator)Item; }
46      set { base.Item = value; }
47    }
48
49    /// <summary>
50    /// Removes the eventhandlers in all children and from the underlying <see cref="CombinedOperator"/>.
51    /// </summary>
52    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
53    protected override void RemoveItemEvents() {
54      operatorGraphView.OperatorGraph = null;
55      operatorBaseVariableInfosView.Operator = null;
56      operatorBaseVariablesView.Operator = null;
57      CombinedOperator.DescriptionChanged -= new EventHandler(CombinedOperator_DescriptionChanged);
58      base.RemoveItemEvents();
59    }
60   
61    /// <summary>
62    /// Adds event handlers in all children and to the underlying <see cref="CombinedOperator"/>.
63    /// </summary>
64    /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
65    protected override void AddItemEvents() {
66      base.AddItemEvents();
67      operatorGraphView.OperatorGraph = CombinedOperator.OperatorGraph;
68      operatorBaseVariableInfosView.Operator = CombinedOperator;
69      operatorBaseVariablesView.Operator = CombinedOperator;
70      CombinedOperator.DescriptionChanged += new EventHandler(CombinedOperator_DescriptionChanged);
71    }
72
73    /// <summary>
74    /// Initializes a new instance of <see cref="CombinedOperatorView"/>.
75    /// </summary>
76    public CombinedOperatorView() {
77      InitializeComponent();
78    }
79    /// <summary>
80    /// Initializes a new instance of <see cref="CombinedOperatorView"/> with the specified
81    /// <paramref name="combinedOperator"/>.
82    /// </summary>
83    /// <param name="combinedOperator">The combined operator to display.</param>
84    public CombinedOperatorView(CombinedOperator combinedOperator)
85      : this() {
86      CombinedOperator = combinedOperator;
87    }
88
89    /// <summary>
90    /// Updates all controls with the latest data of the model.
91    /// </summary>
92    protected override void UpdateControls() {
93      base.UpdateControls();
94      if (CombinedOperator == null) {
95        descriptionTextBox.Text = "";
96        descriptionTextBox.Enabled = false;
97      } else {
98        descriptionTextBox.Text = CombinedOperator.Description;
99        descriptionTextBox.Enabled = true;
100      }
101    }
102
103    private void CombinedOperator_DescriptionChanged(object sender, EventArgs e) {
104      descriptionTextBox.Text = CombinedOperator.Description;
105    }
106    private void descriptionTextBox_Validated(object sender, EventArgs e) {
107      CombinedOperator.SetDescription(descriptionTextBox.Text);
108    }
109
110    private void operatorBaseVariableInfosView_SelectedVariableInfosChanged(object sender, EventArgs e) {
111      removeVariableInfoButton.Enabled = operatorBaseVariableInfosView.SelectedVariableInfos.Count > 0;
112    }
113
114    #region Click Events
115    private void addVariableInfoButton_Click(object sender, EventArgs e) {
116      AddVariableInfoDialog dialog = new AddVariableInfoDialog();
117      if (dialog.ShowDialog(this) == DialogResult.OK) {
118        if (CombinedOperator.GetVariableInfo(dialog.VariableInfo.FormalName) != null)
119          HeuristicLab.Core.Views.Auxiliary.ShowErrorMessageBox("A variable info with the same formal name already exists.");
120        else
121          CombinedOperator.AddVariableInfo(dialog.VariableInfo);
122      }
123      dialog.Dispose();
124    }
125    private void removeVariableInfoButton_Click(object sender, EventArgs e) {
126      IVariableInfo[] selected = new IVariableInfo[operatorBaseVariableInfosView.SelectedVariableInfos.Count];
127      operatorBaseVariableInfosView.SelectedVariableInfos.CopyTo(selected, 0);
128      for (int i = 0; i < selected.Length; i++)
129        CombinedOperator.RemoveVariableInfo(selected[i].FormalName);
130    }
131    #endregion
132  }
133}
Note: See TracBrowser for help on using the repository browser.