Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 89178 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/actions/LaunchShortcutAction.java (-2 / +39 lines)
Lines 17-27 Link Here
17
import org.eclipse.core.expressions.Expression;
17
import org.eclipse.core.expressions.Expression;
18
import org.eclipse.core.expressions.IEvaluationContext;
18
import org.eclipse.core.expressions.IEvaluationContext;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.debug.core.ILaunchConfiguration;
20
import org.eclipse.debug.internal.ui.DebugUIPlugin;
21
import org.eclipse.debug.internal.ui.DebugUIPlugin;
21
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
22
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
23
import org.eclipse.debug.ui.DebugUITools;
22
import org.eclipse.jface.action.Action;
24
import org.eclipse.jface.action.Action;
23
import org.eclipse.jface.viewers.ISelection;
25
import org.eclipse.jface.viewers.ISelection;
24
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.jface.viewers.IStructuredSelection;
27
import org.eclipse.jface.viewers.StructuredSelection;
28
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.IEditorPart;
26
import org.eclipse.ui.IWorkbenchPage;
31
import org.eclipse.ui.IWorkbenchPage;
27
import org.eclipse.ui.IWorkbenchWindow;
32
import org.eclipse.ui.IWorkbenchWindow;
Lines 44-51 Link Here
44
		fShortcut = shortcut;
49
		fShortcut = shortcut;
45
		updateEnablement();
50
		updateEnablement();
46
	}
51
	}
47
	
48
	
49
52
50
	/**
53
	/**
51
	 * Runs with either the active editor or workbench selection.
54
	 * Runs with either the active editor or workbench selection.
Lines 72-77 Link Here
72
		}
75
		}
73
	}
76
	}
74
	
77
	
78
	/* (non-Javadoc)
79
	 * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
80
	 */
81
	public void runWithEvent(Event event) {
82
		if ((event.stateMask & SWT.MOD1) > 0) {
83
			IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow();
84
			ILaunchConfiguration config = null;
85
			if (wb != null) {
86
				IWorkbenchPage page = wb.getActivePage();
87
				if (page != null) {
88
					if (page.getActivePart() == page.getActiveEditor()) {
89
						IEditorPart editor = page.getActiveEditor();
90
						if (editor != null) {
91
							config = fShortcut.getLaunchConfiguration(editor);
92
						}
93
					} else {
94
						ISelection selection = page.getSelection();
95
						if (selection instanceof IStructuredSelection) {
96
							config = fShortcut.getLaunchConfiguration(selection);
97
						}
98
					}
99
				}
100
			}
101
			if(config != null) {
102
				IStructuredSelection selection = new StructuredSelection(config);
103
				String id = DebugUITools.getLaunchGroup(config, fMode).getIdentifier();
104
				DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, id);
105
				return;
106
			}
107
		} 
108
		//anything fails, run it
109
		run();
110
	}
111
75
	/**
112
	/**
76
	 * Since these actions are re-created each time the run/debug as menu is
113
	 * Since these actions are re-created each time the run/debug as menu is
77
	 * filled, the enablement of this action is static.
114
	 * filled, the enablement of this action is static.
(-)ui/org/eclipse/debug/internal/ui/actions/SharedLaunchConfigAction.java (+18 lines)
Lines 11-19 Link Here
11
package org.eclipse.debug.internal.ui.actions;
11
package org.eclipse.debug.internal.ui.actions;
12
12
13
import org.eclipse.debug.core.ILaunchConfiguration;
13
import org.eclipse.debug.core.ILaunchConfiguration;
14
import org.eclipse.debug.internal.ui.DebugUIPlugin;
14
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.debug.ui.DebugUITools;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.resource.ImageDescriptor;
17
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Event;
17
22
18
/**
23
/**
19
 * This class provides an action warpper for adding shared launch configuration actions to the context menu
24
 * This class provides an action warpper for adding shared launch configuration actions to the context menu
Lines 51-55 Link Here
51
	public void run() {
56
	public void run() {
52
		DebugUITools.launch(fConfig, fMode);
57
		DebugUITools.launch(fConfig, fMode);
53
	}
58
	}
59
	
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.jface.action.Action#runWithEvent(org.eclipse.swt.widgets.Event)
62
	 */
63
	public void runWithEvent(Event event) {
64
		if ((event.stateMask & SWT.MOD1) > 0) {
65
			IStructuredSelection selection = new StructuredSelection(getLaunchConfiguration());
66
			String id = DebugUITools.getLaunchGroup(getLaunchConfiguration(), fMode).getIdentifier();
67
			DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), selection, id);
68
		} else {
69
			run();
70
		}
71
	}
54
72
55
}
73
}
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java (-1 / +41 lines)
Lines 29-38 Link Here
29
import org.eclipse.core.expressions.IEvaluationContext;
29
import org.eclipse.core.expressions.IEvaluationContext;
30
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IConfigurationElement;
31
import org.eclipse.core.runtime.IConfigurationElement;
32
import org.eclipse.debug.core.ILaunchConfiguration;
32
import org.eclipse.debug.internal.ui.DebugUIPlugin;
33
import org.eclipse.debug.internal.ui.DebugUIPlugin;
33
import org.eclipse.debug.internal.ui.Pair;
34
import org.eclipse.debug.internal.ui.Pair;
34
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
35
import org.eclipse.debug.internal.ui.actions.LaunchShortcutAction;
35
import org.eclipse.debug.ui.ILaunchShortcut;
36
import org.eclipse.debug.ui.ILaunchShortcut;
37
import org.eclipse.debug.ui.ILaunchShortcut2;
36
import org.eclipse.jface.resource.ImageDescriptor;
38
import org.eclipse.jface.resource.ImageDescriptor;
37
import org.eclipse.jface.viewers.ISelection;
39
import org.eclipse.jface.viewers.ISelection;
38
import org.eclipse.jface.viewers.StructuredSelection;
40
import org.eclipse.jface.viewers.StructuredSelection;
Lines 45-51 Link Here
45
/**
47
/**
46
 * Proxy to a launch shortcut extension
48
 * Proxy to a launch shortcut extension
47
 */
