use of org.openide.util.ContextAwareAction in project ACS by ACS-Community.
the class ToolsAction method generate.
/** Implementation method that regenerates the items in the menu or
* in the array.
*
* @param forMenu true if Presenter.Menu should be used false if Presenter.Popup
* @param list (can be null)
*/
private static List generate(Action toolsAction, boolean forMenu) {
ActionManager am = (ActionManager) Lookup.getDefault().lookup(ActionManager.class);
SystemAction[] actions = am.getContextActions();
List list = new ArrayList(actions.length);
boolean separator = false;
// flag to prevent adding separator before actual menu items
boolean firstItemAdded = false;
// Get action context.
Lookup lookup;
if (toolsAction instanceof Lookup.Provider) {
lookup = ((Lookup.Provider) toolsAction).getLookup();
} else {
lookup = null;
}
for (int i = 0; i < actions.length; i++) {
Action a;
// Retrieve context sensitive action instance if possible.
if (lookup != null && actions[i] instanceof ContextAwareAction) {
a = ((ContextAwareAction) actions[i]).createContextAwareInstance(lookup);
} else {
a = actions[i];
}
if (a == null) {
if (firstItemAdded)
separator = true;
} else if (forMenu) {
if (a instanceof Presenter.Menu && a.isEnabled()) {
if (separator) {
list.add(null);
separator = false;
}
JMenuItem mi = ((Presenter.Menu) a).getMenuPresenter();
list.add(mi);
firstItemAdded = true;
}
} else if (a instanceof Presenter.Popup && a.isEnabled()) {
if (separator) {
list.add(null);
separator = false;
}
JMenuItem mi = ((Presenter.Popup) a).getPopupPresenter();
list.add(mi);
firstItemAdded = true;
}
}
return list;
}
use of org.openide.util.ContextAwareAction in project blue by kunstmusik.
the class AlignActionsPresenter method getPopupPresenter.
@Override
public JMenuItem getPopupPresenter() {
JMenu menu = new JMenu(NbBundle.getMessage(AlignActionsPresenter.class, "CTL_AlignActionsPresenter"));
org.openide.awt.Mnemonics.setLocalizedText(menu, menu.getText());
ScoreTopComponent scoreTC = (ScoreTopComponent) WindowManager.getDefault().findTopComponent("ScoreTopComponent");
for (Action action : actions) {
Action temp = action;
if (action instanceof ContextAwareAction) {
temp = ((ContextAwareAction) action).createContextAwareInstance(scoreTC.getLookup());
}
menu.add(new JMenuItem(temp));
}
return menu;
}
Aggregations