From e453c2257d80c878c00729d7f17aad0b7280ed1f Mon Sep 17 00:00:00 2001 From: "U-bobgato\\cortell" Date: Fri, 14 Oct 2011 20:58:16 -0500 Subject: [PATCH] Bug 339708 - [Memory Browser] Need a public method for getting selected memory space --- .../META-INF/MANIFEST.MF | 3 +- .../memory/memorybrowser/MemoryBrowser.java | 69 ++++++++++++++++++- .../memorybrowser/api/IMemoryBrowser.java | 63 +++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100755 memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/api/IMemoryBrowser.java diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/META-INF/MANIFEST.MF b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/META-INF/MANIFEST.MF index bd81ea84c96..df1664041ff 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/META-INF/MANIFEST.MF +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/META-INF/MANIFEST.MF @@ -14,4 +14,5 @@ Require-Bundle: org.eclipse.ui, org.eclipse.cdt.debug.ui;bundle-version="7.0.0" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.cdt.debug.ui.memory.memorybrowser +Export-Package: org.eclipse.cdt.debug.ui.memory.memorybrowser, + org.eclipse.cdt.debug.ui.memory.memorybrowser.api diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java index 850e0d5f23f..346effcc136 100644 --- a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/MemoryBrowser.java @@ -24,6 +24,7 @@ import java.util.Map; import org.eclipse.cdt.debug.core.model.provisional.IMemoryRenderingViewportProvider; import org.eclipse.cdt.debug.core.model.provisional.IMemorySpaceAwareMemoryBlockRetrieval; import org.eclipse.cdt.debug.internal.core.CRequest; +import org.eclipse.cdt.debug.ui.memory.memorybrowser.api.IMemoryBrowser; import org.eclipse.cdt.debug.ui.provisional.IRepositionableMemoryRendering2; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; @@ -125,8 +126,9 @@ import org.eclipse.ui.progress.WorkbenchJob; * */ -@SuppressWarnings("restriction") -public class MemoryBrowser extends ViewPart implements IDebugContextListener, IMemoryRenderingSite, IDebugEventSetListener +@SuppressWarnings("restriction") /* Debug Platform's Flexibile hierarchy is still provisional */ + +public class MemoryBrowser extends ViewPart implements IDebugContextListener, IMemoryRenderingSite, IDebugEventSetListener, IMemoryBrowser { public static final String ID = "org.eclipse.cdt.debug.ui.memory.memorybrowser.MemoryBrowser"; //$NON-NLS-1$ @@ -475,6 +477,17 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM performGo(inNewTab, expression, memorySpace); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.ui.memory.memorybrowser.api.IMemoryBrowser#getActiveRetrieval() + */ + public IMemoryBlockRetrieval getActiveRetrieval() { + final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl; + if (activeFolder == null) + return null; + + return (IMemoryBlockRetrieval) activeFolder.getData(KEY_RETRIEVAL); + } public void performGo(boolean inNewTab, final String expression, final String memorySpaceId) { final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl; @@ -1293,4 +1306,56 @@ public class MemoryBrowser extends ViewPart implements IDebugContextListener, IM job.schedule(); } } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.ui.memory.memorybrowser.api.IMemoryBrowser#go(java.lang.String, java.lang.String, boolean) + */ + public void go(String expression, String memorySpaceId, boolean inNewTab) + throws CoreException { + if (expression == null) { + throw new IllegalArgumentException("expression cannot be null"); + } + expression = expression.trim(); + if (expression.length() == 0) { + throw new IllegalArgumentException("expression cannot be empty"); + } + if (!fGotoMemorySpaceControl.isDisposed() && fGotoMemorySpaceControl.isVisible()) { + if (memorySpaceId == null) { + // if caller passed null, use whatever memory space is selected in the control + memorySpaceId = fGotoMemorySpaceControl.getText(); + if (memorySpaceId.equals(NA_MEMORY_SPACE_ID)) { + memorySpaceId = null; + } + } + else { + // if caller passed empty string, it means n/a (same as "----" in the selector) + memorySpaceId = memorySpaceId.trim(); + if (memorySpaceId.length() == 0) { + memorySpaceId = null; + } + else { + // Check that the ID requested by the user is a valid one + if (fGotoMemorySpaceControl.indexOf(memorySpaceId) == -1) { + throw new IllegalArgumentException("unrecognized memory space ID"); + } + } + + fGotoMemorySpaceControl.setText(memorySpaceId == null ? NA_MEMORY_SPACE_ID : memorySpaceId); + } + } + + fGotoAddressBar.setExpressionText(expression); + performGo(inNewTab, expression, memorySpaceId); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.debug.ui.memory.memorybrowser.api.IMemoryBrowser#getSelectedMemorySpace() + */ + public String getSelectedMemorySpace() { + if (!fGotoMemorySpaceControl.isDisposed() && fGotoMemorySpaceControl.isVisible()) { + String id = fGotoMemorySpaceControl.getText(); + return id.equals(NA_MEMORY_SPACE_ID) ? null : id; + } + return null; + } } diff --git a/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/api/IMemoryBrowser.java b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/api/IMemoryBrowser.java new file mode 100755 index 00000000000..7731500e7c5 --- /dev/null +++ b/memory/org.eclipse.cdt.debug.ui.memory.memorybrowser/src/org/eclipse/cdt/debug/ui/memory/memorybrowser/api/IMemoryBrowser.java @@ -0,0 +1,63 @@ +package org.eclipse.cdt.debug.ui.memory.memorybrowser.api; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.model.IMemoryBlockRetrieval; + +/** + * Public API for accessing the memory browser. + * + *

+ * All methods must be called on the UI thread, unless otherwise noted. + */ +public interface IMemoryBrowser { + /** + * Tells the memory browser to go to a new memory location. Updates the goto + * address bar and memory space selector (if present). + * + *

+ * This operation is a no-op if there is no active memory retrieval object. + * + * @param expression + * the expression to go to. Cannot be null or empty string. + * Expression is trimmed. + * @param memorySpaceId + * optional memory space ID. Argument is ignored if the memory + * browser is not currently showing a memory space selector. If + * selector is showing, this argument is interpreted as follows: + * empty string means no memory space (as if the user selected + * the "----" memory space), and null means use whatever memory + * space is selected. Passing an ID that is not present in the + * selector will result in an IllegalArgumentException + * @param inNewTab + * if true, memory is shown in a new tab + * @throws CoreException + */ + public void go(String expression, String memorySpaceId, boolean inNewTab) throws CoreException; + + /** + * Returns the selected memory space. + * + *

+ * The memory browser exposes a memory space selector when debugging a + * target with multiple memory spaces. The selection provides the context + * for the expression when the user performs a GO action. This method will + * return the currently selected memory space. + * + * @return null if the memory space selector is not shown, or if the n/a + * entry is selected. Otherwise the selected memory space ID. Never + * an empty string. + */ + public String getSelectedMemorySpace(); + + /** + * Returns the active memory retrieval object, or null if none is active. + * + * This is the retrieval object being used to obtain the memory shown in the + * active tab. Note that all simultaneously visible tabs use the same + * retrieval object. The retrieval object is obtained from the active debug + * context. + * + * @return the active memory retrieval object, or null if none is active + */ + public IMemoryBlockRetrieval getActiveRetrieval(); +}