Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Chuong2011-03-04 16:06:51 +0000
committerPatrick Chuong2011-03-04 16:06:51 +0000
commitc57cf3cce366ba1d36b09a95799c1d2cdf5a0038 (patch)
tree4c39bad0df6b3f2ffe25c4a6056b437fa0841376 /dsf/org.eclipse.cdt.examples.dsf.pda.ui
parentda8a1d0b28cd6be12d2b771ef40861b1bd0ade19 (diff)
downloadorg.eclipse.cdt-c57cf3cce366ba1d36b09a95799c1d2cdf5a0038.tar.gz
org.eclipse.cdt-c57cf3cce366ba1d36b09a95799c1d2cdf5a0038.tar.xz
org.eclipse.cdt-c57cf3cce366ba1d36b09a95799c1d2cdf5a0038.zip
Bug 202556 - [variables][registers][expressions] Allow setting of numeric format for individual variables in the view.
Diffstat (limited to 'dsf/org.eclipse.cdt.examples.dsf.pda.ui')
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml7
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAExpressionVMProvider.java115
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAVMAdapter.java7
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistable.java81
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistableFactory.java32
5 files changed, 239 insertions, 3 deletions
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
index 2a0a9b3d948..16608bd2233 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/plugin.xml
@@ -103,5 +103,12 @@
adaptableType="org.eclipse.cdt.examples.dsf.pda.ui.editor.PDAEditor">
<adapter type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget"/>
</factory>
+ </extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+ class="org.eclipse.cdt.examples.dsf.pda.ui.viewmodel.VariablePersistableFactory"
+ id="org.eclipse.cdt.examples.dsf.pda.ui.variablePersitableFactory">
+ </factory>
</extension> -->
</plugin>
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAExpressionVMProvider.java b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAExpressionVMProvider.java
new file mode 100644
index 00000000000..e3a7340d3fb
--- /dev/null
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAExpressionVMProvider.java
@@ -0,0 +1,115 @@
+/*****************************************************************
+ * Copyright (c) 2011 Texas Instruments 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Winnie Lai (Texas Instruments) - Individual Element Number Format example (Bug 202556)
+ *****************************************************************/
+package org.eclipse.cdt.examples.dsf.pda.ui.viewmodel;
+
+import java.util.ArrayList;
+
+import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
+import org.eclipse.cdt.dsf.datamodel.DMContexts;
+import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionVMProvider;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.numberformat.IElementFormatProvider;
+import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMNode;
+import org.eclipse.cdt.dsf.service.DsfSession;
+import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMContext;
+import org.eclipse.cdt.dsf.ui.viewmodel.IVMNode;
+import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
+import org.eclipse.debug.core.model.IExpression;
+import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext;
+import org.eclipse.jface.viewers.TreePath;
+
+/**
+ * PDA View Model provider for the expression view.
+ */
+@SuppressWarnings("restriction")
+public class PDAExpressionVMProvider extends ExpressionVMProvider implements IElementFormatProvider {
+
+ static String myPersistId = "org.eclipse.cdt.examples.dsf.pda.ui.variablePersistable";
+
+ public PDAExpressionVMProvider(AbstractVMAdapter adapter, IPresentationContext context, DsfSession session) {
+ super(adapter, context, session);
+ }
+
+ public void getActiveFormat(IPresentationContext context, IVMNode node, Object viewerInput, TreePath elementPath,
+ DataRequestMonitor<String> rm) {
+ Object p = context.getProperty(myPersistId);
+ if (p instanceof VariablePersistable == false) {
+ rm.setData(null);
+ rm.done();
+ return;
+ }
+ VariablePersistable persistable = (VariablePersistable) p;
+ Object x = elementPath.getLastSegment();
+ if (x instanceof VariableVMNode.VariableExpressionVMC) {
+ IExpressionDMContext ctx = DMContexts.getAncestorOfType(((VariableVMNode.VariableExpressionVMC) x).getDMContext(), IExpressionDMContext.class);
+ if (ctx == null) {
+ rm.setData(null);
+ } else {
+ rm.setData(persistable.getFormat(ctx.getExpression()));
+ }
+ rm.done();
+ return;
+ } else if (x instanceof IDMVMContext) {
+ // register and bit field context are covered here.
+ // When these show up in expression view, the register/bit field vm node's associateExpression has called
+ // RegisterVMC/BitFieldVMC's setExpression
+ IExpression y = (IExpression) ((IVMContext) x).getAdapter(IExpression.class);
+ if (y == null) {
+ rm.setData(null);
+ } else {
+ rm.setData(persistable.getFormat(y.getExpressionText()));
+ }
+ rm.done();
+ return;
+ }
+ rm.setData(null);
+ rm.done();
+ return;
+ }
+
+ public void setActiveFormat(IPresentationContext context, IVMNode[] node, Object viewerInput, TreePath[] elementPath, String format) {
+ Object p = context.getProperty(myPersistId);
+ VariablePersistable persistable = null;
+ if (p instanceof VariablePersistable) {
+ persistable = (VariablePersistable) p;
+ } else {
+ persistable = new VariablePersistable();
+ context.setProperty(myPersistId, persistable);
+ }
+ ArrayList<IDMVMContext> changed = new ArrayList<IDMVMContext>(elementPath.length);
+ for (int i = 0; i < elementPath.length; i++) {
+ Object x = elementPath[i].getLastSegment();
+ if (x instanceof VariableVMNode.VariableExpressionVMC) {
+ IExpressionDMContext ctx = DMContexts.getAncestorOfType(((VariableVMNode.VariableExpressionVMC) x).getDMContext(), IExpressionDMContext.class);
+ if (ctx == null)
+ continue;
+ persistable.setFormat(ctx.getExpression(), format);
+ changed.add((IDMVMContext) x);
+ } else if (x instanceof IDMVMContext) {
+ IExpression y = (IExpression) ((IVMContext) x).getAdapter(IExpression.class);
+ if (y == null)
+ continue;
+ persistable.setFormat(y.getExpressionText(), format);
+ }
+ }
+ if (changed.size() > 0) {
+ refresh();
+ }
+ }
+
+ public boolean supportFormat(IVMContext context) {
+ if (context instanceof VariableVMNode.VariableExpressionVMC) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAVMAdapter.java b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAVMAdapter.java
index 530e2a35385..93e12289e65 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAVMAdapter.java
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/PDAVMAdapter.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,13 +7,14 @@
*
* Contributors:
* Wind River Systems - initial API and implementation
+ * Winnie Lai (Texas Instruments) - Individual Element Number Format example (Bug 202556)
*******************************************************************************/
package org.eclipse.cdt.examples.dsf.pda.ui.viewmodel;
import org.eclipse.cdt.dsf.concurrent.ThreadSafe;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.AbstractDebugVMAdapter;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.SteppingController;
-import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionVMProvider;
+//import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionVMProvider;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.RegisterVMProvider;
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMProvider;
import org.eclipse.cdt.dsf.service.DsfSession;
@@ -45,7 +46,7 @@ public class PDAVMAdapter extends AbstractDebugVMAdapter
} else if (IDebugUIConstants.ID_VARIABLE_VIEW.equals(context.getId()) ) {
return new VariableVMProvider(this, context, getSession());
} else if (IDebugUIConstants.ID_EXPRESSION_VIEW.equals(context.getId()) ) {
- return new ExpressionVMProvider(this, context, getSession());
+ return new PDAExpressionVMProvider(this, context, getSession());
} else if (IDebugUIConstants.ID_REGISTER_VIEW.equals(context.getId()) ) {
return new RegisterVMProvider(this, context, getSession());
}
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistable.java b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistable.java
new file mode 100644
index 00000000000..e723b106548
--- /dev/null
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistable.java
@@ -0,0 +1,81 @@
+/*****************************************************************
+ * Copyright (c) 2011 Texas Instruments 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Winnie Lai (Texas Instruments) - Individual Element Number Format example (Bug 202556)
+ *****************************************************************/
+package org.eclipse.cdt.examples.dsf.pda.ui.viewmodel;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * Variable persistable for variable settings
+ */
+class VariablePersistable implements IPersistableElement, IAdaptable {
+
+ HashMap<String, String> map = new HashMap<String, String>();
+
+ public void saveState(IMemento memento) {
+ HashMap<String, String> clone = null;
+ synchronized (map) {
+ clone = new HashMap<String, String>(map);
+ }
+ Iterator<Entry<String, String> > it = clone.entrySet().iterator();
+ while (it.hasNext()) {
+ Entry<String, String> entry = it.next();
+ IMemento value = memento.createChild("variable", entry.getKey());
+ value.putString("format", entry.getValue());
+ }
+ }
+
+ void restore(IMemento memento) {
+ IMemento[] list = memento.getChildren("variable");
+ HashMap<String, String> clone = new HashMap<String, String>();
+ for (int i = 0; i < list.length; i++) {
+ clone.put(list[i].getID(), list[i].getString("format"));
+ }
+ synchronized(map) {
+ map.clear();
+ map.putAll(clone);
+ }
+ }
+
+ String getFormat(String key) {
+ if (key == null)
+ return null;
+ synchronized (map) {
+ return map.get(key);
+ }
+ }
+
+ void setFormat(String key, String format) {
+ synchronized (map) {
+ if (format == null) {
+ map.remove(key);
+ } else {
+ map.put(key, format);
+ }
+ }
+ }
+
+ public String getFactoryId() {
+ return VariablePersistableFactory.getFactoryId();
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ if (adapter.isInstance(this)) {
+ return this;
+ }
+ return null;
+ }
+}
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistableFactory.java b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistableFactory.java
new file mode 100644
index 00000000000..914fd8c6056
--- /dev/null
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda.ui/src/org/eclipse/cdt/examples/dsf/pda/ui/viewmodel/VariablePersistableFactory.java
@@ -0,0 +1,32 @@
+/*****************************************************************
+ * Copyright (c) 2011 Texas Instruments 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Winnie Lai (Texas Instruments) - Individual Element Number Format example (Bug 202556)
+ *****************************************************************/
+package org.eclipse.cdt.examples.dsf.pda.ui.viewmodel;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ * Variable persistable factory for VariablePersistable
+ */
+public class VariablePersistableFactory implements IElementFactory {
+
+ public static String getFactoryId() {
+ return "org.eclipse.cdt.examples.dsf.pda.ui.variablePersitableFactory";
+ }
+
+ public IAdaptable createElement(IMemento memento) {
+ VariablePersistable x = new VariablePersistable();
+ x.restore(memento);
+ return x;
+ }
+
+}

Back to the top