49
 */
48
public class LaunchShortcutExtension implements ILaunchShortcut, IPluginContribution {
50
public class LaunchShortcutExtension implements IPluginContribution {
49
	
51
	
50
	private ImageDescriptor fImageDescriptor = null;
52
	private ImageDescriptor fImageDescriptor = null;
51
	private List fPerspectives = null;
53
	private List fPerspectives = null;
Lines 421-425 Link Here
421
	public String getPluginId() {
423
	public String getPluginId() {
422
		return fConfig.getContributor().getName();
424
		return fConfig.getContributor().getName();
423
	}
425
	}
426
427
	/**
428
	 * This method returns the associated <code>ILaunchConfiguration</code> for this
429
	 * view part selection, or <code>null</code> if there isn't one, or access to the launch configuration
430
	 * is not supported
431
	 * @param selection the current view part selection
432
	 * @return the asscoiated launch configuration or <code>null</code> if none or access is not supported
433
	 * 
434
	 * @since 3.3
435
	 */
436
	public ILaunchConfiguration getLaunchConfiguration(ISelection selection) {
437
		if(fDelegate == null) {
438
			getDelegate();
439
		}
440
		if(fDelegate instanceof ILaunchShortcut2) { 
441
			return ((ILaunchShortcut2)fDelegate).getLaunchConfiguration(selection);
442
		}
443
		return null;
444
	}
445
446
	/**
447
	 * This method returns the associated <code>ILaunchConfiguration</code> for this
448
	 * editor part, or <code>null</code> if there isn't one, or access to the launch configuration
449
	 * is not supported
450
	 * @param editor the current editor part context
451
	 * @return the associated launch configuration or <code>null</code> if none or access is not supported
452
	 * 
453
	 * @since 3.3
454
	 */
455
	public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor) {
456
		if(fDelegate == null) {
457
			getDelegate();
458
		}
459
		if(fDelegate instanceof ILaunchShortcut2) {
460
			return ((ILaunchShortcut2)fDelegate).getLaunchConfiguration(editor);
461
		}
462
		return null;
463
	}
424
}
464
}
425
465
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.properties (+2 lines)
Lines 181-183 Link Here
181
SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use when multiple launchers are available for a configuration and launch mode.
181
SelectLaunchersDialog_2=This dialog allows you to specify which launcher to use when multiple launchers are available for a configuration and launch mode.
182
SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a>
182
SelectLaunchersDialog_4=<a href="ws">Change Workspace Settings...</a>
183
SelectLaunchersDialog_5=Description
183
SelectLaunchersDialog_5=Description
184
AbstractLaunchShortcut_0=Select {0}
185
AbstractLaunchShortcut_1=&Select existing configuration:
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationsMessages.java (+4 lines)
Lines 15-20 Link Here
15
public class LaunchConfigurationsMessages extends NLS {
15
public class LaunchConfigurationsMessages extends NLS {
16
	private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages";//$NON-NLS-1$
16
	private static final String BUNDLE_NAME = "org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages";//$NON-NLS-1$
17
17
18
	public static String AbstractLaunchShortcut_0;
19
20
	public static String AbstractLaunchShortcut_1;
21
18
	public static String CommonTab__Browse_6;
22
	public static String CommonTab__Browse_6;
19
	public static String CommonTab__Common_15;
23
	public static String CommonTab__Common_15;
20
	public static String CommonTab_Display_in_favorites_menu__10;
24
	public static String CommonTab_Display_in_favorites_menu__10;
(-)ui/org/eclipse/debug/ui/AbstractLaunchShortcut.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui;
12
13
import java.util.List;
14
15
import org.eclipse.debug.core.DebugPlugin;
16
import org.eclipse.debug.core.ILaunchConfiguration;
17
import org.eclipse.debug.core.ILaunchConfigurationType;
18
import org.eclipse.debug.core.ILaunchManager;
19
import org.eclipse.debug.internal.ui.DebugUIPlugin;
20
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsMessages;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.window.Window;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
26
27
import com.ibm.icu.text.MessageFormat;
28
29
/**
30
 * <p>
31
 * This class provides a base implementation of an <code>ILaunchShortcut</code>, including the new 
32
 * <code>ILaunchShortcut2</code>, providing support for Ctrl+clicking the shortcut to quick edit
33
 * associated launch configurations.
34
 * </p>
35
 * 
36
 * <p>
37
 * Clients are only required to implement two methods:
38
 * <ul>
39
 * <li><code>findConfiguration</code>, which is used to find an existing launch configuration to use or 
40
 * create a new one as needed</li>
41
 * <li><code>getConfigurationType</code>, which returns the <code>ILaunchConfigurationType</code> that this 
42
 * launch shorcut applies to</li>
43
 * </ul>
44
 * </p>
45
 * 
46
 * @since 3.3
47
 */
48
public abstract class AbstractLaunchShortcut implements ILaunchShortcut2 {
49
50
	/**
51
	 * Returns the type of configuration this shortcut is applicable to.
52
	 * 
53
	 * @return the type of configuration this shortcut is applicable to
54
	 */
55
	protected abstract ILaunchConfigurationType getConfigurationType();
56
	
57
	/**
58
	 * Searches for the associated launch configuration for the specified items, if one is not found
59
	 * a new configuration should be created.
60
	 * @param context the currently selected context, which is typically from within an editor part or a structured view selection
61
	 * @param mode the mode to constrain to 
62
	 * @param editor true if activated on an editor, false if activated from a selection in a viewer
63
	 * @return the associated launch configuraiton or null if none found
64
	 */
65
	protected abstract ILaunchConfiguration findConfiguration(Object context, boolean editor);
66
	
67
	/**
68
	 * Show a selection dialog that allows the user to choose one of the specified
69
	 * launch configurations.  Return the chosen config, or <code>null</code> if the
70
	 * user cancelled the dialog.
71
	 */
72
	protected ILaunchConfiguration chooseConfiguration(List configList) {
73
		IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
74
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
75
		dialog.setElements(configList.toArray());
76
		dialog.setTitle(getConfigurationSelectionTitle());  
77
		dialog.setMessage(getConfigurationSelectionMessage());
78
		dialog.setMultipleSelection(false);
79
		int result = dialog.open();
80
		labelProvider.dispose();
81
		if (result == Window.OK) {
82
			return (ILaunchConfiguration) dialog.getFirstResult();
83
		}
84
		return null;		
85
	}
86
	
87
	/**
88
	 * Convenience method to get the window that owns this action's Shell.
89
	 * This method should be over-loaded to provide the appropriate shell for the launch shortcut
90
	 */
91
	protected Shell getShell() {
92
		return DebugUIPlugin.getActiveWorkbenchWindow().getShell();
93
	}
94
	
95
	/**
96
	 * Returns the title text for the type selection dialog
97
	 * @return the title text for the type selection dialog
98
	 */
99
	protected String getConfigurationSelectionTitle() {
100
		return MessageFormat.format(LaunchConfigurationsMessages.AbstractLaunchShortcut_0, new String[] {getConfigurationType().getName()});
101
	}
102
	
103
	/**
104
	 * Returns the message for the launch configuration selection dialog
105
	 * @return the message for the launch configuration selection dialog
106
	 */
107
	protected String getConfigurationSelectionMessage() {
108
		return LaunchConfigurationsMessages.AbstractLaunchShortcut_1;
109
	}
110
	
111
	/**
112
	 * returns the launch manager
113
	 * @return the launch mananger
114
	 */
115
	protected ILaunchManager getLaunchManager() {
116
		return DebugPlugin.getDefault().getLaunchManager();
117
	}
118
119
	/**
120
	 * @see org.eclipse.debug.ui.ILaunchShortcut2#getLaunchConfiguration(org.eclipse.jface.viewers.ISelection)
121
	 */
122
	public ILaunchConfiguration getLaunchConfiguration(ISelection selection) {
123
		return findConfiguration(selection, false);
124
	}
125
126
	/**
127
	 * @see ILaunchShortcut#launch(ISelection, String)
128
	 */
129
	public void launch(ISelection selection, String mode) {
130
		searchAndLaunch(selection, mode, false);
131
	}
132
	
133
	/**
134
	 * @see org.eclipse.debug.ui.ILaunchShortcut2#getLaunchConfiguration(org.eclipse.ui.IEditorPart)
135
	 */
136
	public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor) {
137
		return findConfiguration(editor, true);
138
	}
139
	
140
	/**
141
	 * @see ILaunchShortcut#launch(IEditorPart, String)
142
	 */
143
	public void launch(IEditorPart editor, String mode) {
144
		searchAndLaunch(editor, mode, true);
145
	}
146
	
147
	/**
148
	 * Searches for and launches a launch configuration for the specified objects.
149
	 * <p>
150
	 * This method uses the method <code>findTypes</code> to find the types of concern taht might be launched.
151
	 * It is up to implementors to decide how types are found and how launch configurations are created.
152
	 * </p>
153
	 * @param context the currently selected context, which is typically from within an editor part or a structured view selection
154
	 * @param mode the mode to launch in
155
	 * @param editor true if activated on an editor, false if activated from a selection in a viewer
156
	 */
157
	protected void searchAndLaunch(Object context, String mode, boolean editor) {
158
		ILaunchConfiguration config = findConfiguration(context, editor);
159
		if(config != null) {
160
			DebugUITools.launch(config, mode);
161
		}
162
	}	
163
164
}
(-)ui/org/eclipse/debug/ui/ILaunchShortcut2.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui;
12
13
import org.eclipse.debug.core.ILaunchConfiguration;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.ui.IEditorPart;
16
17
/**
18
 * Provides new capabilities to have access to the associated <code>ILaunchCongfiguration</code>.
19
 * This interface is intended to be used in the event your launch shortcut will provide access to 
20
 * the <code>LaunchConfigurationsDialog</code> via the Ctrl+Click mechanism in the Run->... menu
21
 * @since 3.3
22
 */
23
public interface ILaunchShortcut2 extends ILaunchShortcut {
24
	
25
	/**
26
	 * Locates and returns the associated <code>ILaunchConfiguration</code> for the specified
27
	 * <code>ISelection</code>. This method can return <code>null</code>.
28
	 * @param selection the selection to search for a config for
29
	 * @return the associated <code>ILaunchConfiguration</code> or <code>null</code> if none found
30
	 * @since 3.3
31
	 */
32
	public ILaunchConfiguration getLaunchConfiguration(ISelection selection);
33
	
34
	/**
35
	 * Locates and returns the associated <code>ILaunchConfiguration</code> for the specified
36
	 * <code>IEditorPart</code>. This method can return <code>null</code>.
37
	 * @param editor the editor to search for the associated config for
38
	 * @return the associated <code>IlaunchConfiguration</code> or <code>null</code> if none found.
39
	 * @since 3.3
40
	 */
41
	public ILaunchConfiguration getLaunchConfiguration(IEditorPart editor);
42
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaLaunchShortcut.java (-266 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.debug.ui.launcher;
12
13
 
14
import java.util.ArrayList;
15
import java.util.Collections;
16
import java.util.List;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationType;
22
import org.eclipse.debug.core.ILaunchManager;
23
import org.eclipse.debug.ui.DebugUITools;
24
import org.eclipse.debug.ui.IDebugModelPresentation;
25
import org.eclipse.debug.ui.ILaunchShortcut;
26
import org.eclipse.jdt.core.IJavaElement;
27
import org.eclipse.jdt.core.IType;
28
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.core.search.SearchEngine;
30
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
31
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
32
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
33
import org.eclipse.jdt.ui.JavaUI;
34
import org.eclipse.jface.dialogs.MessageDialog;
35
import org.eclipse.jface.operation.IRunnableContext;
36
import org.eclipse.jface.viewers.ISelection;
37
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.jface.window.Window;
39
import org.eclipse.swt.widgets.Shell;
40
import org.eclipse.ui.IEditorInput;
41
import org.eclipse.ui.IEditorPart;
42
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
44
import org.eclipse.ui.dialogs.SelectionDialog;
45
46
/**
47
 * Common behavior for Java launch shortcuts
48
 * 
49
 * @since 3.2
50
 */
51
public abstract class JavaLaunchShortcut implements ILaunchShortcut {
52
	
53
	/**
54
	 * @param search the java elements to search for a main type
55
	 * @param mode the mode to launch in
56
	 * @param editor activated on an editor (or from a selection in a viewer)
57
	 */
58
	public void searchAndLaunch(Object[] search, String mode, String selectMessage, String emptyMessage) {
59
		IType[] types = null;
60
		try {
61
			types = findTypes(search, PlatformUI.getWorkbench().getProgressService());
62
		} catch (InterruptedException e) {
63
			return;
64
		} catch (CoreException e) {
65
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_0, e.getMessage()); 
66
			return;
67
		}
68
		IType type = null;
69
		if (types.length == 0) {
70
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_1, emptyMessage); 
71
		} else if (types.length > 1) {
72
			try {
73
				type = chooseType(types, selectMessage);
74
			} catch (JavaModelException e) {
75
				reportErorr(e); 
76
				return;
77
			}
78
		} else {
79
			type = types[0];
80
		}
81
		if (type != null) {
82
			launch(type, mode);
83
		}
84
	}	
85
	
86
	/**
87
	 * Finds and returns the launchable types in the given selection of elements.
88
	 * 
89
	 * @param elements scope to search for launchable types
90
	 * @param context progess reporting context
91
	 * @return launchable types, possibly empty
92
	 * @exception InterruptedException if the search is cancelled
93
	 * @exception org.eclipse.core.runtime.CoreException if the search fails
94
	 */
95
	protected abstract IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException;
96
97
	/**
98
	 * Prompts the user to select a type from the given types.
99
	 * 
100
	 * @param types the types to choose from
101
	 * @param title the selection dialog title
102
	 * 
103
	 * @return the selected type or <code>null</code> if none.
104
	 */
105
	protected IType chooseType(IType[] types, String title) throws JavaModelException {
106
		SelectionDialog dialog = JavaUI.createTypeDialog(
107
				getShell(),
108
				PlatformUI.getWorkbench().getProgressService(), 
109
				SearchEngine.createJavaSearchScope(types), 
110
				IJavaElementSearchConstants.CONSIDER_CLASSES, 
111
				false, "**"); //$NON-NLS-1$
112
		dialog.setMessage(LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
113
		dialog.setTitle(title);
114
		if (dialog.open() == Window.OK) {
115
			return (IType)dialog.getResult()[0];
116
		}
117
		return null;
118
	}
119
	
120
	/**
121
	 * Launches a configuration for the given type
122
	 */
123
	protected void launch(IType type, String mode) {
124
		ILaunchConfiguration config = findLaunchConfiguration(type, getConfigurationType());
125
		if (config != null) {
126
			DebugUITools.launch(config, mode);
127
		}			
128
	}
129
	
130
	/**
131
	 * Returns the type of configuration this shortcut is applicable to.
132
	 * 
133
	 * @return the type of configuration this shortcut is applicable to
134
	 */
135
	protected abstract ILaunchConfigurationType getConfigurationType();
136
	
137
	/**
138
	 * Locate a configuration to relaunch for the given type.  If one cannot be found, create one.
139
	 * 
140
	 * @return a re-useable config or <code>null</code> if none
141
	 */
142
	protected ILaunchConfiguration findLaunchConfiguration(IType type, ILaunchConfigurationType configType) {
143
		List candidateConfigs = Collections.EMPTY_LIST;
144
		try {
145
			ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType);
146
			candidateConfigs = new ArrayList(configs.length);
147
			for (int i = 0; i < configs.length; i++) {
148
				ILaunchConfiguration config = configs[i];
149
				if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "").equals(type.getFullyQualifiedName())) { //$NON-NLS-1$
150
					if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "").equals(type.getJavaProject().getElementName())) { //$NON-NLS-1$
151
						candidateConfigs.add(config);
152
					}
153
				}
154
			}
