/** * Since these actions are re-created each time the run/debug as menu is filled, the enablement of * this action is static. */ private void updateEnablement() { IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); boolean enabled = false; if (wb != null) { IWorkbenchPage page = wb.getActivePage(); if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; try { // check enablement logic, if any Expression expression = fShortcut.getShortcutEnablementExpression(); if (expression == null) { enabled = !structuredSelection.isEmpty(); } else { List list = structuredSelection.toList(); IEvaluationContext context = new EvaluationContext(null, list); context.addVariable("selection", list); // $NON-NLS-1$ enabled = fShortcut.evalEnablementExpression(context, expression); } } catch (CoreException e) { } } else { IEditorPart editor = page.getActiveEditor(); if (editor != null) { enabled = true; } } } } setEnabled(enabled); }
public static void run(IEditorPart editor) { List<LaunchShortcutExtension> launchShortcuts = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchShortcuts(); for (LaunchShortcutExtension lse : launchShortcuts) { if (lse.getId().equals(TalendDebugUIConstants.TALEND_JOB_LAUNCH_SHORTCUT_ID)) { lse.launch(editor, ILaunchManager.RUN_MODE); return; } } }
protected void launchTests(String prefixForErrorMessage, int howManyNumbersInErrorString) throws CoreException, JavaModelException { // have to set up an 1.3 project to avoid requiring a 5.0 VM JavaProjectHelper.addRTJar13(fProject); JavaProjectHelper.addVariableEntry(fProject, new Path("JUNIT_HOME/junit.jar"), null, null); IPackageFragmentRoot root = JavaProjectHelper.addSourceContainer(fProject, "src"); IPackageFragment pack = root.createPackageFragment("pack", true, null); ICompilationUnit cu1 = pack.getCompilationUnit("LongTraceLines.java"); String initialString = prefixForErrorMessage + "Numbers:"; String initializeString = "String errorString = \"" + initialString + "\";"; String contents = "public class LongTraceLines extends TestCase {\n" + " public void testLongTraceLine() throws Exception {\n" + (" " + initializeString + "\n") + (" for (int i = 0; i < " + howManyNumbersInErrorString + "; i++) {\n") + " errorString += \" \" + i;\n" + " }\n" + " throw new RuntimeException(errorString);\n" + " }\n" + "}"; IType type = cu1.createType(contents, null, true, null); cu1.createImport("junit.framework.TestCase", null, Flags.AccDefault, null); cu1.createImport("java.util.Arrays", null, Flags.AccDefault, null); ILaunchManager lm = DebugPlugin.getDefault().getLaunchManager(); lm.addLaunchListener(this); LaunchConfigurationManager manager = DebugUIPlugin.getDefault().getLaunchConfigurationManager(); List launchShortcuts = manager.getLaunchShortcuts(); LaunchShortcutExtension ext = null; for (Iterator iter = launchShortcuts.iterator(); iter.hasNext(); ) { ext = (LaunchShortcutExtension) iter.next(); if (ext.getLabel().equals("JUnit Test")) break; } ext.launch(new StructuredSelection(type), ILaunchManager.RUN_MODE); }
/** * Runs with either the active editor or workbench selection. * * @see IAction#run() */ public void run() { IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); if (wb != null) { IWorkbenchPage page = wb.getActivePage(); if (page != null) { if (page.getActivePart() == page.getActiveEditor()) { IEditorPart editor = page.getActiveEditor(); if (editor != null) { fShortcut.launch(editor, fMode); } } else if (page.getActivePart() instanceof IJobSettingsView) { ISelection selection = ((IJobSettingsView) page.getActivePart()).getSelection(); fShortcut.launch(selection, fMode); } else { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { fShortcut.launch(selection, fMode); } } } } }
/** Constructor for LaunchShortcutAction. */ public TalendLaunchShortcutAction(String mode, LaunchShortcutExtension shortcut) { super(shortcut.getLabel(), shortcut.getImageDescriptor()); fMode = mode; fShortcut = shortcut; updateEnablement(); }