author | Steve Sobek <steve.sobek@nokia.com> |
Fri, 30 Oct 2009 10:27:11 -0500 | |
changeset 105 | fbceb3d6fb44 |
parent 37 | c2bce6dd59e7 |
child 129 | 723898599d35 |
permissions | -rw-r--r-- |
37 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2006, 2008 Wind River Systems and others. |
|
3 |
* All rights reserved. This program and the accompanying materials |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
5 |
* which accompanies this distribution, and is available at |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
7 |
* |
|
8 |
* Contributors: |
|
9 |
* Wind River Systems - initial API and implementation |
|
10 |
*******************************************************************************/ |
|
11 |
||
12 |
package org.eclipse.cdt.dsf.debug.ui.viewmodel.variable; |
|
13 |
||
14 |
import java.util.ArrayList; |
|
15 |
import java.util.Arrays; |
|
16 |
import java.util.List; |
|
17 |
import java.util.Map; |
|
18 |
import java.util.concurrent.RejectedExecutionException; |
|
19 |
||
20 |
import org.eclipse.cdt.core.IAddress; |
|
21 |
import org.eclipse.cdt.debug.internal.ui.CDebugImages; |
|
22 |
import org.eclipse.cdt.dsf.concurrent.ConfinedToDsfExecutor; |
|
23 |
import org.eclipse.cdt.dsf.concurrent.CountingRequestMonitor; |
|
24 |
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; |
|
25 |
import org.eclipse.cdt.dsf.concurrent.DsfExecutor; |
|
26 |
import org.eclipse.cdt.dsf.concurrent.DsfRunnable; |
|
27 |
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; |
|
28 |
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; |
|
29 |
import org.eclipse.cdt.dsf.concurrent.MultiRequestMonitor; |
|
30 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
|
31 |
import org.eclipse.cdt.dsf.datamodel.DMContexts; |
|
32 |
import org.eclipse.cdt.dsf.datamodel.IDMContext; |
|
33 |
import org.eclipse.cdt.dsf.debug.service.IExpressions; |
|
34 |
import org.eclipse.cdt.dsf.debug.service.IFormattedValues; |
|
35 |
import org.eclipse.cdt.dsf.debug.service.IStack; |
|
36 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionChangedDMEvent; |
|
37 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMAddress; |
|
38 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; |
|
39 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMData; |
|
40 |
import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent; |
|
41 |
import org.eclipse.cdt.dsf.debug.service.IRunControl.ISuspendedDMEvent; |
|
42 |
import org.eclipse.cdt.dsf.debug.service.IStack.IFrameDMContext; |
|
43 |
import org.eclipse.cdt.dsf.debug.service.IStack.IVariableDMContext; |
|
44 |
import org.eclipse.cdt.dsf.debug.service.IStack.IVariableDMData; |
|
45 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.ErrorLabelText; |
|
46 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants; |
|
47 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.AbstractExpressionVMNode; |
|
48 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.IExpressionUpdate; |
|
49 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueLabelText; |
|
50 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil; |
|
51 |
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.IFormattedValueVMContext; |
|
52 |
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin; |
|
53 |
import org.eclipse.cdt.dsf.service.DsfSession; |
|
54 |
import org.eclipse.cdt.dsf.ui.concurrent.ViewerDataRequestMonitor; |
|
55 |
import org.eclipse.cdt.dsf.ui.viewmodel.VMDelta; |
|
56 |
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.AbstractDMVMProvider; |
|
57 |
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext; |
|
58 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IElementPropertiesProvider; |
|
59 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.IPropertiesUpdate; |
|
60 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelAttribute; |
|
61 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelBackground; |
|
62 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelColumnInfo; |
|
63 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelForeground; |
|
64 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelImage; |
|
65 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.LabelText; |
|
66 |
import org.eclipse.cdt.dsf.ui.viewmodel.properties.PropertiesBasedLabelProvider; |
|
67 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.ICachingVMProvider; |
|
68 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.StaleDataLabelBackground; |
|
69 |
import org.eclipse.cdt.dsf.ui.viewmodel.update.StaleDataLabelForeground; |
|
70 |
import org.eclipse.core.runtime.CoreException; |
|
71 |
import org.eclipse.core.runtime.IStatus; |
|
72 |
import org.eclipse.core.runtime.Status; |
|
73 |
import org.eclipse.debug.core.DebugPlugin; |
|
74 |
import org.eclipse.debug.core.model.IExpression; |
|
75 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; |
|
76 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementCompareRequest; |
|
77 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementEditor; |
|
78 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementLabelProvider; |
|
79 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoProvider; |
|
80 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IElementMementoRequest; |
|
81 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.ILabelUpdate; |
|
82 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; |
|
83 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; |
|
84 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; |
|
85 |
import org.eclipse.debug.ui.DebugUITools; |
|
86 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
|
87 |
import org.eclipse.debug.ui.IDebugUIConstants; |
|
88 |
import org.eclipse.debug.ui.actions.IWatchExpressionFactoryAdapter2; |
|
89 |
import org.eclipse.jface.util.PropertyChangeEvent; |
|
90 |
import org.eclipse.jface.viewers.CellEditor; |
|
91 |
import org.eclipse.jface.viewers.ICellModifier; |
|
92 |
import org.eclipse.jface.viewers.TextCellEditor; |
|
93 |
import org.eclipse.jface.viewers.TreePath; |
|
94 |
import org.eclipse.swt.graphics.RGB; |
|
95 |
import org.eclipse.swt.widgets.Composite; |
|
96 |
import org.eclipse.ui.IMemento; |
|
97 |
||
98 |
@SuppressWarnings("restriction") |
|
99 |
public class VariableVMNode extends AbstractExpressionVMNode |
|
100 |
implements IElementEditor, IElementLabelProvider, IElementPropertiesProvider, IElementMementoProvider |
|
101 |
{ |
|
102 |
/** |
|
103 |
* @since 2.0 |
|
104 |
*/ |
|
105 |
private static final String PROP_VARIABLE_TYPE_NAME = "variable_type_name"; //$NON-NLS-1$ |
|
106 |
||
107 |
/** |
|
108 |
* @since 2.0 |
|
109 |
*/ |
|
110 |
private static final String PROP_VARIABLE_BASIC_TYPE = "variable_basic_type"; //$NON-NLS-1$ |
|
111 |
||
112 |
/** |
|
113 |
* @since 2.0 |
|
114 |
*/ |
|
115 |
private static final String PROP_VARIABLE_ADDRESS = "variable_address"; //$NON-NLS-1$ |
|
116 |
||
117 |
/** |
|
118 |
* @since 2.0 |
|
119 |
*/ |
|
120 |
private static final String PROP_VARIABLE_SHOW_TYPE_NAMES = "variable_show_type_names"; //$NON-NLS-1$ |
|
121 |
||
122 |
/** |
|
123 |
* @since 2.0 |
|
124 |
*/ |
|
125 |
private static final String PROP_VARIABLE_ADDRESS_CHANGED = ICachingVMProvider.PROP_IS_CHANGED_PREFIX + PROP_VARIABLE_ADDRESS; |
|
126 |
||
127 |
private final SyncVariableDataAccess fSyncVariableDataAccess; |
|
128 |
||
129 |
/** |
|
130 |
* The label provider delegate. This VM node will delegate label updates to this provider |
|
131 |
* which can be created by sub-classes. |
|
132 |
* |
|
133 |
* @since 2.0 |
|
134 |
*/ |
|
135 |
private IElementLabelProvider fLabelProvider; |
|
136 |
||
137 |
public class VariableExpressionVMC extends DMVMContext implements IFormattedValueVMContext { |
|
138 |
||
139 |
private IExpression fExpression; |
|
140 |
||
141 |
public VariableExpressionVMC(IDMContext dmc) { |
|
142 |
super(dmc); |
|
143 |
} |
|
144 |
||
145 |
public void setExpression(IExpression expression) { |
|
146 |
fExpression = expression; |
|
147 |
} |
|
148 |
||
149 |
@Override |
|
150 |
@SuppressWarnings("unchecked") |
|
151 |
public Object getAdapter(Class adapter) { |
|
152 |
if (fExpression != null && adapter.isAssignableFrom(fExpression.getClass())) { |
|
153 |
return fExpression; |
|
154 |
} else if (adapter.isAssignableFrom(IWatchExpressionFactoryAdapter2.class)) { |
|
155 |
return fVariableExpressionFactory; |
|
156 |
} else { |
|
157 |
return super.getAdapter(adapter); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
@Override |
|
162 |
public boolean equals(Object other) { |
|
163 |
if (other instanceof VariableExpressionVMC && super.equals(other)) { |
|
164 |
VariableExpressionVMC otherGroup = (VariableExpressionVMC)other; |
|
165 |
return (otherGroup.fExpression == null && fExpression == null) || |
|
166 |
(otherGroup.fExpression != null && otherGroup.fExpression.equals(fExpression)); |
|
167 |
} |
|
168 |
return false; |
|
169 |
} |
|
170 |
||
171 |
@Override |
|
172 |
public int hashCode() { |
|
173 |
return super.hashCode() + (fExpression != null ? fExpression.hashCode() : 0); |
|
174 |
} |
|
175 |
} |
|
176 |
||
177 |
protected class VariableExpressionFactory implements IWatchExpressionFactoryAdapter2 { |
|
178 |
||
179 |
public boolean canCreateWatchExpression(Object element) { |
|
180 |
return element instanceof VariableExpressionVMC; |
|
181 |
} |
|
182 |
||
183 |
public String createWatchExpression(Object element) throws CoreException { |
|
184 |
||
185 |
VariableExpressionVMC exprVmc = (VariableExpressionVMC) element; |
|
186 |
||
187 |
IExpressionDMContext exprDmc = DMContexts.getAncestorOfType(exprVmc.getDMContext(), IExpressionDMContext.class); |
|
188 |
if (exprDmc != null) { |
|
189 |
return exprDmc.getExpression(); |
|
190 |
} |
|
191 |
||
192 |
return null; |
|
193 |
} |
|
194 |
} |
|
195 |
||
196 |
final protected VariableExpressionFactory fVariableExpressionFactory = new VariableExpressionFactory(); |
|
197 |
||
198 |
public VariableVMNode(AbstractDMVMProvider provider, DsfSession session, |
|
199 |
SyncVariableDataAccess syncVariableDataAccess) |
|
200 |
{ |
|
201 |
super(provider, session, IExpressions.IExpressionDMContext.class); |
|
202 |
fSyncVariableDataAccess = syncVariableDataAccess; |
|
203 |
fLabelProvider = createLabelProvider(); |
|
204 |
} |
|
205 |
||
206 |
/** |
|
207 |
* Creates the label provider delegate. This VM node will delegate label |
|
208 |
* updates to this provider which can be created by sub-classes. |
|
209 |
* |
|
210 |
* @return Returns the label provider for this node. |
|
211 |
* |
|
212 |
* @since 2.0 |
|
213 |
*/ |
|
214 |
protected IElementLabelProvider createLabelProvider() { |
|
215 |
PropertiesBasedLabelProvider provider = new PropertiesBasedLabelProvider(); |
|
216 |
||
217 |
// |
|
218 |
// Create label image objects which are used in more than one column. |
|
219 |
// |
|
220 |
||
221 |
// Pointer image is used for variable and function pointers. |
|
222 |
LabelImage pointerLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_POINTER) { |
|
223 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); } |
|
224 |
||
225 |
@Override |
|
226 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
227 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE); |
|
228 |
return IExpressionDMData.BasicType.pointer.name().equals(type) || |
|
229 |
IExpressionDMData.BasicType.function.name().equals(type); |
|
230 |
}; |
|
231 |
}; |
|
232 |
||
233 |
// Aggregate image is used for array, struct, etc. |
|
234 |
LabelImage aggregateLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_AGGREGATE) { |
|
235 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); } |
|
236 |
||
237 |
@Override |
|
238 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
239 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE); |
|
240 |
return IExpressionDMData.BasicType.array.name().equals(type) || |
|
241 |
IExpressionDMData.BasicType.composite.name().equals(type); |
|
242 |
}; |
|
243 |
}; |
|
244 |
||
245 |
// Simple variable image is used for all other types, except when there is no type specified. |
|
246 |
LabelImage simpleLabelImage = new LabelImage(CDebugImages.DESC_OBJS_VARIABLE_SIMPLE) { |
|
247 |
{ setPropertyNames(new String[] { PROP_VARIABLE_BASIC_TYPE }); } |
|
248 |
||
249 |
@Override |
|
250 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
251 |
String type = (String)properties.get(PROP_VARIABLE_BASIC_TYPE); |
|
252 |
return type != null; |
|
253 |
}; |
|
254 |
}; |
|
255 |
||
256 |
// The name column consists of the expression name. The name column image depends on the variable type. |
|
257 |
provider.setColumnInfo( |
|
258 |
IDebugVMConstants.COLUMN_ID__NAME, |
|
259 |
new LabelColumnInfo(new LabelAttribute[] { |
|
260 |
new LabelText( |
|
261 |
MessagesForVariablesVM.VariableVMNode_Name_column__text_format, |
|
262 |
new String[] { PROP_NAME }), |
|
263 |
pointerLabelImage, |
|
264 |
aggregateLabelImage, |
|
265 |
simpleLabelImage, |
|
266 |
new StaleDataLabelForeground(), |
|
267 |
new VariableLabelFont(), |
|
268 |
})); |
|
269 |
||
270 |
// Expression column is visible only in the expressions view. It shows the expression string that the user |
|
271 |
// entered. Expression column images are the same as for the name column. |
|
272 |
provider.setColumnInfo( |
|
273 |
IDebugVMConstants.COLUMN_ID__EXPRESSION, |
|
274 |
new LabelColumnInfo(new LabelAttribute[] { |
|
275 |
new LabelText( |
|
276 |
MessagesForVariablesVM.VariableVMNode_Expression_column__text_format, |
|
277 |
new String[] { PROP_ELEMENT_EXPRESSION }), |
|
278 |
pointerLabelImage, |
|
279 |
aggregateLabelImage, |
|
280 |
simpleLabelImage, |
|
281 |
new StaleDataLabelForeground(), |
|
282 |
new VariableLabelFont(), |
|
283 |
})); |
|
284 |
||
285 |
// Type column only contains the type name. |
|
286 |
provider.setColumnInfo( |
|
287 |
IDebugVMConstants.COLUMN_ID__TYPE, |
|
288 |
new LabelColumnInfo(new LabelAttribute[] { |
|
289 |
new LabelText( |
|
290 |
MessagesForVariablesVM.VariableVMNode_Type_column__text_format, |
|
291 |
new String[] { PROP_VARIABLE_TYPE_NAME }), |
|
292 |
new LabelText( MessagesForVariablesVM.VariableVMNode_Type_column__Error__text_format, new String[] {}), |
|
293 |
new StaleDataLabelForeground(), |
|
294 |
new VariableLabelFont(), |
|
295 |
})); |
|
296 |
||
297 |
// Value column is more complicated: |
|
298 |
// - If a STRING value format is supported. Then the value label consists of the active format label followed |
|
299 |
// by the string format. |
|
300 |
// - If the STRIGN value format is not supported. Then only show the active value format. The GDB reference |
|
301 |
// implementation currently does not support the string format, but by default it does append extra |
|
302 |
// information to the value label itself. |
|
303 |
// |
|
304 |
// In case of error, show the error message in the value column (instead of the usual "...". This is needed |
|
305 |
// for the expressions view, where an invalid expression entered by the user is a normal use case. |
|
306 |
// |
|
307 |
// For changed value high-lighting check both the string value and the value in the active format. But, |
|
308 |
// ignore the active format value change if the format itself has changed. |
|
309 |
provider.setColumnInfo( |
|
310 |
IDebugVMConstants.COLUMN_ID__VALUE, |
|
311 |
new LabelColumnInfo(new LabelAttribute[] { |
|
312 |
new FormattedValueLabelText( |
|
313 |
MessagesForVariablesVM.VariableVMNode_Value_column__text_format, |
|
314 |
new String[] { |
|
315 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
316 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
317 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS}) |
|
318 |
{ |
|
319 |
@Override |
|
320 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) { |
|
321 |
String[] formatIds = |
|
322 |
(String[])properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS); |
|
323 |
String activeFormat = (String)properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT); |
|
324 |
return |
|
325 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) && |
|
326 |
formatIds != null && |
|
327 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) && |
|
328 |
super.isEnabled(status, properties); |
|
329 |
} |
|
330 |
}, |
|
331 |
new FormattedValueLabelText(), |
|
332 |
new ErrorLabelText(), |
|
333 |
new LabelForeground(new RGB(255, 0, 0)) // TODO: replace with preference error color |
|
334 |
{ |
|
335 |
{ setPropertyNames(new String[] { PROP_NAME }); } |
|
336 |
||
337 |
@Override |
|
338 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
339 |
return !status.isOK(); |
|
340 |
} |
|
341 |
}, |
|
342 |
// |
|
343 |
new LabelBackground( |
|
344 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB()) |
|
345 |
{ |
|
346 |
{ |
|
347 |
setPropertyNames(new String[] { |
|
348 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
349 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
350 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
351 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
352 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT, |
|
353 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT}); |
|
354 |
} |
|
355 |
||
356 |
@Override |
|
357 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
358 |
Boolean activeFormatChanged = (Boolean)properties.get( |
|
359 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT); |
|
360 |
Boolean activeChanged = (Boolean)properties.get( |
|
361 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE); |
|
362 |
Boolean stringChanged = (Boolean)properties.get( |
|
363 |
ICachingVMProvider.PROP_IS_CHANGED_PREFIX + FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT)); |
|
364 |
return Boolean.TRUE.equals(stringChanged) || |
|
365 |
( Boolean.TRUE.equals(activeChanged) && !Boolean.TRUE.equals(activeFormatChanged)); |
|
366 |
}; |
|
367 |
}, |
|
368 |
new StaleDataLabelForeground(), |
|
369 |
new VariableLabelFont(), |
|
370 |
})); |
|
371 |
||
372 |
// Address column shows the variable's address. It is highlighted with the change background color when the |
|
373 |
// address value changes. |
|
374 |
provider.setColumnInfo( |
|
375 |
IDebugVMConstants.COLUMN_ID__ADDRESS, |
|
376 |
new LabelColumnInfo(new LabelAttribute[] { |
|
377 |
new LabelText( |
|
378 |
MessagesForVariablesVM.VariableVMNode_Address_column__text_format, |
|
379 |
new String[] { PROP_VARIABLE_ADDRESS }), |
|
380 |
new LabelText(MessagesForVariablesVM.VariableVMNode_Address_column__Error__text_format, new String[] {}), |
|
381 |
new LabelBackground( |
|
382 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND).getRGB()) |
|
383 |
{ |
|
384 |
{ setPropertyNames(new String[] { PROP_VARIABLE_ADDRESS, PROP_VARIABLE_ADDRESS_CHANGED}); } |
|
385 |
||
386 |
@Override |
|
387 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
388 |
Boolean changed = (Boolean)properties.get(PROP_VARIABLE_ADDRESS_CHANGED); |
|
389 |
return Boolean.TRUE.equals(changed); |
|
390 |
}; |
|
391 |
}, |
|
392 |
new StaleDataLabelForeground(), |
|
393 |
new VariableLabelFont(), |
|
394 |
})); |
|
395 |
||
396 |
// Description column is shown in the expression view, but is not supported for variables. |
|
397 |
provider.setColumnInfo( |
|
398 |
IDebugVMConstants.COLUMN_ID__DESCRIPTION, |
|
399 |
||
400 |
new LabelColumnInfo(new LabelAttribute[] { |
|
401 |
new LabelText(MessagesForVariablesVM.VariableVMNode_Description_column__text_format, new String[] {}), |
|
402 |
new VariableLabelFont(), |
|
403 |
})); |
|
404 |
||
405 |
// Configure the case where there are no columns visible. It basically combines the name and the value columns only. |
|
406 |
provider.setColumnInfo( |
|
407 |
PropertiesBasedLabelProvider.ID_COLUMN_NO_COLUMNS, |
|
408 |
new LabelColumnInfo(new LabelAttribute[] { |
|
409 |
new FormattedValueLabelText( |
|
410 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__text_format, |
|
411 |
new String[] { |
|
412 |
PROP_NAME, |
|
413 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
414 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
415 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS, |
|
416 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT, |
|
417 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, |
|
418 |
PROP_VARIABLE_SHOW_TYPE_NAMES}) |
|
419 |
{ |
|
420 |
@Override |
|
421 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) { |
|
422 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES); |
|
423 |
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS); |
|
424 |
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT); |
|
425 |
return |
|
426 |
showTypeNames != null && |
|
427 |
!showTypeNames.booleanValue() && |
|
428 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) && |
|
429 |
formatIds != null && |
|
430 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) && |
|
431 |
super.isEnabled(status, properties); |
|
432 |
} |
|
433 |
}, |
|
434 |
new FormattedValueLabelText( |
|
435 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format, |
|
436 |
new String[] { |
|
437 |
PROP_NAME, |
|
438 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
439 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS, |
|
440 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT, |
|
441 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, |
|
442 |
PROP_VARIABLE_SHOW_TYPE_NAMES}) |
|
443 |
{ |
|
444 |
@Override |
|
445 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) { |
|
446 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES); |
|
447 |
return |
|
448 |
showTypeNames != null && |
|
449 |
!showTypeNames.booleanValue() && |
|
450 |
super.isEnabled(status, properties); |
|
451 |
} |
|
452 |
}, |
|
453 |
new FormattedValueLabelText( |
|
454 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__text_format_with_type, |
|
455 |
new String[] { |
|
456 |
PROP_NAME, |
|
457 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
458 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
459 |
PROP_VARIABLE_TYPE_NAME, |
|
460 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS, |
|
461 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT, |
|
462 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, |
|
463 |
PROP_VARIABLE_SHOW_TYPE_NAMES}) |
|
464 |
{ |
|
465 |
@Override |
|
466 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) { |
|
467 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES); |
|
468 |
String[] formatIds = (String[]) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS); |
|
469 |
String activeFormat = (String) properties.get(IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT); |
|
470 |
return |
|
471 |
showTypeNames != null && |
|
472 |
showTypeNames.booleanValue() && |
|
473 |
!IFormattedValues.STRING_FORMAT.equals(activeFormat) && |
|
474 |
formatIds != null && |
|
475 |
Arrays.asList(formatIds).contains(IFormattedValues.STRING_FORMAT) && |
|
476 |
super.isEnabled(status, properties); |
|
477 |
} |
|
478 |
}, |
|
479 |
new FormattedValueLabelText( |
|
480 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__No_string__text_format_with_type, |
|
481 |
new String[] { |
|
482 |
PROP_NAME, |
|
483 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT_VALUE, |
|
484 |
PROP_VARIABLE_TYPE_NAME, |
|
485 |
IDebugVMConstants.PROP_FORMATTED_VALUE_AVAILABLE_FORMATS, |
|
486 |
IDebugVMConstants.PROP_FORMATTED_VALUE_ACTIVE_FORMAT, |
|
487 |
IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE, |
|
488 |
PROP_VARIABLE_SHOW_TYPE_NAMES}) |
|
489 |
{ |
|
490 |
@Override |
|
491 |
public boolean isEnabled(IStatus status, Map<String, Object> properties) { |
|
492 |
Boolean showTypeNames = (Boolean) properties.get(PROP_VARIABLE_SHOW_TYPE_NAMES); |
|
493 |
return |
|
494 |
showTypeNames != null && |
|
495 |
showTypeNames.booleanValue() && |
|
496 |
super.isEnabled(status, properties); |
|
497 |
} |
|
498 |
}, |
|
499 |
new ErrorLabelText( |
|
500 |
MessagesForVariablesVM.VariableVMNode_NoColumns_column__Error__text_format, |
|
501 |
new String[] { PROP_NAME }), |
|
502 |
pointerLabelImage, |
|
503 |
aggregateLabelImage, |
|
504 |
simpleLabelImage, |
|
505 |
new LabelForeground(new RGB(255, 0, 0)) // TODO: replace with preference error color |
|
506 |
{ |
|
507 |
{ setPropertyNames(new String[] { PROP_NAME }); } |
|
508 |
||
509 |
@Override |
|
510 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
511 |
return !status.isOK(); |
|
512 |
} |
|
513 |
}, |
|
514 |
new LabelForeground( |
|
515 |
DebugUITools.getPreferenceColor(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR).getRGB()) |
|
516 |
{ |
|
517 |
{ |
|
518 |
setPropertyNames(new String[] { |
|
519 |
FormattedValueVMUtil.getPropertyForFormatId(IFormattedValues.STRING_FORMAT), |
|
520 |
IDebugVMConstants.PROP_IS_STRING_FORMAT_VALUE_CHANGED, |
|
521 |
IDebugVMConstants.PROP_IS_ACTIVE_FORMATTED_VALUE_CHANGED}); |
|
522 |
} |
|
523 |
||
524 |
@Override |
|
525 |
public boolean isEnabled(IStatus status, java.util.Map<String,Object> properties) { |
|
526 |
Boolean stringChanged = |
|
527 |
(Boolean)properties.get(IDebugVMConstants.PROP_IS_STRING_FORMAT_VALUE_CHANGED); |
|
528 |
Boolean activeChanged = |
|
529 |
(Boolean)properties.get(IDebugVMConstants.PROP_IS_ACTIVE_FORMATTED_VALUE_CHANGED); |
|
530 |
return Boolean.TRUE.equals(stringChanged) || Boolean.TRUE.equals(activeChanged); |
|
531 |
}; |
|
532 |
}, |
|
533 |
new StaleDataLabelBackground(), |
|
534 |
new VariableLabelFont(), |
|
535 |
})); |
|
536 |
||
537 |
return provider; |
|
538 |
} |
|
539 |
||
540 |
@Override |
|
541 |
public String toString() { |
|
542 |
return "VariableVMNode(" + getSession().getId() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ |
|
543 |
} |
|
544 |
||
545 |
@Override |
|
546 |
protected IDMVMContext createVMContext(IDMContext dmc) { |
|
547 |
return new VariableExpressionVMC(dmc); |
|
548 |
} |
|
549 |
||
550 |
||
551 |
public void update(final ILabelUpdate[] updates) { |
|
552 |
fLabelProvider.update(updates); |
|
553 |
} |
|
554 |
||
555 |
/** |
|
556 |
* @see IElementPropertiesProvider#update(IPropertiesUpdate[]) |
|
557 |
* |
|
558 |
* @since 2.0 |
|
559 |
*/ |
|
560 |
public void update(final IPropertiesUpdate[] updates) { |
|
561 |
try { |
|
562 |
getSession().getExecutor().execute(new DsfRunnable() { |
|
563 |
public void run() { |
|
564 |
updatePropertiesInSessionThread(updates); |
|
565 |
}}); |
|
566 |
} catch (RejectedExecutionException e) { |
|
567 |
for (IPropertiesUpdate update : updates) { |
|
568 |
handleFailedUpdate(update); |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
||
573 |
// |
|
574 |
// @param return-value Boolean.TRUE --> Show Types ICON is selected/depressed |
|
575 |
// @param return-value Boolean.FALSE --> Show Types ICON is not selected/depressed |
|
576 |
// |
|
577 |
private Boolean getShowTypeNamesState( IPresentationContext context ) { |
|
578 |
Boolean attribute = (Boolean) context.getProperty(IDebugModelPresentation.DISPLAY_VARIABLE_TYPE_NAMES); |
|
579 |
||
580 |
if (attribute != null) { |
|
581 |
return attribute; |
|
582 |
} |
|
583 |
||
584 |
return Boolean.FALSE; |
|
585 |
} |
|
586 |
||
587 |
/** |
|
588 |
* @since 2.0 |
|
589 |
*/ |
|
590 |
@ConfinedToDsfExecutor("getSession().getExecutor()") |
|
591 |
protected void updatePropertiesInSessionThread(final IPropertiesUpdate[] updates) { |
|
592 |
IExpressions service = getServicesTracker().getService(IExpressions.class, null); |
|
593 |
||
594 |
final CountingRequestMonitor countingRm = new CountingRequestMonitor(ImmediateExecutor.getInstance(), null) { |
|
595 |
@Override |
|
596 |
protected void handleCompleted() { |
|
597 |
for (final IPropertiesUpdate update : updates) { |
|
598 |
update.done(); |
|
599 |
} |
|
600 |
}; |
|
601 |
}; |
|
602 |
int count = 0; |
|
603 |
||
604 |
if (service != null) { |
|
605 |
FormattedValueVMUtil.updateFormattedValues(updates, service, IExpressionDMContext.class, countingRm); |
|
606 |
count++; |
|
607 |
} |
|
608 |
||
609 |
for (final IPropertiesUpdate update : updates) { |
|
610 |
IExpression expression = (IExpression)DebugPlugin.getAdapter(update.getElement(), IExpression.class); |
|
611 |
if (expression != null) { |
|
612 |
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, expression.getExpressionText()); |
|
613 |
} |
|
614 |
||
615 |
// Capture the current "Show Type Names" ICON state in case there are no columns. |
|
616 |
if (update.getProperties().contains(PROP_VARIABLE_SHOW_TYPE_NAMES)) { |
|
617 |
update.setProperty(PROP_VARIABLE_SHOW_TYPE_NAMES, getShowTypeNamesState(update.getPresentationContext())); |
|
618 |
} |
|
619 |
||
620 |
IExpressionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressions.IExpressionDMContext.class); |
|
621 |
if ( dmc == null || service == null) { |
|
622 |
update.setStatus(DsfUIPlugin.newErrorStatus(IDsfStatusConstants.INVALID_STATE, "Invalid context or service not available.", null)); //$NON-NLS-1$ |
|
623 |
continue; |
|
624 |
} |
|
625 |
||
626 |
if (update.getProperties().contains(PROP_NAME) || |
|
627 |
update.getProperties().contains(PROP_VARIABLE_TYPE_NAME) || |
|
628 |
update.getProperties().contains(PROP_VARIABLE_BASIC_TYPE)) |
|
629 |
{ |
|
630 |
service.getExpressionData( |
|
631 |
dmc, |
|
632 |
// Use the ViewerDataRequestMonitor in order to propagate the update's cancel request. Use an immediate |
|
633 |
// executor to avoid the possibility of a rejected execution exception. |
|
634 |
new ViewerDataRequestMonitor<IExpressionDMData>(ImmediateExecutor.getInstance(), update) { |
|
635 |
@Override |
|
636 |
protected void handleCompleted() { |
|
637 |
if (isSuccess()) { |
|
638 |
fillExpressionDataProperties(update, getData()); |
|
639 |
} else { |
|
640 |
// In case of an error fill in the expression next in the name column. |
|
641 |
IExpressionDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressions.IExpressionDMContext.class); |
|
642 |
if (dmc != null && dmc.getExpression() != null) { |
|
643 |
update.setProperty(PROP_NAME, dmc.getExpression()); |
|
644 |
} |
|
645 |
update.setStatus(getStatus()); |
|
646 |
} |
|
647 |
countingRm.done(); |
|
648 |
} |
|
649 |
}); |
|
650 |
||
651 |
count++; |
|
652 |
} |
|
653 |
||
654 |
if (update.getProperties().contains(PROP_VARIABLE_ADDRESS)) { |
|
655 |
service.getExpressionAddressData( |
|
656 |
dmc, |
|
657 |
// Use the ViewerDataRequestMonitor in order to propagate the update's cancel request. Use an immediate |
|
658 |
// executor to avoid the possibility of a rejected execution exception. |
|
659 |
new ViewerDataRequestMonitor<IExpressionDMAddress>(ImmediateExecutor.getInstance(), update) { |
|
660 |
@Override |
|
661 |
protected void handleCompleted() { |
|
662 |
if (isSuccess()) { |
|
663 |
fillAddressDataProperties(update, getData()); |
|
664 |
} else if (getStatus().getCode() != IDsfStatusConstants.NOT_SUPPORTED && |
|
665 |
getStatus().getCode() != IDsfStatusConstants.INVALID_STATE) |
|
666 |
{ |
|
667 |
update.setStatus(getStatus()); |
|
668 |
} |
|
669 |
countingRm.done(); |
|
670 |
} |
|
671 |
}); |
|
672 |
count++; |
|
673 |
} |
|
674 |
} |
|
675 |
countingRm.setDoneCount(count); |
|
676 |
} |
|
677 |
||
678 |
/** |
|
679 |
* @since 2.0 |
|
680 |
*/ |
|
681 |
@ConfinedToDsfExecutor("getSession().getExecutor()") |
|
682 |
protected void fillExpressionDataProperties(IPropertiesUpdate update, IExpressionDMData data) |
|
683 |
{ |
|
684 |
update.setProperty(PROP_NAME, data.getName()); |
|
685 |
update.setProperty(PROP_VARIABLE_TYPE_NAME, data.getTypeName()); |
|
686 |
IExpressionDMData.BasicType type = data.getBasicType(); |
|
687 |
if (type != null) { |
|
688 |
update.setProperty(PROP_VARIABLE_BASIC_TYPE, type.name()); |
|
689 |
} |
|
690 |
||
691 |
// |
|
692 |
// If this node has an expression then it has already been filled in by the higher |
|
693 |
// level logic. If not then we need to supply something. In the previous version |
|
694 |
// ( pre-property based ) we supplied the name. So we will do that here also. |
|
695 |
// |
|
696 |
IExpression expression = (IExpression)DebugPlugin.getAdapter(update.getElement(), IExpression.class); |
|
697 |
if (expression == null) { |
|
698 |
update.setProperty(AbstractExpressionVMNode.PROP_ELEMENT_EXPRESSION, data.getName()); |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
/** |
|
703 |
* Private data access routine which performs the extra level of data access needed to |
|
704 |
* get the formatted data value for a specific register. |
|
705 |
*/ |
|
706 |
@ConfinedToDsfExecutor("getSession().getExecutor()") |
|
707 |
protected void fillAddressDataProperties(IPropertiesUpdate update, IExpressionDMAddress address) |
|
708 |
{ |
|
709 |
IExpressionDMAddress expression = address; |
|
105
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
710 |
Object expAddress = expression.getAddress(); |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
711 |
|
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
712 |
String addrString = ""; //$NON-NLS-1$ |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
713 |
if (expAddress instanceof IAddress) |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
714 |
addrString = "0x" + ((IAddress)expAddress).toString(16); //$NON-NLS-1$ |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
715 |
else if (expAddress instanceof String) |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
716 |
addrString = (String)expAddress; |
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
717 |
|
fbceb3d6fb44
let expression getAddress() return a string, such as register name or invalid access message
Steve Sobek <steve.sobek@nokia.com>
parents:
37
diff
changeset
|
718 |
update.setProperty(PROP_VARIABLE_ADDRESS, addrString); |
37 | 719 |
} |
720 |
||
721 |
public CellEditor getCellEditor(IPresentationContext context, String columnId, Object element, Composite parent) { |
|
722 |
if (IDebugVMConstants.COLUMN_ID__VALUE.equals(columnId)) { |
|
723 |
return new TextCellEditor(parent); |
|
724 |
} |
|
725 |
else if (IDebugVMConstants.COLUMN_ID__EXPRESSION.equals(columnId)) { |
|
726 |
return new TextCellEditor(parent); |
|
727 |
} |
|
728 |
||
729 |
return null; |
|
730 |
} |
|
731 |
||
732 |
public ICellModifier getCellModifier(IPresentationContext context, Object element) { |
|
733 |
return new VariableCellModifier(getDMVMProvider(), fSyncVariableDataAccess); |
|
734 |
} |
|
735 |
||
736 |
public boolean canParseExpression(IExpression expression) { |
|
737 |
// At this point we are going to say we will allow anything as an expression. |
|
738 |
// Since the evaluation of VM Node implementations searches in the order of |
|
739 |
// registration and we always make sure we register the VariableVMNode last, |
|
740 |
// we know that the other possible handlers have passed the expression by. So |
|
741 |
// we are going to say OK and let the expression evaluation of whatever debug |
|
742 |
// backend is connected to decide. This does not allow us to put up any good |
|
743 |
// diagnostic error message ( instead the error will come from the backend ). |
|
744 |
// But it does allow for the most flexibility |
|
745 |
||
746 |
return true; |
|
747 |
} |
|
748 |
||
749 |
@Override |
|
750 |
public void update(final IExpressionUpdate update) { |
|
751 |
try { |
|
752 |
getSession().getExecutor().execute(new Runnable() { |
|
753 |
public void run() { |
|
754 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); |
|
755 |
if (expressionService != null) { |
|
756 |
IExpressionDMContext expressionDMC = expressionService.createExpression( |
|
757 |
createCompositeDMVMContext(update), |
|
758 |
update.getExpression().getExpressionText()); |
|
759 |
VariableExpressionVMC variableVmc = new VariableExpressionVMC(expressionDMC); |
|
760 |
variableVmc.setExpression(update.getExpression()); |
|
761 |
||
762 |
update.setExpressionElement(variableVmc); |
|
763 |
update.done(); |
|
764 |
} else { |
|
765 |
handleFailedUpdate(update); |
|
766 |
} |
|
767 |
} |
|
768 |
}); |
|
769 |
} catch (RejectedExecutionException e) { |
|
770 |
handleFailedUpdate(update); |
|
771 |
} |
|
772 |
} |
|
773 |
||
774 |
||
775 |
@Override |
|
776 |
protected void handleFailedUpdate(IViewerUpdate update) { |
|
777 |
if (update instanceof IExpressionUpdate) { |
|
778 |
update.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfStatusConstants.INVALID_STATE, "Update failed", null)); //$NON-NLS-1$ |
|
779 |
update.done(); |
|
780 |
} else { |
|
781 |
super.handleFailedUpdate(update); |
|
782 |
} |
|
783 |
} |
|
784 |
@Override |
|
785 |
protected void associateExpression(Object element, IExpression expression) { |
|
786 |
if (element instanceof VariableExpressionVMC) { |
|
787 |
((VariableExpressionVMC)element).setExpression(expression); |
|
788 |
} |
|
789 |
} |
|
790 |
||
791 |
@Override |
|
792 |
protected void updateElementsInSessionThread(final IChildrenUpdate update) { |
|
793 |
// Get the data model context object for the current node in the hierarchy. |
|
794 |
||
795 |
final IExpressionDMContext expressionDMC = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressionDMContext.class); |
|
796 |
||
797 |
if ( expressionDMC != null ) { |
|
798 |
getSubexpressionsUpdateElementsInSessionThread( update ); |
|
799 |
} |
|
800 |
else { |
|
801 |
getLocalsUpdateElementsInSessionThread( update ); |
|
802 |
} |
|
803 |
} |
|
804 |
||
805 |
private void getSubexpressionsUpdateElementsInSessionThread(final IChildrenUpdate update) { |
|
806 |
||
807 |
final IExpressionDMContext expressionDMC = findDmcInPath(update.getViewerInput(), update.getElementPath(), IExpressionDMContext.class); |
|
808 |
||
809 |
if ( expressionDMC != null ) { |
|
810 |
||
811 |
// Get the services we need to use. |
|
812 |
||
813 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); |
|
814 |
||
815 |
if (expressionService == null) { |
|
816 |
handleFailedUpdate(update); |
|
817 |
return; |
|
818 |
} |
|
819 |
||
820 |
final DsfExecutor dsfExecutor = getSession().getExecutor(); |
|
821 |
||
822 |
// Call IExpressions.getSubExpressions() to get an Iterable of IExpressionDMContext objects representing |
|
823 |
// the sub-expressions of the expression represented by the current expression node. |
|
824 |
||
825 |
final DataRequestMonitor<IExpressionDMContext[]> rm = |
|
826 |
new ViewerDataRequestMonitor<IExpressionDMContext[]>(dsfExecutor, update) { |
|
827 |
@Override |
|
828 |
public void handleCompleted() { |
|
829 |
if (!isSuccess()) { |
|
830 |
handleFailedUpdate(update); |
|
831 |
return; |
|
832 |
} |
|
833 |
fillUpdateWithVMCs(update, getData()); |
|
834 |
update.done(); |
|
835 |
} |
|
836 |
}; |
|
837 |
||
838 |
// Make the asynchronous call to IExpressions.getSubExpressions(). The results are processed in the |
|
839 |
// DataRequestMonitor.handleCompleted() above. |
|
840 |
||
841 |
expressionService.getSubExpressions(expressionDMC, rm); |
|
842 |
} else { |
|
843 |
handleFailedUpdate(update); |
|
844 |
} |
|
845 |
} |
|
846 |
||
847 |
private void getLocalsUpdateElementsInSessionThread(final IChildrenUpdate update) { |
|
848 |
||
849 |
final IFrameDMContext frameDmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), IFrameDMContext.class); |
|
850 |
||
851 |
// Get the services we need to use. |
|
852 |
||
853 |
final IExpressions expressionService = getServicesTracker().getService(IExpressions.class); |
|
854 |
final IStack stackFrameService = getServicesTracker().getService(IStack.class); |
|
855 |
||
856 |
if ( frameDmc == null || expressionService == null || stackFrameService == null) { |
|
857 |
handleFailedUpdate(update); |
|
858 |
return; |
|
859 |
} |
|
860 |
||
861 |
final DsfExecutor dsfExecutor = getSession().getExecutor(); |
|
862 |
||
863 |
// Call IStack.getLocals() to get an array of IVariableDMContext objects representing the local |
|
864 |
// variables in the stack frame represented by frameDmc. |
|
865 |
||
866 |
final DataRequestMonitor<IVariableDMContext[]> rm = |
|
867 |
new ViewerDataRequestMonitor<IVariableDMContext[]>(dsfExecutor, update) { |
|
868 |
@Override |
|
869 |
public void handleCompleted() { |
|
870 |
if (!isSuccess()) { |
|
871 |
handleFailedUpdate(update); |
|
872 |
return; |
|
873 |
} |
|
874 |
||
875 |
// For each IVariableDMContext object returned by IStack.getLocals(), call |
|
876 |
// MIStackFrameService.getModelData() to get the IVariableDMData object. This requires |
|
877 |
// a MultiRequestMonitor object. |
|
878 |
||
879 |
// First, get the data model context objects for the local variables. |
|
880 |
||
881 |
IVariableDMContext[] localsDMCs = getData(); |
|
882 |
||
883 |
if (localsDMCs == null) { |
|
884 |
handleFailedUpdate(update); |
|
885 |
return; |
|
886 |
} |
|
887 |
||
888 |
if ( localsDMCs.length == 0 ) { |
|
889 |
// There are no locals so just complete the request |
|
890 |
update.done(); |
|
891 |
return; |
|
892 |
} |
|
893 |
||
894 |
// Create a List in which we store the DM data objects for the local variables. This is |
|
895 |
// necessary because there is no MultiDataRequestMonitor. :) |
|
896 |
||
897 |
final List<IVariableDMData> localsDMData = new ArrayList<IVariableDMData>(); |
|
898 |
||
899 |
// Create the MultiRequestMonitor to handle completion of the set of getModelData() calls. |
|
900 |
||
901 |
final MultiRequestMonitor<DataRequestMonitor<IVariableDMData>> mrm = |
|
902 |
new MultiRequestMonitor<DataRequestMonitor<IVariableDMData>>(dsfExecutor, null) { |
|
903 |
@Override |
|
904 |
public void handleCompleted() { |
|
905 |
// Now that all the calls to getModelData() are complete, we create an |
|
906 |
// IExpressionDMContext object for each local variable name, saving them all |
|
907 |
// in an array. |
|
908 |
||
909 |
if (!isSuccess()) { |
|
910 |
handleFailedUpdate(update); |
|
911 |
return; |
|
912 |
} |
|
913 |
||
914 |
IExpressionDMContext[] expressionDMCs = new IExpressionDMContext[localsDMData.size()]; |
|
915 |
||
916 |
int i = 0; |
|
917 |
||
918 |
for (IVariableDMData localDMData : localsDMData) { |
|
919 |
expressionDMCs[i++] = expressionService.createExpression(frameDmc, localDMData.getName()); |
|
920 |
} |
|
921 |
||
922 |
// Lastly, we fill the update from the array of view model context objects |
|
923 |
// that reference the ExpressionDMC objects for the local variables. This is |
|
924 |
// the last code to run for a given call to updateElementsInSessionThread(). |
|
925 |
// We can now leave anonymous-inner-class hell. |
|
926 |
||
927 |
fillUpdateWithVMCs(update, expressionDMCs); |
|
928 |
update.done(); |
|
929 |
} |
|
930 |
}; |
|
931 |
||
932 |
// Perform a set of getModelData() calls, one for each local variable's data model |
|
933 |
// context object. In the handleCompleted() method of the DataRequestMonitor, add the |
|
934 |
// IVariableDMData object to the localsDMData List for later processing (see above). |
|
935 |
||
936 |
for (IVariableDMContext localDMC : localsDMCs) { |
|
937 |
DataRequestMonitor<IVariableDMData> rm = |
|
938 |
new ViewerDataRequestMonitor<IVariableDMData>(dsfExecutor, update) { |
|
939 |
@Override |
|
940 |
public void handleCompleted() { |
|
941 |
localsDMData.add(getData()); |
|
942 |
mrm.requestMonitorDone(this); |
|
943 |
} |
|
944 |
}; |
|
945 |
||
946 |
mrm.add(rm); |
|
947 |
||
948 |
stackFrameService.getVariableData(localDMC, rm); |
|
949 |
} |
|
950 |
} |
|
951 |
}; |
|
952 |
||
953 |
// Make the asynchronous call to IStack.getLocals(). The results are processed in the |
|
954 |
// DataRequestMonitor.handleCompleted() above. |
|
955 |
||
956 |
stackFrameService.getLocals(frameDmc, rm); |
|
957 |
} |
|
958 |
||
959 |
public int getDeltaFlags(Object e) { |
|
960 |
if ( e instanceof ISuspendedDMEvent || |
|
961 |
e instanceof IMemoryChangedEvent || |
|
962 |
e instanceof IExpressionChangedDMEvent || |
|
963 |
(e instanceof PropertyChangeEvent && |
|
964 |
((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) ) |
|
965 |
{ |
|
966 |
// Create a delta that the whole register group has changed. |
|
967 |
return IModelDelta.CONTENT; |
|
968 |
} |
|
969 |
||
970 |
return IModelDelta.NO_CHANGE; |
|
971 |
} |
|
972 |
||
973 |
public void buildDelta(final Object e, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) { |
|
974 |
||
975 |
// The following events can affect any expression's values, |
|
976 |
// refresh the contents of the parent element (i.e. all the expressions). |
|
977 |
if ( e instanceof ISuspendedDMEvent || |
|
978 |
e instanceof IMemoryChangedEvent || |
|
979 |
e instanceof IExpressionChangedDMEvent || |
|
980 |
(e instanceof PropertyChangeEvent && |
|
981 |
((PropertyChangeEvent)e).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) ) |
|
982 |
{ |
|
983 |
// Create a delta that the whole register group has changed. |
|
984 |
parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT); |
|
985 |
} |
|
986 |
||
987 |
requestMonitor.done(); |
|
988 |
} |
|
989 |
||
990 |
public int getDeltaFlagsForExpression(IExpression expression, Object event) { |
|
991 |
if ( event instanceof IExpressionChangedDMEvent || |
|
992 |
event instanceof IMemoryChangedEvent || |
|
993 |
(event instanceof PropertyChangeEvent && |
|
994 |
((PropertyChangeEvent)event).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) ) |
|
995 |
{ |
|
996 |
return IModelDelta.CONTENT; |
|
997 |
} |
|
998 |
||
999 |
if (event instanceof ISuspendedDMEvent) |
|
1000 |
{ |
|
1001 |
return IModelDelta.CONTENT; |
|
1002 |
} |
|
1003 |
||
1004 |
return IModelDelta.NO_CHANGE; |
|
1005 |
} |
|
1006 |
||
1007 |
public void buildDeltaForExpression(IExpression expression, int elementIdx, Object event, VMDelta parentDelta, |
|
1008 |
TreePath path, RequestMonitor rm) |
|
1009 |
{ |
|
1010 |
// Always refresh the contents of the view upon suspended event. |
|
1011 |
if (event instanceof ISuspendedDMEvent) { |
|
1012 |
parentDelta.setFlags(parentDelta.getFlags() | IModelDelta.CONTENT); |
|
1013 |
} |
|
1014 |
||
1015 |
rm.done(); |
|
1016 |
} |
|
1017 |
||
1018 |
public void buildDeltaForExpressionElement(Object element, int elementIdx, Object event, VMDelta parentDelta, |
|
1019 |
RequestMonitor rm) |
|
1020 |
{ |
|
1021 |
// The following events can affect expression values, refresh the state |
|
1022 |
// of the expression. |
|
1023 |
if ( event instanceof IExpressionChangedDMEvent || |
|
1024 |
event instanceof IMemoryChangedEvent || |
|
1025 |
(event instanceof PropertyChangeEvent && |
|
1026 |
((PropertyChangeEvent)event).getProperty() == IDebugVMConstants.PROP_FORMATTED_VALUE_FORMAT_PREFERENCE) ) |
|
1027 |
{ |
|
1028 |
parentDelta.addNode(element, IModelDelta.CONTENT); |
|
1029 |
} |
|
1030 |
||
1031 |
rm.done(); |
|
1032 |
} |
|
1033 |
||
1034 |
||
1035 |
||
1036 |
private String produceExpressionElementName( String viewName , IExpressionDMContext expression ) { |
|
1037 |
||
1038 |
return "Variable." + expression.getExpression(); //$NON-NLS-1$ |
|
1039 |
} |
|
1040 |
||
1041 |
private final String MEMENTO_NAME = "VARIABLE_MEMENTO_NAME"; //$NON-NLS-1$ |
|
1042 |
||
1043 |
public void compareElements(IElementCompareRequest[] requests) { |
|
1044 |
||
1045 |
for ( IElementCompareRequest request : requests ) { |
|
1046 |
||
1047 |
Object element = request.getElement(); |
|
1048 |
IMemento memento = request.getMemento(); |
|
1049 |
String mementoName = memento.getString(MEMENTO_NAME); |
|
1050 |
||
1051 |
if (mementoName != null) { |
|
1052 |
if (element instanceof IDMVMContext) { |
|
1053 |
||
1054 |
IDMContext dmc = ((IDMVMContext)element).getDMContext(); |
|
1055 |
||
1056 |
if ( dmc instanceof IExpressionDMContext) { |
|
1057 |
||
1058 |
String elementName = produceExpressionElementName( request.getPresentationContext().getId(), (IExpressionDMContext) dmc ); |
|
1059 |
request.setEqual( elementName.equals( mementoName ) ); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
} |
|
1063 |
request.done(); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
||
1067 |
public void encodeElements(IElementMementoRequest[] requests) { |
|
1068 |
||
1069 |
for ( IElementMementoRequest request : requests ) { |
|
1070 |
||
1071 |
Object element = request.getElement(); |
|
1072 |
IMemento memento = request.getMemento(); |
|
1073 |
||
1074 |
if (element instanceof IDMVMContext) { |
|
1075 |
||
1076 |
IDMContext dmc = ((IDMVMContext)element).getDMContext(); |
|
1077 |
||
1078 |
if ( dmc instanceof IExpressionDMContext) { |
|
1079 |
||
1080 |
String elementName = produceExpressionElementName( request.getPresentationContext().getId(), (IExpressionDMContext) dmc ); |
|
1081 |
memento.putString(MEMENTO_NAME, elementName); |
|
1082 |
} |
|
1083 |
} |
|
1084 |
request.done(); |
|
1085 |
} |
|
1086 |
} |
|
1087 |
} |