Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DebugEngine/OperatorTraceView.cs @ 5000

Last change on this file since 5000 was 4998, checked in by epitzer, 14 years ago

remove resources, add license headers, update plug-in dependencies (#47)

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