Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Rennie2007-05-09 15:02:45 +0000
committerMichael Rennie2007-05-09 15:02:45 +0000
commit82eb34fd71c1aba127e9641f66b7340c769e71e2 (patch)
tree4b59b485cabb77a5f725ec836eef10fb88f176da /org.eclipse.debug.ui
parent3c6d0eda872a02b31a3c7e8c309e466f68c7e1b4 (diff)
downloadeclipse.platform.debug-82eb34fd71c1aba127e9641f66b7340c769e71e2.tar.gz
eclipse.platform.debug-82eb34fd71c1aba127e9641f66b7340c769e71e2.tar.xz
eclipse.platform.debug-82eb34fd71c1aba127e9641f66b7340c769e71e2.zip
Bug 184970
[Memory View] NPE in SwitchMemoryBlockAction
Diffstat (limited to 'org.eclipse.debug.ui')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/SwitchMemoryBlockAction.java288
1 files changed, 157 insertions, 131 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/SwitchMemoryBlockAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/SwitchMemoryBlockAction.java
index 0ee988663..2c3cfe2f8 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/SwitchMemoryBlockAction.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/memory/SwitchMemoryBlockAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2007 IBM Corporation 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
@@ -14,6 +14,7 @@ package org.eclipse.debug.internal.ui.views.memory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
@@ -42,59 +43,124 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionDelegate2;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.progress.UIJob;
import org.eclipse.ui.progress.WorkbenchJob;
+/**
+ * The switch memory block action, used
+ */
public class SwitchMemoryBlockAction extends Action implements IViewActionDelegate, IActionDelegate2 {
+ /**
+ * A job that updates the enablement of the of the backing action delegate in the UI thread
+ *
+ * @since 3.3.0
+ */
+ class UpdateActionEnablementJob extends UIJob {
+
+ /**
+ * Constructor
+ */
+ public UpdateActionEnablementJob() {
+ super("Update Action Enablement"); //$NON-NLS-1$
+ setSystem(true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus runInUIThread(IProgressMonitor monitor) {
+ if (fAction != null) {
+ IAdaptable context = DebugUITools.getDebugContext();
+ if (context != null) {
+ IMemoryBlockRetrieval retrieval = null;
+ if (context.getAdapter(IMemoryBlockRetrieval.class) != null) {
+ retrieval = (IMemoryBlockRetrieval)context.getAdapter(IMemoryBlockRetrieval.class);
+ }
+ if (retrieval == null) {
+ if(context instanceof IMemoryBlockRetrieval) {
+ retrieval = (IMemoryBlockRetrieval)context;
+ }
+ else if(context instanceof IDebugElement) {
+ retrieval = ((IDebugElement)context).getDebugTarget();
+ }
+ }
+ if (retrieval != null) {
+ IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
+ fAction.setEnabled(memoryBlocks.length > 0);
+ return Status.OK_STATUS;
+ }
+ else if (getViewer() != null) {
+ Object input = getViewer().getInput();
+ if (input instanceof IMemoryBlockRetrieval) {
+ retrieval = (IMemoryBlockRetrieval)input;
+ IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
+ fAction.setEnabled(memoryBlocks.length > 0);
+ return Status.OK_STATUS;
+ }
+ }
+ }
+ fAction.setEnabled(false);
+ }
+ return Status.CANCEL_STATUS;
+ }
+ }
+
private IViewPart fView;
private MenuCreator fMenuCreator;
private IAction fAction;
+ private UpdateActionEnablementJob fUpdateJob = new UpdateActionEnablementJob();
+ /**
+ * Memoryblock listener to update action delegate enablement
+ */
private IMemoryBlockListener fListener = new IMemoryBlockListener() {
public void memoryBlocksAdded(IMemoryBlock[] memory) {
- updateActionEnablement();
+ if (fAction != null) {
+ fUpdateJob.schedule();
+ }
}
public void memoryBlocksRemoved(IMemoryBlock[] memory) {
- updateActionEnablement();
+ if (fAction != null) {
+ fUpdateJob.schedule();
+ }
}
};
+ /**
+ * Listens for debug context changes and updates action delegate enablement
+ */
private IDebugContextListener fDebugContextListener = new IDebugContextListener() {
-
public void debugContextChanged(DebugContextEvent event) {
- updateActionEnablement();
+ if (fAction != null) {
+ fUpdateJob.schedule();
+ }
}
-
};
/**
* Switch tab folder for fMemoryBlock to the top in Memory Rendering View
*/
- class SwitchToAction extends Action
- {
+ class SwitchToAction extends Action {
private IMemoryBlock fMemoryblock;
/* (non-Javadoc)
* @see org.eclipse.jface.action.IAction#run()
*/
public void run() {
- if (fView == null)
+ if (fView == null) {
return;
-
+ }
// tell the view to switch memory block
fView.getSite().getSelectionProvider().setSelection(new StructuredSelection(fMemoryblock));
}
- public SwitchToAction(final IMemoryBlock memBlk, boolean buildLabel)
- {
+ public SwitchToAction(final IMemoryBlock memBlk, boolean buildLabel) {
super();
-
- if (buildLabel)
- {
+ if (buildLabel) {
setText(DebugUIMessages.SwitchMemoryBlockAction_4);
Job job = new Job("SwtichToAction"){ //$NON-NLS-1$
-
protected IStatus run(IProgressMonitor monitor) {
getLabels(memBlk);
return Status.OK_STATUS;
@@ -102,31 +168,25 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
job.setSystem(true);
job.schedule();
}
-
fMemoryblock = memBlk;
}
- public SwitchToAction(final IMemoryBlock memBlk, String label)
- {
+ public SwitchToAction(final IMemoryBlock memBlk, String label) {
super(label);
fMemoryblock = memBlk;
}
-
- private void getLabels(final IMemoryBlock memBlk)
- {
+ private void getLabels(final IMemoryBlock memBlk) {
StringBuffer text = new StringBuffer(""); //$NON-NLS-1$
String label = new String(""); //$NON-NLS-1$
- if (memBlk instanceof IMemoryBlockExtension)
- {
+ if (memBlk instanceof IMemoryBlockExtension) {
String expression = ((IMemoryBlockExtension)memBlk).getExpression();
- if (expression == null)
+ if (expression == null) {
expression = DebugUIMessages.SwitchMemoryBlockAction_0;
-
+ }
text.append(expression);
}
- else
- {
+ else {
long address = memBlk.getStartAddress();
text.append(Long.toHexString(address));
}
@@ -145,8 +205,10 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
}
}
- class MenuCreator implements IMenuCreator
- {
+ /**
+ * Menu creator for the action
+ */
+ class MenuCreator implements IMenuCreator {
Menu dropdown;
/* (non-Javadoc)
@@ -161,15 +223,11 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
* @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
*/
public Menu getMenu(Control parent) {
-
- if (dropdown != null)
- {
+ if (dropdown != null) {
dropdown.dispose();
dropdown = null;
}
-
- if (dropdown == null)
- {
+ if (dropdown == null) {
dropdown = new Menu(parent);
// get all memory blocks from tree viewer
@@ -180,28 +238,21 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
Object context = DebugUITools.getDebugContext();
IMemoryBlockRetrieval retrieval = MemoryViewUtil.getMemoryBlockRetrieval(context);
- if (retrieval != null)
- {
+ if (retrieval != null) {
allMemoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
}
-
- if (allMemoryBlocks != null)
- {
- for (int i=0; i<allMemoryBlocks.length; i++)
- {
+ if (allMemoryBlocks != null) {
+ for (int i=0; i<allMemoryBlocks.length; i++) {
SwitchToAction action = new SwitchToAction(allMemoryBlocks[i], true);
-
- if (allMemoryBlocks[i] == memoryBlock)
+ if (allMemoryBlocks[i] == memoryBlock) {
action.setChecked(true);
-
+ }
ActionContributionItem item = new ActionContributionItem(action);
item.fill(dropdown, -1);
-
item.getAction().setChecked(true);
}
}
}
-
return dropdown;
}
@@ -214,24 +265,25 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
+ */
public void init(IViewPart view) {
fView = view;
DebugUITools.getDebugContextManager().getContextService(fView.getViewSite().getWorkbenchWindow()).addDebugContextListener(fDebugContextListener);
DebugPlugin.getDefault().getMemoryBlockManager().addListener(fListener);
- updateActionEnablement();
+ fUpdateJob.runInUIThread(new NullProgressMonitor());
}
- private StructuredViewer getViewer()
- {
- if (fView == null)
- return null;
-
- if (fView instanceof MemoryView)
- {
+ /**
+ * Returns the current memory blocks tree viewer, or <code>null</code>
+ * @return the memory blocks tree viewer or <code>null</code>
+ */
+ private StructuredViewer getViewer() {
+ if (fView instanceof MemoryView) {
MemoryView memView = (MemoryView)fView;
IMemoryViewPane pane = memView.getViewPane(MemoryBlocksTreeViewPane.PANE_ID);
- if (pane instanceof MemoryBlocksTreeViewPane)
- {
+ if (pane instanceof MemoryBlocksTreeViewPane) {
StructuredViewer viewer = ((MemoryBlocksTreeViewPane)pane).getViewer();
return viewer;
}
@@ -239,65 +291,29 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
return null;
}
- private void updateActionEnablement()
- {
- if (fAction != null)
- {
- IAdaptable context = DebugUITools.getDebugContext();
- if (context != null)
- {
- IMemoryBlockRetrieval retrieval = null;
-
- if (context.getAdapter(IMemoryBlockRetrieval.class) != null)
- retrieval = (IMemoryBlockRetrieval)context.getAdapter(IMemoryBlockRetrieval.class);
-
- if (retrieval == null && context instanceof IMemoryBlockRetrieval)
- retrieval = (IMemoryBlockRetrieval)context;
-
- if (retrieval == null && context instanceof IDebugElement)
- retrieval = ((IDebugElement)context).getDebugTarget();
-
- if (retrieval != null)
- {
- IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
- fAction.setEnabled(memoryBlocks.length > 0);
- return;
- }
- else if (getViewer() != null)
- {
- StructuredViewer viewer = getViewer();
- if (viewer.getInput() != null && viewer.getInput() instanceof IMemoryBlockRetrieval)
- {
- retrieval = (IMemoryBlockRetrieval)viewer.getInput();
- IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
- fAction.setEnabled(memoryBlocks.length > 0);
- return;
- }
- }
- }
- fAction.setEnabled(false);
- }
- }
-
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
public void run(IAction action) {
switchToNext();
}
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
public void run() {
switchToNext();
}
private void switchToNext() {
IAdaptable context = DebugUITools.getDebugContext();
- if (context instanceof IDebugElement)
- {
+ if (context instanceof IDebugElement) {
IDebugElement debugContext = (IDebugElement)context;
IMemoryBlockRetrieval retrieval = (IMemoryBlockRetrieval)debugContext.getAdapter(IMemoryBlockRetrieval.class);
- if (retrieval == null)
+ if (retrieval == null) {
retrieval = debugContext.getDebugTarget();
-
- if (retrieval != null)
- {
+ }
+ if (retrieval != null) {
IMemoryBlock[] memoryBlocks = DebugPlugin.getDefault().getMemoryBlockManager().getMemoryBlocks(retrieval);
doSwitchToNext(memoryBlocks);
}
@@ -309,69 +325,76 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
*/
private void doSwitchToNext(IMemoryBlock[] memoryBlocks) {
// only run if there is more than one memory block
- if (memoryBlocks.length > 1)
- {
+ if (memoryBlocks.length > 1) {
IMemoryBlock current = getCurrentMemoryBlock();
-
int next = 0;
- if (current != null)
- {
- for (int i=0; i<memoryBlocks.length; i++)
- {
- if (memoryBlocks[i] == current)
+ if (current != null) {
+ for (int i=0; i<memoryBlocks.length; i++) {
+ if (memoryBlocks[i] == current) {
next = i+1;
+ }
}
}
-
- if (next > memoryBlocks.length-1)
+ if (next > memoryBlocks.length-1) {
next = 0;
-
+ }
SwitchToAction switchAction = new SwitchToAction(memoryBlocks[next], false);
switchAction.run();
}
}
- public void selectionChanged(IAction action, ISelection selection) {
- }
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
+ */
public void init(IAction action) {
fAction = action;
- updateActionEnablement();
+ fUpdateJob.runInUIThread(new NullProgressMonitor());
fMenuCreator = new MenuCreator();
action.setMenuCreator(fMenuCreator);
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#dispose()
+ */
public void dispose() {
fAction = null;
DebugPlugin.getDefault().getMemoryBlockManager().removeListener(fListener);
DebugUITools.getDebugContextManager().getContextService(fView.getViewSite().getWorkbenchWindow()).removeDebugContextListener(fDebugContextListener);
-
- if (fMenuCreator != null)
+ if (fMenuCreator != null) {
fMenuCreator.dispose();
+ }
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
+ */
public void runWithEvent(IAction action, Event event) {
switchToNext();
}
+ /**
+ * Returns the current memory block
+ * @return the current memory block or <code>null</code>
+ */
private IMemoryBlock getCurrentMemoryBlock() {
- if (fView == null)
+ if (fView == null) {
return null;
-
+ }
ISelection memBlkSelection = fView.getSite().getSelectionProvider().getSelection();
IMemoryBlock memoryBlock = null;
- if (memBlkSelection != null)
- {
- if (!memBlkSelection.isEmpty() && memBlkSelection instanceof IStructuredSelection)
- {
+ if (memBlkSelection != null) {
+ if (!memBlkSelection.isEmpty() && memBlkSelection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection)memBlkSelection).getFirstElement();
-
- if (obj instanceof IMemoryBlock)
- {
+ if (obj instanceof IMemoryBlock) {
memoryBlock = (IMemoryBlock)obj;
}
- else if (obj instanceof IMemoryRendering){
+ else if (obj instanceof IMemoryRendering) {
memoryBlock = ((IMemoryRendering)obj).getMemoryBlock();
}
}
@@ -380,13 +403,16 @@ public class SwitchMemoryBlockAction extends Action implements IViewActionDelega
}
/**
+ * Decorate the label for the specified <code>IMemoryBlock</code>
* @param memBlk
* @param label
+ * @return the decorated label for the specified <code>IMemoryBlock</code>
*/
private String decorateLabel(final IMemoryBlock memBlk, String label) {
ILabelDecorator decorator = (ILabelDecorator)memBlk.getAdapter(ILabelDecorator.class);
- if (decorator != null)
+ if (decorator != null) {
label = decorator.decorateText(label, memBlk);
+ }
return label;
}

Back to the top