Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.1/sources/HeuristicLab.Core/OperatorBaseVariableInfosView.cs @ 9674

Last change on this file since 9674 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 6.0 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;
29
30namespace HeuristicLab.Core {
31  public partial class OperatorBaseVariableInfosView : ViewBase {
32    public IOperator Operator {
33      get { return (IOperator)Item; }
34      set { base.Item = value; }
35    }
36    public ICollection<IVariableInfo> SelectedVariableInfos {
37      get {
38        List<IVariableInfo> selected = new List<IVariableInfo>();
39        foreach (ListViewItem item in variableInfosListView.SelectedItems)
40          selected.Add((IVariableInfo)item.Tag);
41        return selected.AsReadOnly();
42      }
43    }
44
45    public OperatorBaseVariableInfosView() {
46      InitializeComponent();
47      variableInfosListView.Columns[0].Width = Math.Max(0, variableInfosListView.Width - 25);
48      Caption = "Operator";
49    }
50    public OperatorBaseVariableInfosView(IOperator op)
51      : this() {
52      Operator = op;
53    }
54
55    protected override void RemoveItemEvents() {
56      Operator.VariableInfoAdded -= new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoAdded);
57      Operator.VariableInfoRemoved -= new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoRemoved);
58      base.RemoveItemEvents();
59    }
60    protected override void AddItemEvents() {
61      base.AddItemEvents();
62      Operator.VariableInfoAdded += new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoAdded);
63      Operator.VariableInfoRemoved += new EventHandler<VariableInfoEventArgs>(OperatorBase_VariableInfoRemoved);
64    }
65
66    protected override void UpdateControls() {
67      base.UpdateControls();
68      variableInfoDetailsGroupBox.Controls.Clear();
69      if (Operator == null) {
70        Caption = "Operator";
71        variableInfosListView.Enabled = false;
72        variableInfoDetailsGroupBox.Enabled = false;
73      } else {
74        Caption = Operator.Name + " (" + Operator.GetType().Name + ")";
75        variableInfosListView.Enabled = true;
76        foreach (ListViewItem item in variableInfosListView.Items) {
77          ((IVariableInfo)item.Tag).ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
78        }
79        variableInfosListView.Items.Clear();
80        foreach (IVariableInfo variableInfo in Operator.VariableInfos) {
81          ListViewItem item = new ListViewItem();
82          item.Text = variableInfo.ActualName;
83          item.Tag = variableInfo;
84          variableInfosListView.Items.Add(item);
85          variableInfo.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
86        }
87        if (variableInfosListView.Items.Count > 0)
88          variableInfosListView.SelectedIndices.Add(0);
89      }
90    }
91
92    private void variableInfosListView_SelectedIndexChanged(object sender, EventArgs e) {
93      if (variableInfoDetailsGroupBox.Controls.Count > 0)
94        variableInfoDetailsGroupBox.Controls[0].Dispose();
95      variableInfoDetailsGroupBox.Controls.Clear();
96      variableInfoDetailsGroupBox.Enabled = false;
97      if (variableInfosListView.SelectedItems.Count == 1) {
98        IVariableInfo variableInfo = (IVariableInfo)variableInfosListView.SelectedItems[0].Tag;
99        Control control = (Control)variableInfo.CreateView();
100        variableInfoDetailsGroupBox.Controls.Add(control);
101        control.Dock = DockStyle.Fill;
102        variableInfoDetailsGroupBox.Enabled = true;
103      }
104      OnSelectedVariableInfosChanged();
105    }
106
107    public event EventHandler SelectedVariableInfosChanged;
108    protected virtual void OnSelectedVariableInfosChanged() {
109      if (SelectedVariableInfosChanged != null)
110        SelectedVariableInfosChanged(this, new EventArgs());
111    }
112
113    #region Size Changed Events
114    private void variableInfosListView_SizeChanged(object sender, EventArgs e) {
115      if (variableInfosListView.Columns.Count > 0)
116        variableInfosListView.Columns[0].Width = Math.Max(0, variableInfosListView.Width - 25);
117    }
118    #endregion
119
120    #region VariableInfo Events
121    private void VariableInfo_ActualNameChanged(object sender, EventArgs e) {
122      IVariableInfo variableInfo = (IVariableInfo)sender;
123      foreach (ListViewItem item in variableInfosListView.Items) {
124        if (item.Tag == variableInfo)
125          item.Text = variableInfo.ActualName;
126      }
127    }
128    #endregion
129
130    #region OperatorBase Events
131    private void OperatorBase_VariableInfoAdded(object sender, VariableInfoEventArgs e) {
132      ListViewItem item = new ListViewItem();
133      item.Text = e.VariableInfo.ActualName;
134      item.Tag = e.VariableInfo;
135      variableInfosListView.Items.Add(item);
136      e.VariableInfo.ActualNameChanged += new EventHandler(VariableInfo_ActualNameChanged);
137    }
138    private void OperatorBase_VariableInfoRemoved(object sender, VariableInfoEventArgs e) {
139      ListViewItem itemToDelete = null;
140      foreach (ListViewItem item in variableInfosListView.Items) {
141        if (item.Tag == e.VariableInfo)
142          itemToDelete = item;
143      }
144      e.VariableInfo.ActualNameChanged -= new EventHandler(VariableInfo_ActualNameChanged);
145      variableInfosListView.Items.Remove(itemToDelete);
146    }
147    #endregion
148  }
149}
Note: See TracBrowser for help on using the repository browser.