Runtime

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

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.CreateViewAndOptionallyElementCommand
All Implemented Interfaces:
ICommand, org.eclipse.gmf.runtime.common.core.internal.command.ICommandWithSettableResult, IUndoableOperation

public class CreateViewAndOptionallyElementCommand
extends AbstractCommand

A command used to optionally create a new view and new element. This command is used when it is not known at command creation time whether or not an element should be created as well. For example, when creating a connection to an unspecified target, did the user want to

  • create a new element for the target (view and element)?
  • use an existing element and its view already on the diagram (nothing created)?
  • use an existing element and add a new view to the diagram (view only)?

    Note: This command will pop up a dialog box if the element exists already and there is a view for it on the diagram to ask the user what they want to do.


    Constructor Summary
    CreateViewAndOptionallyElementCommand(IAdaptable elementAdapter, IGraphicalEditPart containerEP, Point location, PreferencesHint preferencesHint)
              Creates a new CreateViewAndOptionallyElementCommand.
     
    Method Summary
     boolean canRedo()
               
     boolean canUndo()
               
    protected  CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
              If the element adapter is empty, this command creates a new element and view for it.
    protected  CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info)
              Performs the actual work of redoing this command.
    protected  CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info)
              Performs the actual work of undoing this command.
     java.util.List getAffectedFiles()
              Returns the IFiles that may be modified when the operation is executed, undone or redone.
    protected  Command getCommand()
              Gets the command.
    protected  IGraphicalEditPart getContainerEP()
              Gets the containerEP.
    protected  IAdaptable getElementAdapter()
              Gets the elementAdapter.
    protected  View getExistingView(EObject element)
              Searches the container editpart to see if the element passed in already has a view.
    protected  Point getLocation()
              Gets the location.
    protected  PreferencesHint getPreferencesHint()
              Gets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values.
     IAdaptable getResult()
               
    protected  void setCommand(Command command)
              Sets the command.
    protected  void setContainerEP(IGraphicalEditPart containerEP)
              Sets the containerEP.
    protected  void setElementAdapter(IAdaptable elementAdapter)
              Sets the elementAdapter.
    protected  void setLocation(Point location)
              Sets the location.
    protected  void setPreferencesHint(PreferencesHint preferencesHint)
              Sets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values.
    protected  void setResult(IAdaptable viewAdapter)
              Sets the result to adapt to the view passed in.
    protected  boolean useExistingView(View view)
              Prompts the user to see if they would like to use an existing view on the diagram.
     
    Methods inherited from class org.eclipse.gmf.runtime.common.core.command.AbstractCommand
    compose, dispose, execute, 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
     

    Constructor Detail

    CreateViewAndOptionallyElementCommand

    public CreateViewAndOptionallyElementCommand(IAdaptable elementAdapter,
                                                 IGraphicalEditPart containerEP,
                                                 Point location,
                                                 PreferencesHint preferencesHint)
    Creates a new CreateViewAndOptionallyElementCommand.

    Parameters:
    elementAdapter - Adapts to the element, if null at command execution time, an element is to be created.
    containerEP - The container edit part, where the view request is sent.
    location - The location to create the new view. If null, a default location is used
    preferencesHint - The preference hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values. The preference hint is mapped to a preference store in the preference registry <@link DiagramPreferencesRegistry>.
    Method Detail

    getAffectedFiles

    public java.util.List getAffectedFiles()
    Description copied from class: AbstractCommand
    Returns the IFiles that may be modified when the operation is executed, undone or redone.

    Specified by:
    getAffectedFiles in interface ICommand
    Overrides:
    getAffectedFiles in class AbstractCommand

    getExistingView

    protected View getExistingView(EObject element)
    Searches the container editpart to see if the element passed in already has a view.

    Parameters:
    element -
    Returns:
    IView the view if found; or null

    useExistingView

    protected boolean useExistingView(View view)
    Prompts the user to see if they would like to use an existing view on the diagram. Clients may subclass this method to customize the message dialog.

    Parameters:
    view - the existing view
    Returns:
    true if this view should be used; false otherwise

    doExecuteWithResult

    protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor,
                                                IAdaptable info)
                                         throws ExecutionException
  • If the element adapter is empty, this command creates a new element and view for it.
  • If the element adapter is not empty, and a view for this element exists in the container, this command will prompt the user to see if they want to use the existing view or create a new view for the element and then execute accordingly.
  • If the element adapter is not empty, and a view for this element does not exist in the container, this command will create a new element and view.
  • Specified by:
    doExecuteWithResult in class AbstractCommand
    Parameters:
    progressMonitor - the progress monitor provided by the operation history. Must never be null.
    info - the IAdaptable (or null) provided by the caller in order to supply UI information for prompting the user if necessary. When this parameter is not null, it should minimally contain an adapter for the org.eclipse.swt.widgets.Shell.class.
    Returns:
    The result of executing this command. May be null if the execution status is OK, but there is no meaningful result to be returned.
    Throws:
    ExecutionException - if, for some reason, I fail to complete the operation

    canUndo

    public boolean canUndo()

    canRedo

    public boolean canRedo()

    doRedoWithResult

    protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor,
                                             IAdaptable info)
                                      throws ExecutionException
    Description copied from class: AbstractCommand
    Performs the actual work of redoing this command. Subclasses must implement this method to perform the redo.

    Specified by:
    doRedoWithResult in class AbstractCommand
    Parameters:
    progressMonitor - the progress monitor provided by the operation history. Must never be null.
    info - the IAdaptable (or null) provided by the caller in order to supply UI information for prompting the user if necessary. When this parameter is not null, it should minimally contain an adapter for the org.eclipse.swt.widgets.Shell.class.
    Returns:
    The result of redoing this command. May be null if the execution status is OK, but there is no meaningful result to be returned.
    Throws:
    ExecutionException - on failure to redo

    doUndoWithResult

    protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor,
                                             IAdaptable info)
                                      throws ExecutionException
    Description copied from class: AbstractCommand
    Performs the actual work of undoing this command. Subclasses must implement this method to perform the undo.

    Specified by:
    doUndoWithResult in class AbstractCommand
    Parameters:
    progressMonitor - the progress monitor provided by the operation history. Must never be null.
    info - the IAdaptable (or null) provided by the caller in order to supply UI information for prompting the user if necessary. When this parameter is not null, it should minimally contain an adapter for the org.eclipse.swt.widgets.Shell.class.
    Returns:
    The result of undoing this command. May be null if the execution status is OK, but there is no meaningful result to be returned.
    Throws:
    ExecutionException - on failure to undo

    getResult

    public IAdaptable getResult()
    Returns:
    the adapter from which the view can be retrieved.

    setResult

    protected void setResult(IAdaptable viewAdapter)
    Sets the result to adapt to the view passed in.

    Parameters:
    viewAdapter -

    getElementAdapter

    protected IAdaptable getElementAdapter()
    Gets the elementAdapter.

    Returns:
    Returns the elementAdapter.

    setElementAdapter

    protected void setElementAdapter(IAdaptable elementAdapter)
    Sets the elementAdapter.

    Parameters:
    elementAdapter - The elementAdapter to set.

    getLocation

    protected Point getLocation()
    Gets the location.

    Returns:
    Returns the location.

    setLocation

    protected void setLocation(Point location)
    Sets the location.

    Parameters:
    location - The location to set.

    getContainerEP

    protected IGraphicalEditPart getContainerEP()
    Gets the containerEP.

    Returns:
    Returns the containerEP.

    setContainerEP

    protected void setContainerEP(IGraphicalEditPart containerEP)
    Sets the containerEP.

    Parameters:
    containerEP - The containerEP to set.

    getPreferencesHint

    protected PreferencesHint getPreferencesHint()
    Gets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values. The preference hint is mapped to a preference store in the preference registry <@link DiagramPreferencesRegistry>.

    Returns:
    the preferences hint

    setPreferencesHint

    protected void setPreferencesHint(PreferencesHint preferencesHint)
    Sets the preferences hint that is to be used to find the appropriate preference store from which to retrieve diagram preference values. The preference hint is mapped to a preference store in the preference registry <@link DiagramPreferencesRegistry>.

    Parameters:
    preferencesHint - the preferences hint

    getCommand

    protected Command getCommand()
    Gets the command.

    Returns:
    Returns the command.

    setCommand

    protected void setCommand(Command command)
    Sets the command.

    Parameters:
    command - The command to set.

    Runtime

    Guidelines for using Eclipse APIs.

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