Java Code Examples for org.netbeans.spi.project.ActionProvider#getSupportedActions()

The following examples show how to use org.netbeans.spi.project.ActionProvider#getSupportedActions() . 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: CreateBundleAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 2
Source File: J2SEActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public CompileOnSaveAction forRoot(URL root) {
    try {
        final Project p = FileOwnerQuery.getOwner(root.toURI());
        if (p != null) {
            ActionProvider prov = p.getLookup().lookup(ActionProvider.class);  
            if (prov != null) {
                prov.getSupportedActions(); //Force initialization
            }
            final CosAction action = CosAction.getInstance(p);
            return action;
        }
    } catch (URISyntaxException e) {
        Exceptions.printStackTrace(e);
    }
    return null;
}
 
Example 3
Source File: ProjectUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean hasAction(Project project, String actionName) {
    ActionProvider ap = project.getLookup().lookup(ActionProvider.class);

    if (ap == null) {
        return false; // return false if no ActionProvider available
    }

    String[] actions = ap.getSupportedActions();

    for (int i = 0; i < actions.length; i++) {
        if ((actions[i] != null) && actionName.equals(actions[i])) {
            return true;
        }
    }

    return false;
}
 
Example 4
Source File: ProjectUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static boolean hasAction(Project project, String actionName) {
    ActionProvider ap = project.getLookup().lookup(ActionProvider.class);

    if (ap == null) {
        return false; // return false if no ActionProvider available
    }

    String[] actions = ap.getSupportedActions();

    for (int i = 0; i < actions.length; i++) {
        if ((actions[i] != null) && actionName.equals(actions[i])) {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: JspRunToCursorActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static boolean isDebuggableProject(Project p) {
    ActionProvider 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.equals (sa [i])) {
            break;
        }
    }
    if (i == k) {
        return false;
    }

    // check if this action should be enabled
    return ((ActionProvider) p.getLookup ().lookup (
            ActionProvider.class
        )).isActionEnabled (
            ActionProvider.COMMAND_DEBUG, 
            p.getLookup ()
        );
}
 
Example 6
Source File: ProjectsRootNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: StepIntoActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 8
Source File: FixActionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean shouldBeEnabled () {
    // check if current debugger supports this action
    if (!debugger.canFixClasses()) {
        return false;
    }
    // check if current project supports this action
    isFixCommandSupported = false;
    Project p = getCurrentProject();
    if (p != null) {
        ActionProvider actionProvider = (ActionProvider) p.getLookup ().
            lookup (ActionProvider.class);
        if (actionProvider != null) {
            String[] sa = actionProvider.getSupportedActions ();
            int i, k = sa.length;
            for (i = 0; i < k; i++) {
                if (JavaProjectConstants.COMMAND_DEBUG_FIX.equals (sa [i])) {
                    break;
                }
            }
            isFixCommandSupported = i < k &&
                    actionProvider.isActionEnabled(JavaProjectConstants.COMMAND_DEBUG_FIX, getLookup());
        }
    }
    if (!isFixCommandSupported) {
        // No fix command, let's see whether we have some changed classes to reload:
        return ClassesToReload.getInstance().hasClassesToReload(debugger, getSourceRootsFO(sp));
        /*Sources sources = ProjectUtils.getSources(p);
        SourceGroup[] srcGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (SourceGroup srcGroup : srcGroups) {
            FileObject src = srcGroup.getRootFolder();
            if (hasClassesToReload(debugger, src)) {
                return true;
            }
        }
        return false;
         */
    } else {
        return true;
    }
}
 
Example 9
Source File: JUnitExecutionManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 10
Source File: ExecJSAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static boolean isEnabledAction(String command, FileObject fo, Lookup actionContext) {
    Project p = findProject(fo);
    if (p != null) {
        ActionProvider ap = p.getLookup().lookup(ActionProvider.class);
        if (ap != null && ap.getSupportedActions() != null && Arrays.asList(ap.getSupportedActions()).contains(command)) {
            return ap.isActionEnabled(command, actionContext);
        }
    }
    return false;
}
 
Example 11
Source File: Command.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static boolean isSupportedAction(String command, ActionProvider actionProvider) {
    for (String action : actionProvider.getSupportedActions()) {
        if (command.equals(action)) {
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: MavenJUnitTestMethodNode.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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()]);
}
 
Example 13
Source File: RunToCursorActionProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean shouldBeEnabled () {
    if (editorContext.getCurrentLineNumber () < 0) {
        return false;
    }
    FileObject fo = editorContext.getCurrentFile();
    if (fo == null || !fo.hasExt("java")) {
        return false;
    }
    
    // check if current project supports this action
    Project p = MainProjectManager.getDefault ().getMainProject ();
    if (p == null) {
        return false;
    }
    synchronized (projectBreakpoints) {
        if (projectBreakpoints.containsKey(p)) {
            // Already debugging this project
            return false;
        }
    }
    ActionProvider 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.equals (sa [i])) {
            break;
        }
    }
    if (i == k) {
        return false;
    }

    // check if this action should be enabled
    return actionProvider.isActionEnabled (
            ActionProvider.COMMAND_DEBUG, 
            p.getLookup ()
        );
}