Class LayoutEditPolicy

All Implemented Interfaces:
EditPolicy, RequestConstants
Direct Known Subclasses:
ConstrainedLayoutEditPolicy, OrderedLayoutEditPolicy

public abstract class LayoutEditPolicy extends GraphicalEditPolicy
Provides support for interacting with children GraphicalEditParts with the host figure's current LayoutManager.

LayoutEditPolicies are responsible for moving, resizing, re-parenting, and creating children. The should provide Commands for all of these operations. Feedback on the container can also be useful for some layouts like grids.

LayoutEditPolicies will decorate the host's children with "satellite" EditPolicies. These policies are installed using the EditPolicy.PRIMARY_DRAG_ROLE. Simple layouts will use either ResizableEditPolicy or NonResizableEditPolicy, depending on how the LayoutManager works, and/or attributes of the child EditPart.

  • Constructor Details

    • LayoutEditPolicy

      public LayoutEditPolicy()
  • Method Details

    • activate

      public void activate()
      Extends activate() to allow proper decoration of children.
      Specified by:
      activate in interface EditPolicy
      Overrides:
      activate in class AbstractEditPolicy
      See Also:
    • createChildEditPolicy

      protected abstract EditPolicy createChildEditPolicy(EditPart child)
      Returns the "satellite" EditPolicy used to decorate the child.
      Parameters:
      child - the child EditPart
      Returns:
      an EditPolicy to be installed as the EditPolicy.PRIMARY_DRAG_ROLE
    • createListener

      protected EditPartListener createListener()
      creates the EditPartListener for observing when children are added to the host.
      Returns:
      EditPartListener
    • createSizeOnDropFeedback

      protected IFigure createSizeOnDropFeedback(CreateRequest createRequest)
      Override to provide custom feedback figure for the given create request.
      Parameters:
      createRequest - the create request
      Returns:
      custom feedback figure
    • deactivate

      public void deactivate()
      Overrides deactivate to remove the EditPartListener.
      Specified by:
      deactivate in interface EditPolicy
      Overrides:
      deactivate in class AbstractEditPolicy
      See Also:
    • decorateChild

      protected void decorateChild(EditPart child)
      Decorates the child with a EditPolicy.PRIMARY_DRAG_ROLE such as ResizableEditPolicy.
      Parameters:
      child - the child EditPart being decorated
    • decorateChildren

      protected void decorateChildren()
      Decorates all existing children. This method is called on activation.
    • eraseLayoutTargetFeedback

      protected void eraseLayoutTargetFeedback(Request request)
      Erases target layout feedback. This method is the inverse of showLayoutTargetFeedback(Request).
      Parameters:
      request - the Request
    • eraseSizeOnDropFeedback

      protected void eraseSizeOnDropFeedback(Request request)
      Erases size-on-drop feedback used during creation.
      Parameters:
      request - the Request
    • eraseTargetFeedback

      public void eraseTargetFeedback(Request request)
      Calls two more specific methods depending on the Request.
      Specified by:
      eraseTargetFeedback in interface EditPolicy
      Overrides:
      eraseTargetFeedback in class AbstractEditPolicy
      Parameters:
      request - the Request
      See Also:
    • getAddCommand

      protected Command getAddCommand(Request request)
      Override to return the Command to perform an ADD. By default, null is returned.
      Parameters:
      request - the ADD Request
      Returns:
      A command to perform the ADD.
    • getCloneCommand

      protected Command getCloneCommand(ChangeBoundsRequest request)
      Override to contribute to clone requests.
      Parameters:
      request - the clone request
      Returns:
      the command contribution to the clone
    • getCommand

      public Command getCommand(Request request)
      Factors incoming requests into various specific methods.
      Specified by:
      getCommand in interface EditPolicy
      Overrides:
      getCommand in class AbstractEditPolicy
      Parameters:
      request - the Request
      Returns:
      null or a Command contribution
      See Also:
    • getCreateCommand

      protected abstract Command getCreateCommand(CreateRequest request)
      Returns the Command to perform a create.
      Parameters:
      request - the CreateRequest
      Returns:
      a Command to perform a create
    • getCreationFeedbackOffset

      protected Insets getCreationFeedbackOffset(CreateRequest request)
      Returns any insets that need to be applied to the creation feedback's bounds.
      Parameters:
      request - the create request
      Returns:
      insets, if necessary
    • getDeleteDependantCommand

      protected Command getDeleteDependantCommand(Request request)
      Returns the Command to delete a child. This method does not get called unless the child forwards an additional request to the container editpart.
      Parameters:
      request - the Request
      Returns:
      the Command to delete the child
    • getLayoutContainer

      protected IFigure getLayoutContainer()
      Returns the host's contentPane . The contentPane is the Figure which parents the childrens' figures. It is also the figure which has the LayoutManager that corresponds to this EditPolicy. All operations should be interpreted with respect to this figure.
      Returns:
      the Figure that owns the corresponding LayoutManager
    • getMoveChildrenCommand

      protected abstract Command getMoveChildrenCommand(Request request)
      Returns the Command to move a group of children.
      Parameters:
      request - the Request
      Returns:
      the Command to perform the move
    • getOrphanChildrenCommand

      protected Command getOrphanChildrenCommand(Request request)
      Returns the Command to orphan a group of children. The contribution to orphan might contain two parts, both of which are optional. The first part is to actually remove the children from their existing parent. Some application models will perform an orphan implicitly when the children are added to their new parent. The second part is to perform some adjustments on the remaining children. For example, a Table layout might simplify itself by collapsing any unused columns and rows.
      Parameters:
      request - the Request
      Returns:
      null or a Command to perform an orphan
    • getSizeOnDropFeedback

      protected IFigure getSizeOnDropFeedback(CreateRequest createRequest)
      Lazily creates and returns the Figure to use for size-on-drop feedback.
      Parameters:
      createRequest - the createRequest
      Returns:
      the size-on-drop feedback figure
    • getSizeOnDropFeedback

      protected IFigure getSizeOnDropFeedback()
      Lazily creates and returns the Figure to use for size-on-drop feedback.
      Returns:
      the size-on-drop feedback figure
    • getTargetEditPart

      public EditPart getTargetEditPart(Request request)
      Returns the host if the Request is an ADD, MOVE, or CREATE.
      Specified by:
      getTargetEditPart in interface EditPolicy
      Overrides:
      getTargetEditPart in class AbstractEditPolicy
      Parameters:
      request - the Request
      Returns:
      null or the appropriate target EditPart
      See Also:
    • setListener

      protected void setListener(EditPartListener listener)
      Sets the EditPartListener used to decorate new children. If the listener is currently set, it will be unhooked. If the new value is not null, it will be hooked.

      The listener must be remembered in case this EditPolicy is removed from the host and replaced with another LayoutEditPolicy.

      Parameters:
      listener - null or the listener.
    • showLayoutTargetFeedback

      protected void showLayoutTargetFeedback(Request request)
      Shows target layout feedback. During moves, reparents, and creation, this method is called to allow the LayoutEditPolicy to temporarily show features of its layout that will help the User understand what will happen if the operation is performed in the current location.

      By default, no feedback is shown.

      Parameters:
      request - the Request
      See Also:
    • showSizeOnDropFeedback

      protected void showSizeOnDropFeedback(CreateRequest request)
      Shows size-on-drop feedback during creation.
      Parameters:
      request - the CreateRequest
    • showTargetFeedback

      public void showTargetFeedback(Request request)
      Factors feedback requests into two more specific methods.
      Specified by:
      showTargetFeedback in interface EditPolicy
      Overrides:
      showTargetFeedback in class AbstractEditPolicy
      Parameters:
      request - the Request
      See Also:
    • undecorateChild

      protected void undecorateChild(EditPart child)
      Removes the decoration added in decorateChild(EditPart).
      Parameters:
      child - the child whose decoration is being removed.
    • undecorateChildren

      protected void undecorateChildren()
      Removes all decorations added by decorateChildren().
    • getLayoutOrigin

      protected Point getLayoutOrigin()
      Returns the layout's origin relative to the getLayoutContainer(). In other words, what Point on the parent Figure does the LayoutManager use a reference when generating the child figure's bounds from the child's constraint.

      By default, it is assumed that the layout manager positions children relative to the client area of the layout container. Thus, when processing Viewer-relative Points or Rectangles, the clientArea's location (top-left corner) will be subtracted from the Point/Rectangle, resulting in an offset from the LayoutOrigin.

      Returns:
      Point
      Since:
      3.7 Moved up from ConstrainedLayoutEditPolicy
    • translateFromAbsoluteToLayoutRelative

      protected void translateFromAbsoluteToLayoutRelative(Translatable t)
      Translates a Translatable in absolute coordinates to be layout-relative, i.e. relative to the getLayoutContainer()'s origin, which is obtained via getLayoutOrigin().
      Parameters:
      t - the Translatable in absolute coordinates to be translated to layout-relative coordinates.
      Since:
      3.7
    • translateFromLayoutRelativeToAbsolute

      protected void translateFromLayoutRelativeToAbsolute(Translatable t)
      Translates a Translatable in layout-relative coordinates, i.e. relative to getLayoutContainer()'s origin which is obtained via getLayoutOrigin(), into absolute coordinates.
      Parameters:
      t - the Translatable in layout-relative coordinates to be translated into absolute coordinates.
      Since:
      3.7