Class CreationTool

  • All Implemented Interfaces:
    RequestConstants, Tool

    public class CreationTool
    extends TargetingTool
    The CreationTool creates new EditParts via a CreationFactory. If the user simply clicks on the viewer, the default sized EditPart will be created at that point. If the user clicks and drags, the created EditPart will be sized based on where the user clicked and dragged.
    • Constructor Detail

      • CreationTool

        public CreationTool()
        Default constructor. Sets the default and disabled cursors.
      • CreationTool

        public CreationTool​(CreationFactory aFactory)
        Constructs a new CreationTool with the given factory.
        Parameters:
        aFactory - the creation factory
    • Method Detail

      • calculateCursor

        protected Cursor calculateCursor()
        Description copied from class: AbstractTool
        Returns the appropriate cursor for the tools current state. If the tool is in its terminal state, null is returned. Otherwise, either the default or disabled cursor is returned, based on the existence of a current command, and whether that current command is executable.

        Subclasses may override or extend this method to calculate the appropriate cursor based on other conditions.

        Overrides:
        calculateCursor in class AbstractTool
        Returns:
        null or a cursor to be displayed.
        See Also:
        AbstractTool.calculateCursor()
      • deactivate

        public void deactivate()
        Description copied from class: AbstractTool
        Deactivates the tool. This method is called whenever the user switches to another tool. Use this method to do some clean-up when the tool is switched. The abstract tool allows cursors for viewers to be changed. When the tool is deactivated it must revert to normal the cursor of the last tool it changed.
        Specified by:
        deactivate in interface Tool
        Overrides:
        deactivate in class TargetingTool
        See Also:
        Tool.deactivate()
      • getCommandName

        protected java.lang.String getCommandName()
        Description copied from class: AbstractTool
        Returns the identifier of the command that is being sought. This name is also the named that will be logged in the debug view.
        Specified by:
        getCommandName in class AbstractTool
        Returns:
        the identifier for the command
        See Also:
        AbstractTool.getCommandName()
      • getFactory

        protected CreationFactory getFactory()
        Returns the creation factory used to create the new EditParts.
        Returns:
        the creation factory
      • handleButtonDown

        protected boolean handleButtonDown​(int button)
        The creation tool only works by clicking mouse button 1 (the left mouse button in a right-handed world). If any other button is pressed, the tool goes into an invalid state. Otherwise, it goes into the drag state, updates the request's location and calls TargetingTool.lockTargetEditPart(EditPart) with the edit part that was just clicked on.
        Overrides:
        handleButtonDown in class AbstractTool
        Parameters:
        button - which button went down
        Returns:
        true if the buttonDown was handled
        See Also:
        AbstractTool.handleButtonDown(int)
      • handleButtonUp

        protected boolean handleButtonUp​(int button)
        If the tool is currently in a drag or drag-in-progress state, it goes into the terminal state, performs some cleanup (erasing feedback, unlocking target edit part), and then calls performCreation(int) .
        Overrides:
        handleButtonUp in class AbstractTool
        Parameters:
        button - the button being released
        Returns:
        true if the button up was handled
        See Also:
        AbstractTool.handleButtonUp(int)
      • handleDragStarted

        protected boolean handleDragStarted()
        Description copied from class: AbstractTool
        Called only one time during a drag when the drag threshold has been exceeded. By default, nothing happens and false is returned. Subclasses may override to interpret the drag starting. Returning true indicates that the event was handled.
        Overrides:
        handleDragStarted in class AbstractTool
        Returns:
        true if the drag starting was handled
        See Also:
        AbstractTool.handleDragStarted()
      • handleFocusLost

        protected boolean handleFocusLost()
        If the user is in the middle of creating a new edit part, the tool erases feedback and goes into the invalid state when focus is lost.
        Overrides:
        handleFocusLost in class AbstractTool
        Returns:
        true if the event was handled
        See Also:
        AbstractTool.handleFocusLost()
      • handleHover

        protected boolean handleHover()
        Description copied from class: AbstractTool
        Handles high-level processing of a mouse hover event. By default, nothing happens and false is returned. Subclasses may override this method to interpret the hover. Return true to indicate that the hover was handled.
        Overrides:
        handleHover in class AbstractTool
        Returns:
        true if the hover was handled
        See Also:
        AbstractTool.handleHover()
      • handleMove

        protected boolean handleMove()
        Updates the request and mouse target, gets the current command and asks to show feedback.
        Overrides:
        handleMove in class AbstractTool
        Returns:
        true if the mouse move was handled
        See Also:
        AbstractTool.handleMove()
      • performCreation

        protected void performCreation​(int button)
        Executes the current command and selects the newly created object. The button that was released to cause this creation is passed in, but since handleButtonDown(int) goes into the invalid state if the button pressed is not button 1, this will always be button 1.
        Parameters:
        button - the button that was pressed
      • setFactory

        public void setFactory​(CreationFactory factory)
        Sets the creation factory used to create the new edit parts.
        Parameters:
        factory - the factory
      • enforceConstraintsForSizeOnDropCreate

        protected void enforceConstraintsForSizeOnDropCreate​(CreateRequest request)
        Ensures size constraints (by default minimum and maximum) are respected by the given request. May be overwritten by clients to enforce additional constraints.
        Since:
        3.7
      • getMaximumSizeFor

        protected org.eclipse.draw2d.geometry.Dimension getMaximumSizeFor​(CreateRequest request)
        Determines the maximum size for CreateRequest's size on drop. It is called from enforceConstraintsForSizeOnDropCreate(CreateRequest) during creation. By default, a large Dimension is returned.
        Parameters:
        request - the request.
        Returns:
        the minimum size
        Since:
        3.7
      • getMinimumSizeFor

        protected org.eclipse.draw2d.geometry.Dimension getMinimumSizeFor​(CreateRequest request)
        Determines the minimum size for CreateRequest's size on drop. It is called from enforceConstraintsForSizeOnDropCreate(CreateRequest) during creation. By default, a small Dimension is returned.
        Parameters:
        request - the request.
        Returns:
        the minimum size
        Since:
        3.7