net.rim.device.api.ui.menu
Interface CommandItemProvider


public interface CommandItemProvider

Provides a field's command items. Command items are provided in a Vector of CommandItem elements in order of importance. Invoke Field.setCommandItemProvider() to configure a field as a CommandItemProvider.

Code sample

In the following code sample, the command item only provides a single command. This command item provider would be associated with a field by invoking Field.setCommandItemProvider(). See DefaultContextMenuProvider for an example of this. See the Command Framework API for more information about commands and how you can use the framework to register commands across applications.

 class ItemProvider implements CommandItemProvider
 {
     public Object getContext(Field field)
     {
         return field;
     }

     public Vector getItems(Field field)
     {
        Vector items = new Vector();

        CommandItem defaultCmd = new CommandItem(new StringProvider("My Menu Item"), null, new Command(new DialogCommandHandler()));

        items.addElement(defaultCmd);

        return items;
     }
 }

 class DialogCommandHandler extends CommandHandler
 {
     public void execute(ReadOnlyCommandMetadata metadata, Object context)
     {
         Dialog.alert("Executing command for " + context.toString());
     }
 }
 

Since:
BlackBerry API 6.0.0

Method Summary
 Object getContext(Field field)
          Provides a context.
 Vector getItems(Field field)
          Provides command items.
 



Method Detail

getContext

Object getContext(Field field)
Provides a context.

Parameters:
field - The field providing the context.
Returns:
Object providing the context.
Since:
BlackBerry API 6.0.0

getItems

Vector getItems(Field field)
Provides command items.

Parameters:
field - The field providing the command items.
Returns:
Vector of CommandItems in order of importance. The most important item becomes the default in the pop-up menu.
Since:
BlackBerry API 6.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal