1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-21 21:52:10 +02:00

[268031] Memory Browser - initial commit

This commit is contained in:
Ted Williams 2009-03-13 18:54:20 +00:00
parent e5674e350e
commit 4a37b19237
14 changed files with 916 additions and 0 deletions

View file

@ -46,4 +46,11 @@
version="0.0.0"
unpack="false"/>
<plugin
id="org.eclipse.cdt.debug.ui.memory.memorybrowser"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>
</feature>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.debug.ui.memory.memorybrowser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
#Sat Feb 14 20:02:08 PST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5

View file

@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Memory Browser
Bundle-SymbolicName: org.eclipse.cdt.debug.ui.memory.memorybrowser;singleton:=true
Bundle-Version: 1.2.0
Bundle-Activator: org.cdt.debug.ui.memory.memorybrowser.MemoryBrowserPlugin
Bundle-Vendor: org.eclipse
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.debug.core;bundle-version="3.5.0",
org.eclipse.debug.ui;bundle-version="3.5.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Eclipse-AutoStart: true

View file

@ -0,0 +1,24 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>About</title></head><body lang="EN-US">
<h2>About This Content</h2>
<p>June 5, 2007</p>
<h3>License</h3>
<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
indicated below, the Content is provided to you under the terms and conditions of the
Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
For purposes of the EPL, "Program" will mean the Content.</p>
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
being redistributed by another party ("Redistributor") and different terms and conditions may
apply to your use of any object code in the Content. Check the Redistributor's license that was
provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
</body></html>

View file

@ -0,0 +1,9 @@
source.. = src/
output.. = bin/
bin.includes = plugin.xml,\
META-INF/,\
.,\
icons/,\
contexts.xml,\
about.html
src.includes = about.html

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 B

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<view
name="Memory Browser"
icon="icons/memorybrowser_view.gif"
category="org.eclipse.debug.ui"
class="org.cdt.debug.ui.memory.memorybrowser.MemoryBrowser"
id="org.cdt.debug.ui.memory.memorybrowser.MemoryBrowser">
</view>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
</plugin>

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. 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:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
*******************************************************************************/
package org.cdt.debug.ui.memory.memorybrowser;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
public class GoToAddressBarWidget {
private Text fExpression;
private Button fOKButton;
private Button fOKNewTabButton;
private Composite fComposite;
protected static int ID_GO_NEW_TAB = 2000;
/**
* @param parent
* @return
*/
public Control createControl(Composite parent)
{
fComposite = new Composite(parent, SWT.NONE);
PlatformUI.getWorkbench().getHelpSystem().setHelp(fComposite, // FIXME
".GoToAddressComposite_context"); //$NON-NLS-1$
GridLayout layout = new GridLayout();
layout.numColumns = 6;
layout.makeColumnsEqualWidth = false;
layout.marginHeight = 0;
layout.marginLeft = 0;
fComposite.setLayout(layout);
fExpression = new Text(fComposite, SWT.SINGLE | SWT.BORDER);
fExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fOKButton = new Button(fComposite, SWT.NONE);
fOKButton.setText("Go");
fOKNewTabButton = new Button(fComposite, SWT.NONE);
fOKNewTabButton.setText("New Tab");
return fComposite;
}
public int getHeight()
{
int height = fComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
return height;
}
public Button getButton(int id)
{
if (id == IDialogConstants.OK_ID)
return fOKButton;
if (id == ID_GO_NEW_TAB)
return fOKNewTabButton;
return null;
}
public String getExpressionText()
{
return fExpression.getText().trim();
}
public Text getExpressionWidget()
{
return fExpression;
}
}

View file

@ -0,0 +1,595 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. 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:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
*******************************************************************************/
package org.cdt.debug.ui.memory.memorybrowser;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchListener;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IMemoryBlock;
import org.eclipse.debug.core.model.IMemoryBlockExtension;
import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
import org.eclipse.debug.core.model.MemoryByte;
import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.contexts.DebugContextEvent;
import org.eclipse.debug.ui.contexts.IDebugContextListener;
import org.eclipse.debug.ui.memory.IMemoryRendering;
import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
import org.eclipse.debug.ui.memory.IMemoryRenderingSynchronizationService;
import org.eclipse.debug.ui.memory.IMemoryRenderingType;
import org.eclipse.debug.ui.memory.IRepositionableMemoryRendering;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.resource.ColorRegistry;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.IBasicPropertyConstants;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabFolder2Adapter;
import org.eclipse.swt.custom.CTabFolderEvent;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchPreferenceConstants;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.progress.WorkbenchJob;
/**
* A lightweight rendering container.
*
* Debug model requirements:
* IMemoryBlockExtension (IMemoryBlock not supported)
* IMemoryBlockRetrievalExtension
* <p>
* Rendering requirements:
* IRepositionableMemoryRendering
*
*/
public class MemoryBrowser extends ViewPart implements IDebugContextListener, ILaunchListener
{
public static final String ID = "org.cdt.debug.ui.memory.memorybrowser.MemoryBrowser"; //$NON-NLS-1$
protected StackLayout fStackLayout;
private Composite fRenderingsComposite;
private HashMap<Object,CTabFolder> fContextFolders = new HashMap<Object,CTabFolder> ();
private GoToAddressBarWidget fGotoAddressBar;
private Control fGotoAddressBarControl;
private Label fUnsupportedLabel;
private Composite fMainComposite;
private String defaultRenderingTypeId = null; //$NON-NLS-1$
private final static String KEY_RENDERING = "RENDERING"; //$NON-NLS-1$
private final static String KEY_CONTEXT = "CONTEXT"; //$NON-NLS-1$
private final static String KEY_RETRIEVAL = "RETRIEVAL"; //$NON-NLS-1$
public MemoryBrowser() {
}
private Control getControl()
{
return fMainComposite;
}
public void createPartControl(Composite parent) {
// set default rendering type. use the traditional rendering if available. fallback on first registered type.
// this should eventually be configurable via a preference page.
boolean isTraditionalRenderingAvailable = false;
final String traditionalRenderingId = "org.eclipse.cdt.debug.ui.memory.traditional.TraditionalRendering"; //$NON-NLS-1$
IMemoryRenderingType[] types = getRenderingTypes();
for(final IMemoryRenderingType type : types)
{
if(type.getId().equals(traditionalRenderingId))
{
isTraditionalRenderingAvailable = true;
break;
}
}
if(isTraditionalRenderingAvailable)
defaultRenderingTypeId = traditionalRenderingId;
else if(types.length > 0)
defaultRenderingTypeId = types[0].getId();
getSite().setSelectionProvider(new ISelectionProvider() {
public void addSelectionChangedListener(
ISelectionChangedListener listener) {}
public ISelection getSelection() {
return null;
}
public void removeSelectionChangedListener(
ISelectionChangedListener listener) {}
public void setSelection(ISelection selection) {}
});
fMainComposite = new Composite(parent, SWT.NONE);
FormLayout layout = new FormLayout();
layout.spacing = 0;
fMainComposite.setLayout(layout);
fGotoAddressBar = new GoToAddressBarWidget();
fGotoAddressBarControl = fGotoAddressBar.createControl(fMainComposite);
fGotoAddressBar.getButton(IDialogConstants.OK_ID).addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
performGo(false);
}
});
fGotoAddressBar.getButton(GoToAddressBarWidget.ID_GO_NEW_TAB).addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {}
public void widgetSelected(SelectionEvent e) {
performGo(true);
}
});
fGotoAddressBar.getExpressionWidget().addKeyListener(new KeyListener(){
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) {
if(e.keyCode == SWT.CR)
performGo(false);
}
});
FormData data = new FormData();
data.top = new FormAttachment(0);
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
fGotoAddressBarControl.setLayoutData(data);
fRenderingsComposite = new Composite(fMainComposite, SWT.NONE);
data = new FormData();
data.top = new FormAttachment(fGotoAddressBarControl);
data.left = new FormAttachment(0);
data.right = new FormAttachment(100);
data.bottom = new FormAttachment(100);
fRenderingsComposite.setLayoutData(data);
fStackLayout = new StackLayout();
fRenderingsComposite.setLayout(fStackLayout);
fUnsupportedLabel = new Label(fRenderingsComposite, SWT.NONE);
fUnsupportedLabel.setText(""); //$NON-NLS-1$
handleUnsupportedSelection();
PlatformUI.getWorkbench().getHelpSystem().setHelp(fMainComposite, MemoryBrowserPlugin.PLUGIN_ID);
makeActions();
hookContextMenu();
contributeToActionBars();
DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow())
.addDebugContextListener(this);
DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
}
public void dispose() {
DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow())
.removeDebugContextListener(this);
super.dispose();
}
public void launchAdded(ILaunch launch) {}
public void launchChanged(ILaunch launch) {}
public void launchRemoved(ILaunch launch) {
IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) launch.getAdapter(IMemoryBlockRetrieval.class));
if(retrieval != null)
releaseTabFolder(retrieval);
}
private void handleUnsupportedSelection()
{
fStackLayout.topControl = fUnsupportedLabel;
fGotoAddressBarControl.setVisible(false);
}
private void performGo(boolean inNewTab)
{
final CTabFolder activeFolder = (CTabFolder) fStackLayout.topControl;
if(activeFolder != null)
{
final IMemoryBlockRetrieval retrieval = (IMemoryBlockRetrieval) activeFolder.getData(KEY_RETRIEVAL);
final Object context = activeFolder.getData(KEY_CONTEXT);
if(inNewTab || activeFolder.getSelection() == null)
{
CTabItem item = createTab(activeFolder, activeFolder.getSelectionIndex() + 1);
populateTabWithRendering(item, retrieval, context);
setTabFolder(retrieval, activeFolder);
activeFolder.setSelection(item);
}
Control c = activeFolder.getSelection().getControl();
final IRepositionableMemoryRendering rendering = (IRepositionableMemoryRendering) activeFolder.getSelection().getData(KEY_RENDERING);
final String expression = fGotoAddressBar.getExpressionText();
if(retrieval instanceof IMemoryBlockRetrievalExtension)
{
new Thread()
{
public void run()
{
IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension) retrieval;
try {
IMemoryBlockExtension newBlock = retrievalExtension.getExtendedMemoryBlock(expression, context);
BigInteger newBase = newBlock.getBigBaseAddress();
if(((IMemoryBlockExtension) rendering.getMemoryBlock()).supportBaseAddressModification())
((IMemoryBlockExtension) rendering.getMemoryBlock()).setBaseAddress(newBase);
rendering.goToAddress(newBase);
Display.getDefault().asyncExec(new Runnable(){
public void run()
{
updateLabel(activeFolder.getSelection(), rendering);
}
});
} catch (DebugException e1) {
MemoryBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, MemoryBrowserPlugin.PLUGIN_ID, "", e1)); //$NON-NLS-1$
}
}
}.start();
}
}
}
private void updateLabel(CTabItem tab, IMemoryRendering rendering)
{
String label = null;
// would like to avoid using reflection
try {
Method m = rendering.getControl().getClass().getMethod("getViewportStartAddress", new Class[0]); //$NON-NLS-1$
if(m != null)
label = "0x" + ((BigInteger) m.invoke(rendering.getControl(), new Object[0])).toString(16).toUpperCase(); //$NON-NLS-1$
}
catch (Exception e)
{
}
if(label == null)
label = rendering.getLabel();
tab.setText(label);
}
private CTabFolder createTabFolder(Composite parent)
{
CTabFolder folder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT);
ColorRegistry reg = JFaceResources.getColorRegistry();
Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
folder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true);
folder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
folder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
folder.setBorderVisible(true);
folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
event.doit = false;
}
});
return folder;
}
private CTabItem createTab(CTabFolder tabFolder, int index) {
int swtStyle = SWT.CLOSE;
CTabItem tab = new CTabItem(tabFolder, swtStyle, index);
return tab;
}
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
MemoryBrowser.this.fillContextMenu(manager);
}
});
Menu menu = menuMgr.createContextMenu(getControl());
getControl().setMenu(menu);
}
private void contributeToActionBars() {
IActionBars bars = getViewSite().getActionBars();
fillLocalPullDown(bars.getMenuManager());
fillLocalToolBar(bars.getToolBarManager());
}
private void fillLocalPullDown(IMenuManager manager) {
MenuManager sub = new MenuManager(Messages.getString("MemoryBrowser.DefaultRendering")); //$NON-NLS-1$
for(final IMemoryRenderingType type : getRenderingTypes())
{
final Action action = new Action(
type.getLabel(), IAction.AS_CHECK_BOX)
{
public void run()
{
setDefaultRenderingTypeId(type.getId());
}
};
action.setChecked(type.getId().equals(getDefaultRenderingTypeId()));
sub.add(action);
}
manager.add(sub);
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private void fillContextMenu(IMenuManager manager) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private void fillLocalToolBar(IToolBarManager manager) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private void makeActions() {
}
private IMemoryRenderingType[] getRenderingTypes()
{
return MemoryRenderingManager.getDefault().getRenderingTypes(new IMemoryBlockExtension(){
public void connect(Object client) {}
public void disconnect(Object client) {}
public void dispose() throws DebugException {}
public int getAddressSize() throws DebugException { return 0; }
public int getAddressableSize() throws DebugException { return 0; }
public BigInteger getBigBaseAddress() throws DebugException { return null; }
public BigInteger getBigLength() throws DebugException { return null; }
public MemoryByte[] getBytesFromAddress(BigInteger address, long units) throws DebugException { return null; }
public MemoryByte[] getBytesFromOffset(BigInteger unitOffset, long addressableUnits) throws DebugException { return null; }
public Object[] getConnections() { return null; }
public String getExpression() { return null; }
public BigInteger getMemoryBlockEndAddress() throws DebugException { return null; }
public IMemoryBlockRetrieval getMemoryBlockRetrieval() { return null; }
public BigInteger getMemoryBlockStartAddress() throws DebugException { return null; }
public void setBaseAddress(BigInteger address) throws DebugException {}
public void setValue(BigInteger offset, byte[] bytes) throws DebugException {}
public boolean supportBaseAddressModification() throws DebugException { return false; }
public boolean supportsChangeManagement() { return false; }
public byte[] getBytes() throws DebugException { return null; }
public long getLength() { return 0; }
public long getStartAddress() { return 0; }
public void setValue(long offset, byte[] bytes) throws DebugException {}
public boolean supportsValueModification() { return false; }
public IDebugTarget getDebugTarget() { return null; }
public ILaunch getLaunch() { return null; }
public String getModelIdentifier() { return null; }
public Object getAdapter(Class adapter) { return null; }
});
}
public void setFocus() {
getControl().setFocus();
}
public void debugContextChanged(DebugContextEvent event) {
if(defaultRenderingTypeId == null)
return;
if(event.getContext() instanceof StructuredSelection)
{
Object context = ((StructuredSelection) event.getContext()).getFirstElement();
if(context instanceof IAdaptable)
{
IMemoryBlockRetrieval retrieval = ((IMemoryBlockRetrieval) ((IAdaptable) context).getAdapter(IMemoryBlockRetrieval.class));
if(retrieval != null)
{
fGotoAddressBarControl.setVisible(true);
if(getTabFolder(retrieval) != null)
{
fStackLayout.topControl = getTabFolder(retrieval);
}
else
{
CTabFolder newFolder = this.createTabFolder(fRenderingsComposite);
newFolder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
event.doit = true;
}
});
newFolder.setData(KEY_CONTEXT, context);
newFolder.setData(KEY_RETRIEVAL, retrieval);
CTabItem item = createTab(newFolder, 0);
populateTabWithRendering(item, retrieval, context);
setTabFolder(retrieval, newFolder);
fStackLayout.topControl = getTabFolder(retrieval);
}
}
else
{
handleUnsupportedSelection();
}
fStackLayout.topControl.getParent().layout(true);
}
}
}
private String getDefaultRenderingTypeId()
{
return defaultRenderingTypeId;
}
private void setDefaultRenderingTypeId(String id)
{
defaultRenderingTypeId = id;
}
private void populateTabWithRendering(final CTabItem tab, final IMemoryBlockRetrieval retrieval, Object context)
{
IMemoryRenderingType type = DebugUITools.getMemoryRenderingManager().getRenderingType(getDefaultRenderingTypeId());
try {
final IMemoryRendering rendering = type.createRendering();
IMemoryRenderingContainer container = new IMemoryRenderingContainer()
{
public void addMemoryRendering(IMemoryRendering rendering) {}
public IMemoryRendering getActiveRendering() {
return rendering;
}
public String getId() {
return "???"; //$NON-NLS-1$
}
public String getLabel() {
return rendering.getLabel();
}
public IMemoryRenderingSite getMemoryRenderingSite() {
return new IMemoryRenderingSite() {
public IMemoryRenderingContainer getContainer(String id) {
return null;
}
public IMemoryRenderingContainer[] getMemoryRenderingContainers() {
return null;
}
public IWorkbenchPartSite getSite() {
return MemoryBrowser.this.getSite();
}
public IMemoryRenderingSynchronizationService getSynchronizationService() {
return null;
}
};
}
public IMemoryRendering[] getRenderings() {
return null;
}
public void removeMemoryRendering(IMemoryRendering rendering) {}
};
IMemoryBlock block = null;
if(retrieval instanceof IAdaptable)
{
IMemoryBlockRetrievalExtension retrievalExtension = (IMemoryBlockRetrievalExtension)
((IAdaptable) retrieval).getAdapter(IMemoryBlockRetrievalExtension.class);
if(retrievalExtension != null)
block = retrievalExtension.getExtendedMemoryBlock("0", context); //$NON-NLS-1$
}
rendering.init(container, block);
rendering.createControl(tab.getParent());
tab.setControl(rendering.getControl());
tab.getParent().setSelection(0);
tab.setData(KEY_RENDERING, rendering);
updateLabel(tab, rendering);
rendering.addPropertyChangeListener(new IPropertyChangeListener()
{
public void propertyChange(final PropertyChangeEvent event) {
WorkbenchJob job = new WorkbenchJob("MemoryBrowser PropertyChanged") { //$NON-NLS-1$
public IStatus runInUIThread(IProgressMonitor monitor) {
if(tab.isDisposed())
return Status.OK_STATUS;
if (event.getProperty().equals(IBasicPropertyConstants.P_TEXT))
updateLabel(tab, rendering);
return Status.OK_STATUS;
}
};
job.setSystem(true);
job.schedule();
}
});
} catch (CoreException e) {
MemoryBrowserPlugin.getDefault().getLog().log(new Status(Status.ERROR, MemoryBrowserPlugin.PLUGIN_ID, "", e)); //$NON-NLS-1$
}
}
private CTabFolder getTabFolder(Object context)
{
return fContextFolders.get(context);
}
private CTabFolder setTabFolder(Object context, CTabFolder folder)
{
return fContextFolders.put(context, folder);
}
private void releaseTabFolder(Object context)
{
final CTabFolder folder = getTabFolder(context);
if(folder != null)
{
for(CTabItem tab : folder.getItems())
tab.dispose();
}
fContextFolders.remove(context);
}
}

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. 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:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
*******************************************************************************/
package org.cdt.debug.ui.memory.memorybrowser;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class MemoryBrowserPlugin extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.cdt.debug.ui.memory.memorybrowser";
// The shared instance
private static MemoryBrowserPlugin plugin;
/**
* The constructor
*/
public MemoryBrowserPlugin() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static MemoryBrowserPlugin getDefault() {
return plugin;
}
/**
* Returns an image descriptor for the image file at the given
* plug-in relative path
*
* @param path the path
* @return the image descriptor
*/
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2009 Wind River Systems, Inc. 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:
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
*******************************************************************************/
package org.cdt.debug.ui.memory.memorybrowser;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "org.cdt.debug.ui.memory.memorybrowser.messages"; //$NON-NLS-1$
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}

View file

@ -0,0 +1,12 @@
# Copyright (c) 2009 Wind River Systems, Inc. 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:
# Ted R Williams (Wind River Systems, Inc.) - initial implementation
GoToAddressBarWidget.Go=Go
GoToAddressBarWidget.NewTab=New Tab
MemoryBrowser.DefaultRendering=Default Rendering