Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Rubezhny2014-05-08 14:12:02 +0000
committerGerrit Code Review @ Eclipse.org2014-05-08 14:12:02 +0000
commit8f1498398099575cab103462b2a014deefd90eb5 (patch)
tree820b09da4b550a2b12906d67f78c1fd68267d931
parent8fcf7659833598c3a13e2cd22f6e3042a256aac2 (diff)
parent7cbbad76c83626ebc58e23db6e4a91e6b8d2317f (diff)
downloadwebtools.maps-8f1498398099575cab103462b2a014deefd90eb5.tar.gz
webtools.maps-8f1498398099575cab103462b2a014deefd90eb5.tar.xz
webtools.maps-8f1498398099575cab103462b2a014deefd90eb5.zip
Merge "Bug 434158 - Debug runs even select cancel for ElementListSelectionDialog for debug configuration if multiple configuration exists for same file."v201405081515
-rw-r--r--bundles/org.eclipse.wst.jsdt.debug.rhino.ui/src/org/eclipse/wst/jsdt/debug/internal/rhino/ui/launching/RhinoLaunchShortcut.java158
1 files changed, 101 insertions, 57 deletions
diff --git a/bundles/org.eclipse.wst.jsdt.debug.rhino.ui/src/org/eclipse/wst/jsdt/debug/internal/rhino/ui/launching/RhinoLaunchShortcut.java b/bundles/org.eclipse.wst.jsdt.debug.rhino.ui/src/org/eclipse/wst/jsdt/debug/internal/rhino/ui/launching/RhinoLaunchShortcut.java
index 96c7c0261..a75b52b6d 100644
--- a/bundles/org.eclipse.wst.jsdt.debug.rhino.ui/src/org/eclipse/wst/jsdt/debug/internal/rhino/ui/launching/RhinoLaunchShortcut.java
+++ b/bundles/org.eclipse.wst.jsdt.debug.rhino.ui/src/org/eclipse/wst/jsdt/debug/internal/rhino/ui/launching/RhinoLaunchShortcut.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 2014 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
@@ -7,6 +7,9 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Sumit Singh <sumit.singh@infineon.com> - 434158 - Debug runs even select
+ * cancel for ElementListSelectionDialog for debug configuration if
+ * multiple configuration exists for same file.
*******************************************************************************/
package org.eclipse.wst.jsdt.debug.internal.rhino.ui.launching;
@@ -64,60 +67,70 @@ public class RhinoLaunchShortcut implements ILaunchShortcut2 {
* @param mode
*/
void launch(IResource resource, String mode) {
- if(resource != null) {
- ILaunchConfiguration config = findConfig(resource);
- if(config == null) {
- //TODO should we select a script to launch if a container is selected?
- ILaunchConfigurationType type = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
- String project = resource.getProject().getName();
- String script = (resource instanceof IFile ? resource.getFullPath().toString() : null);
- try {
- if(script != null) {
- ILaunchConfigurationWorkingCopy copy = type.newInstance(null, NLS.bind(Messages.config_name, new String[]{project, resource.getName()}));
- copy.setAttribute(ILaunchConstants.ATTR_SCRIPT, script);
- copy.setAttribute(ILaunchConstants.ATTR_LOG_INTERPRETER_EXCEPTIONS, true);
- copy.setAttribute(ILaunchConstants.ATTR_ECMA_VERSION, ILaunchConstants.ECMA_170);
- copy.setAttribute(ILaunchConstants.ATTR_OPT_LEVEL, -1);
- copy.setAttribute(ILaunchConstants.ATTR_STRICT_MODE, false);
- copy.setMappedResources(new IResource[] {resource});
- config = copy.doSave();
+ if (resource != null) {
+ List configs = getCandidates(resource);
+ if (configs != null) {
+ ILaunchConfiguration config = null;
+ int count = configs.size();
+ if (count == 1) {
+ config = (ILaunchConfiguration) configs.get(0);
+ } else if (count > 1) {
+ config = chooseConfiguration(configs);
+ if (config == null) {
+ return;
}
}
- catch (CoreException ce) {
- RhinoUIPlugin.log(ce);
+ if (config == null) {
+ config = createConfiguration(resource);
+ }
+ if (config != null) {
+ DebugUITools.launch(config, mode);
}
- }
- if(config != null) {
- DebugUITools.launch(config, mode);
}
}
}
-
+
/**
- * Finds an existing configuration to launch, returns <code>null</code> if none found, prompts for selection if
- * more than one found.
+ * Creates and returns a new configuration for JavaScript based on the
+ * resource.
*
- * @param resource the resource to find the configuration for
+ * @param resource
+ * the resource to find the configuration for
+ * @param config
* @return
*/
- ILaunchConfiguration findConfig(IResource resource) {
- List candidates = Collections.EMPTY_LIST;
+ ILaunchConfiguration createConfiguration(IResource resource) {
+ ILaunchConfiguration config = null;
+ ILaunchConfigurationType type = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
+ String project = resource.getProject().getName();
+ String script = (resource instanceof IFile ? resource.getFullPath().toString() : null);
try {
- ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfigurationType type = lm.getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
- ILaunchConfiguration[] configs = lm.getLaunchConfigurations(type);
- candidates = new ArrayList(configs.length);
- for (int i = 0; i < configs.length; i++) {
- ILaunchConfiguration config = configs[i];
- if(config.hasAttribute(ILaunchConstants.ATTR_SCRIPT)) {
- if (config.getAttribute(ILaunchConstants.ATTR_SCRIPT, ILaunchConstants.EMPTY_STRING).equals(resource.getFullPath().toString())) {
- candidates.add(config);
- }
- }
+ if (script != null) {
+ ILaunchConfigurationWorkingCopy copy = type.newInstance(null, NLS.bind(Messages.config_name, new String[] { project, resource.getName() }));
+ copy.setAttribute(ILaunchConstants.ATTR_SCRIPT, script);
+ copy.setAttribute(ILaunchConstants.ATTR_LOG_INTERPRETER_EXCEPTIONS, true);
+ copy.setAttribute(ILaunchConstants.ATTR_ECMA_VERSION, ILaunchConstants.ECMA_170);
+ copy.setAttribute(ILaunchConstants.ATTR_OPT_LEVEL, -1);
+ copy.setAttribute(ILaunchConstants.ATTR_STRICT_MODE, false);
+ copy.setMappedResources(new IResource[] { resource });
+ config = copy.doSave();
}
- } catch (CoreException e) {
- RhinoUIPlugin.log(e);
+ } catch (CoreException ce) {
+ RhinoUIPlugin.log(ce);
}
+ return config;
+ }
+
+ /**
+ * Finds an existing configuration to launch, returns <code>null</code> if
+ * none found, prompts for selection if more than one found.
+ *
+ * @param resource
+ * the resource to find the configuration for
+ * @return
+ */
+ ILaunchConfiguration findConfig(IResource resource) {
+ List candidates = getCandidates(resource);
int candidateCount = candidates.size();
if (candidateCount == 1) {
return (ILaunchConfiguration) candidates.get(0);
@@ -126,21 +139,23 @@ public class RhinoLaunchShortcut implements ILaunchShortcut2 {
}
return null;
}
-
+
/**
- * Returns a configuration from the given collection of configurations that should be launched,
- * or <code>null</code> to cancel. Default implementation opens a selection dialog that allows
- * the user to choose one of the specified launch configurations. Returns the chosen configuration,
- * or <code>null</code> if the user cancels.
+ * Returns a configuration from the given collection of configurations that
+ * should be launched, or <code>null</code> to cancel. Default
+ * implementation opens a selection dialog that allows the user to choose
+ * one of the specified launch configurations. Returns the chosen
+ * configuration, or <code>null</code> if the user cancels.
*
- * @param configList list of configurations to choose from
+ * @param configList
+ * list of configurations to choose from
* @return configuration to launch or <code>null</code> to cancel
*/
protected ILaunchConfiguration chooseConfiguration(List configList) {
IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
- ElementListSelectionDialog dialog= new ElementListSelectionDialog(RhinoUIPlugin.getActiveWorkbenchWindow().getShell(), labelProvider);
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(RhinoUIPlugin.getActiveWorkbenchWindow().getShell(), labelProvider);
dialog.setElements(configList.toArray());
- dialog.setTitle(Messages.select_rhino_config);
+ dialog.setTitle(Messages.select_rhino_config);
dialog.setMessage(Messages.select_existing_config);
dialog.setMultipleSelection(false);
int result = dialog.open();
@@ -148,9 +163,9 @@ public class RhinoLaunchShortcut implements ILaunchShortcut2 {
if (result == Window.OK) {
return (ILaunchConfiguration) dialog.getFirstResult();
}
- return null;
+ return null;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.debug.ui.ILaunchShortcut2#getLaunchConfigurations(org.eclipse.jface.viewers.ISelection)
*/
@@ -172,7 +187,7 @@ public class RhinoLaunchShortcut implements ILaunchShortcut2 {
*/
public IResource getLaunchableResource(ISelection selection) {
if (selection instanceof IStructuredSelection) {
- IStructuredSelection ss = (IStructuredSelection)selection;
+ IStructuredSelection ss = (IStructuredSelection) selection;
Object obj = ss.getFirstElement();
if (obj instanceof IAdaptable) {
return getResource((IAdaptable) obj);
@@ -187,17 +202,46 @@ public class RhinoLaunchShortcut implements ILaunchShortcut2 {
public IResource getLaunchableResource(IEditorPart editorpart) {
return getResource(editorpart.getEditorInput());
}
-
+
+ /**
+ * Collect the listing of {@link ILaunchConfiguration}s that apply to the
+ * given {@link IResource}.
+ *
+ * @param resource
+ * @return the list of {@link ILaunchConfiguration}s or an empty list, never
+ * <code>null</code>
+ */
+ List getCandidates(IResource resource) {
+ List candidates = Collections.EMPTY_LIST;
+ try {
+ ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = lm.getLaunchConfigurationType(ILaunchConstants.LAUNCH_CONFIG_TYPE);
+ ILaunchConfiguration[] configs = lm.getLaunchConfigurations(type);
+ candidates = new ArrayList(configs.length);
+ for (int i = 0; i < configs.length; i++) {
+ ILaunchConfiguration config = configs[i];
+ if (config.hasAttribute(ILaunchConstants.ATTR_SCRIPT)) {
+ if (config.getAttribute(ILaunchConstants.ATTR_SCRIPT, ILaunchConstants.EMPTY_STRING).equals(resource.getFullPath().toString())) {
+ candidates.add(config);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ RhinoUIPlugin.log(e);
+ }
+ return candidates;
+ }
+
/**
- * Returns the resource backing the {@link IAdaptable} providing it has an {@link IJavaScriptElement}
- * adapter.
+ * Returns the resource backing the {@link IAdaptable} providing it has an
+ * {@link IJavaScriptElement} adapter.
*
* @param adaptable
* @return the backing {@link IResource} or <code>null</code>
*/
IResource getResource(IAdaptable adaptable) {
IJavaScriptElement element = (IJavaScriptElement) adaptable.getAdapter(IJavaScriptElement.class);
- if(element != null) {
+ if (element != null) {
return element.getResource();
}
return (IResource) adaptable.getAdapter(IResource.class);

Back to the top