Java Reference
In-Depth Information
created in startWidget() ; or manually using the menu.open()
method. As we have only two views, there would be no advantage in
implementing the callback to return a single Menu . Therefore this code
uses the second approach, implemented in the actionPerformed()
method of your widget class, avoiding the overhead of another func-
tion call:
void actionPerformed(final Shell shell, final Component source,
final int action)
{
// omitted code
else if(action == CMD_OPEN) {
menu.open(shell);
} // omitted code
}
CMD_OPEN is an action, represented by an int value, defined at
the beginning of the class and passed to the OK MenuItem when it is
constructed.
Having finished creating the Form view, let's look at the functionality
it provides: an input field used to type in the search criteria (tags), a
choice list for setting the search mode (All tags or Any tag) and a menu.
The menu has three options: Search, Save Search and Load Search. The
first option proceeds to pull data from Flickr's public photo feed, using
the parameters defined by the user and the other two options allow the
user to save and load a favorite seach. Let's see how this functionality is
implemented.
When we created the menu, we passed a few IDs to its add() method.
These IDs are passed back in the actionPerformed() method, where
we can take action according to the menu item that was pressed:
void actionPerformed(final Shell shell, final Component source,
final int action)
{
// omitted code
else if(action == CMD_SAVE) {
saveSearch();
} else if(action == CMD_LOAD) {
loadSearch();
}
}
Depending on the item, we choose to save or load a search query.
Here are the implementations for saveSearch() and loadSearch() :
void saveSearch() {
Store store = getStore();
Search WWH ::




Custom Search