Package org.eclipse.gef.editpolicies
Class ConstrainedLayoutEditPolicy
- java.lang.Object
-
- org.eclipse.gef.editpolicies.AbstractEditPolicy
-
- org.eclipse.gef.editpolicies.GraphicalEditPolicy
-
- org.eclipse.gef.editpolicies.LayoutEditPolicy
-
- org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
-
- All Implemented Interfaces:
EditPolicy
,RequestConstants
- Direct Known Subclasses:
XYLayoutEditPolicy
public abstract class ConstrainedLayoutEditPolicy extends LayoutEditPolicy
For use withLayoutManager
that require a constraint. ConstrainedLayoutEditPolicy understandsRequestConstants.REQ_ALIGN_CHILDREN
in addition to the Requests handled in the superclass.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.eclipse.draw2d.geometry.Dimension
UNSPECIFIED_SIZE
Constant being used to indicate that upon creation (or during move) a size was not specified.-
Fields inherited from interface org.eclipse.gef.EditPolicy
COMPONENT_ROLE, CONNECTION_BENDPOINTS_ROLE, CONNECTION_ENDPOINTS_ROLE, CONNECTION_ROLE, CONTAINER_ROLE, DIRECT_EDIT_ROLE, GRAPHICAL_NODE_ROLE, LAYOUT_ROLE, NODE_ROLE, PRIMARY_DRAG_ROLE, SELECTION_FEEDBACK_ROLE, TREE_CONTAINER_ROLE
-
Fields inherited from interface org.eclipse.gef.RequestConstants
REQ_ADD, REQ_ALIGN, REQ_ALIGN_CHILDREN, REQ_CLONE, REQ_CONNECTION_END, REQ_CONNECTION_START, REQ_CREATE, REQ_CREATE_BENDPOINT, REQ_DELETE, REQ_DELETE_DEPENDANT, REQ_DIRECT_EDIT, REQ_MOVE, REQ_MOVE_BENDPOINT, REQ_MOVE_CHILDREN, REQ_OPEN, REQ_ORPHAN, REQ_ORPHAN_CHILDREN, REQ_RECONNECT_SOURCE, REQ_RECONNECT_TARGET, REQ_RESIZE, REQ_RESIZE_CHILDREN, REQ_SELECTION, REQ_SELECTION_HOVER
-
-
Constructor Summary
Constructors Constructor Description ConstrainedLayoutEditPolicy()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected Command
createAddCommand(EditPart child, java.lang.Object constraint)
Deprecated.protected Command
createAddCommand(ChangeBoundsRequest request, EditPart child, java.lang.Object constraint)
Returns theCommand
to perform an Add with the specified child and constraint.protected Command
createChangeConstraintCommand(EditPart child, java.lang.Object constraint)
Deprecated.protected Command
createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, java.lang.Object constraint)
The request is now made available when creating the change constraint command.protected EditPolicy
createChildEditPolicy(EditPart child)
AResizableEditPolicy
is used by default for children.protected Command
getAddCommand(Request generic)
OverridesgetAddCommand()
to generate the proper constraint for each child being added.protected Command
getAlignChildrenCommand(AlignmentRequest request)
Returns the command to align a group of children.protected Command
getChangeConstraintCommand(ChangeBoundsRequest request)
Returns theCommand
for changing bounds for a group of children.Command
getCommand(Request request)
Factors out RESIZE and ALIGN requests, otherwise callssuper
.protected abstract java.lang.Object
getConstraintFor(org.eclipse.draw2d.geometry.Point point)
Generates a draw2d constraint given aPoint
.protected abstract java.lang.Object
getConstraintFor(org.eclipse.draw2d.geometry.Rectangle rect)
Generates a draw2d constraint given aRectangle
.protected java.lang.Object
getConstraintFor(Request request, GraphicalEditPart child, org.eclipse.draw2d.geometry.Rectangle rectangle)
Responsible of generating a draw2d constraint for the given Rectangle, which represents the already transformed (layout-relative) position and size of the given Request.protected java.lang.Object
getConstraintFor(ChangeBoundsRequest request, GraphicalEditPart child)
Generates a draw2d constraint object for the givenChangeBoundsRequest
and child EditPart by delegating togetConstraintFor(Request, GraphicalEditPart, Rectangle)
.protected java.lang.Object
getConstraintFor(CreateRequest request)
Generates a draw2d constraint for the givenCreateRequest
by delegating togetConstraintFor(Request, GraphicalEditPart, Rectangle)
.protected java.lang.Object
getConstraintForClone(GraphicalEditPart part, ChangeBoundsRequest request)
Deprecated.protected Command
getMoveChildrenCommand(Request request)
Returns theCommand
to move a group of children.protected Command
getResizeChildrenCommand(ChangeBoundsRequest request)
Returns theCommand
to resize a group of children.protected java.lang.Object
translateToModelConstraint(java.lang.Object figureConstraint)
Converts a constraint from the format used by LayoutManagers, to the form stored in the model.-
Methods inherited from class org.eclipse.gef.editpolicies.LayoutEditPolicy
activate, createListener, createSizeOnDropFeedback, deactivate, decorateChild, decorateChildren, eraseLayoutTargetFeedback, eraseSizeOnDropFeedback, eraseTargetFeedback, getCloneCommand, getCreateCommand, getCreationFeedbackOffset, getDeleteDependantCommand, getLayoutContainer, getLayoutOrigin, getOrphanChildrenCommand, getSizeOnDropFeedback, getSizeOnDropFeedback, getTargetEditPart, setListener, showLayoutTargetFeedback, showSizeOnDropFeedback, showTargetFeedback, translateFromAbsoluteToLayoutRelative, translateFromLayoutRelativeToAbsolute, undecorateChild, undecorateChildren
-
Methods inherited from class org.eclipse.gef.editpolicies.GraphicalEditPolicy
addFeedback, getFeedbackLayer, getHostFigure, getLayer, removeFeedback
-
Methods inherited from class org.eclipse.gef.editpolicies.AbstractEditPolicy
debugFeedback, eraseSourceFeedback, getHost, setHost, showSourceFeedback, toString, understandsRequest
-
-
-
-
Method Detail
-
createAddCommand
protected Command createAddCommand(ChangeBoundsRequest request, EditPart child, java.lang.Object constraint)
Returns theCommand
to perform an Add with the specified child and constraint. The constraint has been converted from a draw2d constraint to an object suitable for the model by callingtranslateToModelConstraint(Object)
.- Parameters:
request
- the ChangeBoundsRequestchild
- the EditPart of the child being addedconstraint
- the model constraint, after beingtranslated
- Returns:
- the Command to add the child
- Since:
- 3.7
-
createAddCommand
protected Command createAddCommand(EditPart child, java.lang.Object constraint)
Deprecated.Returns theCommand
to perform an Add with the specified child and constraint. The constraint has been converted from a draw2d constraint to an object suitable for the model by callingtranslateToModelConstraint(Object)
.- Parameters:
child
- the EditPart of the child being addedconstraint
- the model constraint, after beingtranslated
- Returns:
- the Command to add the child
-
createChangeConstraintCommand
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, java.lang.Object constraint)
The request is now made available when creating the change constraint command. By default, this method invokes the oldmethod
.- Parameters:
request
- the ChangeBoundsRequestchild
- the EditPart of the child being changedconstraint
- the new constraint, after beingtranslated
- Returns:
- A Command to change the constraints of the given child as specified in the given request
- Since:
- 3.0
- See Also:
createChangeConstraintCommand(EditPart, Object)
-
createChangeConstraintCommand
protected Command createChangeConstraintCommand(EditPart child, java.lang.Object constraint)
Deprecated.Returns theCommand
to change the specified child's constraint. The constraint has been converted from a draw2d constraint to an object suitable for the model. Clients should overwritecreateChangeConstraintCommand(ChangeBoundsRequest, EditPart, Object)
instead.- Parameters:
child
- the EditPart of the child being changedconstraint
- the new constraint, after beingtranslated
- Returns:
- Command
- See Also:
createChangeConstraintCommand(ChangeBoundsRequest, EditPart, Object)
-
createChildEditPolicy
protected EditPolicy createChildEditPolicy(EditPart child)
AResizableEditPolicy
is used by default for children. Subclasses may override this method to supply a different EditPolicy.- Specified by:
createChildEditPolicy
in classLayoutEditPolicy
- Parameters:
child
- the child EditPart- Returns:
- an EditPolicy to be installed as the
EditPolicy.PRIMARY_DRAG_ROLE
- See Also:
LayoutEditPolicy.createChildEditPolicy(EditPart)
-
getAddCommand
protected Command getAddCommand(Request generic)
OverridesgetAddCommand()
to generate the proper constraint for each child being added. Once the constraint is calculated,createAddCommand(EditPart,Object)
is called. Subclasses must implement this method.- Overrides:
getAddCommand
in classLayoutEditPolicy
- Parameters:
generic
- the ADD Request- Returns:
- A command to perform the ADD.
- See Also:
LayoutEditPolicy.getAddCommand(Request)
-
getAlignChildrenCommand
protected Command getAlignChildrenCommand(AlignmentRequest request)
Returns the command to align a group of children. By default, this is treated the same as a resize, andgetResizeChildrenCommand(ChangeBoundsRequest)
is returned.- Parameters:
request
- the AligmentRequest- Returns:
- the command to perform alignment
-
getCommand
public Command getCommand(Request request)
Factors out RESIZE and ALIGN requests, otherwise callssuper
.- Specified by:
getCommand
in interfaceEditPolicy
- Overrides:
getCommand
in classLayoutEditPolicy
- Parameters:
request
- the Request- Returns:
null
or a Command contribution- See Also:
EditPolicy.getCommand(Request)
-
getConstraintFor
protected java.lang.Object getConstraintFor(ChangeBoundsRequest request, GraphicalEditPart child)
Generates a draw2d constraint object for the givenChangeBoundsRequest
and child EditPart by delegating togetConstraintFor(Request, GraphicalEditPart, Rectangle)
. The rectangle being passed over togetConstraintFor(Request, GraphicalEditPart, Rectangle)
is calculated based on the child figure's current bounds and the ChangeBoundsRequest's move and resize deltas. It is made layout-relative by usingLayoutEditPolicy.translateFromAbsoluteToLayoutRelative(Translatable)
before callinggetConstraintFor(Request, GraphicalEditPart, Rectangle)
.- Parameters:
request
- the ChangeBoundsRequestchild
- the child EditPart for which the constraint should be generated- Returns:
- the draw2d constraint
-
getConstraintFor
protected java.lang.Object getConstraintFor(Request request, GraphicalEditPart child, org.eclipse.draw2d.geometry.Rectangle rectangle)
Responsible of generating a draw2d constraint for the given Rectangle, which represents the already transformed (layout-relative) position and size of the given Request. By default, this method delegates togetConstraintFor(Point)
orgetConstraintFor(Rectangle)
, dependent on whether the size of the rectangle is anUNSPECIFIED_SIZE
or not. Subclasses may overwrite this method in case they need the request or the edit part (which will of course not be set during creation) to calculate a layout constraint for the request.- Parameters:
rectangle
- the Rectangle relative to thelayout origin
- Returns:
- the constraint
- Since:
- 3.7
-
getConstraintFor
protected abstract java.lang.Object getConstraintFor(org.eclipse.draw2d.geometry.Point point)
Generates a draw2d constraint given aPoint
. This method is called during creation, when only a mouse location is available, as well as during move, in case no resizing is involved.- Parameters:
point
- the Point relative to thelayout origin
- Returns:
- the constraint
-
getConstraintFor
protected abstract java.lang.Object getConstraintFor(org.eclipse.draw2d.geometry.Rectangle rect)
Generates a draw2d constraint given aRectangle
. This method is called during most operations.- Parameters:
rect
- the Rectangle relative to thelayout origin
- Returns:
- the constraint
-
getConstraintFor
protected java.lang.Object getConstraintFor(CreateRequest request)
Generates a draw2d constraint for the givenCreateRequest
by delegating togetConstraintFor(Request, GraphicalEditPart, Rectangle)
. If the CreateRequest has a size, is used during size-on-drop creation, a Rectangle of the request's location and size is passed with the delegation. Otherwise, a rectangle with the request's location and an empty size (0,0) is passed over.The CreateRequest's location is relative to the Viewer. The location is made layout-relative by using
LayoutEditPolicy.translateFromAbsoluteToLayoutRelative(Translatable)
before callinggetConstraintFor(Request, GraphicalEditPart, Rectangle)
.- Parameters:
request
- the CreateRequest- Returns:
- a draw2d constraint
-
getConstraintForClone
protected java.lang.Object getConstraintForClone(GraphicalEditPart part, ChangeBoundsRequest request)
Deprecated.Returns the correct rectangle bounds for the new clone's location.- Parameters:
part
- the graphical edit part representing the object to be cloned.request
- the ChangeBoundsRequest that knows where to place the new object.- Returns:
- the bounds that will be used for the new object.
-
translateToModelConstraint
protected java.lang.Object translateToModelConstraint(java.lang.Object figureConstraint)
Converts a constraint from the format used by LayoutManagers, to the form stored in the model.- Parameters:
figureConstraint
- the draw2d constraint- Returns:
- the model constraint
-
getResizeChildrenCommand
protected Command getResizeChildrenCommand(ChangeBoundsRequest request)
Returns theCommand
to resize a group of children.- Parameters:
request
- the ChangeBoundsRequest- Returns:
- the Command
-
getChangeConstraintCommand
protected Command getChangeConstraintCommand(ChangeBoundsRequest request)
Returns theCommand
for changing bounds for a group of children.- Parameters:
request
- the ChangeBoundsRequest- Returns:
- the Command
- Since:
- 3.7
-
getMoveChildrenCommand
protected Command getMoveChildrenCommand(Request request)
Returns theCommand
to move a group of children. By default, move is treated the same as a resize.- Specified by:
getMoveChildrenCommand
in classLayoutEditPolicy
- Parameters:
request
- the Request- Returns:
- the Command to perform the move
- See Also:
LayoutEditPolicy.getMoveChildrenCommand(Request)
-
-