Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5002 was 5002, checked in by epitzer, 13 years ago

unseal views, rename OperatorTrace.Generate to Regenerate, and remove questionable virtual from property with private setter (#47)

File size: 4.1 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 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      listView.BeginUpdate();
75      listView.Items.Clear();
76      listView.SmallImageList.Images.Clear();
77      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Method);
78      listView.SmallImageList.Images.Add(VS2008ImageLibrary.Module);
79      foreach (var item in Content) {
80        var viewItem = listView.Items.Add(item.Name ?? item.ItemName);
81        viewItem.ToolTipText = string.Format("{0}{1}{1}{2}",
82          Utils.TypeName(item), Environment.NewLine,
83          Utils.Wrap(item.Description, 60));
84        viewItem.Tag = item;
85        viewItem.ImageIndex = item is CombinedOperator ? 1 : 0;
86      }
87      if (listView.Items.Count > 0) {
88        for (int i = 0; i < listView.Columns.Count; i++)
89          listView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
90      }
91      listView.EndUpdate();
92    }
93
94    protected override void OnContentChanged() {
95      base.OnContentChanged();
96      if (Content == null) {
97        listView.Items.Clear();
98      } else {
99        UpdateOperatorTrace();
100      }
101    }
102
103    #region Event Handlers (child controls)
104    private void listView_ItemActivate(object sender, EventArgs e) {
105      if (listView.SelectedItems.Count > 0) {
106        IOperator op = listView.SelectedItems[0].Tag as IOperator;
107        if (op != null) {
108          MainFormManager.MainForm.ShowContent(op);
109        }
110      }
111    }
112    #endregion
113  }
114
115}
Note: See TracBrowser for help on using the repository browser.