- Category:
- The categories represent semantic groupings of the actions.
- Either select a preexisting category or create a new one.
- CallableSystemAction
- CallbackSystemAction
- Is a subclass of CallableSystemAction
- Can delegate to another action, which is typically a context sensitive action.
- Contains no action logic, but delegates to an action performer.
- Are used especially by global actions – that is, actions that provide different behavior depending on their context.
- searches
- copying
- pasting
- such global actions are offered out of the box by the NetBeans Actions API.
- The action performer:
- Is made available by a Java ActionMap
- is made available via a Lookup.
- Is delivered via the getActionMapKey()
- All classes that derive from JComponent can make use of an ActionMap.
- That means the NetBeans superclass TopComponent, which creates windows that integrate into NetBeans Platform applications, also has an ActionMap.
- CookieAction
- NodeAction
- Are dependent on nodes
- A node is the visual representation of a particular piece of data.
- Each TopComponent (and therefore each window within the NetBeans Platform) can make use of one or many activated nodes.
- It is precisely these activated nodes that form the context of a CookieAction.
- Context-sensitivity is constructed from interfaces, which are called cookies.
- General Context-Sensitive Action Classes
- Yet another approach:
- Providing generic context-sensitive action classes with the help of the Lookup class
- You will not be dependent upon a Node class, nor any other NetBeans superclass, since you will boserve how any class or interface can be used to determine the applicable context of an action.
public abstract class ContextAction<T> extends AbstractAction
implements LookupListener, ContextAwareAction {
private Lookup context = null;
private Lookup.Result result = null;
public ContextAction(Lookup context) {
init(context);
}
private void init(Lookup context) {
this.context = context;
result = context.lookupResult(contextClass());
result.addLookupListener(this);
resultChanged(null);
}
public void resultChanged(LookupEvent ev) {
setEnabled(result.allItems().size() != 0);
}
public void actionPerformed(ActionEvent e) {
performAction(result.allInstances().iterator().next());
}
public abstract Class contextClass();
public abstract void performAction(T context);
}
No comments:
Post a Comment