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 18338 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+4 lines)
Lines 168-173 Link Here
168
vmPageName=Runtime JRE
168
vmPageName=Runtime JRE
169
169
170
JavaApplicationShortcut.label=Java Application
170
JavaApplicationShortcut.label=Java Application
171
ContextualRunJavaApplication.label=Run Java Application
172
ContextualDebugJavaApplication.label=Debug Java Application
171
173
172
jreSystemLibrary.name=JRE System Library
174
jreSystemLibrary.name=JRE System Library
173
175
Lines 194-199 Link Here
194
ThreadView.tooltip=Switch to Thread View
196
ThreadView.tooltip=Switch to Thread View
195
197
196
AppletShortcut.label=Java Applet
198
AppletShortcut.label=Java Applet
199
ContextualRunJavaApplet.label=Run Java Applet
200
ContextualDebugJavaApplet.label=Debug Java Applet
197
201
198
ActionDefinition.localJavaShortcut.name=Run as Java Application
202
ActionDefinition.localJavaShortcut.name=Run as Java Application
199
ActionDefinition.localJavaShortcut.description=Attempts to run the currently selected element as a Java application
203
ActionDefinition.localJavaShortcut.description=Attempts to run the currently selected element as a Java application
(-)plugin.xml (+26 lines)
Lines 1973-1980 Link Here
1973
            icon="icons/full/ctool16/java_app.gif"
1973
            icon="icons/full/ctool16/java_app.gif"
1974
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
1974
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_local_java_application"
1975
            modes="run, debug"
1975
            modes="run, debug"
1976
            filterClass="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1976
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1977
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaApplicationLaunchShortcut"
1977
            id="org.eclipse.jdt.debug.ui.localJavaShortcut">
1978
            id="org.eclipse.jdt.debug.ui.localJavaShortcut">
1979
         <contextLabel
1980
         	mode="run"
1981
         	label="%ContextualRunJavaApplication.label"/>
1982
  		 <contextLabel
1983
  		 	mode="debug"
1984
  		 	label="%ContextualDebugJavaApplication.label"/>
1985
         <filter
1986
            name="NameMatches"
1987
            value="*.java"/>
1988
         <filter
1989
         	name="ContextualLaunchActionFilter"
1990
         	value="supportsContextualLaunch"/>
1978
         <perspective
1991
         <perspective
1979
               id="org.eclipse.jdt.ui.JavaPerspective">
1992
               id="org.eclipse.jdt.ui.JavaPerspective">
1980
         </perspective>
1993
         </perspective>
Lines 1993-2000 Link Here
1993
            icon="icons/full/ctool16/java_applet.gif"
2006
            icon="icons/full/ctool16/java_applet.gif"
1994
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_java_applet"
2007
            helpContextId="org.eclipse.jdt.debug.ui.shortcut_java_applet"
1995
            modes="run, debug"
2008
            modes="run, debug"
2009
            filterClass="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
1996
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
2010
            class="org.eclipse.jdt.internal.debug.ui.launcher.JavaAppletLaunchShortcut"
1997
            id="org.eclipse.jdt.debug.ui.javaAppletShortcut">
2011
            id="org.eclipse.jdt.debug.ui.javaAppletShortcut">
2012
         <filter
2013
            name="NameMatches"
2014
            value="*.java"/>
2015
         <filter
2016
         	name="ContextualLaunchActionFilter"
2017
         	value="supportsContextualLaunch"/>
2018
         <contextLabel
2019
         	mode="run"
2020
         	label="%ContextualRunJavaApplet.label"/>
2021
  		 <contextLabel
2022
  		 	mode="debug"
2023
  		 	label="%ContextualDebugJavaApplet.label"/>
1998
         <perspective
2024
         <perspective
1999
               id="org.eclipse.jdt.ui.JavaPerspective">
2025
               id="org.eclipse.jdt.ui.JavaPerspective">
2000
         </perspective>
2026
         </perspective>
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/AppletLaunchConfigurationUtils.java (-1 / +1 lines)
Lines 129-135 Link Here
129
		return result;
129
		return result;
130
	}
130
	}
131
	
131
	
