From 6a9144e8e026879060714e2a8479bf91da8fff85 Mon Sep 17 00:00:00 2001 From: Patrick Chuong Date: Thu, 28 Apr 2011 19:29:07 +0000 Subject: [PATCH] Bug 343021 - variable/expression/register cell modifier need to try to get element format when in editing values --- .../WatchExpressionCellModifier.java | 105 +++++++++++++++++- .../RegisterBitFieldCellModifier.java | 28 ++--- .../register/RegisterCellModifier.java | 28 ++--- .../variable/VariableCellModifier.java | 28 ++--- 4 files changed, 133 insertions(+), 56 deletions(-) diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java index ec102a5906d..c9a6576df24 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/expression/WatchExpressionCellModifier.java @@ -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,7 +90,88 @@ public class WatchExpressionCellModifier implements ICellModifier { } } - private IWatchExpression getWatchExpression(Object element) { + /** + * 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 query = new Query() { + @Override + protected void execute(final DataRequestMonitor 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(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); } diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterBitFieldCellModifier.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterBitFieldCellModifier.java index 8f800709710..5686a500800 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterBitFieldCellModifier.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterBitFieldCellModifier.java @@ -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; diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterCellModifier.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterCellModifier.java index ad4553921ee..24af2ba212e 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterCellModifier.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/register/RegisterCellModifier.java @@ -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; diff --git a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/variable/VariableCellModifier.java b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/variable/VariableCellModifier.java index fd030c3621e..098d76d550d 100644 --- a/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/variable/VariableCellModifier.java +++ b/dsf/org.eclipse.cdt.dsf.ui/src/org/eclipse/cdt/dsf/debug/ui/viewmodel/variable/VariableCellModifier.java @@ -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;