Java Code Examples for org.netbeans.spi.project.ActionProvider#isActionEnabled()
The following examples show how to use
org.netbeans.spi.project.ActionProvider#isActionEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrowserCommand.java From netbeans with Apache License 2.0 | 6 votes |
@Override boolean isActionEnabledInternal(Lookup context) { if (project.isJsLibrary()) { return false; } if (!project.isRunBrowser()) { return false; } if (isFileCommand() && isJsFileCommand(context)) { return false; } ActionProvider actionProvider = getBrowserActionProvider(); if (actionProvider != null && isSupportedAction(getCommandId(), actionProvider)) { return actionProvider.isActionEnabled(getCommandId(), context); } return false; }
Example 2
Source File: ActiveBrowserAction.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean commandSupported( Project project, String command, Lookup context ) { //We have to look whether the command is supported by the project ActionProvider ap = project.getLookup().lookup(ActionProvider.class); if ( ap != null ) { List<String> commands = Arrays.asList(ap.getSupportedActions()); if ( commands.contains( command ) ) { try { if (context == null || ap.isActionEnabled(command, context)) { //System.err.println("cS: true project=" + project + " command=" + command + " context=" + context); return true; } } catch (IllegalArgumentException x) { Logger.getLogger(ActiveBrowserAction.class.getName()).log(Level.INFO, "#213589: possible race condition in MergedActionProvider", x); } } } //System.err.println("cS: false project=" + project + " command=" + command + " context=" + context); return false; }
Example 3
Source File: ProjectsRootNode.java From netbeans with Apache License 2.0 | 6 votes |
@Override public boolean canDestroy() { Project p = getLookup().lookup(Project.class); if (p == null) { return false; } ActionProvider ap = p.getLookup().lookup(ActionProvider.class); String[] sa = ap != null ? ap.getSupportedActions() : new String[0]; int k = sa.length; for (int i = 0; i < k; i++) { if (ActionProvider.COMMAND_DELETE.equals(sa[i])) { return ap.isActionEnabled(ActionProvider.COMMAND_DELETE, getLookup()); } } return false; }
Example 4
Source File: ActionsUtil.java From netbeans with Apache License 2.0 | 6 votes |
/** * Tests whether given command is available on the project and whether * the action as to be enabled in current Context * @param project Project to test * @param command Command for test * @param context Lookup representing current context or null if context * does not matter. */ public static boolean commandSupported( Project project, String command, Lookup context ) { //We have to look whether the command is supported by the project ActionProvider ap = project.getLookup().lookup(ActionProvider.class); if ( ap != null ) { List<String> commands = Arrays.asList(ap.getSupportedActions()); if ( commands.contains( command ) ) { try { if (context == null || ap.isActionEnabled(command, context)) { //System.err.println("cS: true project=" + project + " command=" + command + " context=" + context); return true; } } catch (IllegalArgumentException x) { Logger.getLogger(ActionsUtil.class.getName()).log(Level.INFO, "#213589: possible race condition in MergedActionProvider", x); } } } //System.err.println("cS: false project=" + project + " command=" + command + " context=" + context); return false; }
Example 5
Source File: LookupMergerImpl.java From netbeans with Apache License 2.0 | 6 votes |
public boolean isActionEnabled(String command, Lookup context) throws IllegalArgumentException { boolean supported = false; for (ActionProvider ap : delegates()) { if (Arrays.asList(ap.getSupportedActions()).contains(command)) { supported = true; boolean enabled = ap.isActionEnabled(command, context); LOG.log(Level.FINE, "delegate {0} says enabled={1} for {2} in {3}", new Object[] {ap, enabled, command, context}); if (enabled) { return true; } } } if (supported) { return false; } else { // Not supported by anyone. throw new IllegalArgumentException(command); } }
Example 6
Source File: TestNGExecutionManager.java From netbeans with Apache License 2.0 | 6 votes |
public void rerun() { if ((properties.getProperty("test.includes") != null && properties.getProperty("test.includes").endsWith(".xml")) || //NOI18N (properties.getProperty("test.class") != null && properties.getProperty("test.class").endsWith(".xml"))) { //NOI18N if (properties.getProperty("continue.after.failing.tests") == null) { //NOI18N properties.setProperty("continue.after.failing.tests", "true"); //NOI18N } try { runAnt(FileUtil.toFileObject(scriptFile), targets, properties); } catch (IOException ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); } } else { Project project = testSession.getProject(); if(ProjectManager.getDefault().isValid(project)) { ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class); String[] actionNames = getActionNames(targets); if (actionProvider != null) { if (Arrays.asList(actionProvider.getSupportedActions()).contains(actionNames[0]) && actionProvider.isActionEnabled(actionNames[0], lookup)) { actionProvider.invokeAction(actionNames[0], lookup); } } } } }
Example 7
Source File: CreateBundleAction.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean supportsImages( @NullAllowed final ActionProvider ap, @NonNull final Lookup ctx) { if (ap == null) { return false; } String found = null; for (String action : ap.getSupportedActions()) { if (NativeBundleType.forCommand(action)!= null) { found = action; break; } } if (found == null) { return false; } return ap.isActionEnabled(found, ctx); }
Example 8
Source File: JUnitExecutionManager.java From netbeans with Apache License 2.0 | 5 votes |
public boolean enabled(RerunType type) { if ((scriptFile == null) || (targets == null) || (targets.length == 0)){ return false; } if (scriptFile.getName().equals(JUNIT_CUSTOM_FILENAME + ".xml")){ //NOI18N return true; } Project project = testSession.getProject(); if(project == null) { // could not locate the project for which the testSession was invoked for return false; } ActionProvider actionProvider = project.getLookup().lookup(ActionProvider.class); if (actionProvider != null){ boolean runSupported = false; for (String action : actionProvider.getSupportedActions()) { if (action.equals(targets[0])) { runSupported = true; break; } } if (runSupported && actionProvider.isActionEnabled(targets[0], lookup)) { return true; } } return false; }
Example 9
Source File: PlatformCommand.java From netbeans with Apache License 2.0 | 5 votes |
@Override boolean isActionEnabledInternal(Lookup context) { for (PlatformProvider provider : project.getPlatformProviders()) { ActionProvider actionProvider = provider.getActionProvider(project); if (actionProvider != null && isSupportedAction(commandId, actionProvider) && actionProvider.isActionEnabled(commandId, context)) { return true; } } return false; }
Example 10
Source File: ProjectSensitivePerformer.java From netbeans with Apache License 2.0 | 5 votes |
static boolean supportsProfileProject(String command, Project project) { if (project == null) return false; ActionProvider ap = project.getLookup().lookup(ActionProvider.class); try { if (ap != null && contains(ap.getSupportedActions(), command)) { ProjectProfilingSupport ppp = ProjectProfilingSupport.get(project); return ppp.isProfilingSupported() && ap.isActionEnabled(command, project.getLookup()); } } catch (IllegalArgumentException e) { // command not supported } return false; }
Example 11
Source File: AntJUnitTestsuiteNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Action[] getActions(boolean context) { List<Action> actions = new ArrayList<Action>(); Action preferred = getPreferredAction(); if (preferred != null) { actions.add(preferred); } FileObject testFO = ((JUnitTestSuite)getSuite()).getSuiteFO(); if (testFO != null){ ActionProvider actionProvider = OutputUtils.getActionProvider(testFO); if (actionProvider != null){ List supportedActions = Arrays.asList(actionProvider.getSupportedActions()); Lookup nodeContext = Lookups.singleton(testFO); if (supportedActions.contains(ActionProvider.COMMAND_TEST_SINGLE) && actionProvider.isActionEnabled(ActionProvider.COMMAND_TEST_SINGLE, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, ActionProvider.COMMAND_TEST_SINGLE, Bundle.LBL_RerunTest())); } if (supportedActions.contains(ActionProvider.COMMAND_DEBUG_TEST_SINGLE) && actionProvider.isActionEnabled(ActionProvider.COMMAND_DEBUG_TEST_SINGLE, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, ActionProvider.COMMAND_DEBUG_TEST_SINGLE, Bundle.LBL_DebugTest())); } } } return actions.toArray(new Action[actions.size()]); }
Example 12
Source File: LookupProviderSupport.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void invokeAction(String command, Lookup context) throws IllegalArgumentException { for (ActionProvider ap : lkpResult.allInstances()) { if (Arrays.asList(ap.getSupportedActions()).contains(command) && ap.isActionEnabled(command, context)) { ap.invokeAction(command, context); return; } } throw new IllegalArgumentException(String.format(command)); }
Example 13
Source File: LookupMergerImpl.java From netbeans with Apache License 2.0 | 5 votes |
public void invokeAction(String command, Lookup context) throws IllegalArgumentException { for (ActionProvider ap : delegates()) { if (Arrays.asList(ap.getSupportedActions()).contains(command) && ap.isActionEnabled(command, context)) { LOG.log(Level.FINE, "delegating {0} on {1} to {2}", new Object[] {command, context, ap}); ap.invokeAction(command, context); return; } } throw new IllegalArgumentException(command); }
Example 14
Source File: REPLAction2.java From netbeans with Apache License 2.0 | 5 votes |
@NbBundle.Messages({ "ERR_CannotBuildProject=Could not build the project", "ERR_ProjectBuildFailed=Project build failed, please check Output window", }) @Override public void perform(Project project) { ActionProvider p = project.getLookup().lookup(ActionProvider.class); // check whether the is CoS enabled fo the project if (ShellProjectUtils.isCompileOnSave(project)) { doRunShell(project); return; } if (p == null || !p.isActionEnabled(ActionProvider.COMMAND_BUILD, Lookups.singleton(project))) { StatusDisplayer.getDefault().setStatusText(Bundle.ERR_CannotBuildProject()); return; } p.invokeAction(ActionProvider.COMMAND_BUILD, Lookups.fixed(project, new ActionProgress() { @Override protected void started() { // no op } @Override public void finished(boolean success) { if (success) { doRunShell(project); } else { StatusDisplayer.getDefault().setStatusText(Bundle.ERR_ProjectBuildFailed()); } } })); }
Example 15
Source File: REPLAction2.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean enable(Project project) { if (ShellProjectUtils.findPlatform(project) == null) { return false; } ActionProvider p = project.getLookup().lookup(ActionProvider.class); if (p == null) { return false; } return p.isActionEnabled(ActionProvider.COMMAND_BUILD, Lookups.singleton(project)); }
Example 16
Source File: StepIntoActionProvider.java From netbeans with Apache License 2.0 | 5 votes |
private boolean shouldBeEnabled () { // check if current project supports this action Project p = MainProjectManager.getDefault ().getMainProject (); if (p == null) { return false; } ActionProvider actionProvider = p.getLookup().lookup(ActionProvider.class); if (actionProvider == null) { return false; } String[] sa = actionProvider.getSupportedActions (); int i, k = sa.length; for (i = 0; i < k; i++) { if (ActionProvider.COMMAND_DEBUG_STEP_INTO.equals (sa [i])) { break; } } if (i == k) { return false; } if (DebuggerManager.getDebuggerManager().getDebuggerEngines().length > 0) { // Do not enable this non-contextual action when some debugging session is already running. return false; } // check if this action should be enabled return actionProvider.isActionEnabled ( ActionProvider.COMMAND_DEBUG_STEP_INTO, p.getLookup () ); }
Example 17
Source File: FileAction.java From netbeans with Apache License 2.0 | 5 votes |
private ActionProvider globalProvider(Lookup context) { for (ActionProvider ap : Lookup.getDefault().lookupAll(ActionProvider.class)) { if (Arrays.asList(ap.getSupportedActions()).contains(command) && ap.isActionEnabled(command, context)) { return ap; } } return null; }
Example 18
Source File: ActionProviderImpl.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void invokeAction(String command, Lookup context) throws IllegalArgumentException { if (COMMAND_PROFILE_TEST_SINGLE.equals(command)) { for (ActionProvider ap : Lookup.getDefault().lookupAll(ActionProvider.class)) { if (new HashSet<>(Arrays.asList(ap.getSupportedActions())).contains(COMMAND_PROFILE_TEST_SINGLE) && ap.isActionEnabled(COMMAND_PROFILE_TEST_SINGLE, context)) { ap.invokeAction(COMMAND_PROFILE_TEST_SINGLE, context); return ; } } } FileObject scriptFO = script; Settings settings = project.getLookup().lookup(Settings.class); Properties props = new Properties(); if (settings.isUseAntBuild()) { props.put("langtools.build.location", settings.getAntBuildLocation()); } else { scriptFO = genericScript; if (COMMAND_BUILD_FAST.equals(command)) { command = COMMAND_BUILD_GENERIC_FAST; } } if (COMMAND_BUILD_GENERIC_FAST.equals(command)) { switch (settings.getRunBuildSetting()) { case NEVER: ActionProgress.start(context).finished(true); return; case ALWAYS: default: break; } scriptFO = genericScript; command = COMMAND_BUILD_FAST; //XXX: should only do this if genericScript supports it } FileObject basedirFO = project.currentModule != null ? scriptFO == genericScript ? project.moduleRepository.getJDKRoot() : repository : repository.getParent(); props.put("basedir", FileUtil.toFile(basedirFO).getAbsolutePath()); props.put("CONF", project.configurations.getActiveConfiguration().getLocation().getName()); props.put("nb.jdk.project.target.java.home", BuildUtils.findTargetJavaHome(project.getProjectDirectory()).getAbsolutePath()); RootKind kind = getKind(context); RunSingleConfig singleFileProperty = command2Properties.get(Pair.of(command, kind)); if (singleFileProperty != null) { String srcdir = ""; String moduleName = ""; StringBuilder value = new StringBuilder(); String sep = ""; for (FileObject file : context.lookupAll(FileObject.class)) { value.append(sep); ClassPath sourceCP; switch (kind) { case SOURCE: sourceCP = ClassPath.getClassPath(file, ClassPath.SOURCE); break; case TEST: sourceCP = ClassPathSupport.createClassPath(BuildUtils.getFileObject(project.getProjectDirectory(), "../../test")); break; default: throw new IllegalStateException(kind.name()); } value.append(singleFileProperty.valueType.convert(sourceCP, file)); sep = singleFileProperty.separator; FileObject ownerRoot = sourceCP.findOwnerRoot(file); srcdir = FileUtil.getRelativePath(BuildUtils.getFileObject(project.getProjectDirectory(), "../.."), ownerRoot); moduleName = ownerRoot.getParent().getParent().getNameExt(); } props.put(singleFileProperty.propertyName, value.toString()); props.put("srcdir", srcdir); props.put("module.name", moduleName); } final ActionProgress progress = ActionProgress.start(context); try { ActionUtils.runTarget(scriptFO, command2Targets.get(Pair.of(command, kind)), props) .addTaskListener(new TaskListener() { @Override public void taskFinished(Task task) { progress.finished(((ExecutorTask) task).result() == 0); } }); } catch (IOException ex) { //??? Exceptions.printStackTrace(ex); progress.finished(false); } }
Example 19
Source File: CreateArchetypeTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testCreateFromArchetype() throws Exception { FileObject dir = FileUtil.getConfigFile("Templates/Project/Gradle/org-netbeans-modules-gradle-htmlui-HtmlJavaApplicationProjectWizard"); assertNotNull("Templates directory found", dir); FileObject dest = FileUtil.createFolder(workFo, "sample/dest"); Map<String,Object> map = new HashMap<>(); map.put("packageBase", "my.pkg.x"); GradleArchetype ga = new GradleArchetype(dir, dest, map); ga.copyTemplates(); assertFile("Build script found", dest, "build.gradle"); assertFile("Main class found", dest, "src", "main", "java", "my", "pkg", "x", "Demo.java"). assertPackage("my.pkg.x"). assertName("Demo"). assertNoLicense(). appendLine("applyBindings(model);", "System.exit(0);"); assertFile("index.html found", dest, "src", "main", "webapp", "pages", "index.html"). assertNoLicense(); assertFile("DesktopMain class found", dest, "desktop", "src", "main", "java", "my", "pkg", "x", "DesktopMain.java"). assertPackage("my.pkg.x"). assertName("DesktopMain"). assertNoLicense(); assertFile("Desktop script found", dest, "desktop", "build.gradle"). assertText("mainClassName = 'my.pkg.x.DesktopMain'"). assertNoLicense(); assertFile("Browser script found", dest, "web", "build.gradle"). assertText("mainClassName = 'my.pkg.x.BrowserMain'"). assertNoLicense(); assertFile("BrowserMain class found", dest, "web", "src", "main", "java", "my", "pkg", "x", "BrowserMain.java"). assertPackage("my.pkg.x"). assertName("BrowserMain"). assertNoLicense(); assertFile("settings include only desktop and web", dest, "settings.gradle"). assertText("//include 'app'"). assertText("//include 'ios'"). assertText("include 'desktop'"). assertText("include 'web'"); Project mainPrj = ProjectManager.getDefault().findProject(dest); assertNotNull("Project found", mainPrj); OpenProjects.getDefault().open(new Project[] { mainPrj }, true); ActionProvider actions = mainPrj.getLookup().lookup(ActionProvider.class); assertTrue(Arrays.asList(actions.getSupportedActions()).contains(ActionProvider.COMMAND_BUILD)); actions.isActionEnabled(ActionProvider.COMMAND_BUILD, mainPrj.getLookup()); invokeCommand(actions, ActionProvider.COMMAND_BUILD, mainPrj); assertFile("JAR created", dest, "build", "libs", "dest-1.0-SNAPSHOT.jar"); FileObject desktopFo = mainPrj.getProjectDirectory().getFileObject("desktop"); assertNotNull("desktop dir found", desktopFo); Project desktopPrj = ProjectManager.getDefault().findProject(desktopFo); assertNotNull("desktop project found", desktopPrj); invokeCommand(actions, ActionProvider.COMMAND_RUN, desktopPrj); assertFile("JAR created", dest, "desktop", "build", "libs", "desktop.jar"); FileObject webFo = mainPrj.getProjectDirectory().getFileObject("web"); assertNotNull("web dir found", webFo); Project webPrj = ProjectManager.getDefault().findProject(webFo); assertNotNull("web project found", webPrj); invokeCommand(actions, ActionProvider.COMMAND_RUN, webPrj); assertFile("Main script created", dest, "web", "build", "web", "bck2brwsr.js"); }
Example 20
Source File: MavenJUnitTestMethodNode.java From netbeans with Apache License 2.0 | 4 votes |
@Messages({ "LBL_RerunTest=Run Again", "LBL_DebugTest=Debug" }) @Override public Action[] getActions(boolean context) { List<Action> actions = new ArrayList<Action>(); FileObject testFO = getTestcaseFileObject(); if (testFO != null) { boolean unitTest = getTestcase().getType() == null || "UNIT".equals(getTestcase().getType()); // NOI18N boolean integrationTest = "INTEGRATION".equals(getTestcase().getType()); // NOI18N Project suiteProject = FileOwnerQuery.getOwner(testFO); if (suiteProject != null) { ActionProvider actionProvider = suiteProject.getLookup().lookup(ActionProvider.class); if (actionProvider != null) { SingleMethod methodSpec = new SingleMethod(testFO, testcase.getName()); Lookup nodeContext = Lookups.singleton(methodSpec); for (String action : actionProvider.getSupportedActions()) { if (unitTest && action.equals(COMMAND_RUN_SINGLE_METHOD) && actionProvider.isActionEnabled(action, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, COMMAND_RUN_SINGLE_METHOD, Bundle.LBL_RerunTest())); } if (unitTest && action.equals(COMMAND_DEBUG_SINGLE_METHOD) && actionProvider.isActionEnabled(action, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, COMMAND_DEBUG_SINGLE_METHOD, Bundle.LBL_DebugTest())); } if (integrationTest && action.equals("integration-test.single") && actionProvider.isActionEnabled(action, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, "integration-test.single", Bundle.LBL_RerunTest())); } if (integrationTest && action.equals("debug.integration-test.single") && actionProvider.isActionEnabled(action, nodeContext)) { actions.add(new TestMethodNodeAction(actionProvider, nodeContext, "debug.integration-test.single", Bundle.LBL_DebugTest())); } } } } } Collections.sort(actions, (a, b) -> { String aName = (String)a.getValue(Action.NAME); String bName = (String)b.getValue(Action.NAME); if(aName == null) { aName = ""; } if(bName == null) { bName = ""; } return aName.compareTo(bName); }); Action preferred = getPreferredAction(); if (preferred != null) { actions.add(0, preferred); } actions.addAll(Arrays.asList(super.getActions(context))); return actions.toArray(new Action[actions.size()]); }