155
		} catch (CoreException e) {
156
			JDIDebugUIPlugin.log(e);
157
		}
158
		
159
		// If there are no existing configs associated with the IType, create one.
160
		// If there is exactly one config associated with the IType, return it.
161
		// Otherwise, if there is more than one config associated with the IType, prompt the
162
		// user to choose one.
163
		int candidateCount = candidateConfigs.size();
164
		if (candidateCount < 1) {
165
			return createConfiguration(type);
166
		} else if (candidateCount == 1) {
167
			return (ILaunchConfiguration) candidateConfigs.get(0);
168
		} else {
169
			// Prompt the user to choose a config.  A null result means the user
170
			// cancelled the dialog, in which case this method returns null,
171
			// since cancelling the dialog should also cancel launching anything.
172
			ILaunchConfiguration config = chooseConfiguration(candidateConfigs);
173
			if (config != null) {
174
				return config;
175
			}
176
		}
177
		
178
		return null;
179
	}
180
	
181
	/**
182
	 * Show a selection dialog that allows the user to choose one of the specified
183
	 * launch configurations.  Return the chosen config, or <code>null</code> if the
184
	 * user cancelled the dialog.
185
	 */
186
	protected ILaunchConfiguration chooseConfiguration(List configList) {
187
		IDebugModelPresentation labelProvider = DebugUITools.newDebugModelPresentation();
188
		ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), labelProvider);
