Platinum Partner
netbeans

Adding an Action to the Tab of a TopComponent

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.

 

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}