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