1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Forms;
|
---|
6 | using HeuristicLab.Common;
|
---|
7 | using HeuristicLab.Common.Resources;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.MainForm;
|
---|
10 | using HeuristicLab.MainForm.WindowsForms;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.DebugEngine {
|
---|
13 |
|
---|
14 | [View("Operation Content View")]
|
---|
15 | [Content(typeof(OperationContent), IsDefaultView = true)]
|
---|
16 | public sealed partial class OperationContentView : AsynchronousContentView {
|
---|
17 | public new OperationContent Content {
|
---|
18 | get { return (OperationContent)base.Content; }
|
---|
19 | set { base.Content = value; }
|
---|
20 | }
|
---|
21 |
|
---|
22 | public OperationContentView() {
|
---|
23 | InitializeComponent();
|
---|
24 | }
|
---|
25 |
|
---|
26 | protected override void OnContentChanged() {
|
---|
27 | base.OnContentChanged();
|
---|
28 | if (Content == null) {
|
---|
29 | nameTextBox.Text = "";
|
---|
30 | contextLabel.ForeColor = SystemColors.ControlDark;
|
---|
31 | atomicLabel.ForeColor = SystemColors.ControlDark;
|
---|
32 | collectionLabel.ForeColor = SystemColors.ControlDark;
|
---|
33 | parameterListView.Items.Clear();
|
---|
34 | scopeTreeView.Nodes.Clear();
|
---|
35 | executionContextTreeView.Nodes.Clear();
|
---|
36 | } else {
|
---|
37 | contextLabel.ForeColor = Content.IsContext ? Color.Black : SystemColors.ControlDark;
|
---|
38 | atomicLabel.ForeColor = Content.IsAtomic ? Color.Black : SystemColors.ControlDark;
|
---|
39 | collectionLabel.ForeColor = Content.IsCollection ? Color.Black : SystemColors.ControlDark;
|
---|
40 | nameTextBox.Text = Content.Name;
|
---|
41 | UpdateParameters();
|
---|
42 | UpdateScopeTree();
|
---|
43 | UpdateExecutionContext();
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | private void UpdateParameters() {
|
---|
48 | parameterListView.BeginUpdate();
|
---|
49 | parameterListView.Items.Clear();
|
---|
50 | parameterListView.SmallImageList.Images.Clear();
|
---|
51 | if (Content.IsAtomic) {
|
---|
52 | foreach (var param in Content.AtomicOperation.Operator.Parameters) {
|
---|
53 | ListViewItem item = parameterListView.Items.Add(
|
---|
54 | string.Format("{0} = {1}", param.Name, GetParameterValue(param, Content.ExecutionContext)));
|
---|
55 | item.Tag = param;
|
---|
56 | parameterListView.SmallImageList.Images.Add(param.ItemImage ?? VS2008ImageLibrary.Nothing);
|
---|
57 | item.ImageIndex = parameterListView.SmallImageList.Images.Count - 1;
|
---|
58 | item.ToolTipText = string.Format("{0}{1}{1}{2}",
|
---|
59 | Utils.TypeName(param), Environment.NewLine,
|
---|
60 | Utils.Wrap(param.Description ?? param.ItemDescription, 60));
|
---|
61 | }
|
---|
62 | }
|
---|
63 | if (parameterListView.Items.Count > 0) {
|
---|
64 | for (int i = 0; i < parameterListView.Columns.Count; i++)
|
---|
65 | parameterListView.Columns[i].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
|
---|
66 | }
|
---|
67 | parameterListView.EndUpdate();
|
---|
68 | }
|
---|
69 |
|
---|
70 | private object GetParameterValue(IParameter param, IExecutionContext context) {
|
---|
71 | param = (IParameter)param.Clone();
|
---|
72 | param.ExecutionContext = context;
|
---|
73 | object value = null;
|
---|
74 | try {
|
---|
75 | value = param.ActualValue;
|
---|
76 | } catch (Exception x) {
|
---|
77 | value = x.Message;
|
---|
78 | }
|
---|
79 | return value;
|
---|
80 | }
|
---|
81 |
|
---|
82 | private void UpdateScopeTree() {
|
---|
83 | scopeTreeView.BeginUpdate();
|
---|
84 | scopeTreeView.Nodes.Clear();
|
---|
85 | scopeTreeView.ImageList.Images.Clear();
|
---|
86 | scopeTreeView.ImageList.Images.Add(VS2008ImageLibrary.Namespace);
|
---|
87 | scopeTreeView.ImageList.Images.Add(VS2008ImageLibrary.Field);
|
---|
88 | if (Content.IsContext) {
|
---|
89 | var scope = Content.ExecutionContext.Scope;
|
---|
90 | while (scope != null && scope.Parent != null)
|
---|
91 | scope = scope.Parent;
|
---|
92 | if (scope != null) {
|
---|
93 | AddScope(scopeTreeView.Nodes, scope);
|
---|
94 |
|
---|
95 | }
|
---|
96 | }
|
---|
97 | scopeTreeView.EndUpdate();
|
---|
98 | }
|
---|
99 |
|
---|
100 | private void AddScope(TreeNodeCollection nodes, IScope scope) {
|
---|
101 | TreeNode node = nodes.Add(string.Format("{0} ({1}+{2})",
|
---|
102 | scope.Name, scope.Variables.Count, scope.SubScopes.Count));
|
---|
103 | node.Tag = scope;
|
---|
104 | node.ImageIndex = 0;
|
---|
105 | node.SelectedImageIndex = 0;
|
---|
106 | foreach (var var in scope.Variables) {
|
---|
107 | TreeNode varNode = node.Nodes.Add(string.Format("{0}={1}", var.Name, var.Value));
|
---|
108 | varNode.Tag = var.Value;
|
---|
109 | varNode.ToolTipText = string.Format("{0}{1}{1}{2}",
|
---|
110 | Utils.TypeName(var.Value), Environment.NewLine,
|
---|
111 | Utils.Wrap(var.Description ?? var.ItemDescription, 60));
|
---|
112 | varNode.ImageIndex = 1;
|
---|
113 | varNode.SelectedImageIndex = 1;
|
---|
114 | }
|
---|
115 | foreach (var subScope in scope.SubScopes)
|
---|
116 | AddScope(node.Nodes, subScope);
|
---|
117 | if (Content.IsAtomic && Content.AtomicOperation.Scope == scope) {
|
---|
118 | node.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
119 | node.ForeColor = Color.White;
|
---|
120 | node.BackColor = Color.Crimson;
|
---|
121 | node.Expand();
|
---|
122 | scopeTreeView.TopNode = node;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | private void UpdateExecutionContext() {
|
---|
128 | executionContextTreeView.BeginUpdate();
|
---|
129 | executionContextTreeView.Nodes.Clear();
|
---|
130 | executionContextTreeView.ImageList.Images.Clear();
|
---|
131 | executionContextTreeView.ImageList.Images.Add(VS2008ImageLibrary.Namespace);
|
---|
132 | if (Content.IsContext) {
|
---|
133 | AddExecutionContext(Content.ExecutionContext, executionContextTreeView.Nodes);
|
---|
134 | }
|
---|
135 | executionContextTreeView.ExpandAll();
|
---|
136 | if (executionContextTreeView.Nodes.Count > 0)
|
---|
137 | executionContextTreeView.TopNode = executionContextTreeView.Nodes[0];
|
---|
138 | executionContextTreeView.EndUpdate();
|
---|
139 | }
|
---|
140 |
|
---|
141 | private void AddExecutionContext(IExecutionContext executionContext, TreeNodeCollection nodes) {
|
---|
142 | ExecutionContext context = executionContext as ExecutionContext;
|
---|
143 | StringBuilder name = new StringBuilder();
|
---|
144 | if (context != null && context.Operator != null)
|
---|
145 | name.Append(context.Operator.Name);
|
---|
146 | else
|
---|
147 | name.Append("<Context>");
|
---|
148 | name.Append("@").Append(executionContext.Scope.Name);
|
---|
149 | TreeNode node = nodes.Add(name.ToString());
|
---|
150 | node.Tag = executionContext;
|
---|
151 | node.ImageIndex = 0;
|
---|
152 | node.SelectedImageIndex = 0;
|
---|
153 | foreach (var param in executionContext.Parameters) {
|
---|
154 | TreeNode paramNode = node.Nodes.Add(string.Format("{0}={1}",
|
---|
155 | param.Name, GetParameterValue(param, executionContext)));
|
---|
156 | paramNode.Tag = param;
|
---|
157 | executionContextTreeView.ImageList.Images.Add(param.ItemImage ?? VS2008ImageLibrary.Nothing);
|
---|
158 | paramNode.ImageIndex = executionContextTreeView.ImageList.Images.Count - 1;
|
---|
159 | paramNode.SelectedImageIndex = paramNode.ImageIndex;
|
---|
160 | paramNode.ToolTipText = string.Format("{0}{1}{1}{2}",
|
---|
161 | Utils.TypeName(param), Environment.NewLine,
|
---|
162 | Utils.Wrap(param.Description ?? param.ItemDescription, 60));
|
---|
163 | }
|
---|
164 | if (executionContext.Parent != null)
|
---|
165 | AddExecutionContext(executionContext.Parent, node.Nodes);
|
---|
166 | }
|
---|
167 |
|
---|
168 | #region Event Handlers (child controls)
|
---|
169 |
|
---|
170 | private void parameterListView_ItemActivate(object sender, EventArgs e) {
|
---|
171 | if (parameterListView.SelectedItems.Count > 0) {
|
---|
172 | IParameter param = parameterListView.SelectedItems[0].Tag as IParameter;
|
---|
173 | if (param != null) {
|
---|
174 | MainFormManager.MainForm.ShowContent((IContent)GetParameterValue(param, Content.ExecutionContext));
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | private void executionContextTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
180 | if (e.Node != null) {
|
---|
181 | IParameter param = e.Node.Tag as IParameter;
|
---|
182 | if (param != null)
|
---|
183 | MainFormManager.MainForm.ShowContent(param);
|
---|
184 | }
|
---|
185 | }
|
---|
186 |
|
---|
187 | private void scopeTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
188 | if (e.Node != null) {
|
---|
189 | IItem item = e.Node.Tag as IItem;
|
---|
190 | if (item != null)
|
---|
191 | MainFormManager.MainForm.ShowContent(item);
|
---|
192 | }
|
---|
193 | }
|
---|
194 |
|
---|
195 | private void executionContextTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) {
|
---|
196 | if (e.Node != null) {
|
---|
197 | IExecutionContext context = e.Node.Tag as IExecutionContext;
|
---|
198 | if (context != null && context.Scope != null) {
|
---|
199 | TreeNode scopeNode = FindScopeNode(context.Scope, scopeTreeView.Nodes);
|
---|
200 | if (scopeNode != null) {
|
---|
201 | if (timer.Enabled) {
|
---|
202 | timer_Tick(this, EventArgs.Empty);
|
---|
203 | }
|
---|
204 | timer.Tag = new KeyValuePair<TreeNode, TreeNode>(scopeNode, new TreeNode() {
|
---|
205 | BackColor = scopeNode.BackColor,
|
---|
206 | ForeColor = scopeNode.ForeColor,
|
---|
207 | NodeFont = scopeNode.NodeFont,
|
---|
208 | });
|
---|
209 | scopeNode.BackColor = Color.Blue;
|
---|
210 | scopeNode.ForeColor = Color.White;
|
---|
211 | scopeNode.NodeFont = new Font(DefaultFont, FontStyle.Bold);
|
---|
212 | scopeTreeView.TopNode = scopeNode;
|
---|
213 | timer.Start();
|
---|
214 | }
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 |
|
---|
219 | private void ResetNode(TreeNode node, TreeNode template) {
|
---|
220 | if (InvokeRequired)
|
---|
221 | Invoke(new Action<TreeNode, TreeNode>(ResetNode), node, template);
|
---|
222 | else {
|
---|
223 | node.ForeColor = template.ForeColor;
|
---|
224 | node.BackColor = template.BackColor;
|
---|
225 | node.NodeFont = template.NodeFont;
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 | private TreeNode FindScopeNode(IScope scope, TreeNodeCollection nodes) {
|
---|
230 | foreach (TreeNode node in nodes) {
|
---|
231 | if (node.Tag == scope) {
|
---|
232 | return node;
|
---|
233 | } else {
|
---|
234 | TreeNode childNode = FindScopeNode(scope, node.Nodes);
|
---|
235 | if (childNode != null)
|
---|
236 | return childNode;
|
---|
237 | }
|
---|
238 | }
|
---|
239 | return null;
|
---|
240 | }
|
---|
241 |
|
---|
242 | private void timer_Tick(object sender, EventArgs e) {
|
---|
243 | KeyValuePair<TreeNode, TreeNode> kvp = (KeyValuePair<TreeNode, TreeNode>)timer.Tag;
|
---|
244 | ResetNode(kvp.Key, kvp.Value);
|
---|
245 | timer.Stop();
|
---|
246 | }
|
---|
247 |
|
---|
248 | private void nameTextBox_DoubleClick(object sender, EventArgs e) {
|
---|
249 | if (Content != null && Content.IsAtomic && Content.AtomicOperation.Operator != null)
|
---|
250 | MainFormManager.MainForm.ShowContent(Content.AtomicOperation.Operator);
|
---|
251 | }
|
---|
252 |
|
---|
253 | #endregion
|
---|
254 | }
|
---|
255 | }
|
---|