Runtime

org.eclipse.gmf.runtime.diagram.ui.commands
Class CreateOrSelectElementCommand

java.lang.Object
  extended byorg.eclipse.core.commands.operations.AbstractOperation
      extended byorg.eclipse.gmf.runtime.common.core.command.AbstractCommand
          extended byorg.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand
              extended byorg.eclipse.gmf.runtime.diagram.ui.commands.CreateOrSelectElementCommand
All Implemented Interfaces:
ICommand, org.eclipse.gmf.runtime.common.core.internal.command.ICommandWithSettableResult, IUndoableOperation
Direct Known Subclasses:
GraphicalNodeEditPolicy.PromptAndCreateConnectionCommand

public class CreateOrSelectElementCommand
extends PopupMenuCommand

A command that pops up a menu which can allow the user to select whether they want to create a new type, select an existing element, or leave it unspecified.

The content can be customized, one or more of the above options are permitted. The constants UNSPECIFIED and SELECT_EXISTING can be used as the content of a menu item.

The displayed strings can be customized with a custom label provider.

The options are:

  • Unspecified
  • Select Existing Element
  • Create New Type A
  • Create New Type B
  • If a "Select Existing" menu item is chosen, an additional dialog appears allowing the user to choose an element.

    The getResultAdapter() method returns an adaptable to the result.


    Nested Class Summary
    static class CreateOrSelectElementCommand.LabelProvider
              The default label provider for the the menu items used in this command.
     
    Field Summary
    static java.lang.String CREATE_WITHOUT_BINDING
              Add this to the content list of the popup menu to add a 'create without binding' option.
    static java.lang.String SELECT_EXISTING
              Add this to the content list of the popup menu to add a 'select existing' option.
    static java.lang.String UNSPECIFIED
              Add this to the content list of the popup menu to add an 'unspecified' option.
     
    Fields inherited from class org.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand
    POPUP_DIALOG, POPUP_MENU
     
    Constructor Summary
    CreateOrSelectElementCommand(Shell parentShell, java.util.List content)
              Creates a new CreateOrSelectElementCommand that uses a popup menu to prompt for the selection.
    CreateOrSelectElementCommand(Shell parentShell, java.util.List content, int style)
              Creates a new CreateOrSelectElementCommand.
    CreateOrSelectElementCommand(Shell parentShell, PopupMenu popupMenu)
              Creates a new CreateOrSelectElementCommand.
    CreateOrSelectElementCommand(java.lang.String label, Shell parentShell, java.util.List content)
              Creates a new CreateOrSelectElementCommand that uses a popup menu to prompt for the selection.
    CreateOrSelectElementCommand(java.lang.String label, Shell parentShell, java.util.List content, int style)
              Creates a new CreateOrSelectElementCommand.
     
    Method Summary
    protected  CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
              Pops up the dialog with the content provided.
    protected  ILabelProvider getLabelProvider()
              Gets the label provider that is to be used to display each item in the popup menu.
     ObjectAdapter getResultAdapter()
              Gets the resultAdapter.
    protected  AbstractSelectElementDialog getSelectElementDialog()
              Gets the selectElementDialog.
     void setSelectElementDialog(AbstractSelectElementDialog dialog)
              Sets the selectElementDialog.
     
    Methods inherited from class org.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand
    canRedo, canUndo, doRedoWithResult, doUndoWithResult, getParentShell, getPopupDialog, getPopupMenu, setParentShell, setPopupDialog, setPopupMenu
     
    Methods inherited from class org.eclipse.gmf.runtime.common.core.command.AbstractCommand
    compose, dispose, execute, getAffectedFiles, getCommandResult, internalSetResult, redo, reduce, setResult, undo
     
    Methods inherited from class org.eclipse.core.commands.operations.AbstractOperation
    addContext, canExecute, getContexts, getLabel, hasContext, removeContext, setLabel, toString
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     
    Methods inherited from interface org.eclipse.core.commands.operations.IUndoableOperation
    addContext, canExecute, getContexts, getLabel, hasContext, removeContext
     

    Field Detail

    UNSPECIFIED

    public static final java.lang.String UNSPECIFIED
    Add this to the content list of the popup menu to add an 'unspecified' option.


    SELECT_EXISTING

    public static final java.lang.String SELECT_EXISTING
    Add this to the content list of the popup menu to add a 'select existing' option.


    CREATE_WITHOUT_BINDING

    public static final java.lang.String CREATE_WITHOUT_BINDING
    Add this to the content list of the popup menu to add a 'create without binding' option.

    Constructor Detail

    CreateOrSelectElementCommand

    public CreateOrSelectElementCommand(Shell parentShell,
                                        java.util.List content)
    Creates a new CreateOrSelectElementCommand that uses a popup menu to prompt for the selection.

    Parameters:
    parentShell - the parent shell
    content - The list of items making up the content of the popup menu. This can include element types (IElementType), UNSPECIFIED, and SELECT_EXISTING.

    CreateOrSelectElementCommand

    public CreateOrSelectElementCommand(Shell parentShell,
                                        java.util.List content,
                                        int style)
    Creates a new CreateOrSelectElementCommand.

    Parameters:
    parentShell - the parent shell
    content - The list of items making up the content of the popup menu. This can include element types (IElementType), UNSPECIFIED, and SELECT_EXISTING.
    style - The kind of prompt to use for the selection. One of PopupMenuCommand.POPUP_MENU or PopupMenuCommand.POPUP_DIALOG

    CreateOrSelectElementCommand

    public CreateOrSelectElementCommand(java.lang.String label,
                                        Shell parentShell,
                                        java.util.List content)
    Creates a new CreateOrSelectElementCommand that uses a popup menu to prompt for the selection.

    Parameters:
    label - the command label
    parentShell - the parent shell
    content - The list of items making up the content of the popup menu. This can include element types (IElementType), UNSPECIFIED, and SELECT_EXISTING.

    CreateOrSelectElementCommand

    public CreateOrSelectElementCommand(java.lang.String label,
                                        Shell parentShell,
                                        java.util.List content,
                                        int style)
    Creates a new CreateOrSelectElementCommand.

    Parameters:
    label - the command label
    parentShell - the parent shell
    content - The list of items making up the content of the popup menu. This can include element types (IElementType), UNSPECIFIED, and SELECT_EXISTING.
    style - The kind of prompt to use for the selection. One of PopupMenuCommand.POPUP_MENU or PopupMenuCommand.POPUP_DIALOG

    CreateOrSelectElementCommand

    public CreateOrSelectElementCommand(Shell parentShell,
                                        PopupMenu popupMenu)
    Creates a new CreateOrSelectElementCommand.

    Parameters:
    parentShell - the parent shell
    popupMenu - the popup menu
    Method Detail

    doExecuteWithResult

    protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor,
                                                IAdaptable info)
                                         throws ExecutionException
    Pops up the dialog with the content provided. If the user selects 'select existing', then the select elements dialog also appears.

    Overrides:
    doExecuteWithResult in class PopupMenuCommand
    Throws:
    ExecutionException
    See Also:
    org.eclipse.gmf.runtime.common.core.sandbox.AbstractCommand2#doExecute(org.eclipse.core.runtime.IProgressMonitor)

    getSelectElementDialog

    protected AbstractSelectElementDialog getSelectElementDialog()
    Gets the selectElementDialog.

    Returns:
    Returns the selectElementDialog.

    setSelectElementDialog

    public void setSelectElementDialog(AbstractSelectElementDialog dialog)
    Sets the selectElementDialog.

    Parameters:
    dialog - The dialog to set.

    getResultAdapter

    public ObjectAdapter getResultAdapter()
    Gets the resultAdapter.

    Returns:
    Returns the resultAdapter.

    getLabelProvider

    protected ILabelProvider getLabelProvider()
    Gets the label provider that is to be used to display each item in the popup menu.

    Returns:
    the label provider

    Runtime

    Guidelines for using Eclipse APIs.

    Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.