I want the display text on an Action on a Node to show something about the underlying object. But the Action is registered somewhere in the layer (i.e., in the registry), i.e., I have no control over it. How do I change the display text in this scenario?
Here's how. Below I look in the Actions/Events folder, iterate through all the Actions registered there, look for an Action with display text starting with "Edit", change it to display something from the underlying object, wrap a new Action around that Action, build up a new list of Actions, and return those (together with all the other Actions in that folder) from "getActions" on my Node:
@Override
public Action[] getActions(boolean context) {
List<Action> newEventActions = new ArrayList<Action>();
List<? extends Action> eventActions = Utilities.actionsForPath("Actions/Events");
for (final Action action : eventActions) {
String value = action.getValue(Action.NAME).toString();
if (value.startsWith("Edit")) {
Action editAction = new AbstractAction("Edit " + getLookup().lookup(Event.class).getPlace()) {
@Override
public void actionPerformed(ActionEvent e) {
action.actionPerformed(e);
}
};
newEventActions.add(editAction);
} else {
newEventActions.add(action);
}
}
return newEventActions.toArray(new Action[eventActions.size()]);
}
If someone knows of a better way, please let me know.