132
	private static void collectTypes(Object element, IProgressMonitor monitor, Set result) throws JavaModelException/*, InvocationTargetException*/ {
132
	public static void collectTypes(Object element, IProgressMonitor monitor, Set result) throws JavaModelException/*, InvocationTargetException*/ {
133
		element= computeScope(element);
133
		element= computeScope(element);
134
		while((element instanceof IJavaElement) && !(element instanceof ICompilationUnit) && (element instanceof ISourceReference)) {
134
		while((element instanceof IJavaElement) && !(element instanceof ICompilationUnit) && (element instanceof ISourceReference)) {
135
			if(element instanceof IType) {
135
			if(element instanceof IType) {
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaAppletLaunchShortcut.java (-3 / +57 lines)
Lines 13-21 Link Here
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.Collections;
15
import java.util.Collections;
16
import java.util.HashSet;
16
import java.util.List;
17
import java.util.List;
18
import java.util.Set;
17
19
20
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.debug.core.DebugPlugin;
23
import org.eclipse.debug.core.DebugPlugin;
20
import org.eclipse.debug.core.ILaunchConfiguration;
24
import org.eclipse.debug.core.ILaunchConfiguration;
21
import org.eclipse.debug.core.ILaunchConfigurationType;
25
import org.eclipse.debug.core.ILaunchConfigurationType;
Lines 26-50 Link Here
26
import org.eclipse.debug.ui.ILaunchShortcut;
30
import org.eclipse.debug.ui.ILaunchShortcut;
27
import org.eclipse.jdt.core.IJavaElement;
31
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IType;
32
import org.eclipse.jdt.core.IType;
33
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
34
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
30
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
35
import org.eclipse.jdt.debug.ui.launchConfigurations.AppletParametersTab;
31
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
36
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
37
import org.eclipse.jdt.internal.debug.ui.console.StringMatcher;
32
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
38
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
33
import org.eclipse.jdt.ui.JavaElementLabelProvider;
39
import org.eclipse.jdt.ui.JavaElementLabelProvider;
34
import org.eclipse.jface.dialogs.MessageDialog;
40
import org.eclipse.jface.dialogs.MessageDialog;
35
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
36
import org.eclipse.jface.viewers.ISelection;
41
import org.eclipse.jface.viewers.ISelection;
37
import org.eclipse.jface.viewers.IStructuredSelection;
42
import org.eclipse.jface.viewers.IStructuredSelection;
38
import org.eclipse.jface.viewers.StructuredSelection;
43
import org.eclipse.jface.viewers.StructuredSelection;
39
import org.eclipse.jface.window.Window;
44
import org.eclipse.jface.window.Window;
40
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.swt.widgets.Shell;
46
import org.eclipse.ui.IActionFilter;
41
import org.eclipse.ui.IEditorInput;
47
import org.eclipse.ui.IEditorInput;
42
import org.eclipse.ui.IEditorPart;
48
import org.eclipse.ui.IEditorPart;
43
import org.eclipse.ui.IWorkbenchPage;
49
import org.eclipse.ui.IWorkbenchPage;
44
import org.eclipse.ui.IWorkbenchWindow;
50
import org.eclipse.ui.IWorkbenchWindow;
45
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
51
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
52
import org.eclipse.ui.editors.text.WorkspaceOperationRunner;
46
53
47
public class JavaAppletLaunchShortcut implements ILaunchShortcut {
54
public class JavaAppletLaunchShortcut implements ILaunchShortcut, IActionFilter {
48
55
49
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
56
	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
50
57
Lines 53-59 Link Here
53
60
54
		if (search != null) {
61
		if (search != null) {
55
			try {
62
			try {
56
				types = AppletLaunchConfigurationUtils.findApplets(new ProgressMonitorDialog(getShell()), search);
63
				types = AppletLaunchConfigurationUtils.findApplets(new WorkspaceOperationRunner(), search);
57
			} catch (InterruptedException e) {
64
			} catch (InterruptedException e) {
58
				JDIDebugUIPlugin.log(e);
65
				JDIDebugUIPlugin.log(e);
59
				return;
66
				return;
Lines 261-264 Link Here
261
		}
268
		}
262
		return (IStructuredSelection)selection;
269
		return (IStructuredSelection)selection;
263
	}
270
	}
271
	/* (non-Javadoc)
272
	 * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
273
	 */
274
	public boolean testAttribute(Object target, String name, String value) {
275
		if ("ContextualLaunchActionFilter".equals(name)) {
276
			return isApplet(target);
277
			// return false;
278
		} else if ("NameMatches".equals(name)) {
279
			return nameMatches(target, value);
280
		}
281
		return false;
282
	}
283
	
284
	/**
285
	 * @param target
286
	 * @param value
287
	 * @return
288
	 */
289
	private boolean nameMatches(Object target, String value) {
290
		try {
291
			Object[] selections = ((IStructuredSelection) target).toArray();
292
			IResource resource = (IResource) selections[0];
293
			String filename = resource.getName();
294
			StringMatcher sm = new StringMatcher(value, true, false);
295
			return sm.match(filename);
296
		} catch (ClassCastException e) {
297
			return false;
298
		}
299
	}
300
	
301
	private boolean isApplet(Object target) {
302
		if (target != null && target instanceof IStructuredSelection) {
303
			Object[] selections = ((IStructuredSelection )target).toArray();
304
			IResource resource = (IResource)selections[0];
305
			IType[] types= null;
306
				try {
307
					final Set result= new HashSet();
308
					AppletLaunchConfigurationUtils.collectTypes(resource, new NullProgressMonitor(), result);
309
					if (result.size() > 0) {
310
						return true;
311
					}
312
				} catch (JavaModelException e) {
313
					return false;
314
				}
315
			}
316
		return false;
317
		}
264
}
318
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/JavaApplicationLaunchShortcut.java (-1 / +89 lines)
Lines 14-22 Link Here
14
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.InvocationTargetException;
15
import java.util.ArrayList;
15
import java.util.ArrayList;
16
import java.util.Collections;
16
import java.util.Collections;
17
import java.util.HashSet;
17
import java.util.List;
18
import java.util.List;
19
import java.util.Set;
18
20
21
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.runtime.CoreException;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.debug.core.DebugPlugin;
24
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.ILaunchConfiguration;
25
import org.eclipse.debug.core.ILaunchConfiguration;
22
import org.eclipse.debug.core.ILaunchConfigurationType;
26
import org.eclipse.debug.core.ILaunchConfigurationType;
Lines 25-34 Link Here
25
import org.eclipse.debug.ui.DebugUITools;
29
import org.eclipse.debug.ui.DebugUITools;
26
import org.eclipse.debug.ui.IDebugModelPresentation;
30
import org.eclipse.debug.ui.IDebugModelPresentation;
27
import org.eclipse.debug.ui.ILaunchShortcut;
31
import org.eclipse.debug.ui.ILaunchShortcut;
32
import org.eclipse.jdt.core.IClassFile;
33
import org.eclipse.jdt.core.ICompilationUnit;
28
import org.eclipse.jdt.core.IJavaElement;
34
import org.eclipse.jdt.core.IJavaElement;
29
import org.eclipse.jdt.core.IType;
35
import org.eclipse.jdt.core.IType;
36
import org.eclipse.jdt.core.JavaCore;
37
import org.eclipse.jdt.core.JavaModelException;
38
import org.eclipse.jdt.core.Signature;
30
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
39
import org.eclipse.jdt.debug.ui.JavaUISourceLocator;
40
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
31
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
41
import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
42
import org.eclipse.jdt.internal.debug.ui.console.StringMatcher;
32
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
43
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
33
import org.eclipse.jface.dialogs.ErrorDialog;
44
import org.eclipse.jface.dialogs.ErrorDialog;
34
import org.eclipse.jface.dialogs.MessageDialog;
45
import org.eclipse.jface.dialogs.MessageDialog;
Lines 38-43 Link Here
38
import org.eclipse.jface.window.Window;
49
import org.eclipse.jface.window.Window;
39
import org.eclipse.swt.widgets.Display;
50
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Shell;
51
import org.eclipse.swt.widgets.Shell;
52
import org.eclipse.ui.IActionFilter;
41
import org.eclipse.ui.IEditorInput;
53
import org.eclipse.ui.IEditorInput;
42
import org.eclipse.ui.IEditorPart;
54
import org.eclipse.ui.IEditorPart;
43
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
55
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
Lines 45-51 Link Here
45
/**
57
/**
46
 * Performs single click launching for local Java applications.
58
 * Performs single click launching for local Java applications.
47
 */
59
 */
48
public class JavaApplicationLaunchShortcut implements ILaunchShortcut {
60
public class JavaApplicationLaunchShortcut implements ILaunchShortcut, IActionFilter {
49
	
61
	
50
	/**
62
	/**
51
	 * @param search the java elements to search for a main type
63
	 * @param search the java elements to search for a main type
Lines 258-261 Link Here
258
		}
270
		}
259
	}
271
	}
260
272
273
	/* (non-Javadoc)
274
	 * @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String)
275
	 */
276
	public boolean testAttribute(Object target, String name, String value) {
277
		if ("ContextualLaunchActionFilter".equals(name)) {
278
			return hasMain2(target);
279
		} else if ("NameMatches".equals(name)) {
280
			return nameMatches(target, value);
281
		}
282
		return false;
283
	}
284
	
285
	/**
286
	 * @param target
287
	 * @param value
288
	 * @return
289
	 */
290
	private boolean nameMatches(Object target, String value) {
291
		try {
292
			Object[] selections = ((IStructuredSelection) target).toArray();
293
			IResource resource = (IResource) selections[0];
294
			String filename = resource.getName();
295
			StringMatcher sm = new StringMatcher(value, true, false);
296
			return sm.match(filename);
297
		} catch (ClassCastException e) {
298
			return false;
299
		}
300
	}
301
302
	private boolean hasMain(Object target) {
303
		if (target != null && target instanceof IStructuredSelection) {
304
			Object[] selections = ((IStructuredSelection )target).toArray();
305
			IResource resource = (IResource)selections[0];
306
			IType[] types= null;
307
				try {
308
					final Set result= new HashSet();
309
					MainMethodFinder.collectTypes(resource, new NullProgressMonitor(), result);
310
					if (result.size() > 0) {
311
						return true;
312
					}
313
				} catch (JavaModelException e) {
314
					return false;
315
				}
316
			}
317
		return false;
318
		}
319
	
320
	private boolean hasMain2(Object target) {
321
		if (target != null && target instanceof IStructuredSelection) {
322
			Object[] selections = ((IStructuredSelection )target).toArray();
323
			IResource resource = (IResource)selections[0];
324
			IJavaElement element = JavaCore.create(resource);
325
			if (element instanceof ICompilationUnit) {
326
				ICompilationUnit cu = (ICompilationUnit) element;
327
				IType mainType= cu.getType(Signature.getQualifier(cu.getElementName()));
328
				try {
329
					if (mainType.exists() && JavaModelUtil.hasMainMethod(mainType)) {
330
						return true;
331
					}
332
				} catch (JavaModelException e) {
333
					return false;
334
				}
335
			} else if (element instanceof IClassFile) {
336
				IType mainType;
337
				try {
338
					mainType = ((IClassFile)element).getType();
339
					if (JavaModelUtil.hasMainMethod(mainType)) {
340
						return true;
341
					}
342
				} catch (JavaModelException e) {
343
					return false;
344
				}
345
			}
346
		}
347
		return false;
348
	}
261
}
349
}
(-)ui/org/eclipse/jdt/internal/debug/ui/launcher/MainMethodFinder.java (-1 / +1 lines)
Lines 69-75 Link Here
69
		return (IType[]) result.toArray(new IType[result.size()]) ;
69
		return (IType[]) result.toArray(new IType[result.size()]) ;
70
	}
70
	}
71
			
71
			
72
	private static void collectTypes(Object element, IProgressMonitor monitor, Set result) throws JavaModelException {
72
	public static void collectTypes(Object element, IProgressMonitor monitor, Set result) throws JavaModelException {
73
		if (element instanceof IProcess) {
73
		if (element instanceof IProcess) {
74
			element= ((IProcess)element).getLaunch();
74
			element= ((IProcess)element).getLaunch();
75
		} else if (element instanceof IDebugTarget) {
75
		} else if (element instanceof IDebugTarget) {

Return to bug 18338