[2] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Windows.Forms;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Core {
|
---|
[776] | 31 | /// <summary>
|
---|
| 32 | /// The visual representation of the information of the variables of an operator.
|
---|
| 33 | /// </summary>
|
---|
[2] | 34 | public partial class OperatorBaseVariableInfosView : ViewBase {
|
---|
[776] | 35 | /// <summary>
|
---|
| 36 | /// Gets or sets the operator whose variable infos should be represented visually.
|
---|
| 37 | /// </summary>
|
---|
| 38 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 39 | /// No own data storage present.</remarks>
|
---|
[2] | 40 | public IOperator Operator {
|
---|
| 41 | get { return (IOperator)Item; }
|
---|
| 42 | set { base.Item = value; }
|
---|
| 43 | }
|
---|
[776] | 44 | /// <summary>
|
---|
| 45 | /// Gets all selected variable infos.
|
---|
| 46 | /// <note type="caution"> Variable infos are returned read-only!</note>
|
---|
| 47 | /// </summary>
|
---|
[2] | 48 | public ICollection<IVariableInfo> SelectedVariableInfos {
|
---|
| 49 | get {
|
---|
| 50 | List<IVariableInfo> selected = new List<IVariableInfo>();
|
---|
| 51 | foreach (ListViewItem item in variableInfosListView.SelectedItems)
|
---|
| 52 | selected.Add((IVariableInfo)item.Tag);
|
---|
| 53 | return selected.AsReadOnly();
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[776] | 57 | /// <summary>
|
---|
| 58 | /// Initializes a new instance of <see cref="OperatorBaseVariableInfosView"/> with caption "Operator".
|
---|
| 59 | /// </summary>
|
---|
[2] | 60 | public OperatorBaseVariableInfosView() {
|
---|
| 61 | InitializeComponent();
|
---|
| 62 | variableInfosListView.Columns[0].Width = Math.Max(0, variableInfosListView.Width - 25);
|
---|
| 63 | Caption = "Operator";
|
---|
| 64 | }
|
---|
[776] | 65 | /// <summary>
|
---|
| 66 | /// Initializes a new instance of <see cref="OperatorBaseVariableInfosView"/> with the given operator
|
---|
| 67 | /// <paramref name="op"/>.
|
---|
| 68 | /// </summary>
|
---|
| 69 | /// <remarks>Calls <see cref="OperatorBaseVariableInfosView()"/>.</remarks>
|
---|
| 70 | /// <param name="op">The operator whose variable infos should be displayed.</param>
|
---|
[2] | 71 | public OperatorBaseVariableInfosView(IOperator op)
|
---|
| 72 | : this() {
|
---|
| 73 | Operator = op;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[776] | 76 | /// <summary>
|
---|
| 77 | /// Removes the eventhandlers from the underlying <see cref="IOperator"/>.
|
---|
| 78 | /// </summary>
|
---|
| 79 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 80 | protected override void RemoveItemEvents() {
|
---|
| 81 | Operator.VariableInfoAdded -= new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoAdded);
|
---|
| 82 | Operator.VariableInfoRemoved -= new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoRemoved);
|
---|
| 83 | base.RemoveItemEvents();
|
---|
| 84 | }
|
---|
[776] | 85 | /// <summary>
|
---|
| 86 | /// Adds eventhandlers to the underlying <see cref="IOperator"/>.
|
---|
| 87 | /// </summary>
|
---|
| 88 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 89 | protected override void AddItemEvents() {
|
---|
| 90 | base.AddItemEvents();
|
---|
| 91 | Operator.VariableInfoAdded += new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoAdded);
|
---|
| 92 | Operator.VariableInfoRemoved += new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoRemoved);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[776] | 95 | /// <summary>
|
---|
| 96 | /// Updates all controls with the latest data of the model.
|
---|
| 97 | /// </summary>
|
---|
| 98 | /// <remarks>Calls <see cref="ViewBase.UpdateControls"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
[2] | 99 | protected override void UpdateControls() {
|
---|
| 100 | base.UpdateControls();
|
---|
| 101 | variableInfoDetailsGroupBox.Controls.Clear();
|
---|
| 102 | if (Operator == null) {
|
---|
| 103 | Caption = "Operator";
|
---|
| 104 | variableInfosListView.Enabled = false;
|
---|
| 105 | variableInfoDetailsGroupBox.Enabled = false;
|
---|
| 106 | } else {
|
---|
| 107 | Caption = Operator.Name + " (" + Operator.GetType().Name + ")";
|
---|
| 108 | variableInfosListView.Enabled = true;
|
---|
| 109 | foreach (ListViewItem item in variableInfosListView.Items) {
|
---|
| 110 | ((IVariableInfo)item.Tag).ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
|
---|
| 111 | }
|
---|
| 112 | variableInfosListView.Items.Clear();
|
---|
| 113 | foreach (IVariableInfo variableInfo in Operator.VariableInfos) {
|
---|
| 114 | ListViewItem item = new ListViewItem();
|
---|
| 115 | item.Text = variableInfo.ActualName;
|
---|
| 116 | item.Tag = variableInfo;
|
---|
| 117 | variableInfosListView.Items.Add(item);
|
---|
| 118 | variableInfo.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
|
---|
| 119 | }
|
---|
| 120 | if (variableInfosListView.Items.Count > 0)
|
---|
| 121 | variableInfosListView.SelectedIndices.Add(0);
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | private void variableInfosListView_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 126 | if (variableInfoDetailsGroupBox.Controls.Count > 0)
|
---|
| 127 | variableInfoDetailsGroupBox.Controls[0].Dispose();
|
---|
| 128 | variableInfoDetailsGroupBox.Controls.Clear();
|
---|
| 129 | variableInfoDetailsGroupBox.Enabled = false;
|
---|
| 130 | if (variableInfosListView.SelectedItems.Count == 1) {
|
---|
| 131 | IVariableInfo variableInfo = (IVariableInfo)variableInfosListView.SelectedItems[0].Tag;
|
---|
| 132 | Control control = (Control)variableInfo.CreateView();
|
---|
| 133 | variableInfoDetailsGroupBox.Controls.Add(control);
|
---|
| 134 | control.Dock = DockStyle.Fill;
|
---|
| 135 | variableInfoDetailsGroupBox.Enabled = true;
|
---|
| 136 | }
|
---|
| 137 | OnSelectedVariableInfosChanged();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[776] | 140 | /// <summary>
|
---|
| 141 | /// Occurs when the variables were changed, whose infos should be displayed.
|
---|
| 142 | /// </summary>
|
---|
[2] | 143 | public event EventHandler SelectedVariableInfosChanged;
|
---|
[776] | 144 | /// <summary>
|
---|
| 145 | /// Fires a new <c>SelectedVariableInfosChanged</c>.
|
---|
| 146 | /// </summary>
|
---|
[2] | 147 | protected virtual void OnSelectedVariableInfosChanged() {
|
---|
| 148 | if (SelectedVariableInfosChanged != null)
|
---|
| 149 | SelectedVariableInfosChanged(this, new EventArgs());
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | #region Size Changed Events
|
---|
| 153 | private void variableInfosListView_SizeChanged(object sender, EventArgs e) {
|
---|
| 154 | if (variableInfosListView.Columns.Count > 0)
|
---|
| 155 | variableInfosListView.Columns[0].Width = Math.Max(0, variableInfosListView.Width - 25);
|
---|
| 156 | }
|
---|
| 157 | #endregion
|
---|
| 158 |
|
---|
| 159 | #region VariableInfo Events
|
---|
| 160 | private void VariableInfo_ActualNameChanged(object sender, EventArgs e) {
|
---|
| 161 | IVariableInfo variableInfo = (IVariableInfo)sender;
|
---|
| 162 | foreach (ListViewItem item in variableInfosListView.Items) {
|
---|
| 163 | if (item.Tag == variableInfo)
|
---|
| 164 | item.Text = variableInfo.ActualName;
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 | #endregion
|
---|
| 168 |
|
---|
| 169 | #region OperatorBase Events
|
---|
| 170 | private void OperatorBase_VariableInfoAdded(object sender, VariableInfoEventArgs e) {
|
---|
| 171 | ListViewItem item = new ListViewItem();
|
---|
| 172 | item.Text = e.VariableInfo.ActualName;
|
---|
| 173 | item.Tag = e.VariableInfo;
|
---|
| 174 | variableInfosListView.Items.Add(item);
|
---|
| 175 | e.VariableInfo.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
|
---|
| 176 | }
|
---|
| 177 | private void OperatorBase_VariableInfoRemoved(object sender, VariableInfoEventArgs e) {
|
---|
| 178 | ListViewItem itemToDelete = null;
|
---|
| 179 | foreach (ListViewItem item in variableInfosListView.Items) {
|
---|
| 180 | if (item.Tag == e.VariableInfo)
|
---|
| 181 | itemToDelete = item;
|
---|
| 182 | }
|
---|
| 183 | e.VariableInfo.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
|
---|
| 184 | variableInfosListView.Items.Remove(itemToDelete);
|
---|
| 185 | }
|
---|
| 186 | #endregion
|
---|
| 187 | }
|
---|
| 188 | }
|
---|