diff --git a/plugins/org.eclipse.dd.debug.ui.memory.transport/plugin.xml b/plugins/org.eclipse.dd.debug.ui.memory.transport/plugin.xml index 27317e78ac8..57dd55080dc 100644 --- a/plugins/org.eclipse.dd.debug.ui.memory.transport/plugin.xml +++ b/plugins/org.eclipse.dd.debug.ui.memory.transport/plugin.xml @@ -41,7 +41,6 @@ icon="icons/export.png" id="org.eclipse.dd.debug.ui.memory.transport.actions.ExportMemoryAction" label="%ExportMemoryAction.label" - state="false" style="push" toolbarPath="additions" tooltip="%ExportMemoryAction.label"/> @@ -51,7 +50,6 @@ icon="icons/import.png" id="org.eclipse.dd.debug.ui.memory.transport.actions.ImportMemoryAction" label="%ImportMemoryAction.label" - state="false" style="push" toolbarPath="additions" tooltip="%ImportMemoryAction.label"/> diff --git a/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ExportMemoryAction.java b/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ExportMemoryAction.java index 3ad72347562..fdfb490745e 100644 --- a/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ExportMemoryAction.java +++ b/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ExportMemoryAction.java @@ -37,42 +37,46 @@ public class ExportMemoryAction implements IViewActionDelegate { fView = (MemoryView) view; } - public void run(IAction action) { - - ISelection selection = fView.getSite().getSelectionProvider() - .getSelection(); + private IMemoryBlock getMemoryBlock(ISelection selection) + { + IMemoryBlock memBlock = null; + if (selection instanceof IStructuredSelection) { IStructuredSelection strucSel = (IStructuredSelection) selection; // return if current selection is empty if (strucSel.isEmpty()) - return; + return null; Object obj = strucSel.getFirstElement(); if (obj == null) - return; - - IMemoryBlock memBlock = null; + return null; if (obj instanceof IMemoryRendering) { memBlock = ((IMemoryRendering) obj).getMemoryBlock(); } else if (obj instanceof IMemoryBlock) { memBlock = (IMemoryBlock) obj; } - if(memBlock == null) - return; - - ExportMemoryDialog dialog = new ExportMemoryDialog(DebugUIPlugin.getShell(), memBlock); - dialog.open(); - - dialog.getResult(); } + return memBlock; + } + + public void run(IAction action) { + ISelection selection = fView.getSite().getSelectionProvider() + .getSelection(); + IMemoryBlock memBlock = getMemoryBlock(selection); + if(memBlock == null) + return; + ExportMemoryDialog dialog = new ExportMemoryDialog(DebugUIPlugin.getShell(), memBlock); + dialog.open(); + + dialog.getResult(); } public void selectionChanged(IAction action, ISelection selection) { - + action.setEnabled(getMemoryBlock(selection) != null); } } diff --git a/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ImportMemoryAction.java b/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ImportMemoryAction.java index 4c87cd3bf4e..cc3bc9cd4a1 100644 --- a/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ImportMemoryAction.java +++ b/plugins/org.eclipse.dd.debug.ui.memory.transport/src/org/eclipse/dd/debug/ui/memory/transport/actions/ImportMemoryAction.java @@ -37,43 +37,48 @@ public class ImportMemoryAction implements IViewActionDelegate { if (view instanceof MemoryView) fView = (MemoryView) view; } - - public void run(IAction action) { - - ISelection selection = fView.getSite().getSelectionProvider() - .getSelection(); + + private IMemoryBlock getMemoryBlock(ISelection selection) + { + IMemoryBlock memBlock = null; + if (selection instanceof IStructuredSelection) { IStructuredSelection strucSel = (IStructuredSelection) selection; // return if current selection is empty if (strucSel.isEmpty()) - return; + return null; Object obj = strucSel.getFirstElement(); if (obj == null) - return; - - IMemoryBlock memBlock = null; + return null; if (obj instanceof IMemoryRendering) { memBlock = ((IMemoryRendering) obj).getMemoryBlock(); } else if (obj instanceof IMemoryBlock) { memBlock = (IMemoryBlock) obj; } - if(memBlock == null) - return; - - ImportMemoryDialog dialog = new ImportMemoryDialog(DebugUIPlugin.getShell(), memBlock); - dialog.open(); - - dialog.getResult(); } + return memBlock; + } + public void run(IAction action) { + + ISelection selection = fView.getSite().getSelectionProvider() + .getSelection(); + IMemoryBlock memBlock = getMemoryBlock(selection); + if(memBlock == null) + return; + + ImportMemoryDialog dialog = new ImportMemoryDialog(DebugUIPlugin.getShell(), memBlock); + dialog.open(); + + dialog.getResult(); } public void selectionChanged(IAction action, ISelection selection) { - + action.setEnabled(getMemoryBlock(selection) != null); } }