189
		dialog.setElements(configList.toArray());
190
		dialog.setTitle(getTypeSelectionTitle());  
191
		dialog.setMessage(LauncherMessages.JavaLaunchShortcut_2);
192
		dialog.setMultipleSelection(false);
193
		int result = dialog.open();
194
		labelProvider.dispose();
195
		if (result == Window.OK) {
196
			return (ILaunchConfiguration) dialog.getFirstResult();
197
		}
198
		return null;		
199
	}
200
	
201
	/**
202
	 * Create and returns a new configuration based on the specified <code>IType</code>.
203
	 */
204
	protected abstract ILaunchConfiguration createConfiguration(IType type);
205
	
206
	/**
207
	 * Opens an error dialog on the given excpetion.
208
	 * 
209
	 * @param exception
210
	 */
211
	protected void reportErorr(CoreException exception) {
212
		MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, exception.getStatus().getMessage());  
213
	}
214
	
215
	protected ILaunchManager getLaunchManager() {
216
		return DebugPlugin.getDefault().getLaunchManager();
217
	}
218
	
219
	/**
220
	 * Convenience method to get the window that owns this action's Shell.
221
	 */
222
	protected Shell getShell() {
223
		return JDIDebugUIPlugin.getActiveWorkbenchShell();
224
	}
