DevFaqActionAddProjectOwnTypePopUp

How do I add an action to a project node's popup menu of my own project type?

  • To add the Copy/Delete/Move/Rename action to your project's node, you should:
    1. Implement the corresponding interface such as org.netbeans.spi.project.CopyOperationImplementation.
    2. Implement org.netbeans.spi.project.ActionProvider:
public final class AddActionActions implements ActionProvider {
    private final AddActionProject project; //suppose this is your project
    public AddActionActions(AddActionProject project) {
        this.project = project;
    }
    public String[] getSupportedActions() {
        return new String[] {
            ActionProvider.COMMAND_COPY
        };
    }
    public boolean isActionEnabled(String command, Lookup context) {
        if (command.equals(ActionProvider.COMMAND_COPY)) {
            return true;
        } else {
            throw new IllegalArgumentException(command);
        }
    }
    public void invokeAction(String command, Lookup context) {
        if (command.equalsIgnoreCase(ActionProvider.COMMAND_COPY)){
            DefaultProjectOperations.performDefaultCopyOperation(project);
        }
    }
}
    1. Add these implementations to your project's lookup:
lookup = Lookups.fixed(
    // ... as before
    new AddActionOperation(this),
    new AddActionActions(this),
);
    1. Register the actions into the project node's context menu:
public @Override Action[] getActions(boolean context) {   
    Action[[ | ]] nodeActions = new Action[2];
    nodeActions[0] = CommonProjectActions.copyProjectAction();
    nodeActions[1] = CommonProjectActions.closeProjectAction();
    return nodeActions;
}
  • To add the other actions specified in the Project API such as closeProjectAction, just add it to the list of actions of your node.
  • To add an action you created yourself, just add it to the list of actions of your node.

See also: Common Project Actions

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo