diff options
author | Pawel Piech | 2008-10-24 05:11:57 +0000 |
---|---|---|
committer | Pawel Piech | 2008-10-24 05:11:57 +0000 |
commit | 11d9ef10d10b0d6723d6f42db5c656f30e529fa8 (patch) | |
tree | 73ed308dee49923e0f0ff4cb2484cc2597ff0a9c /org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda | |
parent | ca2de530aea0f7ddda0b312ec46958e600da7a96 (diff) | |
download | eclipse.platform.debug-11d9ef10d10b0d6723d6f42db5c656f30e529fa8.tar.gz eclipse.platform.debug-11d9ef10d10b0d6723d6f42db5c656f30e529fa8.tar.xz eclipse.platform.debug-11d9ef10d10b0d6723d6f42db5c656f30e529fa8.zip |
Bug 229219 - Track "debugContext" with the window evaluation context.
Diffstat (limited to 'org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda')
7 files changed, 201 insertions, 170 deletions
diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java new file mode 100644 index 000000000..2fd5ec826 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/AbstractDataStackViewHandler.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.examples.core.pda.model.PDADebugElement; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Base class for command handlers for data stack view. + */ +abstract public class AbstractDataStackViewHandler extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); + if (part instanceof DataStackView) { + DataStackView view = (DataStackView)part; + + ISelection selection = DebugUITools.getDebugContextForEventChecked(event); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection)selection; + if (ss.getFirstElement() instanceof IAdaptable) { + PDADebugElement element = (PDADebugElement) + ((IAdaptable)ss.getFirstElement()).getAdapter(PDADebugElement.class); + if (element != null) { + doExecute( + view, + (PDADebugTarget)element.getDebugTarget(), + HandlerUtil.getCurrentSelectionChecked(event)); + } + } + } + } else { + throw new ExecutionException("Handler must be with DataStackView only"); + } + return null; + } + + /** + * Performs the actual handler operation. + * + * @param view The view that the handler was invoked in. + * @param target The current active debug target. + * @param selection The current selection in view. + */ + abstract protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException; +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java new file mode 100644 index 000000000..9be29dceb --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/CanPushTester.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.debug.examples.core.pda.model.PDADebugElement; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; + +/** + * Property tester for use with standard expressions to determine whether + * the given debug target can perform a push operation. + */ +public class CanPushTester extends PropertyTester { + + private static final String CAN_PUSH_PROPERTY = "canPush"; + + public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { + if (CAN_PUSH_PROPERTY.equals(property)) { + if (receiver instanceof IAdaptable) { + PDADebugElement element = (PDADebugElement) + ((IAdaptable)receiver).getAdapter(PDADebugElement.class); + if (element != null) { + PDADebugTarget target = (PDADebugTarget)element.getDebugTarget(); + return target.canPush(); + } + } + } + return false; + } +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java index 234fe30ec..5eeaa37a6 100644 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/DataStackView.java @@ -8,7 +8,8 @@ * Contributors: * IBM Corporation - initial API and implementation * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ + * Wind River - Pawel Piech - replaced actions with handlers (bug 229219) +******************************************************************************/ package org.eclipse.debug.examples.ui.pda.views; import org.eclipse.core.runtime.IAdaptable; @@ -39,8 +40,6 @@ import org.eclipse.ui.IWorkbenchPart; public class DataStackView extends AbstractDebugView implements ISelectionListener { private PDADebugTarget fTarget; - private PopAction fPopAction; - private PushAction fPushAction; class StackViewContentProvider implements ITreeContentProvider { @@ -114,8 +113,6 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen * @see org.eclipse.debug.ui.AbstractDebugView#createActions() */ protected void createActions() { - fPopAction = new PopAction(this); - fPushAction = new PushAction(this); } /* (non-Javadoc) * @see org.eclipse.debug.ui.AbstractDebugView#getHelpContextId() @@ -128,15 +125,11 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen */ protected void fillContextMenu(IMenuManager menu) { menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - menu.add(fPopAction); - menu.add(fPushAction); } /* (non-Javadoc) * @see org.eclipse.debug.ui.AbstractDebugView#configureToolBar(org.eclipse.jface.action.IToolBarManager) */ protected void configureToolBar(IToolBarManager tbm) { - tbm.add(fPopAction); - tbm.add(fPushAction); } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchPart#dispose() @@ -171,7 +164,6 @@ public class DataStackView extends AbstractDebugView implements ISelectionListen input = fTarget; } getViewer().setInput(input); - fPushAction.setDebugTarget(fTarget); getViewer().refresh(); } } diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java deleted file mode 100644 index af21fbcc6..000000000 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopAction.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ -package org.eclipse.debug.examples.ui.pda.views; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.model.IValue; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; -import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TreeViewer; - - -/** - * Pops a selected value off the data stack. The selection does <b>not</b> have to be - * the top element on the stack. - */ -public class PopAction extends Action implements ISelectionChangedListener { - - private DataStackView fView; - - /** - * Constructs an action to pop values off the stack - */ - protected PopAction(DataStackView view) { - super("Pop"); - ImageRegistry imageRegistry = DebugUIPlugin.getDefault().getImageRegistry(); - setImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_ELCL_POP)); - setDisabledImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_DLCL_POP)); - setToolTipText("Pop"); - setEnabled(false); - view.getSite().getSelectionProvider().addSelectionChangedListener(this); - fView = view; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) - */ - public void selectionChanged(SelectionChangedEvent event) { - if (event.getSelection().isEmpty()) { - setEnabled(false); - } else { - setEnabled(getDebugTarget().canPop()); - } - } - - public void run() { - TreeViewer viewer = (TreeViewer)fView.getViewer(); - IStructuredSelection selection = (IStructuredSelection)viewer.getSelection(); - Object popee = selection.getFirstElement(); - try { - PDADebugTarget target = getDebugTarget(); - IValue[] stack = target.getDataStack(); - List restore = new ArrayList(); - for (int i = 0; i < stack.length; i++) { - Object value = stack[i]; - if (popee.equals(value)) { - // pop & stop - target.pop(); - break; - } else { - // remember value to push back on - restore.add(target.pop()); - } - } - while (!restore.isEmpty()) { - IValue value = (IValue) restore.remove(restore.size() - 1); - target.push(value.getValueString()); - } - } catch (DebugException e) { - } - viewer.refresh(); - } - - /** - * Returns the debug target assocaited with the data view. - * - * @return the debug target assocaited with the data view - */ - protected PDADebugTarget getDebugTarget() { - TreeViewer viewer = (TreeViewer)fView.getViewer(); - return (PDADebugTarget) viewer.getInput(); - } -} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java new file mode 100644 index 000000000..59f00c857 --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PopHandler.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.model.IValue; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; + +/** + * Pops a selected value off the data stack. The selection does <b>not</b> have to be + * the top element on the stack. + */ +public class PopHandler extends AbstractDataStackViewHandler { + + protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException { + TreeViewer viewer = (TreeViewer)view.getViewer(); + Object popee = selection instanceof IStructuredSelection + ? ((IStructuredSelection)selection).getFirstElement() : null; + if (popee != null) { + try { + IValue[] stack = target.getDataStack(); + List restore = new ArrayList(); + for (int i = 0; i < stack.length; i++) { + Object value = stack[i]; + if (popee.equals(value)) { + // pop & stop + target.pop(); + break; + } else { + // remember value to push back on + restore.add(target.pop()); + } + } + while (!restore.isEmpty()) { + IValue value = (IValue) restore.remove(restore.size() - 1); + target.push(value.getValueString()); + } + } catch (DebugException e) { + throw new ExecutionException("Failed to execute push command", e); + } + viewer.refresh(); + } + } + +} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java deleted file mode 100644 index 8764cf3bc..000000000 --- a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushAction.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Bjorn Freeman-Benson - initial API and implementation - *******************************************************************************/ -package org.eclipse.debug.examples.ui.pda.views; - -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; -import org.eclipse.debug.examples.ui.pda.DebugUIPlugin; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.InputDialog; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.window.Window; - - -/** - * Pushes a value onto the data stack. - */ -public class PushAction extends Action { - - private PDADebugTarget fTarget; - private DataStackView fView; - - /** - * Constructs an action to pop values off the stack - */ - protected PushAction(DataStackView view) { - super("Push"); - ImageRegistry imageRegistry = DebugUIPlugin.getDefault().getImageRegistry(); - setImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_ELCL_PUSH)); - setDisabledImageDescriptor(imageRegistry.getDescriptor(DebugUIPlugin.IMG_DLCL_PUSH)); - setToolTipText("Push"); - setEnabled(false); - fView = view; - } - - public void run() { - InputDialog dialog = new InputDialog(fView.getSite().getShell(), "Specify Value", "Enter value to push", null, null); - if (dialog.open() == Window.OK) { - try { - fTarget.push(dialog.getValue()); - } catch (DebugException e) { - } - } - fView.getViewer().refresh(); - } - - protected void setDebugTarget(PDADebugTarget target) { - fTarget = target; - setEnabled(fTarget != null && fTarget.canPush()); - } - - -} diff --git a/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java new file mode 100644 index 000000000..306508f5a --- /dev/null +++ b/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/views/PushHandler.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2008 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wind River Systems - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.examples.ui.pda.views; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.examples.core.pda.model.PDADebugTarget; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.window.Window; + +/** + * Pushes a value onto the data stack. + */ +public class PushHandler extends AbstractDataStackViewHandler { + + protected void doExecute(DataStackView view, PDADebugTarget target, ISelection selection) throws ExecutionException { + InputDialog dialog = new InputDialog(view.getSite().getShell(), "Specify Value", "Enter value to push", null, null); + if (dialog.open() == Window.OK) { + try { + target.push(dialog.getValue()); + } catch (DebugException e) { + throw new ExecutionException("Failed to execute push command", e); + } + } + view.getViewer().refresh(); + } + +} |