225
	
226
	/**
227
	 * @see ILaunchShortcut#launch(IEditorPart, String)
228
	 */
229
	public void launch(IEditorPart editor, String mode) {
230
		IEditorInput input = editor.getEditorInput();
231
		IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class);
232
		if (je != null) {
233
			searchAndLaunch(new Object[] {je}, mode, getTypeSelectionTitle(), getEditorEmptyMessage());
234
		}
235
	}
236
237
	/**
238
	 * @see ILaunchShortcut#launch(ISelection, String)
239
	 */
240
	public void launch(ISelection selection, String mode) {
241
		if (selection instanceof IStructuredSelection) {
242
			searchAndLaunch(((IStructuredSelection)selection).toArray(), mode, getTypeSelectionTitle(), getSelectionEmptyMessage());
243
		}
244
	}
245
246
	/**
247
	 * Returns the title for type selection dialog for this launch shortcut.
248
	 * 
249
	 * @return type selection dialog title
250
	 */
251
	protected abstract String getTypeSelectionTitle();
252
	
253
	/**
254
	 * Returns an error message to use when the editor does not contain a launchable type.
255
	 * 
256
	 * @return error message
257
	 */
258
	protected abstract String getEditorEmptyMessage();	
259
	
260
	/**
261
	 * Returns an error message to use when the selection does not contain a launchable type.
262
	 * 
263
	 * @return error message
264
	 */
265
	protected abstract String getSelectionEmptyMessage();		
266
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties (-4 / +9 lines)
Lines 39-55 Link Here
39
39
40
JavaMainTab_Choose_a_main__type_to_launch__12=Select &type (? = any character, * = any String, TZ = TimeZone):
40
JavaMainTab_Choose_a_main__type_to_launch__12=Select &type (? = any character, * = any String, TZ = TimeZone):
41
JavaMainTab_Choose_Main_Type_11=Select Main Type
41
JavaMainTab_Choose_Main_Type_11=Select Main Type
42
JavaApplicationLaunchShortcut_0=Select Java Application
43
JavaApplicationLaunchShortcut_1=Editor does not contain a main type
42
JavaApplicationLaunchShortcut_1=Editor does not contain a main type
44
JavaApplicationLaunchShortcut_2=Selection does not contain a main type
43
JavaApplicationLaunchShortcut_2=Selection does not contain a main type
45
JavaLaunchShortcut_0=Error
44
JavaApplicationLaunchShortcut_3=An error occurred during the creation of a new launch configuration.
46
JavaLaunchShortcut_1=Launch Error
45
JavaLaunchShortcut_0=An error has occurred while searching for launchable types for the current selection.  
46
JavaLaunchShortcut_1=Type Selection Error
47
JavaLaunchShortcut_2=&Select existing configuration:
47
JavaLaunchShortcut_2=&Select existing configuration:
48
JavaLaunchShortcut_3=Error
48
JavaLaunchShortcut_3=Error
49
49
50
JavaAppletLaunchShortcut_0=Select Java Applet
51
JavaAppletLaunchShortcut_1=Editor does not contain an applet
50
JavaAppletLaunchShortcut_1=Editor does not contain an applet
52
JavaAppletLaunchShortcut_2=Selection does not contain an applet
51
JavaAppletLaunchShortcut_2=Selection does not contain an applet
52
JavaAppletLaunchShortcut_3=An error occurred during the creation of a new launch configuration.
53
JavaMainTab__Main_19=Main
53
JavaMainTab__Main_19=Main
54
JavaMainTab_E_xt__jars_6=Includ&e libraries when searching for a main class
54
JavaMainTab_E_xt__jars_6=Includ&e libraries when searching for a main class
55
JavaMainTab_Main_cla_ss__4=&Main class:
55
JavaMainTab_Main_cla_ss__4=&Main class:
Lines 161-163 Link Here
161
AbstractJavaMainTab_2=&Search...
161
AbstractJavaMainTab_2=&Search...
162
AbstractJavaMainTab_4=Project Selection
162
AbstractJavaMainTab_4=Project Selection
163
AbstractJavaMainTab_3=Select a project to constrain your search.
163
AbstractJavaMainTab_3=Select a project to constrain your search.
164
AbstractJavaLaunchShortcut_0=Select Type
165
AbstractJavaLaunchShortcut_1=The current context is not applicable to this launch shortcut.
166
AbstractJavaLaunchShortcut_2=The current editor does not contain a launchable type.
167
AbstractJavaLaunchShortcut_3=The current selection does not contain a launchable type.
168
AbstractLaunchShortcut_1=Select {0}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java (-16 / +34 lines)
Lines 21-38 Link Here
21
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchConfigurationType;
22
import org.eclipse.debug.core.ILaunchConfigurationType;
23
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
24
import org.eclipse.jdt.core.IClasspathEntry;
24
import org.eclipse.jdt.core.IJavaElement;
25
import org.eclipse.jdt.core.IJavaElement;
26
import org.eclipse.jdt.core.IJavaProject;
25
import org.eclipse.jdt.core.IMember;
27
import org.eclipse.jdt.core.IMember;
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
26
import org.eclipse.jdt.core.IType;
29
import org.eclipse.jdt.core.IType;
30
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.core.search.IJavaSearchScope;
31
import org.eclipse.jdt.core.search.IJavaSearchScope;
28
import org.eclipse.jdt.core.search.SearchEngine;
32
import org.eclipse.jdt.core.search.SearchEngine;
33
import org.eclipse.jdt.debug.ui.AbstractJavaLaunchShortcut;
29
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
34
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
35
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.operation.IRunnableContext;
36
import org.eclipse.jface.operation.IRunnableContext;
31
37
32
/**
38
/**
33
 * Performs single click launching for local Java applications.
39
 * Performs single click launching for local Java applications.
34
 */
40
 */
35
public class JavaApplicationLaunchShortcut extends JavaLaunchShortcut {
41
public class JavaApplicationLaunchShortcut extends AbstractJavaLaunchShortcut {
36
	
42
	
37
	/**
43
	/**
38
	 * Returns the Java elements corresponding to the given objects.
44
	 * Returns the Java elements corresponding to the given objects.
Lines 54-60 Link Here
54
							element= type;
60
							element= type;
55
						}
61
						}
56
					}
62
					}
57
					list.add(element);
63
					// for projects consider only src and not external libs
64
					if (element instanceof IJavaProject) {
65
						IJavaProject project = (IJavaProject) element;
66
						try {
67
							IClasspathEntry[] cpEntries = project.getRawClasspath();
68
							for (int j = 0; j < cpEntries.length; j++) {
69
								if (cpEntries[j].getEntryKind() == IClasspathEntry.CPE_SOURCE || cpEntries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
70
									IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(cpEntries[j]);
71
									for(int r = 0; r < roots.length; r++){
72
										list.add(roots[r]);
73
									}
74
								}
75
							}
76
						} 
77
						catch (JavaModelException jme) {}
78
					} 
79
					else {
80
						list.add(element);
81
					}
58
				}
82
				}
59
			}
83
			}
60
		}
84
		}
Lines 75-81 Link Here
75
			wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()});
99
			wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()});
76
			config = wc.doSave();
100
			config = wc.doSave();
77
		} catch (CoreException exception) {
101
		} catch (CoreException exception) {
78
			reportErorr(exception);		
102
			MessageDialog.openError(getShell(), LauncherMessages.JavaApplicationLaunchShortcut_3, exception.getStatus().getMessage());		
79
		} 
103
		} 
80
		return config;
104
		return config;
81
	}
105
	}
Lines 87-122 Link Here
87
		return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);		
111
		return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);		
88
	}
112
	}
89
113
114
	/**
115
	 * @see org.eclipse.jdt.debug.ui.AbstractLaunchShortcut#findTypes(java.lang.Object[], org.eclipse.jface.operation.IRunnableContext)
116
	 */
90
	protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException {
117
	protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException {
91
		try {
118
		try {
92
			IJavaElement[] javaElements = getJavaElements(elements);
119
			IJavaElement[] javaElements = getJavaElements(elements);
93
			MainMethodSearchEngine engine = new MainMethodSearchEngine();
120
			MainMethodSearchEngine engine = new MainMethodSearchEngine();
94
			IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, false);
121
			IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, false);
95
			return engine.searchMainMethods(context, scope, true);
122
			return engine.searchMainMethods(context, scope, true);
96
		} catch (InvocationTargetException e) {
123
		} 
97
			throw (CoreException)e.getTargetException(); 
124
		catch (InvocationTargetException e) {throw (CoreException)e.getTargetException();}
98
		}
99
	}
100
101
	/* (non-Javadoc)
102
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle()
103
	 */
104
	protected String getTypeSelectionTitle() {
105
		return LauncherMessages.JavaApplicationLaunchShortcut_0;
106
	}
125
	}
107
126
108
	/* (non-Javadoc)
127
	/* (non-Javadoc)
109
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage()
128
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage()
110
	 */
129
	 */
111
	protected String getEditorEmptyMessage() {
130
	protected String getEditorNoTypeMessage() {
112
		return LauncherMessages.JavaApplicationLaunchShortcut_1;
131
		return LauncherMessages.JavaApplicationLaunchShortcut_1;
113
	}
132
	}
114
133
115
	/* (non-Javadoc)
134
	/* (non-Javadoc)
116
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage()
135
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage()
117
	 */
136
	 */
118
	protected String getSelectionEmptyMessage() {
137
	protected String getSelectionNoTypeMessage() {
119
		return LauncherMessages.JavaApplicationLaunchShortcut_2;
138
		return LauncherMessages.JavaApplicationLaunchShortcut_2;
120
	}
139
	}
121
	
