Change a Foreign Action's Display Text
Posted
by Geertjan
on Oracle Blogs
See other posts from Oracle Blogs
or by Geertjan
Published on Thu, 30 Jun 2011 09:01:22 -0700
Indexed on
2011/06/30
16:27 UTC
Read the original article
Hit count: 314
/NetBeans IDE
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.
© Oracle Blogs or respective owner