Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SimulationCore/HeuristicLab.DebugEngine/3.3/OperatorTraceView.cs @ 7031

Last change on this file since 7031 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 5.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Drawing;
24using System.Windows.Forms;
25using HeuristicLab.Collections;
26using HeuristicLab.Common.Resources;
27using HeuristicLab.Core;
28using HeuristicLab.MainForm;
29using HeuristicLab.MainForm.WindowsForms;
30using HeuristicLab.Operators;
31
32namespace HeuristicLab.DebugEngine {
33
34  [View("Operator Trace View")]
35  [Content(typeof(OperatorTrace), IsDefaultView = true)]
36  public partial class OperatorTraceView : AsynchronousContentView {
37
38    public new OperatorTrace Content {
39      get { return (OperatorTrace)base.Content; }
40      set { base.Content = value; }
41    }
42
43    public OperatorTraceView() {
44      InitializeComponent();
45    }
46
47    protected override void DeregisterContentEvents() {
48      Content.CollectionReset -= Content_CollectionChanged;
49      Content.ItemsAdded -= Content_CollectionChanged;
50      Content.ItemsMoved -= Content_CollectionChanged;
51      Content.ItemsRemoved -= Content_CollectionChanged;
52      Content.ItemsReplaced -= Content_CollectionChanged;
53      Content.IsEnabledChanged -= Content_IsEnabledChanged;
54      base.DeregisterContentEvents();
55    }
56
57    protected override void RegisterContentEvents() {
58      base.RegisterContentEvents();
59      Content.CollectionReset += Content_CollectionChanged;
60      Content.ItemsAdded += Content_CollectionChanged;
61      Content.ItemsMoved += Content_CollectionChanged;
62      Content.ItemsRemoved += Content_CollectionChanged;
63      Content.ItemsReplaced += Content_CollectionChanged;
64      Content.IsEnabledChanged += Content_IsEnabledChanged;
65    }
66
67    #region Event Handlers (Content)
68    void Content_CollectionChanged(object sender, CollectionItemsChangedEventArgs<Collections.IndexedItem<IOperator>> e) {
69      if (InvokeRequired)
70        Invoke(new EventHandler<CollectionItemsChangedEventArgs<IndexedItem<IOperator>>>(Content_CollectionChanged), sender, e);
71      else
72        UpdateOperatorTrace();
73    }
74    void Content_IsEnabledChanged(object sender, EventArgs e) {
75      if (InvokeRequired)
76        Invoke(new EventHandler(Content_IsEnabledChanged), sender, e);
77      else
78        isEnabledCheckbox.Checked = Content.IsEnabled;
79    }
80    #endregion
81
82    private void UpdateOperatorTrace() {
83      listView.BeginUpdate();
84      listView.Items.Clear();
85      listView.SmallImageList.Images.Clear();
86      listView.SmallImageList.Images.Add(VSImageLibrary.Method);
87      listView.SmallImageList.Images.Add(VSImageLibrary.Module);
88      listView.SmallImageList.Images.Add(VSImageLibrary.BreakpointActive);
89      foreach (var item in Content) {
90        var viewItem = listView.Items.Add(item.Name ?? item.ItemName);
91        viewItem.ToolTipText = string.Format("{0}{1}{1}{2}",
92          Utils.TypeName(item), Environment.NewLine,
93          Utils.Wrap(item.Description, 60));
94        viewItem.Tag = item;
95        if (item.Breakpoint) {
96          viewItem.ForeColor = Color.Red;
97          viewItem.ImageIndex = 2;
98        } else {
99          viewItem.ImageIndex = item is CombinedOperator ? 1 : 0;
100        }
101      }
102      if (listView.Items.Count > 0) {
103        for (int i = 0; i < listView.Columns.Count; i++)
104          listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
105      }
106      listView.EndUpdate();
107    }
108
109    protected override void OnContentChanged() {
110      base.OnContentChanged();
111      if (Content == null) {
112        listView.Items.Clear();
113        isEnabledCheckbox.Checked = false;
114      } else {
115        UpdateOperatorTrace();
116        isEnabledCheckbox.Checked = Content.IsEnabled;
117      }
118    }
119
120    protected override void SetEnabledStateOfControls() {
121      base.SetEnabledStateOfControls();
122      isEnabledCheckbox.Enabled = Content != null;
123      listView.Enabled = Content != null && Content.IsEnabled;
124    }
125
126    #region Event Handlers (child controls)
127    private void listView_ItemActivate(object sender, EventArgs e) {
128      if (listView.SelectedItems.Count > 0) {
129        IOperator op = listView.SelectedItems[0].Tag as IOperator;
130        if (op != null) {
131          MainFormManager.MainForm.ShowContent(op);
132        }
133      }
134    }
135    private void isEnabledCheckbox_CheckedChanged(object sender, EventArgs e) {
136      if (Content != null)
137        Content.IsEnabled = isEnabledCheckbox.Checked;
138      SetEnabledStateOfControls();
139    }
140    #endregion
141
142
143  }
144
145}
Note: See TracBrowser for help on using the repository browser.