我正在尝试根据当前节点/节点状态实现启用或禁用的操作(在应用程序顶部菜单中,以及右键单击节点的弹出菜单中)。
@ActionID(
category = "Application",
id = "it.cre.app.tree.actions.ShowEventsAction")
@ActionRegistration(
iconBase = "it/cre/app/tree/actions/show.png",
displayName = "#CTL_ShowAction")
@ActionReferences({
@ActionReference(path = "Menu/Edit", position = 100),
@ActionReference(path = "Toolbars/File", position = 300),
@ActionReference(path = "Application/edit", position = 0)})
@NbBundle.Messages("CTL_ShowAction=Show Events")
public class ShowEventsAction implements ActionListener {
private ShowAuditEventsCapability showAuditEventsCapability;
public ShowEventsAction(ShowAuditEventsCapability context) {
showAuditEventsCapability = context;
}
@Override
public void actionPerformed(ActionEvent e) {
if (showAuditEventsCapability != null) {
doSomething();
}
}
}
For example: This action, to default, is enabled only if one node is selected otherwise is disabled (visible but disabled). 我想要相同的行为,但也基于所选节点的状态。
我所有的节点都实现了我的接口:
public interface INode {
//obviously the state of the node could change at runtime
public boolean someState();
}
所以我可以通过以下方式在我的操作中获取节点的状态:
boolean state = Utilities.actionsGlobalContext().lookup(INode.class).someState();
当我选择节点时,如何使用前面的代码片段来启用/禁用操作,就像选择多个节点时禁用此操作一样?
有什么建议么?