Over a million developers have joined DZone.

Adding an Action to the Tab of a TopComponent

· Java Zone

Thrive in the application economy with an APM model that is strategic. Be E.P.I.C. with CA APM.  Brought to you in partnership with CA Technologies.

I've been working on a 7.0 branch for the JFugue Music Notepad project and added a "Rename Score" action on the tab of the Score window:

Here's how, in the TopComponent:

@Override
public Action[] getActions() {
    int existingActions = super.getActions().length;
    int existingActionsPlusRename = existingActions + 1;
    Action[] scoreActions = new Action[existingActionsPlusRename];
    List<Action> scoreList = new ArrayList(existingActionsPlusRename);
    scoreList.add(new AbstractAction("Rename Score") {
        public void actionPerformed(ActionEvent e) {
            NotifyDescriptor.InputLine newname = new NotifyDescriptor.InputLine("Name: ", "Rename Score");
            DialogDisplayer.getDefault().notify(newname);
            setDisplayName(newname.getInputText());
        }
    });
    scoreList.addAll(Arrays.asList(super.getActions()));
    for (int i = 0; i < scoreList.size(); i++) {
        Action action = scoreList.get(i);
        scoreActions[i] = action;
    }
    return scoreActions;
}

Can't promise it's the best solution, though. Instead of hard coding the Rename Action, it could be defined in the layer and then read from its folder (Utilities.actionsForPath), which would make the tab extensible from the outside.

 

Navigate the Maze of the End-User Experience and pick up this APM Essential guide, brought to you in partnership with CA Technologies

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}