|
11 | 11 | package net.sf.j2s.ui.launching; |
12 | 12 |
|
13 | 13 |
|
14 | | -import java.lang.reflect.InvocationTargetException; |
15 | | -import java.util.ArrayList; |
16 | | -import java.util.List; |
17 | | - |
18 | | -import org.eclipse.core.resources.IResource; |
19 | | -import org.eclipse.core.runtime.CoreException; |
20 | | -import org.eclipse.core.runtime.IAdaptable; |
21 | 14 | import org.eclipse.debug.core.DebugPlugin; |
22 | | -import org.eclipse.debug.core.ILaunchConfiguration; |
23 | 15 | import org.eclipse.debug.core.ILaunchConfigurationType; |
24 | | -import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
25 | | -import org.eclipse.debug.core.Launch; |
26 | | -import org.eclipse.debug.core.model.ISourceLocator; |
27 | | -import org.eclipse.debug.core.model.IStackFrame; |
28 | | -import org.eclipse.debug.internal.ui.DebugUIMessages; |
29 | | -import org.eclipse.debug.ui.DebugUITools; |
30 | | -import org.eclipse.jdt.core.IJavaElement; |
31 | | -import org.eclipse.jdt.core.IMember; |
32 | | -import org.eclipse.jdt.core.IType; |
33 | | -import org.eclipse.jdt.core.search.IJavaSearchScope; |
34 | | -import org.eclipse.jdt.core.search.SearchEngine; |
35 | | -import org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut; |
36 | | -import org.eclipse.jdt.internal.debug.ui.launcher.LauncherMessages; |
37 | | -import org.eclipse.jdt.internal.debug.ui.launcher.MainMethodSearchEngine; |
38 | | -import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
39 | | -import org.eclipse.jface.operation.IRunnableContext; |
| 16 | +import org.eclipse.debug.core.ILaunchManager; |
| 17 | +import org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut; |
40 | 18 |
|
41 | 19 | /** |
42 | 20 | * Performs single click launching for local Java applications. |
43 | 21 | */ |
44 | | -public class J2SApplicationLaunchShortcut extends JavaLaunchShortcut { |
45 | | - |
46 | | - /** |
47 | | - * Returns the Java elements corresponding to the given objects. |
48 | | - * |
49 | | - * @param objects selected objects |
50 | | - * @return corresponding Java elements |
51 | | - */ |
52 | | - private IJavaElement[] getJavaElements(Object[] objects) { |
53 | | - List list= new ArrayList(objects.length); |
54 | | - for (int i = 0; i < objects.length; i++) { |
55 | | - Object object = objects[i]; |
56 | | - if (object instanceof IAdaptable) { |
57 | | - IJavaElement element = (IJavaElement) ((IAdaptable)object).getAdapter(IJavaElement.class); |
58 | | - if (element != null) { |
59 | | - if (element instanceof IMember) { |
60 | | - // Use the declaring type if available |
61 | | - IJavaElement type= ((IMember)element).getDeclaringType(); |
62 | | - if (type != null) { |
63 | | - element= type; |
64 | | - } |
65 | | - } |
66 | | - list.add(element); |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - return (IJavaElement[]) list.toArray(new IJavaElement[list.size()]); |
71 | | - } |
72 | | - |
73 | | - /* (non-Javadoc) |
74 | | - * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#createConfiguration(org.eclipse.jdt.core.IType) |
75 | | - */ |
76 | | - protected ILaunchConfiguration createConfiguration(IType type) { |
77 | | - ILaunchConfiguration config = null; |
78 | | - ILaunchConfigurationWorkingCopy wc = null; |
79 | | - try { |
80 | | - ILaunchConfigurationType configType = getConfigurationType(); |
81 | | - wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(type.getElementName())); |
82 | | - wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, type.getFullyQualifiedName()); |
83 | | - wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, type.getJavaProject().getElementName()); |
84 | | - wc.setMappedResources(new IResource[] {type.getJavaProject().getProject()}); |
85 | | - config = wc.doSave(); |
86 | | - } catch (CoreException exception) { |
87 | | - reportErorr(exception); |
88 | | - } |
89 | | - return config; |
90 | | - } |
| 22 | +public class J2SApplicationLaunchShortcut extends JavaApplicationLaunchShortcut { |
91 | 23 |
|
92 | 24 | /* (non-Javadoc) |
93 | 25 | * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getConfigurationType() |
94 | 26 | */ |
95 | 27 | protected ILaunchConfigurationType getConfigurationType() { |
96 | | -// return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); |
| 28 | + //return getLaunchManager().getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); |
97 | 29 | return getLaunchManager().getLaunchConfigurationType("net.sf.j2s.ui.launching.j2sApplication");//IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION); |
98 | 30 | } |
99 | | - |
100 | | - protected IType[] findTypes(Object[] elements, IRunnableContext context) throws InterruptedException, CoreException { |
101 | | - try { |
102 | | - IJavaElement[] javaElements = getJavaElements(elements); |
103 | | - MainMethodSearchEngine engine = new MainMethodSearchEngine(); |
104 | | - IJavaSearchScope scope = SearchEngine.createJavaSearchScope(javaElements, false); |
105 | | - return engine.searchMainMethods(context, scope, true); |
106 | | - } catch (InvocationTargetException e) { |
107 | | - throw (CoreException)e.getTargetException(); |
108 | | - } |
109 | | - } |
110 | | - |
111 | | - /* (non-Javadoc) |
112 | | - * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getTypeSelectionTitle() |
113 | | - */ |
114 | | - protected String getTypeSelectionTitle() { |
115 | | - return LauncherMessages.JavaApplicationLaunchShortcut_0; |
116 | | - } |
117 | | - |
118 | | - /* (non-Javadoc) |
119 | | - * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getEditorEmptyMessage() |
120 | | - */ |
121 | | - protected String getEditorEmptyMessage() { |
122 | | - return LauncherMessages.JavaApplicationLaunchShortcut_1; |
123 | | - } |
124 | | - |
125 | | - /* (non-Javadoc) |
126 | | - * @see org.eclipse.jdt.internal.debug.ui.launcher.JavaLaunchShortcut#getSelectionEmptyMessage() |
127 | | - */ |
128 | | - protected String getSelectionEmptyMessage() { |
129 | | - return LauncherMessages.JavaApplicationLaunchShortcut_2; |
130 | | - } |
131 | 31 |
|
132 | 32 | /** |
133 | | - * Launches a configuration for the given type |
| 33 | + * Returns the singleton launch manager. |
| 34 | + * |
| 35 | + * @return launch manager |
134 | 36 | */ |
135 | | - protected void launch(IType type, String mode) { |
136 | | - ILaunchConfiguration config = findLaunchConfiguration(type, getConfigurationType()); |
137 | | - if (config != null) { |
138 | | - DebugUITools.launch(config, mode); |
139 | | - } |
| 37 | + private ILaunchManager getLaunchManager() { |
| 38 | + return DebugPlugin.getDefault().getLaunchManager(); |
140 | 39 | } |
141 | | - |
| 40 | + |
142 | 41 | } |
0 commit comments