From 8124e2bb15eb3d3793ac8f160e83bddaf1a5c7d8 Mon Sep 17 00:00:00 2001 From: Sarika Sinha Date: Wed, 13 Jul 2016 10:53:00 +0530 Subject: Bug 492182 - Add Terminate and Relaunch from Configurations, Relaunch actions and Context based launch Change-Id: Icef7f143a7d967c5d7126180a359fd4fcbe3422e --- .../ui/org/eclipse/debug/ui/DebugUITools.java | 167 +++++++++++++++++++-- .../ui/actions/AbstractLaunchHistoryAction.java | 9 +- .../ui/actions/AbstractLaunchToolbarAction.java | 13 +- .../org/eclipse/debug/ui/actions/LaunchAction.java | 31 +--- .../debug/ui/actions/RelaunchLastAction.java | 51 ++++++- 5 files changed, 222 insertions(+), 49 deletions(-) (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui') diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java index c6c85731e..df2c46e61 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2015 IBM Corporation and others. + * Copyright (c) 2000, 2016 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,8 @@ package org.eclipse.debug.ui; +import java.util.HashMap; +import java.util.Iterator; import java.util.Set; import org.eclipse.core.commands.ExecutionEvent; @@ -19,10 +21,8 @@ import org.eclipse.core.commands.operations.IOperationHistory; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.commands.operations.ObjectUndoContext; - import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; - import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; @@ -31,12 +31,14 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; - +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchDelegate; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; @@ -47,6 +49,7 @@ import org.eclipse.debug.internal.ui.DebugPluginImages; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.DefaultLabelProvider; import org.eclipse.debug.internal.ui.DelegatingModelPresentation; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.LazyModelPresentation; import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager; @@ -60,7 +63,6 @@ import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils; import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager; - import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetManager; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextManager; @@ -68,18 +70,20 @@ import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.debug.ui.memory.IMemoryRenderingManager; import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; - import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.window.Window; - +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Shell; - +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IViewSite; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; @@ -754,19 +758,157 @@ public class DebugUITools { } /** - * Saves and builds the workspace according to current preference settings, and - * launches the given launch configuration in the specified mode. + * Saves and builds the workspace according to current preference settings, + * and launches the given launch configuration in the specified mode. It + * terminates the current launch for the same configuration if it was + * specified via Preferences or toggled by Shift. *

* This method must be called in the UI thread. *

+ * * @param configuration the configuration to launch * @param mode launch mode - run or debug * @since 2.1 */ public static void launch(final ILaunchConfiguration configuration, final String mode) { - boolean launchInBackground= true; + launch(configuration, mode, DebugUITools.findTogglelaunchForConfig(configuration)); + } + + private static HashMap fgLaunchToggleTerminateMap = new HashMap<>(); + + /** + * Stores the toggle data for launch in a Map to be used while launching to + * decide if previous launch for same configuration can be terminated. + * + * @param data the editor or selected tree node + * @param isShift is Shift pressed (use false if no support for + * Shift) + * @since 3.12 + */ + public static void storeLaunchToggleTerminate(Object data, Boolean isShift) { + synchronized (fgLaunchToggleTerminateMap) { + fgLaunchToggleTerminateMap.put(data, isShift); + } + } + + /** + * @since 3.12 + */ + private static boolean getAndRemoveLaunchToggleTerminate(Object data) { + + Boolean isShift; + synchronized (fgLaunchToggleTerminateMap) { + isShift = fgLaunchToggleTerminateMap.get(data); + } + if (isShift != null) { + synchronized (fgLaunchToggleTerminateMap) { + fgLaunchToggleTerminateMap.remove(data); + } + return isShift.booleanValue(); + } + return Boolean.FALSE; + } + + /** + * @since 3.12 + */ + private static boolean findTogglelaunchForConfig(ILaunchConfiguration configuration) { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunch[] launches = launchManager.getLaunches(); + for (ILaunch iLaunch : launches) { + if (configuration.contentsEqual(iLaunch.getLaunchConfiguration())) { + try { + IResource[] configResource = iLaunch.getLaunchConfiguration().getMappedResources(); + if (configResource != null && configResource.length == 1) { + for (Iterator iter = fgLaunchToggleTerminateMap.keySet().iterator(); iter.hasNext();) { + Object key = iter.next(); + if (key instanceof IEditorPart) { + IEditorInput input = ((IEditorPart) key).getEditorInput(); + if (input.getAdapter(IResource.class).equals(configResource[0])) { + return getAndRemoveLaunchToggleTerminate(key); + } + } else if (key instanceof TreeSelection) { + TreeSelection selection = (TreeSelection) key; + TreePath[] treePath = selection.getPaths(); + if (treePath != null && treePath.length == 1) { + Object lastSegmentObj = treePath[0].getLastSegment(); + IResource selectedResource = ((IAdaptable) lastSegmentObj).getAdapter(IResource.class); + if (selectedResource!= null && selectedResource.equals(configResource[0])) { + return getAndRemoveLaunchToggleTerminate(key); + } + } + } + } + } + + } catch (CoreException e) { + e.printStackTrace(); + } + } + } + return false; + + } + + /** + * Saves and builds the workspace according to current preference settings, + * and launches the given launch configuration in the specified mode. + *

+ * This method must be called in the UI thread. + *

+ * + * @param configuration the configuration to launch + * @param mode launch mode - run or debug + * @since 3.12 + */ + public static void reLaunch(final ILaunchConfiguration configuration, final String mode) { + boolean launchInBackground = true; try { - launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); + launchInBackground = configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); + } catch (CoreException e) { + DebugUIPlugin.log(e); + } + if (launchInBackground) { + DebugUIPlugin.launchInBackground(configuration, mode); + } else { + DebugUIPlugin.launchInForeground(configuration, mode); + } + + } + + + /** + * Saves and builds the workspace according to current preference settings, + * and launches the given launch configuration in the specified mode. It + * terminates the current launch for the same configuration if it was + * specified via Preferences or toggled by Shift + *

+ * This method must be called in the UI thread. + *

+ * + * @param configuration the configuration to launch + * @param mode launch mode - run or debug + * @param isShift is Shift pressed (use false if no support for + * Shift) + * @since 3.12 + */ + public static void launch(final ILaunchConfiguration configuration, final String mode, boolean isShift) { + if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TERMINATE_AND_RELAUNCH_LAUNCH_ACTION) != isShift) { + ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); + ILaunch[] launches = launchManager.getLaunches(); + for (ILaunch iLaunch : launches) { + if (configuration.contentsEqual(iLaunch.getLaunchConfiguration())) { + try { + iLaunch.terminate(); + } catch (DebugException e) { + DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), NLS.bind(ActionMessages.TerminateAndLaunchFailure, iLaunch.getLaunchConfiguration().getName()), e)); + } + } + } + } + boolean launchInBackground = true; + try { + launchInBackground = configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true); } catch (CoreException e) { DebugUIPlugin.log(e); } @@ -776,7 +918,6 @@ public class DebugUITools { DebugUIPlugin.launchInForeground(configuration, mode); } } - /** 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 4ec985181..65590c866 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 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 @@ -417,6 +417,13 @@ public abstract class AbstractLaunchHistoryAction implements IActionDelegate2, I true); return; } + runInternal(action, ((event.stateMask & SWT.SHIFT) > 0) ? true : false); + } + + /** + * @since 3.12 + */ + protected void runInternal(IAction action, boolean isShift) { run(action); } 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 aed6e70ae..685422b0e 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, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2016 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 @@ -77,17 +77,22 @@ public class AbstractLaunchToolbarAction extends AbstractLaunchHistoryAction { */ @Override public void run(IAction action) { + runInternal(action, false); + } + + @Override + protected void runInternal(IAction action, boolean isShift) { //always ignore external tools during context launching if(LaunchingResourceManager.isContextLaunchEnabled(getLaunchGroupIdentifier())) { - ContextRunner.getDefault().launch(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(getLaunchGroupIdentifier())); + ContextRunner.getDefault().launch(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(getLaunchGroupIdentifier()), isShift); } else { ILaunchConfiguration configuration = getLastLaunch(); if (configuration == null) { DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(), getLaunchGroupIdentifier()); } else { - DebugUITools.launch(configuration, getMode()); + DebugUITools.launch(configuration, getMode(), isShift); } } - } + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/LaunchAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/LaunchAction.java index 8b8500256..527709750 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/LaunchAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/LaunchAction.java @@ -15,14 +15,8 @@ import java.util.ArrayList; import java.util.Set; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugException; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; -import org.eclipse.debug.core.ILaunchManager; import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.IDebugHelpContextIds; import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; @@ -35,7 +29,6 @@ import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Event; import org.eclipse.ui.PlatformUI; @@ -84,24 +77,13 @@ public class LaunchAction extends Action { */ @Override public void run() { - DebugUITools.launch(fConfiguration, fMode); + runInternal(false); } - private void terminateIfPreferred(boolean isShift) { - if (DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TERMINATE_AND_RELAUNCH_LAUNCH_ACTION) != isShift) { - ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); - ILaunch[] launches = launchManager.getLaunches(); - for (ILaunch iLaunch : launches) { - if (fConfiguration.contentsEqual(iLaunch.getLaunchConfiguration())) { - try { - iLaunch.terminate(); - } catch (DebugException e) { - DebugUIPlugin.log(new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), NLS.bind(ActionMessages.TerminateAndLaunchFailure, iLaunch.getLaunchConfiguration().getName()), e)); - } - } - } - } + private void runInternal(boolean isShift) { + DebugUITools.launch(fConfiguration, fMode, isShift); } + /** * If the user has control-clicked the launch history item, open the launch * configuration dialog on the launch configuration, rather than running it. @@ -140,12 +122,11 @@ public class LaunchAction extends Action { DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(fConfiguration), group.getIdentifier()); } else { - run(); + runInternal(((event.stateMask & SWT.SHIFT) > 0) ? true : false); } } else { - terminateIfPreferred(((event.stateMask & SWT.SHIFT) > 0) ? true : false); - run(); + runInternal(((event.stateMask & SWT.SHIFT) > 0) ? true : false); } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RelaunchLastAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RelaunchLastAction.java index 26fe9893e..3de0d7217 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RelaunchLastAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RelaunchLastAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2016 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 @@ -35,7 +35,10 @@ import org.eclipse.debug.ui.ILaunchGroup; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IActionDelegate2; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; import org.eclipse.ui.PlatformUI; @@ -53,7 +56,7 @@ import com.ibm.icu.text.MessageFormat; * @see ProfileLastAction * @since 3.8 */ -public abstract class RelaunchLastAction implements IWorkbenchWindowActionDelegate { +public abstract class RelaunchLastAction implements IWorkbenchWindowActionDelegate, IActionDelegate2 { private class Listener implements IPreferenceChangeListener { /* (non-Javadoc) @@ -94,21 +97,57 @@ public abstract class RelaunchLastAction implements IWorkbenchWindowActionDelega } } + /* + * (non-Javadoc) + * @see + * org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + /** + * @since 3.12 + */ + @Override + public void init(IAction action) { + initialize(action); + IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(DebugUIPlugin.getUniqueIdentifier()); + if (prefs != null) { + prefs.addPreferenceChangeListener(fListener); + } + } + /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ @Override - public void run(IAction action){ + public void run(IAction action) { + runInternal(false); + } + + /* + * (non-Javadoc) + * @see + * org.eclipse.ui.IActionDelegate2#runwithEvent(org.eclipse.jface.action. + * IAction, org.eclipse.swt.widgets.Event) + */ + + /** + * @since 3.12 + */ + @Override + public void runWithEvent(IAction action, Event event) { + runInternal(((event.stateMask & SWT.SHIFT) > 0) ? true : false); + } + + private void runInternal(boolean isShift) { if(LaunchingResourceManager.isContextLaunchEnabled()) { ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(getLaunchGroupId()); - ContextRunner.getDefault().launch(group); + ContextRunner.getDefault().launch(group, isShift); return; } try { final ILaunchConfiguration configuration = getLastLaunch(); if (configuration != null) { if (configuration.supportsMode(getMode())) { - DebugUITools.launch(configuration, getMode()); + DebugUITools.launch(configuration, getMode(), isShift); } else { String configName = configuration.getName(); String title = ActionMessages.RelaunchLastAction_Cannot_relaunch_1; @@ -124,7 +163,7 @@ public abstract class RelaunchLastAction implements IWorkbenchWindowActionDelega DebugUIPlugin.errorDialog(getShell(), ActionMessages.RelaunchLastAction_Error_relaunching_3, ActionMessages.RelaunchLastAction_Error_encountered_attempting_to_relaunch_4, ce); // } } - + /** * Open the launch configuration dialog, passing in the current workbench selection. */ -- cgit v1.2.3