Context menus
A context menu appears when the user right-clicks some component. Vaadin supports context menus for Table
, Tree
, and TreeTable
. Menu options are encapsulated using Action
instances:
final Action action = new Action("Say hello");
To add actions and respond to them, we must add a Handler
. A Handler
is an interface with two methods:
public interface Handler extends Serializable { public Action[] getActions(Object target, Object sender); public void handleAction(Action action, Object sender, Object target); }
getActions
must return an array containing all the actions we want to show in our context menu. handleAction
will be called when an action is performed (the user clicks a menu item). Here is an example implementation that shows a somewhat uncouth salutation:
table.addActionHandler(new Handler() { public void handleAction(Action action, Object sender, Object target) { Notification.show("Ok, here I go... Hello."); } public Action[] getActions(Object...