T
- the context typepublic abstract class ContextSensitiveAction<T extends ContextSensitiveHandler> extends AbstractAction
Component
provides/implements this context. The action will be
enabled if a component inside the provider receives the focus or only one
provider of this type is available in the current UI.
First you need a handler:
public interface SaveHandler extends ContextSensitiveHandler { public void save(); }The action may look like this:
public class SaveAction extends ContextSensitiveAction<SaveHandler> { public SaveAction(XdevUI ui) { super(ui,SaveHandler.class); setCaption("Save"); } @Override public void actionPerformed(ActionEvent e) { getHandler().save(); } }Then any
Component
can provide the handler:
public class EditorView extends XdevView implements SaveHandler { public EditorView() { super(); this.initUI(); } @Override public void save() { // Implement save routine here } private void initUI() { // ... } }For example in the main UI there is a button bar or menu where the action is visible:
public class MainUI extends XdevUI { @Override public void init(VaadinRequest request) { this.initUI(); ... SaveAction saveAction = new SaveAction(this); XdevButton cmdSave = new XdevButton(action); ... // or otherwise cmdSave.setAction(saveAction); } }
getHandler()
,
handlerChanged(ContextSensitiveHandler, ContextSensitiveHandler)
,
ContextSensitiveHandler
,
XdevActionManager
CAPTION_PROPERTY, DESCRIPTION_PROPERTY, ENABLED_PROPERTY, ICON_PROPERTY, SHORTCUT_PROPERTY
addPropertyChangeListener, getCaption, getDescription, getIcon, getShortcut, getUI, isEnabled, removePropertyChangeListener, setCaption, setDescription, setEnabled, setIcon, setShortcut
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
actionPerformed