122
}
140
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java (-3 / +12 lines)
Lines 16-21 Link Here
16
public class LauncherMessages extends NLS {
16
public class LauncherMessages extends NLS {
17
	private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages";//$NON-NLS-1$
17
	private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages";//$NON-NLS-1$
18
18
19
	public static String AbstractJavaLaunchShortcut_0;
20
21
	public static String AbstractJavaLaunchShortcut_1;
22
23
	public static String AbstractJavaLaunchShortcut_2;
24
25
	public static String AbstractJavaLaunchShortcut_3;
26
27
	public static String AbstractLaunchShortcut_1;
28
	public static String JavaAppletLaunchShortcut_3;
29
	public static String JavaApplicationLaunchShortcut_3;
30
19
	public static String JavaArgumentsTab_5;
31
	public static String JavaArgumentsTab_5;
20
	public static String JavaArgumentsTab__Arguments_16;
32
	public static String JavaArgumentsTab__Arguments_16;
21
	public static String JavaArgumentsTab__Program_arguments__5;
33
	public static String JavaArgumentsTab__Program_arguments__5;
Lines 163-173 Link Here
163
	public static String SelectDefaultSystemLibraryQuickFix_Select_default_system_library_5;
175
	public static String SelectDefaultSystemLibraryQuickFix_Select_default_system_library_5;
164
176
165
	public static String AppletSelectionDialog_Searching____1;
177
	public static String AppletSelectionDialog_Searching____1;
166
	
167
	public static String JavaAppletLaunchShortcut_0;
168
	public static String JavaAppletLaunchShortcut_1;
178
	public static String JavaAppletLaunchShortcut_1;
169
	public static String JavaAppletLaunchShortcut_2;
179
	public static String JavaAppletLaunchShortcut_2;
170
	public static String JavaApplicationLaunchShortcut_0;
171
	public static String JavaApplicationLaunchShortcut_1;
180
	public static String JavaApplicationLaunchShortcut_1;
172
	public static String JavaApplicationLaunchShortcut_2;
181
	public static String JavaApplicationLaunchShortcut_2;
173
	public static String JavaLaunchShortcut_0;
182
	public static String JavaLaunchShortcut_0;
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java (-19 / +16 lines)
Lines 18-30 Link Here
18
import org.eclipse.debug.core.ILaunchConfiguration;
18
import org.eclipse.debug.core.ILaunchConfiguration;
19
import org.eclipse.debug.core.ILaunchConfigurationType;
19
import org.eclipse.debug.core.ILaunchConfigurationType;
20
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
20
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
21
import org.eclipse.debug.core.ILaunchManager;
22
import org.eclipse.jdt.core.IType;
21
import org.eclipse.jdt.core.IType;
22
import org.eclipse.jdt.debug.ui.AbstractJavaLaunchShortcut;
23
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
23
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
24
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
24
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
25
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.operation.IRunnableContext;
26
import org.eclipse.jface.operation.IRunnableContext;
26
27
27
public class JavaAppletLaunchShortcut extends JavaLaunchShortcut {
28
/**
29
 * This class provides a concrete implementation of <code>AbstractLaunchShortcut</code> for 
30
 * Java Applets
31
 */
32
public class JavaAppletLaunchShortcut extends AbstractJavaLaunchShortcut {
28
	
33
	
29
	/* (non-Javadoc)
34
	/* (non-Javadoc)
30
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType)
35
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType)
Lines 41-48 Link Here
41
			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_NAME, ""); //$NON-NLS-1$
46
			wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_APPLET_NAME, ""); //$NON-NLS-1$
42
			wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()});
47
			wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()});
43
			config = wc.doSave();		
48
			config = wc.doSave();		
44
		} catch (CoreException ce) {
49
		} 
45
			reportErorr(ce);			
50
		catch (CoreException ce) {
51
			MessageDialog.openError(getShell(), LauncherMessages.JavaAppletLaunchShortcut_3, ce.getStatus().getMessage());			
46
		}
52
		}
47
		return config;
53
		return config;
48
	}
54
	}
Lines 51-58 Link Here
51
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getConfigurationType()
57
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getConfigurationType()
52
	 */
58
	 */
53
	protected ILaunchConfigurationType getConfigurationType() {
59
	protected ILaunchConfigurationType getConfigurationType() {
54
		ILaunchManager lm= DebugPlugin.getDefault().getLaunchManager();
60
		return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLET);		
55
		return lm.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLET);		
56
	}
61
	}
57
62
58
	/* (non-Javadoc)
63
	/* (non-Javadoc)
Lines 61-89 Link Here
61
	protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException {
66
	protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException {
62
		try {
67
		try {
63
			return AppletLaunchConfigurationUtils.findApplets(context, elements);
68
			return AppletLaunchConfigurationUtils.findApplets(context, elements);
64
		} catch (InvocationTargetException e) {
69
		} 
65
			throw (CoreException)e.getTargetException();
70
		catch (InvocationTargetException e) {throw (CoreException)e.getTargetException();}
66
		}
67
	}	
71
	}	
68
72
69
	/* (non-Javadoc)
73
	/* (non-Javadoc)
70
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle()
71
	 */
72
	protected String getTypeSelectionTitle() {
73
		return LauncherMessages.JavaAppletLaunchShortcut_0;
74
	}
75
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage()
74
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage()
78
	 */
75
	 */
79
	protected String getEditorEmptyMessage() {
76
	protected String getEditorNoTypeMessage() {
80
		return LauncherMessages.JavaAppletLaunchShortcut_1;
77
		return LauncherMessages.JavaAppletLaunchShortcut_1;
81
	}
78
	}
82
79
83
	/* (non-Javadoc)
80
	/* (non-Javadoc)
84
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage()
81
	 * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage()
85
	 */
82
	 */
86
	protected String getSelectionEmptyMessage() {
83
	protected String getSelectionNoTypeMessage() {
87
		return LauncherMessages.JavaAppletLaunchShortcut_2;
84
		return LauncherMessages.JavaAppletLaunchShortcut_2;
88
	}	
85
	}
89
}
86
}
(-)ui/org/eclipse/jdt/debug/ui/AbstractJavaLaunchShortcut.java (+200 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.debug.ui;
12
13
import java.util.ArrayList;
14
import java.util.Collections;
15
import java.util.List;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.debug.core.ILaunchConfiguration;
19
import org.eclipse.debug.core.ILaunchConfigurationType;
20
import org.eclipse.debug.ui.AbstractLaunchShortcut;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IType;
23
import org.eclipse.jdt.core.search.SearchEngine;
24
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
25
import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages;
26
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
27
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
28
import org.eclipse.jdt.ui.JavaUI;
29
import org.eclipse.jface.dialogs.MessageDialog;
30
import org.eclipse.jface.operation.IRunnableContext;
31
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.window.Window;
33
import org.eclipse.ui.IEditorInput;
34
import org.eclipse.ui.IEditorPart;
35
import org.eclipse.ui.PlatformUI;
36
import org.eclipse.ui.dialogs.SelectionDialog;
37
38
/**
39
 * <p>
40
 * This class provides an extended implementation of an <code>AbstractLaunchShortcut</code>, providing
41
 * java specific capabilities for launch shortcuts.
42
 * </p>
43
 * <p>
44
 * Clients are only required to implement two methods:
45
 * <ul>
46
 * <li><code>createConfiguration</code>, which is called to create a new launch configuration in the event an
47
 * existing one is not found</li>
48
 * <li><code>findTypes</code>, which searches the specified context for applicable launchable java types</li> 
49
 * </ul>
50
 * Although a default implementation is provided, the method <code>findLaunchConfiguration</code> should
51
 * be over-ridden by clients, unless the default behavior is desired. 
52
 * </p>
53
 * 
54
 *  @since 3.3
55
 */
56
public abstract class AbstractJavaLaunchShortcut extends AbstractLaunchShortcut {
57
	
58
	/**
59
	 * Create and returns a new configuration based on the specified <code>IType</code>.
60
	 */
61
	protected abstract ILaunchConfiguration createConfiguration(IType type);
62
	
63
	/**
64
	 * Finds and returns the launchable <code>IType</code>s in the given selection of elements.
65
	 * 
66
	 * @param elements scope to search for launchable types
67
	 * @param context progess reporting context
68
	 * @return launchable types, possibly empty
69
	 * @exception InterruptedException if the search is cancelled
70
	 * @exception org.eclipse.core.runtime.CoreException if the search fails
71
	 */
72
	protected abstract IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException;
73
	
74
	/**
75
	 * Prompts the user to select a type from the given types.
76
	 * 
77
	 * @param types the types to choose from
78
	 * @param title the selection dialog title
79
	 * 
80
	 * @return the selected type or <code>null</code> if none.
81
	 */
82
	protected IType chooseType(IType[] types, String title, String message) throws CoreException {
83
		SelectionDialog dialog = JavaUI.createTypeDialog(
84
				getShell(),
85
				PlatformUI.getWorkbench().getProgressService(), 
86
				SearchEngine.createJavaSearchScope(types), 
87
				IJavaElementSearchConstants.CONSIDER_CLASSES, 
88
				false, "**"); //$NON-NLS-1$
89
		dialog.setMessage(message);
90
		dialog.setTitle(title);
91
		if (dialog.open() == Window.OK) {
92
			return (IType)dialog.getResult()[0];
93
		}
94
		return null;
95
	}
96
97
	/**
98
	 * This method is used to find launch configurations that are asociated with the specified <code>IType</code>
99
	 * <p>
100
	 * By default this method will find launch configurations whose main type and project name match that of the 
101
	 * the specified type (and it's project, if applicable).
102
	 * </p>
103
	 * <p>
104
	 * Clients should over-ride this method for their intended behavior
105
	 * </p>
106
	 * @param type the <code>IType</code> to look for luanhc configurations for
107
	 * @return a matching luanhc configuration or <code>null</code> if none found
108
	 */
109
	protected ILaunchConfiguration findLaunchConfiguration(IType type) {
110
		ILaunchConfigurationType configType = getConfigurationType();
111
		List candidateConfigs = Collections.EMPTY_LIST;
112
		try {
113
			ILaunchConfiguration[] configs = getLaunchManager().getLaunchConfigurations(configType);
114
			candidateConfigs = new ArrayList(configs.length);
115
			for (int i = 0; i < configs.length; i++) {
116
				ILaunchConfiguration config = configs[i];
117
				if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "").equals(type.getFullyQualifiedName())) { //$NON-NLS-1$
118
					if (config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "").equals(type.getJavaProject().getElementName())) { //$NON-NLS-1$
119
						candidateConfigs.add(config);
120
					}
121
				}
122
			}
123
		} 
