Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 55080 Details for
Bug 89178
[launching] Open Properties dialog by clicking "Run As..." with Ctrl key
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
small update
89178_2.patch (text/plain), 48.44 KB, created by
Michael Rennie
on 2006-12-05 17:29:58 EST
(
hide
)
Description:
small update
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2006-12-05 17:29:58 EST
Size:
48.44 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.debug.ui >Index: ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java,v >retrieving revision 1.11 >diff -u -r1.11 LaunchShortcutAction.java >--- ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java 8 May 2006 20:07:19 -0000 1.11 >+++ ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java 5 Dec 2006 22:27:07 -0000 >@@ -17,11 +17,16 @@ > import org.eclipse.core.expressions.Expression; > import org.eclipse.core.expressions.IEvaluationContext; > import org.eclipse.core.runtime.CoreException; >+import org.eclipse.debug.core.ILaunchConfiguration; > import org.eclipse.debug.internal.ui.DebugUIPlugin; > import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; >+import org.eclipse.debug.ui.DebugUITools; > import org.eclipse.jface.action.Action; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; > import org.eclipse.ui.IEditorPart; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchWindow; >@@ -44,8 +49,6 @@ > fShortcut = shortcut; > updateEnablement(); > } >- >- > > /** > * Runs with either the active editor or workbench selection. >@@ -72,6 +75,40 @@ > } > } > >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) >+ */ >+ public void runWithEvent(Event event) { >+ if ((event.stateMask & SWT.MOD1) > 0) { >+ IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); >+ ILaunchConfiguration config = null; >+ if (wb != null) { >+ IWorkbenchPage page = wb.getActivePage(); >+ if (page != null) { >+ if (page.getActivePart() == page.getActiveEditor()) { >+ IEditorPart editor = page.getActiveEditor(); >+ if (editor != null) { >+ config = fShortcut.getLaunchConfiguration(editor); >+ } >+ } else { >+ ISelection selection = page.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ config = fShortcut.getLaunchConfiguration(selection); >+ } >+ } >+ } >+ } >+ if(config != null) { >+ IStructuredSelection selection = new StructuredSelection(config); >+ String id = DebugUITools.getLaunchGroup(config, fMode).getIdentifier(); >+ DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, id); >+ return; >+ } >+ } >+ //anything fails, run it >+ run(); >+ } >+ > /** > * Since these actions are re-created each time the run/debug as menu is > * filled, the enablement of this action is static. >Index: ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java,v >retrieving revision 1.1 >diff -u -r1.1 SharedLaunchConfigAction.java >--- ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java 22 Jun 2006 15:11:49 -0000 1.1 >+++ ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java 5 Dec 2006 22:27:07 -0000 >@@ -11,9 +11,14 @@ > package org.eclipse.debug.internal.ui.actions; > > import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.debug.internal.ui.DebugUIPlugin; > import org.eclipse.debug.ui.DebugUITools; > import org.eclipse.jface.action.Action; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.widgets.Event; > > /** > * This class provides an action warpper for adding shared launch configuration actions to the context menu >@@ -51,5 +56,18 @@ > public void run() { > DebugUITools.launch(fConfig, fMode); > } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event) >+ */ >+ public void runWithEvent(Event event) { >+ if ((event.stateMask & SWT.MOD1) > 0) { >+ IStructuredSelection selection = new StructuredSelection(getLaunchConfiguration()); >+ String id = DebugUITools.getLaunchGroup(getLaunchConfiguration(), fMode).getIdentifier(); >+ DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, id); >+ } else { >+ run(); >+ } >+ } > > } >Index: ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java,v >retrieving revision 1.30 >diff -u -r1.30 LaunchShortcutExtension.java >--- ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java 8 May 2006 20:07:19 -0000 1.30 >+++ ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java 5 Dec 2006 22:27:07 -0000 >@@ -29,10 +29,12 @@ > import org.eclipse.core.expressions.IEvaluationContext; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.debug.core.ILaunchConfiguration; > import org.eclipse.debug.internal.ui.DebugUIPlugin; > import org.eclipse.debug.internal.ui.Pair; > import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction; > import org.eclipse.debug.ui.ILaunchShortcut; >+import org.eclipse.debug.ui.ILaunchShortcut2; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.StructuredSelection; >@@ -45,7 +47,7 @@ > /** > * Proxy to a launch shortcut extension > */ >-public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribution { >+public class LaunchShortcutExtension implements IPluginContribution { > > private ImageDescriptor fImageDescriptor = null; > private List fPerspectives = null; >@@ -421,5 +423,43 @@ > public String getPluginId() { > return fConfig.getContributor().getName(); > } >+ >+ /** >+ * This method returns the associated <code>ILaunchConfiguration</code> for this >+ * view part selection, or <code>null</code> if there isn't one, or access to the launch configuration >+ * is not supported >+ * @param selection the current view part selection >+ * @return the asscoiated launch configuration or <code>null</code> if none or access is not supported >+ * >+ * @since 3.3 >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(ISelection selection) { >+ if(fDelegate == null) { >+ getDelegate(); >+ } >+ if(fDelegate instanceof ILaunchShortcut2) { >+ return ((ILaunchShortcut2)fDelegate).getLaunchConfiguration(selection); >+ } >+ return null; >+ } >+ >+ /** >+ * This method returns the associated <code>ILaunchConfiguration</code> for this >+ * editor part, or <code>null</code> if there isn't one, or access to the launch configuration >+ * is not supported >+ * @param editor the current editor part context >+ * @return the associated launch configuration or <code>null</code> if none or access is not supported >+ * >+ * @since 3.3 >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor) { >+ if(fDelegate == null) { >+ getDelegate(); >+ } >+ if(fDelegate instanceof ILaunchShortcut2) { >+ return ((ILaunchShortcut2)fDelegate).getLaunchConfiguration(editor); >+ } >+ return null; >+ } > } > >Index: ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties,v >retrieving revision 1.166 >diff -u -r1.166 LaunchConfigurationsMessages.properties >--- ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties 4 Dec 2006 21:57:01 -0000 1.166 >+++ ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties 5 Dec 2006 22:27:07 -0000 >@@ -181,3 +181,5 @@ > SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use when multiple launchers are available for a configuration and launch mode. > SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a> > SelectLaunchersDialog_5=Description >+AbstractLaunchShortcut_0=Select {0} >+AbstractLaunchShortcut_1=&Select existing configuration: >Index: ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java,v >retrieving revision 1.46 >diff -u -r1.46 LaunchConfigurationsMessages.java >--- ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java 4 Dec 2006 21:57:01 -0000 1.46 >+++ ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java 5 Dec 2006 22:27:07 -0000 >@@ -15,6 +15,10 @@ > public class LaunchConfigurationsMessages extends NLS { > private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages";//$NON-NLS-1$ > >+ public static String AbstractLaunchShortcut_0; >+ >+ public static String AbstractLaunchShortcut_1; >+ > public static String CommonTab__Browse_6; > public static String CommonTab__Common_15; > public static String CommonTab_Display_in_favorites_menu__10; >Index: ui/org/eclipse/debug/ui/AbstractLaunchShortcut.java >=================================================================== >RCS file: ui/org/eclipse/debug/ui/AbstractLaunchShortcut.java >diff -N ui/org/eclipse/debug/ui/AbstractLaunchShortcut.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/debug/ui/AbstractLaunchShortcut.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,164 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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; >+ >+import java.util.List; >+ >+import org.eclipse.debug.core.DebugPlugin; >+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.launchConfigurations.LaunchConfigurationsMessages; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.dialogs.ElementListSelectionDialog; >+ >+import com.ibm.icu.text.MessageFormat; >+ >+/** >+ * <p> >+ * This class provides a base implementation of an <code>ILaunchShortcut</code>, including the new >+ * <code>ILaunchShortcut2</code>, providing support for Ctrl+clicking the shortcut to quick edit >+ * associated launch configurations. >+ * </p> >+ * >+ * <p> >+ * Clients are only required to implement two methods: >+ * <ul> >+ * <li><code>findConfiguration</code>, which is used to find an existing launch configuration to use or >+ * create a new one as needed</li> >+ * <li><code>getConfigurationType</code>, which returns the <code>ILaunchConfigurationType</code> that this >+ * launch shorcut applies to</li> >+ * </ul> >+ * </p> >+ * >+ * @since 3.3 >+ */ >+public abstract class AbstractLaunchShortcut implements ILaunchShortcut2 { >+ >+ /** >+ * Returns the type of configuration this shortcut is applicable to. >+ * >+ * @return the type of configuration this shortcut is applicable to >+ */ >+ protected abstract ILaunchConfigurationType getConfigurationType(); >+ >+ /** >+ * Searches for the associated launch configuration for the specified items, if one is not found >+ * a new configuration should be created. >+ * @param context the currently selected context, which is typically from within an editor part or a structured view selection >+ * @param mode the mode to constrain to >+ * @param editor true if activated on an editor, false if activated from a selection in a viewer >+ * @return the associated launch configuraiton or null if none found >+ */ >+ protected abstract ILaunchConfiguration findConfiguration(Object context, boolean editor); >+ >+ /** >+ * Show a selection dialog that allows the user to choose one of the specified >+ * launch configurations. Return the chosen config, or <code>null</code> if the >+ * user cancelled the dialog. >+ */ >+ protected ILaunchConfiguration chooseConfiguration(List configList) { >+ IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); >+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider); >+ dialog.setElements(configList.toArray()); >+ dialog.setTitle(getConfigurationSelectionTitle()); >+ dialog.setMessage(getConfigurationSelectionMessage()); >+ dialog.setMultipleSelection(false); >+ int result = dialog.open(); >+ labelProvider.dispose(); >+ if (result == Window.OK) { >+ return (ILaunchConfiguration) dialog.getFirstResult(); >+ } >+ return null; >+ } >+ >+ /** >+ * Convenience method to get the window that owns this action's Shell. >+ * This method should be over-loaded to provide the appropriate shell for the launch shortcut >+ */ >+ protected Shell getShell() { >+ return DebugUIPlugin.getActiveWorkbenchWindow().getShell(); >+ } >+ >+ /** >+ * Returns the title text for the type selection dialog >+ * @return the title text for the type selection dialog >+ */ >+ protected String getConfigurationSelectionTitle() { >+ return MessageFormat.format(LaunchConfigurationsMessages.AbstractLaunchShortcut_0, new String[] {getConfigurationType().getName()}); >+ } >+ >+ /** >+ * Returns the message for the launch configuration selection dialog >+ * @return the message for the launch configuration selection dialog >+ */ >+ protected String getConfigurationSelectionMessage() { >+ return LaunchConfigurationsMessages.AbstractLaunchShortcut_1; >+ } >+ >+ /** >+ * returns the launch manager >+ * @return the launch mananger >+ */ >+ protected ILaunchManager getLaunchManager() { >+ return DebugPlugin.getDefault().getLaunchManager(); >+ } >+ >+ /** >+ * @see org.eclipse.debug.ui.ILaunchShortcut2#getLaunchConfiguration(org.eclipse.jface.viewers.ISelection) >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(ISelection selection) { >+ return findConfiguration(selection, false); >+ } >+ >+ /** >+ * @see ILaunchShortcut#launch(ISelection, String) >+ */ >+ public void launch(ISelection selection, String mode) { >+ searchAndLaunch(selection, mode, false); >+ } >+ >+ /** >+ * @see org.eclipse.debug.ui.ILaunchShortcut2#getLaunchConfiguration(org.eclipse.ui.IEditorPart) >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor) { >+ return findConfiguration(editor, true); >+ } >+ >+ /** >+ * @see ILaunchShortcut#launch(IEditorPart, String) >+ */ >+ public void launch(IEditorPart editor, String mode) { >+ searchAndLaunch(editor, mode, true); >+ } >+ >+ /** >+ * Searches for and launches a launch configuration for the specified objects. >+ * <p> >+ * This method uses the method <code>findTypes</code> to find the types of concern taht might be launched. >+ * It is up to implementors to decide how types are found and how launch configurations are created. >+ * </p> >+ * @param context the currently selected context, which is typically from within an editor part or a structured view selection >+ * @param mode the mode to launch in >+ * @param editor true if activated on an editor, false if activated from a selection in a viewer >+ */ >+ protected void searchAndLaunch(Object context, String mode, boolean editor) { >+ ILaunchConfiguration config = findConfiguration(context, editor); >+ if(config != null) { >+ DebugUITools.launch(config, mode); >+ } >+ } >+ >+} >Index: ui/org/eclipse/debug/ui/ILaunchShortcut2.java >=================================================================== >RCS file: ui/org/eclipse/debug/ui/ILaunchShortcut2.java >diff -N ui/org/eclipse/debug/ui/ILaunchShortcut2.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/debug/ui/ILaunchShortcut2.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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; >+ >+import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.ui.IEditorPart; >+ >+/** >+ * Provides new capabilities to have access to the associated <code>ILaunchCongfiguration</code>. >+ * This interface is intended to be used in the event your launch shortcut will provide access to >+ * the <code>LaunchConfigurationsDialog</code> via the Ctrl+Click mechanism in the Run->... menu >+ * @since 3.3 >+ */ >+public interface ILaunchShortcut2 extends ILaunchShortcut { >+ >+ /** >+ * Locates and returns the associated <code>ILaunchConfiguration</code> for the specified >+ * <code>ISelection</code>. This method can return <code>null</code>. >+ * @param selection the selection to search for a config for >+ * @return the associated <code>ILaunchConfiguration</code> or <code>null</code> if none found >+ * @since 3.3 >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(ISelection selection); >+ >+ /** >+ * Locates and returns the associated <code>ILaunchConfiguration</code> for the specified >+ * <code>IEditorPart</code>. This method can return <code>null</code>. >+ * @param editor the editor to search for the associated config for >+ * @return the associated <code>IlaunchConfiguration</code> or <code>null</code> if none found. >+ * @since 3.3 >+ */ >+ public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor); >+} >#P org.eclipse.jdt.debug.ui >Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java >=================================================================== >RCS file: ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java >diff -N ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java >--- ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java 4 Nov 2005 20:53:57 -0000 1.1 >+++ /dev/null 1 Jan 1970 00:00:00 -0000 >@@ -1,266 +0,0 @@ >-/******************************************************************************* >- * Copyright (c) 2005 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.jdt.internal.debug.ui.launcher; >- >- >-import java.util.ArrayList; >-import java.util.Collections; >-import java.util.List; >- >-import org.eclipse.core.runtime.CoreException; >-import org.eclipse.debug.core.DebugPlugin; >-import org.eclipse.debug.core.ILaunchConfiguration; >-import org.eclipse.debug.core.ILaunchConfigurationType; >-import org.eclipse.debug.core.ILaunchManager; >-import org.eclipse.debug.ui.DebugUITools; >-import org.eclipse.debug.ui.IDebugModelPresentation; >-import org.eclipse.debug.ui.ILaunchShortcut; >-import org.eclipse.jdt.core.IJavaElement; >-import org.eclipse.jdt.core.IType; >-import org.eclipse.jdt.core.JavaModelException; >-import org.eclipse.jdt.core.search.SearchEngine; >-import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; >-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >-import org.eclipse.jdt.ui.IJavaElementSearchConstants; >-import org.eclipse.jdt.ui.JavaUI; >-import org.eclipse.jface.dialogs.MessageDialog; >-import org.eclipse.jface.operation.IRunnableContext; >-import org.eclipse.jface.viewers.ISelection; >-import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.jface.window.Window; >-import org.eclipse.swt.widgets.Shell; >-import org.eclipse.ui.IEditorInput; >-import org.eclipse.ui.IEditorPart; >-import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.ElementListSelectionDialog; >-import org.eclipse.ui.dialogs.SelectionDialog; >- >-/** >- * Common behavior for Java launch shortcuts >- * >- * @since 3.2 >- */ >-public abstract class JavaLaunchShortcut implements ILaunchShortcut { >- >- /** >- * @param search the java elements to search for a main type >- * @param mode the mode to launch in >- * @param editor activated on an editor (or from a selection in a viewer) >- */ >- public void searchAndLaunch(Object[] search, String mode, String selectMessage, String emptyMessage) { >- IType[] types = null; >- try { >- types = findTypes(search, PlatformUI.getWorkbench().getProgressService()); >- } catch (InterruptedException e) { >- return; >- } catch (CoreException e) { >- MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_0, e.getMessage()); >- return; >- } >- IType type = null; >- if (types.length == 0) { >- MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_1, emptyMessage); >- } else if (types.length > 1) { >- try { >- type = chooseType(types, selectMessage); >- } catch (JavaModelException e) { >- reportErorr(e); >- return; >- } >- } else { >- type = types[0]; >- } >- if (type != null) { >- launch(type, mode); >- } >- } >- >- /** >- * Finds and returns the launchable types in the given selection of elements. >- * >- * @param elements scope to search for launchable types >- * @param context progess reporting context >- * @return launchable types, possibly empty >- * @exception InterruptedException if the search is cancelled >- * @exception org.eclipse.core.runtime.CoreException if the search fails >- */ >- protected abstract IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException; >- >- /** >- * Prompts the user to select a type from the given types. >- * >- * @param types the types to choose from >- * @param title the selection dialog title >- * >- * @return the selected type or <code>null</code> if none. >- */ >- protected IType chooseType(IType[] types, String title) throws JavaModelException { >- SelectionDialog dialog = JavaUI.createTypeDialog( >- getShell(), >- PlatformUI.getWorkbench().getProgressService(), >- SearchEngine.createJavaSearchScope(types), >- IJavaElementSearchConstants.CONSIDER_CLASSES, >- false, "**"); //$NON-NLS-1$ >- dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12); >- dialog.setTitle(title); >- if (dialog.open() == Window.OK) { >- return (IType)dialog.getResult()[0]; >- } >- return null; >- } >- >- /** >- * Launches a configuration for the given type >- */ >- protected void launch(IType type, String mode) { >- ILaunchConfiguration config = findLaunchConfiguration(type, getConfigurationType()); >- if (config != null) { >- DebugUITools.launch(config, mode); >- } >- } >- >- /** >- * Returns the type of configuration this shortcut is applicable to. >- * >- * @return the type of configuration this shortcut is applicable to >- */ >- protected abstract ILaunchConfigurationType getConfigurationType(); >- >- /** >- * Locate a configuration to relaunch for the given type. If one cannot be found, create one. >- * >- * @return a re-useable config or <code>null</code> if none >- */ >- protected ILaunchConfiguration findLaunchConfiguration(IType type, ILaunchConfigurationType configType) { >- List candidateConfigs = Collections.EMPTY_LIST; >- try { >- ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType); >- candidateConfigs = new ArrayList(configs.length); >- for (int i = 0; i < configs.length; i++) { >- ILaunchConfiguration config = configs[i]; >- if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "").equals(type.getFullyQualifiedName())) { //$NON-NLS-1$ >- if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "").equals(type.getJavaProject().getElementName())) { //$NON-NLS-1$ >- candidateConfigs.add(config); >- } >- } >- } >- } catch (CoreException e) { >- JDIDebugUIPlugin.log(e); >- } >- >- // If there are no existing configs associated with the IType, create one. >- // If there is exactly one config associated with the IType, return it. >- // Otherwise, if there is more than one config associated with the IType, prompt the >- // user to choose one. >- int candidateCount = candidateConfigs.size(); >- if (candidateCount < 1) { >- return createConfiguration(type); >- } else if (candidateCount == 1) { >- return (ILaunchConfiguration) candidateConfigs.get(0); >- } else { >- // Prompt the user to choose a config. A null result means the user >- // cancelled the dialog, in which case this method returns null, >- // since cancelling the dialog should also cancel launching anything. >- ILaunchConfiguration config = chooseConfiguration(candidateConfigs); >- if (config != null) { >- return config; >- } >- } >- >- return null; >- } >- >- /** >- * Show a selection dialog that allows the user to choose one of the specified >- * launch configurations. Return the chosen config, or <code>null</code> if the >- * user cancelled the dialog. >- */ >- protected ILaunchConfiguration chooseConfiguration(List configList) { >- IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation(); >- ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider); >- dialog.setElements(configList.toArray()); >- dialog.setTitle(getTypeSelectionTitle()); >- dialog.setMessage(LauncherMessages.JavaLaunchShortcut_2); >- dialog.setMultipleSelection(false); >- int result = dialog.open(); >- labelProvider.dispose(); >- if (result == Window.OK) { >- return (ILaunchConfiguration) dialog.getFirstResult(); >- } >- return null; >- } >- >- /** >- * Create and returns a new configuration based on the specified <code>IType</code>. >- */ >- protected abstract ILaunchConfiguration createConfiguration(IType type); >- >- /** >- * Opens an error dialog on the given excpetion. >- * >- * @param exception >- */ >- protected void reportErorr(CoreException exception) { >- MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage()); >- } >- >- protected ILaunchManager getLaunchManager() { >- return DebugPlugin.getDefault().getLaunchManager(); >- } >- >- /** >- * Convenience method to get the window that owns this action's Shell. >- */ >- protected Shell getShell() { >- return JDIDebugUIPlugin.getActiveWorkbenchShell(); >- } >- >- /** >- * @see ILaunchShortcut#launch(IEditorPart, String) >- */ >- public void launch(IEditorPart editor, String mode) { >- IEditorInput input = editor.getEditorInput(); >- IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class); >- if (je != null) { >- searchAndLaunch(new Object[] {je}, mode, getTypeSelectionTitle(), getEditorEmptyMessage()); >- } >- } >- >- /** >- * @see ILaunchShortcut#launch(ISelection, String) >- */ >- public void launch(ISelection selection, String mode) { >- if (selection instanceof IStructuredSelection) { >- searchAndLaunch(((IStructuredSelection)selection).toArray(), mode, getTypeSelectionTitle(), getSelectionEmptyMessage()); >- } >- } >- >- /** >- * Returns the title for type selection dialog for this launch shortcut. >- * >- * @return type selection dialog title >- */ >- protected abstract String getTypeSelectionTitle(); >- >- /** >- * Returns an error message to use when the editor does not contain a launchable type. >- * >- * @return error message >- */ >- protected abstract String getEditorEmptyMessage(); >- >- /** >- * Returns an error message to use when the selection does not contain a launchable type. >- * >- * @return error message >- */ >- protected abstract String getSelectionEmptyMessage(); >-} >Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties,v >retrieving revision 1.147 >diff -u -r1.147 LauncherMessages.properties >--- ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties 9 Aug 2006 17:24:11 -0000 1.147 >+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties 5 Dec 2006 22:27:09 -0000 >@@ -39,17 +39,17 @@ > > JavaMainTab_Choose_a_main__type_to_launch__12=Select &type (? = any character, * = any String, TZ = TimeZone): > JavaMainTab_Choose_Main_Type_11=Select Main Type >-JavaApplicationLaunchShortcut_0=Select Java Application > JavaApplicationLaunchShortcut_1=Editor does not contain a main type > JavaApplicationLaunchShortcut_2=Selection does not contain a main type >-JavaLaunchShortcut_0=Error >-JavaLaunchShortcut_1=Launch Error >+JavaApplicationLaunchShortcut_3=An error occurred during the creation of a new launch configuration. >+JavaLaunchShortcut_0=An error has occurred while searching for launchable types for the current selection. >+JavaLaunchShortcut_1=Type Selection Error > JavaLaunchShortcut_2=&Select existing configuration: > JavaLaunchShortcut_3=Error > >-JavaAppletLaunchShortcut_0=Select Java Applet > JavaAppletLaunchShortcut_1=Editor does not contain an applet > JavaAppletLaunchShortcut_2=Selection does not contain an applet >+JavaAppletLaunchShortcut_3=An error occurred during the creation of a new launch configuration. > JavaMainTab__Main_19=Main > JavaMainTab_E_xt__jars_6=Includ&e libraries when searching for a main class > JavaMainTab_Main_cla_ss__4=&Main class: >@@ -161,3 +161,8 @@ > AbstractJavaMainTab_2=&Search... > AbstractJavaMainTab_4=Project Selection > AbstractJavaMainTab_3=Select a project to constrain your search. >+AbstractJavaLaunchShortcut_0=Select Type >+AbstractJavaLaunchShortcut_1=The current context is not applicable to this launch shortcut. >+AbstractJavaLaunchShortcut_2=The current editor does not contain a launchable type. >+AbstractJavaLaunchShortcut_3=The current selection does not contain a launchable type. >+AbstractLaunchShortcut_1=Select {0} >Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java,v >retrieving revision 1.30 >diff -u -r1.30 JavaApplicationLaunchShortcut.java >--- ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java 8 May 2006 20:35:08 -0000 1.30 >+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java 5 Dec 2006 22:27:09 -0000 >@@ -21,18 +21,24 @@ > import org.eclipse.debug.core.ILaunchConfiguration; > import org.eclipse.debug.core.ILaunchConfigurationType; > import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; >+import org.eclipse.jdt.core.IClasspathEntry; > import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IJavaProject; > import org.eclipse.jdt.core.IMember; >+import org.eclipse.jdt.core.IPackageFragmentRoot; > import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.search.IJavaSearchScope; > import org.eclipse.jdt.core.search.SearchEngine; >+import org.eclipse.jdt.debug.ui.AbstractJavaLaunchShortcut; > import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >+import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.operation.IRunnableContext; > > /** > * Performs single click launching for local Java applications. > */ >-public class JavaApplicationLaunchShortcut extends JavaLaunchShortcut { >+public class JavaApplicationLaunchShortcut extends AbstractJavaLaunchShortcut { > > /** > * Returns the Java elements corresponding to the given objects. >@@ -54,7 +60,25 @@ > element= type; > } > } >- list.add(element); >+ // for projects consider only src and not external libs >+ if (element instanceof IJavaProject) { >+ IJavaProject project = (IJavaProject) element; >+ try { >+ IClasspathEntry[] cpEntries = project.getRawClasspath(); >+ for (int j = 0; j < cpEntries.length; j++) { >+ if (cpEntries[j].getEntryKind() == IClasspathEntry.CPE_SOURCE || cpEntries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) { >+ IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(cpEntries[j]); >+ for(int r = 0; r < roots.length; r++){ >+ list.add(roots[r]); >+ } >+ } >+ } >+ } >+ catch (JavaModelException jme) {} >+ } >+ else { >+ list.add(element); >+ } > } > } > } >@@ -75,7 +99,7 @@ > wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()}); > config = wc.doSave(); > } catch (CoreException exception) { >- reportErorr(exception); >+ MessageDialog.openError(getShell(), LauncherMessages.JavaApplicationLaunchShortcut_3, exception.getStatus().getMessage()); > } > return config; > } >@@ -87,36 +111,30 @@ > return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); > } > >+ /** >+ * @see org.eclipse.jdt.debug.ui.AbstractLaunchShortcut#findTypes(java.lang.Object[], org.eclipse.jface.operation.IRunnableContext) >+ */ > protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { > try { > IJavaElement[] javaElements = getJavaElements(elements); > MainMethodSearchEngine engine = new MainMethodSearchEngine(); > IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, false); > return engine.searchMainMethods(context, scope, true); >- } catch (InvocationTargetException e) { >- throw (CoreException)e.getTargetException(); >- } >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle() >- */ >- protected String getTypeSelectionTitle() { >- return LauncherMessages.JavaApplicationLaunchShortcut_0; >+ } >+ catch (InvocationTargetException e) {throw (CoreException)e.getTargetException();} > } > > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage() > */ >- protected String getEditorEmptyMessage() { >+ protected String getEditorNoTypeMessage() { > return LauncherMessages.JavaApplicationLaunchShortcut_1; > } > > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage() > */ >- protected String getSelectionEmptyMessage() { >+ protected String getSelectionNoTypeMessage() { > return LauncherMessages.JavaApplicationLaunchShortcut_2; > } >- > } >Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java,v >retrieving revision 1.19 >diff -u -r1.19 LauncherMessages.java >--- ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java 9 Aug 2006 17:24:11 -0000 1.19 >+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java 5 Dec 2006 22:27:09 -0000 >@@ -16,6 +16,18 @@ > public class LauncherMessages extends NLS { > private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages";//$NON-NLS-1$ > >+ public static String AbstractJavaLaunchShortcut_0; >+ >+ public static String AbstractJavaLaunchShortcut_1; >+ >+ public static String AbstractJavaLaunchShortcut_2; >+ >+ public static String AbstractJavaLaunchShortcut_3; >+ >+ public static String AbstractLaunchShortcut_1; >+ public static String JavaAppletLaunchShortcut_3; >+ public static String JavaApplicationLaunchShortcut_3; >+ > public static String JavaArgumentsTab_5; > public static String JavaArgumentsTab__Arguments_16; > public static String JavaArgumentsTab__Program_arguments__5; >@@ -163,11 +175,8 @@ > public static String SelectDefaultSystemLibraryQuickFix_Select_default_system_library_5; > > public static String AppletSelectionDialog_Searching____1; >- >- public static String JavaAppletLaunchShortcut_0; > public static String JavaAppletLaunchShortcut_1; > public static String JavaAppletLaunchShortcut_2; >- public static String JavaApplicationLaunchShortcut_0; > public static String JavaApplicationLaunchShortcut_1; > public static String JavaApplicationLaunchShortcut_2; > public static String JavaLaunchShortcut_0; >Index: ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java,v >retrieving revision 1.24 >diff -u -r1.24 JavaAppletLaunchShortcut.java >--- ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java 8 May 2006 20:35:08 -0000 1.24 >+++ ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java 5 Dec 2006 22:27:09 -0000 >@@ -18,13 +18,18 @@ > import org.eclipse.debug.core.ILaunchConfiguration; > import org.eclipse.debug.core.ILaunchConfigurationType; > import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; >-import org.eclipse.debug.core.ILaunchManager; > import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.debug.ui.AbstractJavaLaunchShortcut; > import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab; > import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >+import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.operation.IRunnableContext; > >-public class JavaAppletLaunchShortcut extends JavaLaunchShortcut { >+/** >+ * This class provides a concrete implementation of <code>AbstractLaunchShortcut</code> for >+ * Java Applets >+ */ >+public class JavaAppletLaunchShortcut extends AbstractJavaLaunchShortcut { > > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType) >@@ -41,8 +46,9 @@ > wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_NAME, ""); //$NON-NLS-1$ > wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()}); > config = wc.doSave(); >- } catch (CoreException ce) { >- reportErorr(ce); >+ } >+ catch (CoreException ce) { >+ MessageDialog.openError(getShell(), LauncherMessages.JavaAppletLaunchShortcut_3, ce.getStatus().getMessage()); > } > return config; > } >@@ -51,8 +57,7 @@ > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getConfigurationType() > */ > protected ILaunchConfigurationType getConfigurationType() { >- ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager(); >- return lm.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLET); >+ return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLET); > } > > /* (non-Javadoc) >@@ -61,29 +66,21 @@ > protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { > try { > return AppletLaunchConfigurationUtils.findApplets(context, elements); >- } catch (InvocationTargetException e) { >- throw (CoreException)e.getTargetException(); >- } >+ } >+ catch (InvocationTargetException e) {throw (CoreException)e.getTargetException();} > } > > /* (non-Javadoc) >- * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle() >- */ >- protected String getTypeSelectionTitle() { >- return LauncherMessages.JavaAppletLaunchShortcut_0; >- } >- >- /* (non-Javadoc) > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage() > */ >- protected String getEditorEmptyMessage() { >+ protected String getEditorNoTypeMessage() { > return LauncherMessages.JavaAppletLaunchShortcut_1; > } > > /* (non-Javadoc) > * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage() > */ >- protected String getSelectionEmptyMessage() { >+ protected String getSelectionNoTypeMessage() { > return LauncherMessages.JavaAppletLaunchShortcut_2; >- } >+ } > } >Index: ui/org/eclipse/jdt/debug/ui/AbstractJavaLaunchShortcut.java >=================================================================== >RCS file: ui/org/eclipse/jdt/debug/ui/AbstractJavaLaunchShortcut.java >diff -N ui/org/eclipse/jdt/debug/ui/AbstractJavaLaunchShortcut.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/jdt/debug/ui/AbstractJavaLaunchShortcut.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,200 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.jdt.debug.ui; >+ >+import java.util.ArrayList; >+import java.util.Collections; >+import java.util.List; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.debug.core.ILaunchConfiguration; >+import org.eclipse.debug.core.ILaunchConfigurationType; >+import org.eclipse.debug.ui.AbstractLaunchShortcut; >+import org.eclipse.jdt.core.IJavaElement; >+import org.eclipse.jdt.core.IType; >+import org.eclipse.jdt.core.search.SearchEngine; >+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; >+import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages; >+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; >+import org.eclipse.jdt.ui.IJavaElementSearchConstants; >+import org.eclipse.jdt.ui.JavaUI; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.operation.IRunnableContext; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.window.Window; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.dialogs.SelectionDialog; >+ >+/** >+ * <p> >+ * This class provides an extended implementation of an <code>AbstractLaunchShortcut</code>, providing >+ * java specific capabilities for launch shortcuts. >+ * </p> >+ * <p> >+ * Clients are only required to implement two methods: >+ * <ul> >+ * <li><code>createConfiguration</code>, which is called to create a new launch configuration in the event an >+ * existing one is not found</li> >+ * <li><code>findTypes</code>, which searches the specified context for applicable launchable java types</li> >+ * </ul> >+ * Although a default implementation is provided, the method <code>findLaunchConfiguration</code> should >+ * be over-ridden by clients, unless the default behavior is desired. >+ * </p> >+ * >+ * @since 3.3 >+ */ >+public abstract class AbstractJavaLaunchShortcut extends AbstractLaunchShortcut { >+ >+ /** >+ * Create and returns a new configuration based on the specified <code>IType</code>. >+ */ >+ protected abstract ILaunchConfiguration createConfiguration(IType type); >+ >+ /** >+ * Finds and returns the launchable <code>IType</code>s in the given selection of elements. >+ * >+ * @param elements scope to search for launchable types >+ * @param context progess reporting context >+ * @return launchable types, possibly empty >+ * @exception InterruptedException if the search is cancelled >+ * @exception org.eclipse.core.runtime.CoreException if the search fails >+ */ >+ protected abstract IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException; >+ >+ /** >+ * Prompts the user to select a type from the given types. >+ * >+ * @param types the types to choose from >+ * @param title the selection dialog title >+ * >+ * @return the selected type or <code>null</code> if none. >+ */ >+ protected IType chooseType(IType[] types, String title, String message) throws CoreException { >+ SelectionDialog dialog = JavaUI.createTypeDialog( >+ getShell(), >+ PlatformUI.getWorkbench().getProgressService(), >+ SearchEngine.createJavaSearchScope(types), >+ IJavaElementSearchConstants.CONSIDER_CLASSES, >+ false, "**"); //$NON-NLS-1$ >+ dialog.setMessage(message); >+ dialog.setTitle(title); >+ if (dialog.open() == Window.OK) { >+ return (IType)dialog.getResult()[0]; >+ } >+ return null; >+ } >+ >+ /** >+ * This method is used to find launch configurations that are asociated with the specified <code>IType</code> >+ * <p> >+ * By default this method will find launch configurations whose main type and project name match that of the >+ * the specified type (and it's project, if applicable). >+ * </p> >+ * <p> >+ * Clients should over-ride this method for their intended behavior >+ * </p> >+ * @param type the <code>IType</code> to look for luanhc configurations for >+ * @return a matching luanhc configuration or <code>null</code> if none found >+ */ >+ protected ILaunchConfiguration findLaunchConfiguration(IType type) { >+ ILaunchConfigurationType configType = getConfigurationType(); >+ List candidateConfigs = Collections.EMPTY_LIST; >+ try { >+ ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType); >+ candidateConfigs = new ArrayList(configs.length); >+ for (int i = 0; i < configs.length; i++) { >+ ILaunchConfiguration config = configs[i]; >+ if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "").equals(type.getFullyQualifiedName())) { //$NON-NLS-1$ >+ if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "").equals(type.getJavaProject().getElementName())) { //$NON-NLS-1$ >+ candidateConfigs.add(config); >+ } >+ } >+ } >+ } >+ catch (CoreException e) {JDIDebugUIPlugin.log(e);} >+ int candidateCount = candidateConfigs.size(); >+ if (candidateCount < 1) { >+ return createConfiguration(type); >+ } >+ else if (candidateCount == 1) { >+ return (ILaunchConfiguration) candidateConfigs.get(0); >+ } >+ else { >+ ILaunchConfiguration config = chooseConfiguration(candidateConfigs); >+ if (config != null) { >+ return config; >+ } >+ } >+ return null; >+ } >+ >+ /** >+ * @see org.eclipse.debug.ui.AbstractLaunchShortcut#findConfiguration(java.lang.Object[], boolean) >+ */ >+ protected ILaunchConfiguration findConfiguration(Object context, boolean editor) { >+ try { >+ Object[] items = null; >+ if(context instanceof IEditorPart) { >+ IEditorInput input = ((IEditorPart)context).getEditorInput(); >+ IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class); >+ items = new Object[] {je}; >+ } >+ else if(context instanceof StructuredSelection) { >+ items = ((StructuredSelection)context).toArray(); >+ } >+ if(items == null) { >+ MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, LauncherMessages.AbstractJavaLaunchShortcut_1); >+ return null; >+ } >+ IType[] types = findTypes(items, PlatformUI.getWorkbench().getProgressService()); >+ IType type = null; >+ if (types.length == 0) { >+ MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, (editor ? getEditorNoTypeMessage() : getSelectionNoTypeMessage())); >+ return null; >+ } >+ else if (types.length > 1) { >+ type = chooseType(types, LauncherMessages.AbstractJavaLaunchShortcut_0, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12); >+ } >+ else { >+ type = types[0]; >+ } >+ if(type != null) { >+ return findLaunchConfiguration(type); >+ } >+ } >+ catch(CoreException ce) { >+ MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, ce.getStatus().getMessage()); >+ JDIDebugUIPlugin.log(ce); >+ } >+ catch(InterruptedException ie) {JDIDebugUIPlugin.log(ie);} >+ return null; >+ } >+ >+ /** >+ * Returns an error message to use when the editor does not contain a launchable type. >+ * >+ * @return error message >+ */ >+ protected String getEditorNoTypeMessage() { >+ return LauncherMessages.AbstractJavaLaunchShortcut_2; >+ } >+ >+ /** >+ * Returns an error message to use when the selection does not contain a launchable type. >+ * >+ * @return error message >+ */ >+ protected String getSelectionNoTypeMessage() { >+ return LauncherMessages.AbstractJavaLaunchShortcut_3; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 89178
:
49870
|
55079
| 55080