diff options
author | Pawel Piech | 2009-09-10 04:29:55 +0000 |
---|---|---|
committer | Pawel Piech | 2009-09-10 04:29:55 +0000 |
commit | de6dcdfb63ae6c3000fc3c70a260f8ff22011165 (patch) | |
tree | 50fe923ac60fff9053564563a73fe9f71308865d /org.eclipse.debug.ui/ui | |
parent | 2dc724990d055465d78c3b4f773ac0d1c5f6f6b2 (diff) | |
download | eclipse.platform.debug-de6dcdfb63ae6c3000fc3c70a260f8ff22011165.tar.gz eclipse.platform.debug-de6dcdfb63ae6c3000fc3c70a260f8ff22011165.tar.xz eclipse.platform.debug-de6dcdfb63ae6c3000fc3c70a260f8ff22011165.zip |
Bug 284363 - Move DebugCommandAction to an API package
Diffstat (limited to 'org.eclipse.debug.ui/ui')
23 files changed, 759 insertions, 430 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ActionsUpdater.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ActionsUpdater.java index 0867805c8..fae69e01e 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ActionsUpdater.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ActionsUpdater.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.debug.internal.ui.commands.actions; -import org.eclipse.jface.action.IAction; /** * Collects votes from handler update requests. @@ -20,13 +19,13 @@ import org.eclipse.jface.action.IAction; */ public class ActionsUpdater { - private IAction[] fActions; + private IEnabledTarget[] fActions; private int fNumVoters; private int fNumOfVotes = 0; private boolean fDone = false; private boolean fEnabled = true; - public ActionsUpdater(IAction[] actions, int numVoters) { + public ActionsUpdater(IEnabledTarget[] actions, int numVoters) { fActions = actions; fNumVoters = numVoters; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java index 0d83a7936..ce50c1338 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -11,6 +11,7 @@ package org.eclipse.debug.internal.ui.commands.actions; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Event; @@ -21,7 +22,7 @@ import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * Abstract base class for debug action delegates performing debug commands. * - * @since 3.3 + * @since 3.3. */ public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 { @@ -30,27 +31,16 @@ public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActi */ private DebugCommandAction fDebugAction; - /** - * The underlying action for this delegate - */ - private IAction fWindowAction; - - /** - * Whether this action has been initialized before it has been run - * (ensures enablement state is up to date when lazily instantiated) - */ - private boolean fInitialized = false; - - public DebugCommandActionDelegate() { + protected void setAction(DebugCommandAction action) { + fDebugAction = action; } - + /* * (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose() { fDebugAction.dispose(); - } /* @@ -58,7 +48,7 @@ public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActi * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) */ public void init(IAction action) { - fWindowAction = action; + fDebugAction.setActionProxy(action); } /* @@ -74,14 +64,6 @@ public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActi * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { - synchronized (this) { - if (!fInitialized) { - try { - wait(); - } catch (InterruptedException e) { - } - } - } fDebugAction.run(); } @@ -105,30 +87,4 @@ public abstract class DebugCommandActionDelegate implements IWorkbenchWindowActi protected DebugCommandAction getAction() { return fDebugAction; } - - protected void setAction(DebugCommandAction action) { - fDebugAction = action; - action.setDelegate(this); - } - - public void setEnabled(boolean enabled) { - synchronized (this) { - if (!fInitialized) { - fInitialized = true; - notifyAll(); - } - } - fWindowAction.setEnabled(enabled); - } - - public void setChecked(boolean checked) { - fWindowAction.setChecked(checked); - } - - protected IAction getWindowAction() - { - return fWindowAction; - } - - } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java index b119670c9..7ce2d3562 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandService.java @@ -24,7 +24,6 @@ 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.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; @@ -111,7 +110,7 @@ public class DebugCommandService implements IDebugContextListener { * @param commandType * @param monitor */ - public void postUpdateCommand(Class commandType, Action action) { + public void postUpdateCommand(Class commandType, IEnabledTarget action) { synchronized (fCommandUpdates) { Job.getJobManager().cancel(commandType); List actions = (List) fCommandUpdates.get(commandType); @@ -129,11 +128,11 @@ public class DebugCommandService implements IDebugContextListener { * @param commandType * @param requestMonitor */ - public void updateCommand(Class commandType, IAction action) { + public void updateCommand(Class commandType, IEnabledTarget action) { ISelection context = fContextService.getActiveContext(); if (context instanceof IStructuredSelection && !context.isEmpty()) { Object[] elements = ((IStructuredSelection)context).toArray(); - updateCommand(commandType, elements, new IAction[]{action}); + updateCommand(commandType, elements, new IEnabledTarget[]{action}); } else { action.setEnabled(false); } @@ -152,7 +151,7 @@ public class DebugCommandService implements IDebugContextListener { Entry entry = (Entry) iterator.next(); Class commandType = (Class)entry.getKey(); List actions = (List) entry.getValue(); - updateCommand(commandType, elements, (IAction[]) actions.toArray(new IAction[actions.size()])); + updateCommand(commandType, elements, (IEnabledTarget[]) actions.toArray(new IEnabledTarget[actions.size()])); } } else { Iterator iterator = commands.values().iterator(); @@ -174,7 +173,7 @@ public class DebugCommandService implements IDebugContextListener { * @param elements elements to update for * @param monitor status monitor */ - private void updateCommand(Class handlerType, Object[] elements, IAction[] actions) { + private void updateCommand(Class handlerType, Object[] elements, IEnabledTarget[] actions) { if (elements.length == 1) { // usual case - one element Object element = elements[0]; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DisconnectCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DisconnectCommandAction.java index 3cd5109ff..033302434 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DisconnectCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DisconnectCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -15,6 +15,7 @@ import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** * Disconnect action. diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DropToFrameCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DropToFrameCommandAction.java index 6cccb37de..3693b0f8d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DropToFrameCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DropToFrameCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.IDropToFrameHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ICommandParticipant.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ICommandParticipant.java index c5daa2f72..635396d41 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ICommandParticipant.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ICommandParticipant.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -15,7 +15,7 @@ import org.eclipse.debug.core.IRequest; /** * Adds function to a command on completion. * - * @since 3.3 + * @since 3.3. */ public interface ICommandParticipant { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/IEnabledTarget.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/IEnabledTarget.java new file mode 100644 index 000000000..cb6642328 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/IEnabledTarget.java @@ -0,0 +1,18 @@ +/*******************************************************************************
+ * Copyright (c) 2008, 2009 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.internal.ui.commands.actions;
+
+/**
+ *
+ */
+public interface IEnabledTarget {
+ public void setEnabled(boolean enabled);
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandAction.java index f14c7f03e..f7f28abe5 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.IResumeHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java index 77a6cb6d2..3a770a612 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ResumeCommandActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -11,17 +11,45 @@ package org.eclipse.debug.internal.ui.commands.actions; +import org.eclipse.debug.ui.actions.DebugCommandAction; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; + /** * Resume action delegate. * * @since 3.3 */ -public class ResumeCommandActionDelegate extends DebugCommandActionDelegate { +public class ResumeCommandActionDelegate implements IWorkbenchWindowActionDelegate, IActionDelegate2 { - public ResumeCommandActionDelegate() { - super(); - setAction(new ResumeCommandAction()); + private DebugCommandAction fDebugAction = new ResumeCommandAction(); + + public void dispose() { + fDebugAction.dispose(); } - + public void init(IWorkbenchWindow window) { + fDebugAction.init(window); + } + + public void run(IAction action) { + fDebugAction.run(); + } + + public void selectionChanged(IAction action, ISelection selection) { + // do nothing + } + + public void init(IAction action) { + fDebugAction.setActionProxy(action); + + } + + public void runWithEvent(IAction action, Event event) { + run(action); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandAction.java index d38a91889..f42a2dd03 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepIntoCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.IStepIntoHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandAction.java index ffc4ecf90..020e34d95 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepOverCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -15,6 +15,7 @@ import org.eclipse.debug.core.commands.IStepOverHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandAction.java index 872f0a87a..73aa93520 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/StepReturnCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.IStepReturnHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandAction.java index ef3deecf3..f6a47bfd9 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/SuspendCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.ISuspendHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAllAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAllAction.java index 90362bd76..b6f8e6e22 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAllAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAllAction.java @@ -18,6 +18,7 @@ import org.eclipse.debug.core.commands.ITerminateHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.StructuredSelection; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java index 83a3519f1..07c5974f7 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRelaunchAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. + * Copyright (c) 2004, 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 @@ -20,6 +20,7 @@ import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.internal.ui.actions.RelaunchActionDelegate; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; @@ -30,37 +31,21 @@ import org.eclipse.jface.viewers.IStructuredSelection; */ public class TerminateAndRelaunchAction extends DebugCommandAction { - class Participant implements ICommandParticipant { - - private Object[] fTargets; - - public Participant(Object[] targets) { - fTargets = targets; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant#requestDone(org.eclipse.debug.core.commands.IRequest) - */ - public void requestDone(IRequest request) { - if (request.getStatus() == null || request.getStatus().isOK()) { - DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - // Must be run in the UI thread since the launch can require - // prompting to proceed - for (int i = 0; i < fTargets.length; i++) { - ILaunch launch = RelaunchActionDelegate.getLaunch(fTargets[i]); - RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode()); - } - } - }); - } - } - - } + public void postExecute(IRequest request, final Object[] targets) { + if (request.getStatus() == null || request.getStatus().isOK()) { + DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable() { + public void run() { + // Must be run in the UI thread since the launch can require + // prompting to proceed + for (int i = 0; i < targets.length; i++) { + ILaunch launch = RelaunchActionDelegate.getLaunch(targets[i]); + RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode()); + } + } + }); + } + } - protected ICommandParticipant getCommandParticipant(Object[] targets) { - return new Participant(targets); - } protected Class getCommandType() { return ITerminateHandler.class; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java index c72284887..e221614d5 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateAndRemoveAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -20,6 +20,7 @@ import org.eclipse.debug.core.model.IProcess; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** @@ -29,38 +30,6 @@ import org.eclipse.jface.resource.ImageDescriptor; */ public class TerminateAndRemoveAction extends DebugCommandAction { - - class TerminateAndRemoveParticipant implements ICommandParticipant { - private Object[] fElements; - - TerminateAndRemoveParticipant(Object[] elements) { - fElements = elements; - } - - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant#requestDone(org.eclipse.debug.core.commands.IRequest) - */ - public void requestDone(IRequest request) { - IStatus status = request.getStatus(); - if(status == null || status.isOK()) { - for (int i = 0; i < fElements.length; i++) { - Object element = fElements[i]; - ILaunch launch= null; - if (element instanceof ILaunch) { - launch= (ILaunch) element; - } else if (element instanceof IDebugElement) { - launch= ((IDebugElement) element).getLaunch(); - } else if (element instanceof IProcess) { - launch= ((IProcess) element).getLaunch(); - } - if (launch != null) - DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); - } - } - } - - } - public String getText() { return ActionMessages.TerminateAndRemoveAction_0; } @@ -93,9 +62,24 @@ public class TerminateAndRemoveAction extends DebugCommandAction { return ITerminateHandler.class; } - protected ICommandParticipant getCommandParticipant(Object[] targets) { - return new TerminateAndRemoveParticipant(targets); - } + protected void requestDone(Object[] elements, IRequest request) { + IStatus status = request.getStatus(); + if(status == null || status.isOK()) { + for (int i = 0; i < elements.length; i++) { + Object element = elements[i]; + ILaunch launch= null; + if (element instanceof ILaunch) { + launch= (ILaunch) element; + } else if (element instanceof IDebugElement) { + launch= ((IDebugElement) element).getLaunch(); + } else if (element instanceof IProcess) { + launch= ((IProcess) element).getLaunch(); + } + if (launch != null) + DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch); + } + } + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandAction.java index d1a507085..a8de94bdc 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/TerminateCommandAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -14,6 +14,7 @@ import org.eclipse.debug.core.commands.ITerminateHandler; import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.jface.resource.ImageDescriptor; /** diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java index fc33a345a..845733b8a 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * 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 @@ -19,7 +19,9 @@ import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.debug.ui.contexts.DebugContextEvent; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchPart; @@ -166,9 +168,9 @@ public class ToggleStepFiltersAction extends DebugCommandAction implements IProp if (event.getProperty().equals(StepFilterManager.PREF_USE_STEP_FILTERS)) { boolean checked = DebugUITools.isUseStepFilters(); setChecked(checked); - DebugCommandActionDelegate delegate = getDelegate(); - if (delegate != null) { - delegate.setChecked(checked); + IAction action = getActionProxy(); + if (action != null) { + action.setChecked(checked); } } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersCommandActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersCommandActionDelegate.java index deee97af0..163927199 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersCommandActionDelegate.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/ToggleStepFiltersCommandActionDelegate.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 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 @@ -12,7 +12,7 @@ package org.eclipse.debug.internal.ui.commands.actions; import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.jface.action.IAction; /** * Toggle step filters action delegate. @@ -29,11 +29,8 @@ public class ToggleStepFiltersCommandActionDelegate extends DebugCommandActionDe setAction(new ToggleStepFiltersAction()); } - /** - * @see org.eclipse.debug.internal.ui.commands.actions.DebugCommandActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) - */ - public void init(IWorkbenchWindow window) { - super.init(window); - setChecked(DebugUITools.isUseStepFilters()); - } + public void init(IAction action) { + super.init(action); + action.setChecked(DebugUITools.isUseStepFilters()); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/UpdateActionsRequest.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/UpdateActionsRequest.java index bcca5c948..142dbb22d 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/UpdateActionsRequest.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/UpdateActionsRequest.java @@ -12,7 +12,6 @@ package org.eclipse.debug.internal.ui.commands.actions; import org.eclipse.debug.core.commands.IEnabledStateRequest; import org.eclipse.debug.internal.core.commands.DebugCommandRequest; -import org.eclipse.jface.action.IAction; /** * Boolean collector that collects boolean results from a number of voters. @@ -23,10 +22,10 @@ import org.eclipse.jface.action.IAction; */ public class UpdateActionsRequest extends DebugCommandRequest implements IEnabledStateRequest { - private IAction[] fActions; + private IEnabledTarget[] fActions; private boolean fEnabled = false; - public UpdateActionsRequest(Object[] elements, IAction[] actions) { + public UpdateActionsRequest(Object[] elements, IEnabledTarget[] actions) { super(elements); fActions = actions; } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java index a9098c74c..563dbdc8a 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java @@ -41,7 +41,6 @@ import org.eclipse.debug.internal.ui.DelegatingModelPresentation; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.actions.AddToFavoritesAction; import org.eclipse.debug.internal.ui.actions.EditLaunchConfigurationAction; -import org.eclipse.debug.internal.ui.commands.actions.DebugCommandAction; import org.eclipse.debug.internal.ui.commands.actions.DisconnectCommandAction; import org.eclipse.debug.internal.ui.commands.actions.DropToFrameCommandAction; import org.eclipse.debug.internal.ui.commands.actions.ResumeCommandAction; @@ -72,6 +71,7 @@ import org.eclipse.debug.ui.AbstractDebugView; import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.debug.ui.actions.DebugCommandAction; import org.eclipse.debug.ui.contexts.AbstractDebugContextProvider; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java index 7d95291fb..7877022d3 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/commands/actions/DebugCommandAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandAction.java @@ -1,269 +1,343 @@ -/******************************************************************************* - * Copyright (c) 2006, 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 - *******************************************************************************/ - -package org.eclipse.debug.internal.ui.commands.actions; - -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.action.Action; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.swt.widgets.Event; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -/** - * Abstract base class for actions performing debug commands - * - * @since 3.3 - */ -public abstract class DebugCommandAction extends Action implements IDebugContextListener { - - /** - * The window this action is working for. - */ - private IWorkbenchWindow fWindow; - - /** - * The part this action is working for, or <code>null</code> if global to - * a window. - */ - private IWorkbenchPart fPart; - - /** - * Command service. - */ - private DebugCommandService fUpdateService; - - /** - * Delegate this action is working for or <code>null</code> if none. - */ - private DebugCommandActionDelegate fDelegate; - - /** - * Constructor - */ - public DebugCommandAction() { - super(); - String helpContextId = getHelpContextId(); - if (helpContextId != null) - PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId); - setEnabled(false); - } - - /** - * Set the current delegate - * @param delegate - */ - public void setDelegate(DebugCommandActionDelegate delegate) { - fDelegate = delegate; - } - - /** - * Executes this action on the given target object - * - * @param target the target to perform the action on - */ - protected boolean execute(Object[] targets) { - return fUpdateService.executeCommand(getCommandType(), targets, getCommandParticipant(targets)); - } - - /** - * Creates and returns the command participant or <code>null</code>. - * - * @return command participant to use on command completion - */ - protected ICommandParticipant getCommandParticipant(Object[] targets) { - return null; - } - - /** - * Returns the command type this action executes. - * - * @return command class. - */ - abstract protected Class getCommandType(); - - /** - * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent) - */ - public void debugContextChanged(DebugContextEvent event) { - fUpdateService.postUpdateCommand(getCommandType(), this); - } - - /** - * @see org.eclipse.jface.action.Action#setEnabled(boolean) - */ - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - if (fDelegate != null) { - fDelegate.setEnabled(enabled); - } - } - - /** - * Initializes this action for a specific part. - * - * @param part workbench part - */ - public void init(IWorkbenchPart part) { - fPart = part; - fWindow = part.getSite().getWorkbenchWindow(); - fUpdateService = DebugCommandService.getService(fWindow); - IDebugContextService service = getDebugContextService(); - String partId = part.getSite().getId(); - service.addDebugContextListener(this, partId); - ISelection activeContext = service.getActiveContext(partId); - if (activeContext != null) { - fUpdateService.updateCommand(getCommandType(), this); - } else { - setEnabled(getInitialEnablement()); - } - } - - /** - * Initializes the context action - * @param window the window - */ - public void init(IWorkbenchWindow window) { - fWindow = window; - fUpdateService = DebugCommandService.getService(fWindow); - IDebugContextService contextService = getDebugContextService(); - contextService.addDebugContextListener(this); - ISelection activeContext = contextService.getActiveContext(); - if (activeContext != null) { - fUpdateService.updateCommand(getCommandType(), this); - } else { - setEnabled(getInitialEnablement()); - } - } - - /** - * 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; - } - - /** - * Returns the most recent selection - * - * @return structured selection - */ - protected ISelection getContext() { - if (fPart != null) { - getDebugContextService().getActiveContext(fPart.getSite().getId()); - } - return getDebugContextService().getActiveContext(); - } - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#run() - */ - public void run() { - ISelection selection = getContext(); - if (selection instanceof IStructuredSelection && isEnabled()) { - IStructuredSelection ss = (IStructuredSelection) selection; - boolean enabled = execute(ss.toArray()); - // disable the action according to the command - setEnabled(enabled); - } - } - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) - */ - public void runWithEvent(Event event) { - run(); - } - - /** - * Clean up when removing - */ - public void dispose() { - IDebugContextService service = getDebugContextService(); - if (fPart != null) { - service.removeDebugContextListener(this, fPart.getSite().getId()); - } else { - service.removeDebugContextListener(this); - } - fWindow = null; - fPart = null; - } - - /** - * Returns the context service this action linked to. - * @return - */ - protected IDebugContextService getDebugContextService() { - return DebugUITools.getDebugContextManager().getContextService(fWindow); - } - - /** - * @return The help context id for this action - */ - public abstract String getHelpContextId(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getId() - */ - public abstract String getId(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getText() - */ - public abstract String getText(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getToolTipText() - */ - public abstract String getToolTipText(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor() - */ - public abstract ImageDescriptor getDisabledImageDescriptor(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getHoverImageDescriptor() - */ - public abstract ImageDescriptor getHoverImageDescriptor(); - - /* - * (non-Javadoc) - * @see org.eclipse.jface.action.Action#getImageDescriptor() - */ - public abstract ImageDescriptor getImageDescriptor(); - - /** - * Returns the delegate associated with this action or <code>null</code> - * if none. - * - * @return delegate or <code>null</code> - */ - protected DebugCommandActionDelegate getDelegate() { - return fDelegate; - } -} +/*******************************************************************************
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.debug.ui.actions;
+
+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.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Abstract base class for re-targeting actions 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>
+ * This base class is an action which can be instantiated directly by views,
+ * etc. In order to contribute an action using an extension point, a class
+ * implementing {@link org.eclipse.ui.IActionDelegate} should be created first.
+ * The delegate should then use a <code>DebugCommandAction</code> to implement
+ * the needed functionality. The IActionDelegate must use {@link #setActionProxy(IAction)}
+ * specifying the workbench's action that is a proxy to the action delegate. This
+ * way, the workbench action can be updated visually as needed.<br>
+ * Note: <code>IDebugCommandHandler</code> command typically act on the active
+ * debug context as opposed to the active selection in view or window. The
+ * action delegate should ignore the active window selection, and instead allow
+ * the <code>DebugCommandAction</code> to update itself based on the active
+ * debug context.
+ * </p>
+ * <p>
+ * Clients may subclass this class.
+ * </p>
+ * @see org.eclipse.debug.core.commands.IDebugCommandHandler
+ * @since 3.6
+ */
+public abstract class DebugCommandAction extends Action implements IDebugContextListener {
+
+ private boolean fInitialized = false;
+
+ /**
+ * The window this action is working for.
+ */
+ private IWorkbenchWindow fWindow;
+
+ /**
+ * The part this action is working for, or <code>null</code> if global to
+ * a window.
+ */
+ private IWorkbenchPart fPart;
+
+ /**
+ * Command service.
+ */
+ private DebugCommandService fUpdateService;
+
+ /**
+ * Delegate this action is working for or <code>null</code> if none.
+ */
+ private IAction fAction;
+
+ private IEnabledTarget fEnabledTarget = new IEnabledTarget() {
+ public void setEnabled(boolean enabled) {
+ DebugCommandAction.this.setEnabled(enabled);
+ }
+ };
+
+ /**
+ * Constructor
+ */
+ public DebugCommandAction() {
+ super();
+ String helpContextId = getHelpContextId();
+ if (helpContextId != null)
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, helpContextId);
+ setEnabled(false);
+ }
+
+ /**
+ * Sets the current workbench action that is a proxy to an {@link org.eclipse.ui.IActionDelegate}
+ * that is using this action to perform its actual work. This only needs to be called when
+ * an {@link org.eclipse.ui.IActionDelegate} is using one of these actions to perform its
+ * function.
+ *
+ * @param action workbench proxy action
+ */
+ public void setActionProxy(IAction action) {
+ fAction = action;
+ fAction.setEnabled(isEnabled());
+ }
+
+ /**
+ * Executes this action on the given target object
+ *
+ * @param target the target to perform the action on
+ */
+ private boolean execute(final Object[] targets) {
+ return fUpdateService.executeCommand(
+ getCommandType(), targets,
+ new ICommandParticipant() {
+ public void requestDone(org.eclipse.debug.core.IRequest request) {
+ DebugCommandAction.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 to 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();
+
+ /**
+ * @see org.eclipse.debug.ui.contexts.IDebugContextListener#debugContextChanged(org.eclipse.debug.ui.contexts.DebugContextEvent)
+ */
+ public void debugContextChanged(DebugContextEvent event) {
+ fUpdateService.postUpdateCommand(getCommandType(), fEnabledTarget);
+ }
+
+ /**
+ * @see org.eclipse.jface.action.Action#setEnabled(boolean)
+ */
+ public void setEnabled(boolean enabled) {
+ synchronized (this) {
+ if (!fInitialized) {
+ fInitialized = true;
+ notifyAll();
+ }
+ }
+ super.setEnabled(enabled);
+ if (fAction != null) {
+ fAction.setEnabled(enabled);
+ }
+ }
+
+ /**
+ * Initializes this action for a specific part.
+ *
+ * @param part workbench part
+ */
+ public void init(IWorkbenchPart part) {
+ fPart = part;
+ fWindow = part.getSite().getWorkbenchWindow();
+ fUpdateService = DebugCommandService.getService(fWindow);
+ IDebugContextService service = getDebugContextService();
+ String partId = part.getSite().getId();
+ service.addDebugContextListener(this, partId);
+ ISelection activeContext = service.getActiveContext(partId);
+ if (activeContext != null) {
+ fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
+ } else {
+ setEnabled(getInitialEnablement());
+ }
+ }
+
+ /**
+ * Initializes the context action
+ * @param window the window
+ */
+ public void init(IWorkbenchWindow window) {
+ fWindow = window;
+ fUpdateService = DebugCommandService.getService(fWindow);
+ IDebugContextService contextService = getDebugContextService();
+ contextService.addDebugContextListener(this);
+ ISelection activeContext = contextService.getActiveContext();
+ if (activeContext != null) {
+ fUpdateService.updateCommand(getCommandType(), fEnabledTarget);
+ } else {
+ setEnabled(getInitialEnablement());
+ }
+ }
+
+ /**
+ * Returns whether this action should be enabled when initialized
+ * and there is no active debug context. By default, <code>false</code>
+ * is returned.
+ *
+ * @return initial enabled state when there is no active context.
+ */
+ protected boolean getInitialEnablement() {
+ return false;
+ }
+
+ /**
+ * Returns the context this action operates on as a selection.
+ *
+ * @return the context this action operates on
+ */
+ private ISelection getContext() {
+ if (fPart != null) {
+ getDebugContextService().getActiveContext(fPart.getSite().getId());
+ }
+ return getDebugContextService().getActiveContext();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ synchronized (this) {
+ if (!fInitialized) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+
+ ISelection selection = getContext();
+ if (selection instanceof IStructuredSelection && isEnabled()) {
+ IStructuredSelection ss = (IStructuredSelection) selection;
+ boolean enabled = execute(ss.toArray());
+ // disable the action according to the command
+ setEnabled(enabled);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
+ */
+ public void runWithEvent(Event event) {
+ run();
+ }
+
+ /**
+ * Clean up when removing
+ */
+ public void dispose() {
+ IDebugContextService service = getDebugContextService();
+ if (fPart != null) {
+ service.removeDebugContextListener(this, fPart.getSite().getId());
+ } else {
+ service.removeDebugContextListener(this);
+ }
+ fWindow = null;
+ fPart = null;
+ }
+
+ /**
+ * Returns the context service this action linked to. By default, this actions is
+ * associated with the context service for the window this action is operating in.
+ *
+ * @return associated context service
+ */
+ protected IDebugContextService getDebugContextService() {
+ return DebugUITools.getDebugContextManager().getContextService(fWindow);
+ }
+
+ /**
+ * Returns the help context id for this action or <code>null</code> if none.
+ *
+ * @return The help context id for this action or <code>null</code>
+ */
+ public abstract String getHelpContextId();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getId()
+ */
+ public abstract String getId();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getText()
+ */
+ public abstract String getText();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getToolTipText()
+ */
+ public abstract String getToolTipText();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getDisabledImageDescriptor()
+ */
+ public abstract ImageDescriptor getDisabledImageDescriptor();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getHoverImageDescriptor()
+ */
+ public abstract ImageDescriptor getHoverImageDescriptor();
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.action.Action#getImageDescriptor()
+ */
+ public abstract ImageDescriptor getImageDescriptor();
+
+ /**
+ * Returns the workbench proxy associated with this action or <code>null</code>
+ * if none. This is the workbench proxy to an {@link org.eclipse.ui.IActionDelegate}
+ * that is using this action to perform its actual work. This is only used when
+ * an {@link org.eclipse.ui.IActionDelegate} is using one of these actions to perform its
+ * function.
+ *
+ * @return workbench proxy action or <code>null</code>
+ */
+ protected IAction getActionProxy() {
+ return fAction;
+ }
+}
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 new file mode 100644 index 000000000..5ec94d494 --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/DebugCommandHandler.java @@ -0,0 +1,279 @@ +/*******************************************************************************
+ * 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;
+ }
+}
|