diff options
author | Pawel Piech | 2010-05-04 17:34:55 +0000 |
---|---|---|
committer | Pawel Piech | 2010-05-04 17:34:55 +0000 |
commit | 0c30d752e01e32da1e2bbcd2dff171244028c1dc (patch) | |
tree | 3907fddf83a21bff1f88e9ed8d7a5d53963cf001 /debug | |
parent | 5691d8b30607c5735e8f3c2aeaa93b9e86838044 (diff) | |
download | org.eclipse.cdt-0c30d752e01e32da1e2bbcd2dff171244028c1dc.tar.gz org.eclipse.cdt-0c30d752e01e32da1e2bbcd2dff171244028c1dc.tar.xz org.eclipse.cdt-0c30d752e01e32da1e2bbcd2dff171244028c1dc.zip |
Bug 289526 - [debug view] Migrate the Restart feature to the new one, as supported by the platform
Diffstat (limited to 'debug')
11 files changed, 170 insertions, 183 deletions
diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java index b836bddb2f0..15af99f8a9d 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/CDebugCorePlugin.java @@ -18,7 +18,9 @@ import java.util.HashSet; import java.util.List; import org.eclipse.cdt.debug.core.breakpointactions.BreakpointActionManager; +import org.eclipse.cdt.debug.core.command.CCommandAdapterFactory; import org.eclipse.cdt.debug.core.disassembly.IDisassemblyContextService; +import org.eclipse.cdt.debug.core.model.IRestart; import org.eclipse.cdt.debug.core.sourcelookup.ICSourceLocation; import org.eclipse.cdt.debug.internal.core.DebugConfiguration; import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants; @@ -31,6 +33,7 @@ import org.eclipse.cdt.debug.internal.core.sourcelookup.SourceUtils; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IStatus; @@ -331,6 +334,7 @@ public class CDebugCorePlugin extends Plugin { public void start( BundleContext context ) throws Exception { super.start( context ); initializeCommonSourceLookupDirector(); + createCommandAdapterFactory(); createBreakpointListenersList(); createDisassemblyContextService(); setSessionManager( new SessionManager() ); @@ -349,6 +353,12 @@ public class CDebugCorePlugin extends Plugin { super.stop( context ); } + private void createCommandAdapterFactory() { + IAdapterManager manager= Platform.getAdapterManager(); + CCommandAdapterFactory actionFactory = new CCommandAdapterFactory(); + manager.registerAdapters(actionFactory, IRestart.class); + } + private void initializeCommonSourceLookupDirector() { if ( fCommonSourceLookupDirector == null ) { fCommonSourceLookupDirector = new CommonSourceLookupDirector(); diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java new file mode 100755 index 00000000000..5c0f666f6bd --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CCommandAdapterFactory.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2006, 2010 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 + * Wind River Systems - copied to use in CDT + *******************************************************************************/ +package org.eclipse.cdt.debug.core.command; + +import org.eclipse.cdt.debug.core.model.IRestart; +import org.eclipse.core.runtime.IAdapterFactory; +import org.eclipse.debug.core.commands.IRestartHandler; + +/** + * Adapter factory for debug commands. + * + * @see org.eclipse.debug.core.command + * + * @since 7.0 + * + */ +public class CCommandAdapterFactory implements IAdapterFactory { + private static IRestartHandler fgRestartCommand = new RestartCommand(); + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) + */ + public Object getAdapter(Object adaptableObject, Class adapterType) { + if (IRestartHandler.class.equals(adapterType)) { + if (adaptableObject instanceof IRestart) { + return fgRestartCommand; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList() + */ + public Class[] getAdapterList() { + return new Class[] { + IRestartHandler.class + }; + } + +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java new file mode 100755 index 00000000000..c2f3abfe277 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/CForEachCommand.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 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 + * Wind River Systems - copied to use in CDT + *******************************************************************************/ +package org.eclipse.cdt.debug.core.command; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.debug.core.IRequest; +import org.eclipse.debug.core.commands.AbstractDebugCommand; +import org.eclipse.debug.core.commands.IEnabledStateRequest; + +/** + * A command that operates on each element individually. + * <p> + * Note: copied from org.eclipse.debug.core.command.ForEachCommand. + * </p> + * @since 7.0 + */ +public abstract class CForEachCommand extends AbstractDebugCommand { + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.commands.DebugCommand#doExecute(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.IRequest) + */ + protected void doExecute(Object[] targets, IProgressMonitor monitor, IRequest request) throws CoreException { + for (int i = 0; i < targets.length; i++) { + execute(targets[i]); + monitor.worked(1); + } + } + + protected abstract void execute(Object target) throws CoreException; + + /* (non-Javadoc) + * @see org.eclipse.debug.internal.core.commands.DebugCommand#isExecutable(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.commands.IEnabledStateRequest) + */ + protected boolean isExecutable(Object[] targets, IProgressMonitor monitor, IEnabledStateRequest request) throws CoreException { + for (int i = 0; i < targets.length; i++) { + if (!isExecutable(targets[i])) { + return false; + } + monitor.worked(1); + } + return true; + } + + protected abstract boolean isExecutable(Object target); + +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java new file mode 100755 index 00000000000..feef3bafd2d --- /dev/null +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/command/RestartCommand.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2006, 2010 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 + * Wind River Systems - adopted to use for restart command + *******************************************************************************/ +package org.eclipse.cdt.debug.core.command; + +import org.eclipse.cdt.debug.core.model.IRestart; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.core.commands.IDebugCommandRequest; +import org.eclipse.debug.core.commands.IRestartHandler; + +/** + * Default restart command for CDI + * + * @since 7.0 + */ +public class RestartCommand extends CForEachCommand implements IRestartHandler { + + protected Object getTarget(Object element) { + return getAdapter(element, IRestart.class); + } + + protected void execute(Object target) throws CoreException { + ((IRestart)target).restart(); + } + + protected boolean isExecutable(Object target) { + return ((IRestart)target).canRestart(); + } + + /* (non-Javadoc) + * @see org.eclipse.debug.core.commands.AbstractDebugCommand#getEnabledStateJobFamily(org.eclipse.debug.core.commands.IDebugCommandRequest) + */ + protected Object getEnabledStateJobFamily(IDebugCommandRequest request) { + return IRestart.class; + } +} diff --git a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java index b9f9ea25c76..38cfd177bf2 100644 --- a/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java +++ b/debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/core/model/IRestart.java @@ -14,10 +14,17 @@ package org.eclipse.cdt.debug.core.model; import org.eclipse.debug.core.DebugException; /** - * Provides the ability to restart a debug target. + * Provides the ability to restart a debug target. + * <p> + * Note: Debug elements which support restart should implement this interface. + * Adopting to this interface is not enough. + * </p> + * <p> + * Note 2: Debugger can also implement the asynchronous + * {@link org.eclipse.debug.core.commands.IRestartHandler}. + * </p> * - * @deprecated Use org.eclipse.debug.core.commands.IRestartHandler instead. IRestartHandler - * handles the call in an asynchronous fashion. + * @see org.eclipse.debug.core.commands.IRestartHandler */ public interface IRestart { diff --git a/debug/org.eclipse.cdt.debug.ui/icons/dlcl16/restart.gif b/debug/org.eclipse.cdt.debug.ui/icons/dlcl16/restart.gif Binary files differdeleted file mode 100644 index a3c6fc5f825..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/icons/dlcl16/restart.gif +++ /dev/null diff --git a/debug/org.eclipse.cdt.debug.ui/icons/elcl16/restart.gif b/debug/org.eclipse.cdt.debug.ui/icons/elcl16/restart.gif Binary files differdeleted file mode 100644 index 5708b00dd2b..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/icons/elcl16/restart.gif +++ /dev/null diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties index 4ad0aecaa06..5fba69e1041 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.properties +++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties @@ -27,9 +27,6 @@ BreakpointActionPage.name=Breakpoint Action UI Page RunMenu.label=&Run DebugActionSet.label=C/C++ Debug -RestartAction.label=Restart -RestartAction.tooltip=Restart - DisassemblyViewAction.label=Go to address... DisassemblyViewAction.tooltip=Enter memory address for the assembly code diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index 1853b0395c2..1ee1f7d9635 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -247,15 +247,6 @@ helpContextId="move_to_line_action_context" label="%GlobalMoveToLineAction.label" menubarPath="org.eclipse.ui.run/stepGroup"/> - <action - id="org.eclipse.cdt.debug.ui.internal.actions.RestartActionDelegate" - class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate" - disabledIcon="icons/dlcl16/restart.gif" - icon="icons/elcl16/restart.gif" - helpContextId="restart_action_context" - label="%RestartAction.label" - menubarPath="org.eclipse.ui.run/stepGroup"> - </action> </actionSet> </extension> <extension @@ -372,32 +363,6 @@ </propertyTester> </extension> - <!-- Bug 289526 [debug view] Migrate the Restart feature to the new one, as supported by the platform - Don't contribute this action to context menu if selection isn't an IRestart. Debug platform - already contributes it. --> - <extension - point="org.eclipse.ui.popupMenus"> - <viewerContribution - targetID="org.eclipse.debug.ui.DebugView" - id="org.eclipse.cdt.debug.ui.debugview.popupMenu2"> - <action - label="%RestartAction.label" - icon="icons/elcl16/restart.gif" - helpContextId="restart_action_context" - class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate" - menubarPath="stepGroup" - enablesFor="1" - id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"> - <selection class="org.eclipse.cdt.debug.core.model.IRestart"/> - - </action> - <visibility> - <objectClass name="org.eclipse.cdt.debug.core.model.IRestart"/> - </visibility> - </viewerContribution> - </extension> - - <extension point="org.eclipse.ui.popupMenus"> <viewerContribution diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties index 853a40bc1ca..1a111ac9964 100644 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties @@ -65,9 +65,6 @@ ManageFunctionBreakpointActionDelegate.Error_1=Error ManageFunctionBreakpointActionDelegate.Operation_failed_1=Operation failed. SignalActionDelegate.0=Unable to deliver the signal to the target. SignalActionDelegate.1=Operation failed. -RestartActionDelegate.0=Exception(s) occurred attempting to restart. -RestartActionDelegate.1=Restart failed. -RestartActionDelegate.2=Restart AddGlobalsActionDelegate.0=Select Variables: AddGlobalsActionDelegate.1=Add global variables failed. VariableFormatActionDelegate.0=Unable to set format. diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java deleted file mode 100644 index 34dae0eb789..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/RestartActionDelegate.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2010 QNX Software 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: - * QNX Software Systems - Initial API and implementation - * Navid Mehregani (TI) - Bug 289526 - Migrate the Restart feature to the new one, as supported by the platform - * Wind River Systems - Bug 289526 - Additional fixes - *******************************************************************************/ -package org.eclipse.cdt.debug.internal.ui.actions; - -import org.eclipse.cdt.debug.core.model.IRestart; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.commands.IRestartHandler; -import org.eclipse.debug.core.model.IDebugElement; -import org.eclipse.debug.core.model.IDebugTarget; -import org.eclipse.debug.internal.ui.commands.actions.RestartCommandAction; -import org.eclipse.jface.action.IAction; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchWindow; - -/** - * The delegate of the "Restart" action. - */ -public class RestartActionDelegate extends AbstractListenerActionDelegate { - - private RestartCommandAction fRestartCommandAction; - - @Override - public void init(IAction action) { - setAction(action); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object) - */ - protected void doAction( Object element ) throws DebugException { - IRestartHandler asynchronousRestartHandler = getAsynchronousRestartHandler( element ); - if (asynchronousRestartHandler!=null && fRestartCommandAction!=null ) { - fRestartCommandAction.run(); - } else { - IRestart restartTarget = getRestartTarget( element ); - if ( restartTarget != null ) { - restartTarget.restart(); - } - - } - } - - @Override - public void init(IViewPart view) { - super.init(view); - fRestartCommandAction = new RestartCommandAction(); - fRestartCommandAction.setActionProxy(getAction()); - fRestartCommandAction.init(getView()); - } - - @Override - public void init(IWorkbenchWindow window) { - super.init(window); - fRestartCommandAction = new RestartCommandAction(); - fRestartCommandAction.setActionProxy(getAction()); - fRestartCommandAction.init(getWindow()); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isEnabledFor(java.lang.Object) - */ - protected boolean isEnabledFor( Object element ) { - IRestartHandler asynchronousRestartHandler = getAsynchronousRestartHandler( element ); - if (asynchronousRestartHandler!=null && fRestartCommandAction!=null) { - return fRestartCommandAction.isEnabled(); - } else { - IRestart restartTarget = getRestartTarget( element ); - if ( restartTarget != null ) { - return checkCapability( restartTarget ); - } - } - return false; - } - - protected boolean checkCapability( IRestart element ) { - return element.canRestart(); - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getStatusMessage() - */ - protected String getStatusMessage() { - return ActionMessages.getString( "RestartActionDelegate.0" ); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getErrorDialogMessage() - */ - protected String getErrorDialogMessage() { - return ActionMessages.getString( "RestartActionDelegate.1" ); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#getErrorDialogTitle() - */ - protected String getErrorDialogTitle() { - return ActionMessages.getString( "RestartActionDelegate.2" ); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.cdt.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground() - */ - protected boolean isRunInBackground() { - return true; - } - - protected IRestart getRestartTarget( Object element ) { - if ( element instanceof IAdaptable ) - return (IRestart)((IAdaptable)element).getAdapter( IRestart.class ); - return getDefaultRestartTarget( element ); - } - - protected IRestartHandler getAsynchronousRestartHandler( Object element ) { - if ( element instanceof IAdaptable ) - return (IRestartHandler)((IAdaptable)element).getAdapter( IRestartHandler.class ); - - return null; - } - - private IRestart getDefaultRestartTarget( Object element ) { - if ( element instanceof IDebugElement ) { - IDebugTarget target = ((IDebugElement)element).getDebugTarget(); - if ( target instanceof IRestart ) - return (IRestart)target; - } - return null; - } -} |