Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2016-07-13 01:23:00 -0400
committerSarika Sinha2016-07-30 05:33:50 -0400
commit8124e2bb15eb3d3793ac8f160e83bddaf1a5c7d8 (patch)
tree2d5ae6749f01aaeb28f90eb7b28100b0c0ceddea /org.eclipse.debug.ui/ui/org/eclipse/debug/ui
parent9ed73a19c85b0cf7c1f48d0dc5fc370f9d9ced61 (diff)
downloadeclipse.platform.debug-8124e2bb15eb3d3793ac8f160e83bddaf1a5c7d8.tar.gz
eclipse.platform.debug-8124e2bb15eb3d3793ac8f160e83bddaf1a5c7d8.tar.xz
eclipse.platform.debug-8124e2bb15eb3d3793ac8f160e83bddaf1a5c7d8.zip
actions and Context based launch Change-Id: Icef7f143a7d967c5d7126180a359fd4fcbe3422e
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui')
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java167
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchHistoryAction.java9
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/AbstractLaunchToolbarAction.java13
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/LaunchAction.java31
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RelaunchLastAction.java51
5 files changed, 222 insertions, 49 deletions
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.
* <p>
* This method must be called in the UI thread.
* </p>
+ *
* @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<Object, Boolean> 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 <code>false</code> 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<Object> 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.
+ * <p>
+ * This method must be called in the UI thread.
+ * </p>
+ *
+ * @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
+ * <p>
+ * This method must be called in the UI thread.
+ * </p>
+ *
+ * @param configuration the configuration to launch
+ * @param mode launch mode - run or debug
+ * @param isShift is Shift pressed (use <code>false</code> 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.
*/

Back to the top