124
		catch (CoreException e) {JDIDebugUIPlugin.log(e);}
125
		int candidateCount = candidateConfigs.size();
126
		if (candidateCount < 1) {
127
			return createConfiguration(type);
128
		} 
129
		else if (candidateCount == 1) {
130
			return (ILaunchConfiguration) candidateConfigs.get(0);
131
		} 
132
		else {
133
			ILaunchConfiguration config = chooseConfiguration(candidateConfigs);
134
			if (config != null) {
135
				return config;
136
			}
137
		}
138
		return null;
139
	}
140
	
141
	/**
142
	 * @see org.eclipse.debug.ui.AbstractLaunchShortcut#findConfiguration(java.lang.Object[], boolean)
143
	 */
144
	protected ILaunchConfiguration findConfiguration(Object context, boolean editor) {
145
		try {
146
			Object[] items = null;
147
			if(context instanceof IEditorPart) {
148
				IEditorInput input = ((IEditorPart)context).getEditorInput();
149
				IJavaElement je = (IJavaElement) input.getAdapter(IJavaElement.class);
150
				items = new Object[] {je};
151
			}
152
			else if(context instanceof StructuredSelection) {
153
				items = ((StructuredSelection)context).toArray();
154
			}
155
			if(items == null) {
156
				MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, LauncherMessages.AbstractJavaLaunchShortcut_1);
157
				return null;
158
			}
159
			IType[] types = findTypes(items, PlatformUI.getWorkbench().getProgressService());
160
			IType type = null;
161
			if (types.length == 0) {
162
				MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, (editor ? getEditorNoTypeMessage() : getSelectionNoTypeMessage()));
163
				return null;
164
			} 
165
			else if (types.length > 1) {
166
				type = chooseType(types, LauncherMessages.AbstractJavaLaunchShortcut_0, LauncherMessages.JavaMainTab_Choose_a_main__type_to_launch__12);
167
			} 
168
			else {
169
				type = types[0];
170
			}
171
			if(type != null) {
172
				return findLaunchConfiguration(type);
173
			}
174
		}
175
		catch(CoreException ce) {
176
			MessageDialog.openError(getShell(), LauncherMessages.JavaLaunchShortcut_3, ce.getStatus().getMessage());
177
			JDIDebugUIPlugin.log(ce);
178
		}
179
		catch(InterruptedException ie) {JDIDebugUIPlugin.log(ie);}
180
		return null;
181
	}
182
	
183
	/**
184
	 * Returns an error message to use when the editor does not contain a launchable type.
185
	 * 
186
	 * @return error message
187
	 */
188
	protected String getEditorNoTypeMessage() {
189
		return LauncherMessages.AbstractJavaLaunchShortcut_2;
190
	}
191
	
192
	/**
193
	 * Returns an error message to use when the selection does not contain a launchable type.
194
	 * 
195
	 * @return error message
196
	 */
197
	protected String getSelectionNoTypeMessage() {
198
		return LauncherMessages.AbstractJavaLaunchShortcut_3;
199
	}
200
}

Return to bug 89178