Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DebugEngine/3.3/OperationContentView.cs @ 5163

Last change on this file since 5163 was 5146, checked in by epitzer, 14 years ago

(#47)

  • Show a different icon for breakpoints
  • Show an icon for the active operation
File size: 10.6 KB
RevLine 
[4998]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;
[4876]23using System.Drawing;
24using System.Text;
25using System.Windows.Forms;
[4903]26using HeuristicLab.Common;
[4909]27using HeuristicLab.Common.Resources;
[4903]28using HeuristicLab.Core;
29using HeuristicLab.MainForm;
[4876]30using HeuristicLab.MainForm.WindowsForms;
31
32namespace HeuristicLab.DebugEngine {
33
34  [View("Operation Content View")]
35  [Content(typeof(OperationContent), IsDefaultView = true)]
[5003]36  public partial class OperationContentView : AsynchronousContentView {
[4876]37    public new OperationContent Content {
38      get { return (OperationContent)base.Content; }
39      set { base.Content = value; }
40    }
41
42    public OperationContentView() {
43      InitializeComponent();
44    }
45
46    protected override void OnContentChanged() {
47      base.OnContentChanged();
48      if (Content == null) {
49        nameTextBox.Text = "";
50        scopeTreeView.Nodes.Clear();
51        executionContextTreeView.Nodes.Clear();
[5146]52        iconBox.Image = null;
[4876]53      } else {
54        nameTextBox.Text = Content.Name;
55        UpdateScopeTree();
56        UpdateExecutionContext();
[5146]57        iconBox.Image = Content.Icon;
[4876]58      }
59    }
60
[5116]61    private object GetParameterValue(IParameter param, IExecutionContext context, out string actualName) {
[4903]62      param = (IParameter)param.Clone();
[4876]63      param.ExecutionContext = context;
64      object value = null;
65      try {
[4903]66        value = param.ActualValue;
67      } catch (Exception x) {
68        value = x.Message;
[4876]69      }
[5116]70      ILookupParameter lookupParam = param as ILookupParameter;
71      if (lookupParam != null)
72        actualName = lookupParam.ActualName;
73      else
74        actualName = null;
[4876]75      return value;
76    }
77
78    private void UpdateScopeTree() {
79      scopeTreeView.BeginUpdate();
80      scopeTreeView.Nodes.Clear();
[4909]81      scopeTreeView.ImageList.Images.Clear();
82      scopeTreeView.ImageList.Images.Add(VS2008ImageLibrary.Namespace);
83      scopeTreeView.ImageList.Images.Add(VS2008ImageLibrary.Field);
[4876]84      if (Content.IsContext) {
85        var scope = Content.ExecutionContext.Scope;
86        while (scope != null && scope.Parent != null)
87          scope = scope.Parent;
[4993]88        if (scope != null)
[4903]89          AddScope(scopeTreeView.Nodes, scope);
[4876]90      }
91      scopeTreeView.EndUpdate();
92    }
93
94    private void AddScope(TreeNodeCollection nodes, IScope scope) {
[4909]95      TreeNode node = nodes.Add(string.Format("{0} ({1}+{2})",
96        scope.Name, scope.Variables.Count, scope.SubScopes.Count));
[4876]97      node.Tag = scope;
[4909]98      node.ImageIndex = 0;
99      node.SelectedImageIndex = 0;
[4876]100      foreach (var var in scope.Variables) {
101        TreeNode varNode = node.Nodes.Add(string.Format("{0}={1}", var.Name, var.Value));
102        varNode.Tag = var.Value;
[4909]103        varNode.ToolTipText = string.Format("{0}{1}{1}{2}",
104          Utils.TypeName(var.Value), Environment.NewLine,
105          Utils.Wrap(var.Description ?? var.ItemDescription, 60));
106        varNode.ImageIndex = 1;
107        varNode.SelectedImageIndex = 1;
[4876]108      }
[4930]109      foreach (var subScope in scope.SubScopes)
[4876]110        AddScope(node.Nodes, subScope);
[4930]111      if (Content.IsAtomic && Content.AtomicOperation.Scope == scope) {
112        node.NodeFont = new Font(DefaultFont, FontStyle.Bold);
113        node.ForeColor = Color.White;
114        node.BackColor = Color.Crimson;
115        node.Expand();
116        scopeTreeView.TopNode = node;
[4931]117        node.ToolTipText = "Current scope of active operation";
[4876]118      }
119    }
120
[4930]121
[4876]122    private void UpdateExecutionContext() {
123      executionContextTreeView.BeginUpdate();
124      executionContextTreeView.Nodes.Clear();
[4909]125      executionContextTreeView.ImageList.Images.Clear();
126      executionContextTreeView.ImageList.Images.Add(VS2008ImageLibrary.Namespace);
[4876]127      if (Content.IsContext) {
128        AddExecutionContext(Content.ExecutionContext, executionContextTreeView.Nodes);
129      }
[4903]130      executionContextTreeView.ExpandAll();
131      if (executionContextTreeView.Nodes.Count > 0)
132        executionContextTreeView.TopNode = executionContextTreeView.Nodes[0];
[4876]133      executionContextTreeView.EndUpdate();
134    }
135
136    private void AddExecutionContext(IExecutionContext executionContext, TreeNodeCollection nodes) {
137      ExecutionContext context = executionContext as ExecutionContext;
138      StringBuilder name = new StringBuilder();
139      if (context != null && context.Operator != null)
[4909]140        name.Append(context.Operator.Name);
[4876]141      else
142        name.Append("<Context>");
143      name.Append("@").Append(executionContext.Scope.Name);
144      TreeNode node = nodes.Add(name.ToString());
145      node.Tag = executionContext;
[4909]146      node.ImageIndex = 0;
147      node.SelectedImageIndex = 0;
[4876]148      foreach (var param in executionContext.Parameters) {
[5116]149        string actualName = null;
150        object value = GetParameterValue(param, executionContext, out actualName);
151        string label = actualName != null && actualName != param.Name ?
152          string.Format("{0}({1})={2}", param.Name, actualName, value) :
153          string.Format("{0}={1}", param.Name, value);
154        TreeNode paramNode = node.Nodes.Add(label);
[4876]155        paramNode.Tag = param;
[4909]156        executionContextTreeView.ImageList.Images.Add(param.ItemImage ?? VS2008ImageLibrary.Nothing);
157        paramNode.ImageIndex = executionContextTreeView.ImageList.Images.Count - 1;
158        paramNode.SelectedImageIndex = paramNode.ImageIndex;
159        paramNode.ToolTipText = string.Format("{0}{1}{1}{2}",
160          Utils.TypeName(param), Environment.NewLine,
161          Utils.Wrap(param.Description ?? param.ItemDescription, 60));
[4876]162      }
163      if (executionContext.Parent != null)
164        AddExecutionContext(executionContext.Parent, node.Nodes);
165    }
166
167    #region Event Handlers (child controls)
168
169    private void executionContextTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
170      if (e.Node != null) {
171        IParameter param = e.Node.Tag as IParameter;
172        if (param != null)
173          MainFormManager.MainForm.ShowContent(param);
174      }
175    }
176
[4909]177    private void scopeTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
178      if (e.Node != null) {
179        IItem item = e.Node.Tag as IItem;
180        if (item != null)
181          MainFormManager.MainForm.ShowContent(item);
182      }
183    }
184
[4993]185    private TreeNode selectedScopeNode = null;
[4876]186    private void executionContextTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
[5116]187      scopeTreeView.BeginUpdate();
[4993]188      if (selectedScopeNode != null) {
189        if (Content.IsAtomic && Content.AtomicOperation.Scope == selectedScopeNode.Tag) {
190          selectedScopeNode.BackColor = Color.Crimson;
191          selectedScopeNode.ForeColor = Color.White;
192          selectedScopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
193        } else {
194          selectedScopeNode.BackColor = Color.White;
195          selectedScopeNode.ForeColor = Color.Black;
196          selectedScopeNode.NodeFont = DefaultFont;
197        }
198      }
[4876]199      if (e.Node != null) {
200        IExecutionContext context = e.Node.Tag as IExecutionContext;
201        if (context != null && context.Scope != null) {
202          TreeNode scopeNode = FindScopeNode(context.Scope, scopeTreeView.Nodes);
203          if (scopeNode != null) {
[4993]204            if (Content.IsAtomic && Content.AtomicOperation.Scope == scopeNode.Tag) {
205              scopeNode.BackColor = Color.DarkViolet;
206              scopeNode.ForeColor = Color.White;
207              scopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
208            } else {
209              scopeNode.BackColor = Color.Blue;
210              scopeNode.ForeColor = Color.White;
211              scopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
[4876]212            }
[4993]213            selectedScopeNode = scopeNode;
[4876]214            scopeTreeView.TopNode = scopeNode;
215          }
216        }
217      }
[5116]218      scopeTreeView.EndUpdate();
[4876]219    }
220
221    private TreeNode FindScopeNode(IScope scope, TreeNodeCollection nodes) {
222      foreach (TreeNode node in nodes) {
223        if (node.Tag == scope) {
224          return node;
225        } else {
226          TreeNode childNode = FindScopeNode(scope, node.Nodes);
227          if (childNode != null)
228            return childNode;
229        }
230      }
231      return null;
232    }
233
[4903]234    private void nameTextBox_DoubleClick(object sender, EventArgs e) {
235      if (Content != null && Content.IsAtomic && Content.AtomicOperation.Operator != null)
236        MainFormManager.MainForm.ShowContent(Content.AtomicOperation.Operator);
237    }
238
[5003]239    private void ShowValue_Click(object sender, EventArgs e) {
240      if (executionContextTreeView.SelectedNode == null)
241        return;
242      IParameter param = executionContextTreeView.SelectedNode.Tag as IParameter;
[5122]243      if (param != null) {
244        string actualName = null;
[5124]245        IExecutionContext context = executionContextTreeView.SelectedNode.Parent.Tag as IExecutionContext ?? Content.ExecutionContext;
[5122]246        MainFormManager.MainForm.ShowContent(GetParameterValue(param, context, out actualName) as IContent);
247      }
[5003]248    }
249
250    private void executionContextConextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
[5077]251      IParameter param = executionContextTreeView.SelectedNode.Tag as IParameter;
[5122]252      if (param != null) {
253        string actualName = null;
254        IExecutionContext context = executionContextTreeView.SelectedNode.Parent.Tag as IExecutionContext ?? Content.ExecutionContext;
255        showValueToolStripMenuItem.Enabled = GetParameterValue(param, context, out actualName) is IContent;
256      } else
[5077]257        e.Cancel = true;
[5003]258    }
259
[5116]260    private void executionContextTreeView_MouseDown(object sender, MouseEventArgs e) {
261      if (e.Button == System.Windows.Forms.MouseButtons.Right)
262        executionContextTreeView.SelectedNode = executionContextTreeView.GetNodeAt(e.Location);
263    }
[5003]264
[5116]265    #endregion
[5003]266
[5116]267
[4876]268  }
269}
Note: See TracBrowser for help on using the repository browser.