diff options
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions')
6 files changed, 299 insertions, 288 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java index b3b82d712..ae21582b3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java @@ -158,6 +158,7 @@ public abstract class AbstractLaunchHistoryAction implements IActionDelegate2, I * Initialize this action so that it can dynamically set its tool-tip. Also set the enabled state * of the underlying action based on whether there are any registered launch configuration types that * understand how to launch in the mode of this action. + * @param action the {@link IAction} to initialize */ private void initialize(IAction action) { getLaunchConfigurationManager().addLaunchHistoryListener(this); @@ -283,8 +284,8 @@ public abstract class AbstractLaunchHistoryAction implements IActionDelegate2, I return fMenu; } - /** - * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu) + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate2#getMenu(org.eclipse.swt.widgets.Menu) */ public Menu getMenu(Menu parent) { setMenu(new Menu(parent)); @@ -368,7 +369,7 @@ public abstract class AbstractLaunchHistoryAction implements IActionDelegate2, I /** * Adds a separator to the given menu * - * @param menu + * @param menu the menu to add the separator to */ protected void addSeparator(Menu menu) { new MenuItem(menu, SWT.SEPARATOR); @@ -462,7 +463,7 @@ public abstract class AbstractLaunchHistoryAction implements IActionDelegate2, I /** * Creates an {@link ILaunchConfiguration} from the given set of {@link ILaunchConfigurationType}s - * @param types + * @param types the set of {@link String} {@link ILaunchConfigurationType} identifiers * @return a new {@link ILaunchConfiguration} * @since 3.6 */ diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java index 574c6644a..78a5a0508 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -62,6 +62,7 @@ public class AbstractLaunchToolbarAction extends AbstractLaunchHistoryAction { /** * Returns an action to open the launch dialog + * @return the new {@link OpenLaunchDialogAction} * @since 3.1 */ protected IAction getOpenDialogAction() { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AddMemoryRenderingActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AddMemoryRenderingActionDelegate.java index 8cf24758d..dc09c3ec7 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AddMemoryRenderingActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AddMemoryRenderingActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -226,6 +226,7 @@ public class AddMemoryRenderingActionDelegate extends Action implements IViewAct /** * @param action - the action to bind with the menu and to update enablement, must not be null + * @param selection the current selection */ private void updateAction(IAction action, ISelection selection) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java index 3a412cdc6..6c43e42fc 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ContextualLaunchAction.java @@ -279,7 +279,10 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I * Evaluate the enablement logic in the contextualLaunch * element description. A true result means that we should * include this shortcut in the context menu. + * @param ext the shortcut extension to get the enablement expression from + * @param context the evaluation context to use * @return true iff shortcut should appear in context menu + * @throws CoreException if an exception occurs */ private boolean isApplicable(LaunchShortcutExtension ext, IEvaluationContext context) throws CoreException { Expression expr = ext.getContextualLaunchEnablementExpression(); @@ -288,6 +291,10 @@ public abstract class ContextualLaunchAction implements IObjectActionDelegate, I /** * Add the shortcut to the context menu's launch sub-menu. + * @param mode the id of the mode + * @param ext the extension to get label and help info from + * @param menu the menu to add to + * @param accelerator the accelerator to use with the new menu item */ private void populateMenuItem(String mode, LaunchShortcutExtension ext, Menu menu, int accelerator) { LaunchShortcutAction action = new LaunchShortcutAction(mode, ext); diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java index 8ffe1c3fe..e69e1829d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation and others. + * Copyright (c) 2006, 2011 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 @@ -111,8 +111,8 @@ public abstract class DebugCommandAction extends Action implements IDebugContext /** * Executes this action on the given target object - * - * @param target the target to perform the action on + * @param targets the targets to perform the action on + * @return if the command stays enabled while the command executes */ private boolean execute(final Object[] targets) { return fUpdateService.executeCommand( diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java index 5ec94d494..c209730f9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java @@ -1,279 +1,280 @@ -/*******************************************************************************
- * Copyright (c) 2006, 2009 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.debug.ui.actions;
-
-import java.util.Iterator;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.HandlerEvent;
-import org.eclipse.core.expressions.IEvaluationContext;
-import org.eclipse.debug.core.IRequest;
-import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService;
-import org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant;
-import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget;
-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.contexts.IDebugContextService;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.ISources;
-import org.eclipse.ui.IWindowListener;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/**
- * Abstract base class for re-targeting command framework handlers, which
- * delegate execution to {@link org.eclipse.debug.core.commands.IDebugCommandHandler}
- * handlers. The specific type of <code>IDebugCommandHandler</code> is
- * determined by the abstract {@link #getCommandType()} method.
- *
- * <p> Note: This class is not an implementation of the <code>IDebugCommandHandler</code>
- * interface, which was somewhat unfortunately named. <code>IDebugCommandHandler</code>
- * is an interface that used only by the debugger plug-ins. This class implements
- * {@link org.eclipse.core.commands.IHandler} interface and is to be used with the
- * platform commands framework. </p>
- *
- * <p>
- * Clients may subclass this class.
- * </p>
- * @see org.eclipse.debug.core.commands.IDebugCommandHandler
- * @see org.eclipse.core.commands.IHandler
- *
- * @since 3.6
- */
-public abstract class DebugCommandHandler extends AbstractHandler {
-
- /**
- * The DebugCommandService is able to evaluate the command handler
- * enablement in each workbench window separately, however the workbench
- * command framework uses only a single handler instance for all windows.
- * This IEnabledTarget implementation tracks enablement of the command
- * for a given window. When the handler enablement is tested, the
- * currently active window is used to determine which enabled target
- * to use.
- */
- private class EnabledTarget implements IEnabledTarget, IDebugContextListener {
- boolean fEnabled = getInitialEnablement();
- IWorkbenchWindow fWindow;
-
- EnabledTarget(IWorkbenchWindow window) {
- fWindow = window;
- DebugCommandService.getService(fWindow).updateCommand(getCommandType(), this);
- getContextService(fWindow).addDebugContextListener(this);
- }
-
- public void setEnabled(boolean enabled) {
- boolean oldEnabled = fEnabled;
- fEnabled = enabled;
- if (fEnabled != oldEnabled && fCurrentEnabledTarget == this) {
- fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false));
- }
- }
-
- public void debugContextChanged(DebugContextEvent event) {
- DebugCommandService.getService(fWindow).postUpdateCommand(getCommandType(), this);
- }
-
- void dispose() {
- if (isDisposed()) {
- return;
- }
- getContextService(fWindow).removeDebugContextListener(this);
- fWindow = null;
- }
-
- boolean isDisposed() {
- return fWindow == null;
- }
- }
-
- /**
- * Window listener is used to make sure that the handler enablement
- * is updated when the active workbench window is changed.
- */
- private IWindowListener fWindowListener = new IWindowListener() {
-
- public void windowOpened(IWorkbenchWindow w) {
- }
-
- public void windowDeactivated(IWorkbenchWindow w) {
- }
-
- public void windowClosed(IWorkbenchWindow w) {
- EnabledTarget enabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w);
- if (enabledTarget != null) {
- enabledTarget.dispose();
- }
- }
-
- public void windowActivated(IWorkbenchWindow w) {
- fCurrentEnabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w);
- fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false));
- }
- };
-
- /**
- * Map of enabled targets keyed by workbench window.
- */
- private Map fEnabledTargetsMap = new WeakHashMap();
-
- /**
- * The current enabled target, based on the active
- * workbench window.
- */
- private EnabledTarget fCurrentEnabledTarget = null;
-
- /**
- * The constructor adds the handler as the
- */
- public DebugCommandHandler() {
- super();
- PlatformUI.getWorkbench().addWindowListener(fWindowListener);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
- */
- public void setEnabled(Object evaluationContext) {
- // This method is called with the current evaluation context
- // just prior to the isEnabled() being called. Check the active
- // window and update the current enabled target based on it
- fCurrentEnabledTarget = null;
-
- if (!(evaluationContext instanceof IEvaluationContext)) {
- return;
- }
- IEvaluationContext context = (IEvaluationContext) evaluationContext;
- Object _window = context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);
- if (_window instanceof IWorkbenchWindow) {
- IWorkbenchWindow window = (IWorkbenchWindow)_window;
- fCurrentEnabledTarget = getEnabledTarget(window);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
- */
- public boolean isEnabled() {
- if (fCurrentEnabledTarget == null) {
- return false;
- }
- return fCurrentEnabledTarget.fEnabled;
- }
-
- private EnabledTarget getEnabledTarget(IWorkbenchWindow window) {
- EnabledTarget target = (EnabledTarget)fEnabledTargetsMap.get(window);
- if (target == null) {
- target = new EnabledTarget(window);
- fEnabledTargetsMap.put(window, target);
- }
- return target;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
- */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
- if (window == null) {
- throw new ExecutionException("No active workbench window."); //$NON-NLS-1$
- }
- fCurrentEnabledTarget = getEnabledTarget(window);
-
- ISelection selection = getContextService(window).getActiveContext();
- if (selection instanceof IStructuredSelection && isEnabled()) {
- IStructuredSelection ss = (IStructuredSelection) selection;
- boolean enabledAfterExecute = execute(window, ss.toArray());
-
- // enable/disable the action according to the command
- fCurrentEnabledTarget.setEnabled(enabledAfterExecute);
- }
-
- return null;
- }
-
- private IDebugContextService getContextService(IWorkbenchWindow window) {
- return DebugUITools.getDebugContextManager().getContextService(window);
- }
-
- /**
- * Executes this action on the given target object
- *
- * @param target the target to perform the action on
- */
- private boolean execute(IWorkbenchWindow window, final Object[] targets) {
- DebugCommandService service = DebugCommandService.getService(window);
- return service.executeCommand(
- getCommandType(), targets,
- new ICommandParticipant() {
- public void requestDone(org.eclipse.debug.core.IRequest request) {
- DebugCommandHandler.this.postExecute(request, targets);
- }
- });
- }
-
- /**
- * This method is called after the completion of the execution of this
- * command. Extending classes may override this method to perform additional
- * operation after command execution.
- *
- * @param request The completed request object which was given the the
- * debug command handler.
- * @param targets Objects which were the targets of this action
- */
- protected void postExecute(IRequest request, Object[] targets) {
- // do nothing by default
- }
-
- /**
- * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler}
- * command handler that type this action executes.
- *
- * @return command class.
- *
- * @see org.eclipse.debug.core.commands.IDebugCommandHandler
- */
- abstract protected Class getCommandType();
-
-
- /**
- * Returns whether this action should be enabled when initialized
- * and there is no active debug context.
- *
- * @return false, by default
- */
- protected boolean getInitialEnablement() {
- return false;
- }
-
-
- /**
- * Clean up when removing
- */
- public void dispose() {
- PlatformUI.getWorkbench().removeWindowListener(fWindowListener);
- for (Iterator itr = fEnabledTargetsMap.values().iterator(); itr.hasNext();) {
- EnabledTarget target = (EnabledTarget)itr.next();
- if (!target.isDisposed()) {
- target.dispose();
- }
- }
- fEnabledTargetsMap.clear();
- fCurrentEnabledTarget = null;
- }
-}
+/******************************************************************************* + * Copyright (c) 2006, 2011 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: + * Wind River Systems - initial API and implementation + *******************************************************************************/ + +package org.eclipse.debug.ui.actions; + +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.commands.HandlerEvent; +import org.eclipse.core.expressions.IEvaluationContext; +import org.eclipse.debug.core.IRequest; +import org.eclipse.debug.internal.ui.commands.actions.DebugCommandService; +import org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant; +import org.eclipse.debug.internal.ui.commands.actions.IEnabledTarget; +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.contexts.IDebugContextService; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISources; +import org.eclipse.ui.IWindowListener; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Abstract base class for re-targeting command framework handlers, which + * delegate execution to {@link org.eclipse.debug.core.commands.IDebugCommandHandler} + * handlers. The specific type of <code>IDebugCommandHandler</code> is + * determined by the abstract {@link #getCommandType()} method. + * + * <p> Note: This class is not an implementation of the <code>IDebugCommandHandler</code> + * interface, which was somewhat unfortunately named. <code>IDebugCommandHandler</code> + * is an interface that used only by the debugger plug-ins. This class implements + * {@link org.eclipse.core.commands.IHandler} interface and is to be used with the + * platform commands framework. </p> + * + * <p> + * Clients may subclass this class. + * </p> + * @see org.eclipse.debug.core.commands.IDebugCommandHandler + * @see org.eclipse.core.commands.IHandler + * + * @since 3.6 + */ +public abstract class DebugCommandHandler extends AbstractHandler { + + /** + * The DebugCommandService is able to evaluate the command handler + * enablement in each workbench window separately, however the workbench + * command framework uses only a single handler instance for all windows. + * This IEnabledTarget implementation tracks enablement of the command + * for a given window. When the handler enablement is tested, the + * currently active window is used to determine which enabled target + * to use. + */ + private class EnabledTarget implements IEnabledTarget, IDebugContextListener { + boolean fEnabled = getInitialEnablement(); + IWorkbenchWindow fWindow; + + EnabledTarget(IWorkbenchWindow window) { + fWindow = window; + DebugCommandService.getService(fWindow).updateCommand(getCommandType(), this); + getContextService(fWindow).addDebugContextListener(this); + } + + public void setEnabled(boolean enabled) { + boolean oldEnabled = fEnabled; + fEnabled = enabled; + if (fEnabled != oldEnabled && fCurrentEnabledTarget == this) { + fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false)); + } + } + + public void debugContextChanged(DebugContextEvent event) { + DebugCommandService.getService(fWindow).postUpdateCommand(getCommandType(), this); + } + + void dispose() { + if (isDisposed()) { + return; + } + getContextService(fWindow).removeDebugContextListener(this); + fWindow = null; + } + + boolean isDisposed() { + return fWindow == null; + } + } + + /** + * Window listener is used to make sure that the handler enablement + * is updated when the active workbench window is changed. + */ + private IWindowListener fWindowListener = new IWindowListener() { + + public void windowOpened(IWorkbenchWindow w) { + } + + public void windowDeactivated(IWorkbenchWindow w) { + } + + public void windowClosed(IWorkbenchWindow w) { + EnabledTarget enabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w); + if (enabledTarget != null) { + enabledTarget.dispose(); + } + } + + public void windowActivated(IWorkbenchWindow w) { + fCurrentEnabledTarget = (EnabledTarget)fEnabledTargetsMap.get(w); + fireHandlerChanged(new HandlerEvent(DebugCommandHandler.this, true, false)); + } + }; + + /** + * Map of enabled targets keyed by workbench window. + */ + private Map fEnabledTargetsMap = new WeakHashMap(); + + /** + * The current enabled target, based on the active + * workbench window. + */ + private EnabledTarget fCurrentEnabledTarget = null; + + /** + * The constructor adds the handler as the + */ + public DebugCommandHandler() { + super(); + PlatformUI.getWorkbench().addWindowListener(fWindowListener); + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object) + */ + public void setEnabled(Object evaluationContext) { + // This method is called with the current evaluation context + // just prior to the isEnabled() being called. Check the active + // window and update the current enabled target based on it + fCurrentEnabledTarget = null; + + if (!(evaluationContext instanceof IEvaluationContext)) { + return; + } + IEvaluationContext context = (IEvaluationContext) evaluationContext; + Object _window = context.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME); + if (_window instanceof IWorkbenchWindow) { + IWorkbenchWindow window = (IWorkbenchWindow)_window; + fCurrentEnabledTarget = getEnabledTarget(window); + } + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#isEnabled() + */ + public boolean isEnabled() { + if (fCurrentEnabledTarget == null) { + return false; + } + return fCurrentEnabledTarget.fEnabled; + } + + private EnabledTarget getEnabledTarget(IWorkbenchWindow window) { + EnabledTarget target = (EnabledTarget)fEnabledTargetsMap.get(window); + if (target == null) { + target = new EnabledTarget(window); + fEnabledTargetsMap.put(window, target); + } + return target; + } + + /* (non-Javadoc) + * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); + if (window == null) { + throw new ExecutionException("No active workbench window."); //$NON-NLS-1$ + } + fCurrentEnabledTarget = getEnabledTarget(window); + + ISelection selection = getContextService(window).getActiveContext(); + if (selection instanceof IStructuredSelection && isEnabled()) { + IStructuredSelection ss = (IStructuredSelection) selection; + boolean enabledAfterExecute = execute(window, ss.toArray()); + + // enable/disable the action according to the command + fCurrentEnabledTarget.setEnabled(enabledAfterExecute); + } + + return null; + } + + private IDebugContextService getContextService(IWorkbenchWindow window) { + return DebugUITools.getDebugContextManager().getContextService(window); + } + + /** + * Executes this action on the given target objects + * @param window the window + * @param targets the targets to execute this action on + * @return if the command stays enabled while the command executes + */ + private boolean execute(IWorkbenchWindow window, final Object[] targets) { + DebugCommandService service = DebugCommandService.getService(window); + return service.executeCommand( + getCommandType(), targets, + new ICommandParticipant() { + public void requestDone(org.eclipse.debug.core.IRequest request) { + DebugCommandHandler.this.postExecute(request, targets); + } + }); + } + + /** + * This method is called after the completion of the execution of this + * command. Extending classes may override this method to perform additional + * operation after command execution. + * + * @param request The completed request object which was given the the + * debug command handler. + * @param targets Objects which were the targets of this action + */ + protected void postExecute(IRequest request, Object[] targets) { + // do nothing by default + } + + /** + * Returns the {@link org.eclipse.debug.core.commands.IDebugCommandHandler} + * command handler that type this action executes. + * + * @return command class. + * + * @see org.eclipse.debug.core.commands.IDebugCommandHandler + */ + abstract protected Class getCommandType(); + + + /** + * Returns whether this action should be enabled when initialized + * and there is no active debug context. + * + * @return false, by default + */ + protected boolean getInitialEnablement() { + return false; + } + + + /** + * Clean up when removing + */ + public void dispose() { + PlatformUI.getWorkbench().removeWindowListener(fWindowListener); + for (Iterator itr = fEnabledTargetsMap.values().iterator(); itr.hasNext();) { + EnabledTarget target = (EnabledTarget)itr.next(); + if (!target.isDisposed()) { + target.dispose(); + } + } + fEnabledTargetsMap.clear(); + fCurrentEnabledTarget = null; + } +} |