When I hear the word “Action” I think about an object that has a description, an icon, and that can receive an ActionEvent. Various Swing containers can add the same action to themselves, and that Action might be a button in one, a link in another, and so on.
Now I come to Vaadin, and I read about Actions, but…I don’t really see a good introduction to them anywhere.
I have read the Javadocs for Action itself–and I see there that it is an object with a caption and an icon–but it itself doesn’t do anything.
Then I read the Javadocs for Action.Handler, and I see there that an Action.Handler (which need not be an Action) can react to a target and a sender. It also seems to be able to provide Actions (that part confuses me).
I see from the Javadocs for Tree, for example, that I can add an Action.Handler, and…well, presumably if I get a sender/target pair that make sense to me I can…do something.
But in these cases, how is my handler called? Can I, for example–and forgive the lack of precision here–somehow add an action handler to a form and then build a dynamic toolbar at the bottom of the form where each button gets wired to a particular action? Or is this a nonsensical way to think about it?
I hope I’m speaking for other Swing developers when I outline my thought processes this way.
Actions are different things in Swing and Vaadin. They are used in Vaadin for shortcut keys and context menus.
Info of the shorcut keys -action can be found in the
Book of Vaadin: Shortcut keys -section, but it is basically that you can bind a keyboard press to do a certain action. For example when user presses ctrl+s the current data is saved or scrolling a table with the arrow keys.
The second, tree and table actions, is meant to add context menus to those components. You get the context menu open with right clicking a row in the components. An example of this with sources can be found in the
Sampler .
So actions in Vaadin don’t have anything to do with objects with descriptions and icons. To do a toolbar I suggest a little bit more manual work. Make a HorizontalLayout with a bunch of buttons and links and attach them all to a clicklistener that decides which “action” to take upon a click.
Just ask if something is still unclear, and I suggest that you create a ticket to the
Vaadin dev site if you’d like to see some improvement in a specific part of the manual.
I would refer you to
the Action javadoc , however, which shows that an Action has an icon and a caption and nothing else; that was the source of my confusion.