private class DemoListField extends ListField {
/**
* @see ListField#getContextMenu()
*/
public ContextMenu getContextMenu() {
final ContextMenu menu = super.getContextMenu();
if (_displayables != null && !isEmpty()) {
menu.clear();
final int i = getSelectedIndex();
final Object element = _displayables.elementAt(i);
if (element instanceof UnifiedSearchDemoEntity) {
final UnifiedSearchDemoEntity item =
(UnifiedSearchDemoEntity) element;
final UiAction action = item.getUiActions(null, null);
if (action != null) {
// Add the appropriate UiAction to the context menu
final MenuItem performActionItem =
new MenuItem(new StringProvider(action
.toString()), 0x230010, 0);
performActionItem.setCommand(new Command(
new CommandHandler() {
/**
* @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
* Object)
*/
public
void
execute(final ReadOnlyCommandMetadata metadata,
final Object context) {
action.performAction(item);
}
}));
menu.addItem(performActionItem);
}
}
}
return menu;