|
Lines 25-30
Link Here
|
| 25 |
import org.eclipse.debug.core.ILaunchManager; |
25 |
import org.eclipse.debug.core.ILaunchManager; |
| 26 |
import org.eclipse.debug.ui.DebugUITools; |
26 |
import org.eclipse.debug.ui.DebugUITools; |
| 27 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
27 |
import org.eclipse.debug.ui.IDebugModelPresentation; |
|
|
28 |
import org.eclipse.debug.ui.ILaunchFilter; |
| 28 |
import org.eclipse.debug.ui.ILaunchShortcut; |
29 |
import org.eclipse.debug.ui.ILaunchShortcut; |
| 29 |
import org.eclipse.jdt.core.IClassFile; |
30 |
import org.eclipse.jdt.core.IClassFile; |
| 30 |
import org.eclipse.jdt.core.ICompilationUnit; |
31 |
import org.eclipse.jdt.core.ICompilationUnit; |
|
Lines 46-52
Link Here
|
| 46 |
import org.eclipse.jface.window.Window; |
47 |
import org.eclipse.jface.window.Window; |
| 47 |
import org.eclipse.swt.widgets.Display; |
48 |
import org.eclipse.swt.widgets.Display; |
| 48 |
import org.eclipse.swt.widgets.Shell; |
49 |
import org.eclipse.swt.widgets.Shell; |
| 49 |
import org.eclipse.ui.IActionFilter; |
|
|
| 50 |
import org.eclipse.ui.IEditorInput; |
50 |
import org.eclipse.ui.IEditorInput; |
| 51 |
import org.eclipse.ui.IEditorPart; |
51 |
import org.eclipse.ui.IEditorPart; |
| 52 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
52 |
import org.eclipse.ui.dialogs.ElementListSelectionDialog; |
|
Lines 54-60
Link Here
|
| 54 |
/** |
54 |
/** |
| 55 |
* Performs single click launching for local Java applications. |
55 |
* Performs single click launching for local Java applications. |
| 56 |
*/ |
56 |
*/ |
| 57 |
public class JavaApplicationLaunchShortcut implements ILaunchShortcut, IActionFilter { |
57 |
public class JavaApplicationLaunchShortcut implements ILaunchShortcut, ILaunchFilter { |
| 58 |
|
58 |
|
| 59 |
/** |
59 |
/** |
| 60 |
* @param search the java elements to search for a main type |
60 |
* @param search the java elements to search for a main type |
|
Lines 270-276
Link Here
|
| 270 |
/* (non-Javadoc) |
270 |
/* (non-Javadoc) |
| 271 |
* @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String) |
271 |
* @see org.eclipse.ui.IActionFilter#testAttribute(java.lang.Object, java.lang.String, java.lang.String) |
| 272 |
*/ |
272 |
*/ |
| 273 |
public boolean testAttribute(Object target, String name, String value) { |
273 |
public boolean testAttribute(IResource target, String name, String value) { |
| 274 |
if ("ContextualLaunchActionFilter".equals(name)) { //$NON-NLS-1$ |
274 |
if ("ContextualLaunchActionFilter".equals(name)) { //$NON-NLS-1$ |
| 275 |
return hasMain(target); |
275 |
return hasMain(target); |
| 276 |
} else if ("NameMatches".equals(name)) { //$NON-NLS-1$ |
276 |
} else if ("NameMatches".equals(name)) { //$NON-NLS-1$ |
|
Lines 279-301
Link Here
|
| 279 |
return false; |
279 |
return false; |
| 280 |
} |
280 |
} |
| 281 |
|
281 |
|
| 282 |
private boolean nameMatches(Object target, String value) { |
282 |
/** |
| 283 |
try { |
283 |
* Test if the name of the target resource matches a pattern. |
| 284 |
Object[] selections = ((IStructuredSelection) target).toArray(); |
284 |
* |
| 285 |
IResource resource = (IResource) selections[0]; |
285 |
* @param target selected resource from workspace |
| 286 |
String filename = resource.getName(); |
286 |
* @param value regular expression pattern to test |
| 287 |
StringMatcher sm = new StringMatcher(value, true, false); |
287 |
* @return true if the pattern matches the resource name, false otherwise |
| 288 |
return sm.match(filename); |
288 |
*/ |
| 289 |
} catch (ClassCastException e) { |
289 |
private boolean nameMatches(IResource target, String regexp) { |
| 290 |
return false; |
290 |
String filename = target.getName(); |
| 291 |
} |
291 |
StringMatcher sm = new StringMatcher(regexp, true, false); |
|
|
292 |
return sm.match(filename); |
| 292 |
} |
293 |
} |
| 293 |
|
294 |
|
| 294 |
private boolean hasMain(Object target) { |
295 |
/** |
| 295 |
if (target != null && target instanceof IStructuredSelection) { |
296 |
* Look for a Java main() method in the specified resource. |
| 296 |
Object[] selections = ((IStructuredSelection )target).toArray(); |
297 |
* @return true if the target resource has a <code>main</code> method, |
| 297 |
IResource resource = (IResource)selections[0]; |
298 |
* <code>false</code> otherwise. |
| 298 |
IJavaElement element = JavaCore.create(resource); |
299 |
*/ |
|
|
300 |
private boolean hasMain(IResource target) { |
| 301 |
if (target != null) { |
| 302 |
IJavaElement element = JavaCore.create(target); |
| 299 |
if (element instanceof ICompilationUnit) { |
303 |
if (element instanceof ICompilationUnit) { |
| 300 |
ICompilationUnit cu = (ICompilationUnit) element; |
304 |
ICompilationUnit cu = (ICompilationUnit) element; |
| 301 |
IType mainType= cu.getType(Signature.getQualifier(cu.getElementName())); |
305 |
IType mainType= cu.getType(Signature.getQualifier(cu.getElementName())); |