1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-15 12:15:47 +02:00

Bug 343021 - variable/expression/register cell modifier need to try to get element format when in editing values

This commit is contained in:
Patrick Chuong 2011-04-28 19:29:07 +00:00
parent 4e4660f725
commit 6a9144e8e0
4 changed files with 133 additions and 56 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems and others.
* Copyright (c) 2006, 2011 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,17 +7,37 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
* Winnie Lai (Texas Instruments) - Individual Element Number Format in editing (Bug 343021)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.expression;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
import org.eclipse.cdt.dsf.concurrent.Query;
import org.eclipse.cdt.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
import org.eclipse.cdt.dsf.datamodel.IDMContext;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionManagerVMNode.NewExpressionVMC;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.IElementFormatProvider;
import org.eclipse.cdt.dsf.service.DsfSession;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IExpressionManager;
import org.eclipse.debug.core.model.IWatchExpression;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IWorkbenchPart;
/**
*
@ -70,6 +90,87 @@ public class WatchExpressionCellModifier implements ICellModifier {
}
}
/**
* Use query to get element format for a vm context from a given provider for given presentation context.
* One use of this method is in cell modifier's getValue() and modify().
* @param provider given provider
* @param presCtx given presentation context
* @param ctx vm context
* @return element format, null if not available
*/
protected String queryElementFormat(final IElementFormatProvider provider, final IPresentationContext presCtx, final IVMContext ctx) {
DsfSession session = null;
if (ctx instanceof IDMVMContext) {
IDMContext dmctx = ((IDMVMContext) ctx).getDMContext();
if (dmctx != null)
session = DsfSession.getSession(dmctx.getSessionId());
}
if (session == null) {
return null;
}
Query<String> query = new Query<String>() {
@Override
protected void execute(final DataRequestMonitor<String> rm) {
// Since cell modifier does not provide the fully qualified
// tree path of the element starting from root, this tree path
// is just the leaf; this is somewhat different than how
// FormatValueRetriever pass in a fully qualified tree path to
// the IElementFormatProvider. It is believed that IVMContext
// can be used to get its parents when needed.
TreePath treePath = new TreePath(new Object[] {ctx});
Object viewerInput = null;
IWorkbenchPart part = presCtx.getPart();
if (part instanceof IDebugView) {
Viewer viewer = ((IDebugView) part).getViewer();
if (viewer != null) {
viewerInput = viewer.getInput();
}
}
provider.getActiveFormat(presCtx, ctx.getVMNode(), viewerInput, treePath,
new DataRequestMonitor<String>(ImmediateExecutor.getInstance(), rm) {
@Override
protected void handleSuccess() {
rm.setData(this.getData());
super.handleSuccess();
}
});
}
};
session.getExecutor().execute(query);
try {
return query.get(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// no op
} catch (ExecutionException e) {
// no op
} catch (TimeoutException e) {
// no op
}
return null;
}
/**
* Use query to get format from a given vm context. This method calls queryElementFormat
* if the vm provider associated with the vm context supports individual element format.
* If the vm provider does not support individual element format or queryElementFormat
* returns null, this method returns the preferred format of the view.
* One use of this method is in cell modifier's getValue() and modify().
* @param ctx the given vm context
* @return the format
*/
protected String queryFormat(IVMContext ctx) {
String formatId = null;
IVMProvider vmprovider = ctx.getVMNode().getVMProvider();
IPresentationContext presCtx = vmprovider.getPresentationContext();
if (vmprovider instanceof IElementFormatProvider) {
formatId = queryElementFormat((IElementFormatProvider) vmprovider, presCtx, ctx);
}
if (formatId == null) {
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
}
return formatId;
}
private IWatchExpression getWatchExpression(Object element) {
if (element instanceof IAdaptable) {
return (IWatchExpression)((IAdaptable)element).getAdapter(IWatchExpression.class);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2009 Wind River Systems and others.
* Copyright (c) 2008, 2011 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
* Winnie Lai (Texas Instruments) - Individual Element Number Format in editing (Bug 343021)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.register;
@ -18,12 +19,10 @@ import org.eclipse.cdt.dsf.debug.service.IRegisters.IBitFieldDMData;
import org.eclipse.cdt.dsf.debug.service.IRegisters.IMnemonic;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.WatchExpressionCellModifier;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.update.AbstractCachingVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.update.UserEditEvent;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
public class RegisterBitFieldCellModifier extends WatchExpressionCellModifier {
@ -34,6 +33,7 @@ public class RegisterBitFieldCellModifier extends WatchExpressionCellModifier {
private IBitFieldDMData fBitFieldData = null;
private Object fElement = null;
private SyncRegisterDataAccess fDataAccess = null;
protected String formatInEditing;
/**
* @since 2.0
@ -101,20 +101,15 @@ public class RegisterBitFieldCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = null;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
formatId = queryFormat((IVMContext) element);
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;
}
formatInEditing = formatId;
String value = fDataAccess.getFormattedBitFieldValue(fElement, formatId);
if ( value == null ) { value = "..."; } //$NON-NLS-1$
@ -158,15 +153,12 @@ public class RegisterBitFieldCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = formatInEditing;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
if (formatId == null) {
formatId = queryFormat((IVMContext) element);
}
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2009 Wind River Systems and others.
* Copyright (c) 2006, 2011 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
* Winnie Lai (Texas Instruments) - Individual Element Number Format in editing (Bug 343021)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.register;
@ -17,17 +18,16 @@ import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMContext;
import org.eclipse.cdt.dsf.debug.service.IRegisters.IRegisterDMData;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.WatchExpressionCellModifier;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.update.AbstractCachingVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.update.UserEditEvent;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
public class RegisterCellModifier extends WatchExpressionCellModifier {
private AbstractCachingVMProvider fProvider;
private SyncRegisterDataAccess fDataAccess = null;
protected String formatInEditing;
public RegisterCellModifier(AbstractCachingVMProvider provider, SyncRegisterDataAccess access)
{
@ -87,20 +87,15 @@ public class RegisterCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = null;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
formatId = queryFormat((IVMContext) element);
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;
}
formatInEditing = formatId;
String value =
fDataAccess.getFormattedRegisterValue(element, formatId);
@ -125,15 +120,12 @@ public class RegisterCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = formatInEditing;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
if (formatId == null) {
formatId = queryFormat((IVMContext) element);
}
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007, 2010 Wind River Systems and others.
* Copyright (c) 2007, 2011 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
* Winnie Lai (Texas Instruments) - Individual Element Number Format in editing (Bug 343021)
*******************************************************************************/
package org.eclipse.cdt.dsf.debug.ui.viewmodel.variable;
@ -15,17 +16,16 @@ import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.IDebugVMConstants;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.WatchExpressionCellModifier;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.FormattedValueVMUtil;
import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
import org.eclipse.cdt.dsf.ui.viewmodel.update.AbstractCachingVMProvider;
import org.eclipse.cdt.dsf.ui.viewmodel.update.UserEditEvent;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
public class VariableCellModifier extends WatchExpressionCellModifier {
private AbstractCachingVMProvider fProvider;
private SyncVariableDataAccess fDataAccess = null;
protected String formatInEditing;
public VariableCellModifier(AbstractCachingVMProvider provider, SyncVariableDataAccess access)
{
@ -76,20 +76,15 @@ public class VariableCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = null;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
formatId = queryFormat((IVMContext) element);
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;
}
formatInEditing = formatId;
String value = fDataAccess.getEditableValue(element, formatId);
if (value == null) {
@ -119,15 +114,12 @@ public class VariableCellModifier extends WatchExpressionCellModifier {
/*
* We let the Model provider supply the current format.
*/
String formatId;
String formatId = formatInEditing;
if ( element instanceof IVMContext) {
/*
* Find the presentation context and then use it to get the current desired format.
*/
IVMContext ctx = (IVMContext) element;
IPresentationContext presCtx = ctx.getVMNode().getVMProvider().getPresentationContext();
formatId = FormattedValueVMUtil.getPreferredFormat(presCtx);
if (formatId == null) {
formatId = queryFormat((IVMContext) element);
}
}
else {
formatId = IFormattedValues.NATURAL_FORMAT;