Modelers

org.topcased.modeler.edit.policies
Class ModelerLayoutEditPolicy

java.lang.Object
  extended by org.eclipse.gef.editpolicies.AbstractEditPolicy
      extended by org.eclipse.gef.editpolicies.GraphicalEditPolicy
          extended by org.eclipse.gef.editpolicies.LayoutEditPolicy
              extended by org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
                  extended by org.eclipse.gef.editpolicies.XYLayoutEditPolicy
                      extended by org.topcased.modeler.edit.policies.ModelerLayoutEditPolicy
All Implemented Interfaces:
org.eclipse.gef.EditPolicy, org.eclipse.gef.RequestConstants

public abstract class ModelerLayoutEditPolicy
extends org.eclipse.gef.editpolicies.XYLayoutEditPolicy

Basic Edit policy for XY layout objects.
Add drag'n drop from outline support.
Add Autolayout support.

creation : 1 juil. 2005


Field Summary
 
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
ModelerLayoutEditPolicy()
           
 
Method Summary
protected  int borderToAttach(GraphNode node)
          Gives the border to attach to.
protected  int calculateChildAttachment(GraphNode node, org.eclipse.draw2d.geometry.Point loc, org.eclipse.draw2d.geometry.Rectangle container)
          Calculate the nearest border where the graphNode should be attached at the creation depending on its location (Point) and its container (Rectangle)
protected  org.eclipse.draw2d.geometry.Point calculateChildPosition(org.eclipse.draw2d.geometry.Rectangle constraint, org.eclipse.gef.GraphicalEditPart parent)
          Calculate the Point where to create the child node
protected  org.eclipse.gef.commands.Command createAddCommand(org.eclipse.gef.EditPart child, java.lang.Object constraint)
           
protected  org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.requests.ChangeBoundsRequest request, org.eclipse.gef.EditPart child, java.lang.Object constraint)
           
protected  org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.EditPart child, java.lang.Object constraint)
          Check if the node (child) is always in the diagram bounds
protected  org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.EditPart child, java.lang.Object constraint, boolean checkConstraint)
          Create the command to change the constraints of the EditPart.
protected  org.eclipse.gef.EditPolicy createChildEditPolicy(org.eclipse.gef.EditPart child)
           
protected  org.eclipse.draw2d.IFigure createFeedbackFigure()
          Creates the default feedback figure
 void deactivate()
           
protected  void eraseLayoutTargetFeedback(org.eclipse.gef.Request request)
           
protected  org.eclipse.draw2d.geometry.Point getAbsoluteMouseLocation(org.eclipse.draw2d.geometry.Point relativeLocation)
          Get the absolute coordinates from relative coordinates given by the pointer Location
protected  org.eclipse.gef.commands.Command getAutoLayoutCommand(AutoLayoutRequest request)
          Create the AutoLayout Command for the given request
 org.eclipse.gef.commands.Command getCommand(org.eclipse.gef.Request request)
          Factors out AUTOLAYOUT, otherwise calls super.
protected  java.lang.Object getConstraintFor(org.eclipse.gef.requests.ChangeBoundsRequest request, org.eclipse.gef.GraphicalEditPart child)
          Overridden to prevent sizes from becoming too small, and to prevent preferred sizes from getting lost.
protected  java.lang.Object getConstraintFor(org.eclipse.gef.requests.CreateRequest request)
           
protected  org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gef.requests.CreateRequest request)
           
protected  org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gef.EditDomain domain, GraphNode newObject, GraphNode newParent, EObject newContainerParent, org.eclipse.draw2d.geometry.Point location, org.eclipse.draw2d.geometry.Dimension dimension, int attach, java.util.List featuresList, boolean needModelUpdate)
          Generate the command.
protected  org.eclipse.gef.commands.Command getCreateCommand(GraphNode parent, GraphNode child, org.eclipse.draw2d.geometry.Point loc, org.eclipse.draw2d.geometry.Dimension dim, int pos, boolean needModelUpdate)
          Returns the command for the GraphElement creation
protected  org.eclipse.draw2d.geometry.Rectangle getCurrentConstraintFor(org.eclipse.gef.GraphicalEditPart child)
          Retrieves the child's current constraint from the LayoutManager.
protected  org.eclipse.gef.commands.Command getDeleteDependantCommand(org.eclipse.gef.Request request)
           
protected  org.eclipse.draw2d.IFigure getFeedbackFigure(org.eclipse.gef.GraphicalEditPart child)
          Lazily creates and returns the feedback figure used during drags.
protected  org.eclipse.draw2d.IFigure getFeedbackLayer()
          Returns the layer used for displaying feedback.
protected  EObject getParentContainerEObject(GraphElement parent, DiagramElement child)
          By default, it is the model object associated with the parent node that should contain the child
protected  boolean isAttachedToBorder(GraphNode node)
          Determine if the object must be attached to the nearest border.
protected  boolean isExternalObjectAllowed(GraphNode parent, GraphNode child)
          Returns true if an external object can be displayed in this container.
protected  boolean isSeveralDisplayAllowed(GraphNode parent, GraphNode child, boolean needModelUpdate)
          Returns true if an model object can be displayed several time in the same diagram.
protected  boolean isValid(EObject child, EObject parent)
          Check if the current EObject is a valid child for the parent EObject.
protected  boolean isValidConstraint(org.eclipse.gef.GraphicalEditPart parent, org.eclipse.draw2d.geometry.Rectangle constraint)
          Check if the given constraint location is valid for a child of this editpart
protected  void showLayoutTargetFeedback(org.eclipse.gef.Request request)
           
 
Methods inherited from class org.eclipse.gef.editpolicies.XYLayoutEditPolicy
getConstraintFor, getConstraintFor, getLayoutOrigin, getMinimumSizeFor, getXYLayout, setXyLayout, showSizeOnDropFeedback
 
Methods inherited from class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
getAddCommand, getAlignChildrenCommand, getConstraintForClone, getMoveChildrenCommand, getResizeChildrenCommand, translateToModelConstraint
 
Methods inherited from class org.eclipse.gef.editpolicies.LayoutEditPolicy
activate, createListener, createSizeOnDropFeedback, decorateChild, decorateChildren, eraseSizeOnDropFeedback, eraseTargetFeedback, getCloneCommand, getCreationFeedbackOffset, getLayoutContainer, getOrphanChildrenCommand, getSizeOnDropFeedback, getSizeOnDropFeedback, getTargetEditPart, setListener, showTargetFeedback, undecorateChild, undecorateChildren
 
Methods inherited from class org.eclipse.gef.editpolicies.GraphicalEditPolicy
addFeedback, getHostFigure, getLayer, removeFeedback
 
Methods inherited from class org.eclipse.gef.editpolicies.AbstractEditPolicy
debugFeedback, eraseSourceFeedback, getHost, setHost, showSourceFeedback, toString, understandsRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ModelerLayoutEditPolicy

public ModelerLayoutEditPolicy()
Method Detail

isExternalObjectAllowed

protected boolean isExternalObjectAllowed(GraphNode parent,
                                          GraphNode child)
Returns true if an external object can be displayed in this container. External objects are objects included in a different container.
This method can be overridden by subclasses to fit with diagram requirement.
Default behavior is only local objects are allowed.

Parameters:
parent - The container
child - the child GraphNode
Returns:
false

isSeveralDisplayAllowed

protected boolean isSeveralDisplayAllowed(GraphNode parent,
                                          GraphNode child,
                                          boolean needModelUpdate)
Returns true if an model object can be displayed several time in the same diagram.
This method can be overridden by subclasses to fit with diagram requirement.
Default behavior is only one representation of an object is allowed.

Parameters:
parent - The container
child - the child GraphNode
needModelUpdate - true if the model is modified by the command
Returns:
false

getCreateCommand

protected org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gef.requests.CreateRequest request)
Specified by:
getCreateCommand in class org.eclipse.gef.editpolicies.LayoutEditPolicy
See Also:
LayoutEditPolicy.getCreateCommand(org.eclipse.gef.requests.CreateRequest)

isAttachedToBorder

protected boolean isAttachedToBorder(GraphNode node)
Determine if the object must be attached to the nearest border. Subclasses should override this method to check if the model object that is created should be attached to the border like a port.

Parameters:
node - the GraphNode that is created
Returns:
false by default

borderToAttach

protected int borderToAttach(GraphNode node)
Gives the border to attach to. The correct returned values are NORTH, SOUTH, EAST, WEST. A combinaison of them can be used by the use of the | operator. For example, to specify nearest border of the right or left border : EAST | WEST. Subclasses should override this method to give the border to attach the model object

Parameters:
node - the GraphNode that is created
Returns:
NORTH | SOUTH | EAST | WEST by default
See Also:
PositionConstants

calculateChildAttachment

protected int calculateChildAttachment(GraphNode node,
                                       org.eclipse.draw2d.geometry.Point loc,
                                       org.eclipse.draw2d.geometry.Rectangle container)
Calculate the nearest border where the graphNode should be attached at the creation depending on its location (Point) and its container (Rectangle)

Parameters:
node - the graphNode that is created
loc - the location where the user has clicked in the container coordinates.
container - the container Figure
Returns:
a PositionConstant

getCreateCommand

protected org.eclipse.gef.commands.Command getCreateCommand(GraphNode parent,
                                                            GraphNode child,
                                                            org.eclipse.draw2d.geometry.Point loc,
                                                            org.eclipse.draw2d.geometry.Dimension dim,
                                                            int pos,
                                                            boolean needModelUpdate)
Returns the command for the GraphElement creation

Parameters:
parent - The container
child - The child to add
loc - The position
dim - The selected area
pos - Specify eventually the attachment of the GraphNode
needModelUpdate - true if the model must be updated with this children, false if we only went to add its graphical representation.
Returns:
The command

getCreateCommand

protected org.eclipse.gef.commands.Command getCreateCommand(org.eclipse.gef.EditDomain domain,
                                                            GraphNode newObject,
                                                            GraphNode newParent,
                                                            EObject newContainerParent,
                                                            org.eclipse.draw2d.geometry.Point location,
                                                            org.eclipse.draw2d.geometry.Dimension dimension,
                                                            int attach,
                                                            java.util.List featuresList,
                                                            boolean needModelUpdate)
Generate the command. By default, the generic CreateGraphNodeCommand is returned. This function should be overriden to return a custumized command.

Parameters:
domain - the EditDomain (used to init the name)
newObject - the node to create
newParent - the parentNode node
newContainerParent - the model object that should contain the new childNode object
location - the location of the created node
dimension - the size of the created node
attach - the newAttachment of the created node
featuresList - the avalaible model element feature of the parentNode node where the model element of the childNode node can be added
needModelUpdate - true if the model must be modified during this command, false if objects already exist in the mode.
Returns:
the command

getParentContainerEObject

protected EObject getParentContainerEObject(GraphElement parent,
                                            DiagramElement child)
By default, it is the model object associated with the parent node that should contain the child

Parameters:
parent - the parent node
Returns:
the model object that should contain the child object

isValid

protected boolean isValid(EObject child,
                          EObject parent)
Check if the current EObject is a valid child for the parent EObject. Subclasses should override this method to proceed a better validation.

Parameters:
child - the child EObject
parent - the parent EObject
Returns:
true if the child can be added

calculateChildPosition

protected org.eclipse.draw2d.geometry.Point calculateChildPosition(org.eclipse.draw2d.geometry.Rectangle constraint,
                                                                   org.eclipse.gef.GraphicalEditPart parent)
Calculate the Point where to create the child node

Parameters:
constraint - the rectangle constraint
parent - the parent zone were graph node will be created
Returns:
the TopLeft Point of the rectangle that contains the graphNode

getFeedbackLayer

protected org.eclipse.draw2d.IFigure getFeedbackLayer()
Returns the layer used for displaying feedback.

Overrides:
getFeedbackLayer in class org.eclipse.gef.editpolicies.GraphicalEditPolicy
Returns:
the feedback layer

getAutoLayoutCommand

protected org.eclipse.gef.commands.Command getAutoLayoutCommand(AutoLayoutRequest request)
Create the AutoLayout Command for the given request

Parameters:
request - the autolayout request
Returns:
the autolayout command

getCommand

public org.eclipse.gef.commands.Command getCommand(org.eclipse.gef.Request request)
Factors out AUTOLAYOUT, otherwise calls super.

Specified by:
getCommand in interface org.eclipse.gef.EditPolicy
Overrides:
getCommand in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
EditPolicy.getCommand(Request)

createChangeConstraintCommand

protected org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.requests.ChangeBoundsRequest request,
                                                                         org.eclipse.gef.EditPart child,
                                                                         java.lang.Object constraint)
Overrides:
createChangeConstraintCommand in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
ConstrainedLayoutEditPolicy.createChangeConstraintCommand(org.eclipse.gef.requests.ChangeBoundsRequest, org.eclipse.gef.EditPart, java.lang.Object)

getConstraintFor

protected java.lang.Object getConstraintFor(org.eclipse.gef.requests.ChangeBoundsRequest request,
                                            org.eclipse.gef.GraphicalEditPart child)
Overridden to prevent sizes from becoming too small, and to prevent preferred sizes from getting lost. If the Request is a MOVE, the existing width and height are preserved. During RESIZE, the new width and height have a lower bound determined by XYLayoutEditPolicy.getMinimumSizeFor(GraphicalEditPart) and the current Attachment is preserved.

Overrides:
getConstraintFor in class org.eclipse.gef.editpolicies.XYLayoutEditPolicy
See Also:
XYLayoutEditPolicy.getConstraintFor(org.eclipse.gef.requests.ChangeBoundsRequest, org.eclipse.gef.GraphicalEditPart)

getConstraintFor

protected java.lang.Object getConstraintFor(org.eclipse.gef.requests.CreateRequest request)
Overrides:
getConstraintFor in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
ConstrainedLayoutEditPolicy.getConstraintFor(org.eclipse.gef.requests.CreateRequest)

getAbsoluteMouseLocation

protected org.eclipse.draw2d.geometry.Point getAbsoluteMouseLocation(org.eclipse.draw2d.geometry.Point relativeLocation)
Get the absolute coordinates from relative coordinates given by the pointer Location

Parameters:
relativeLocation -
Returns:
Point with absolute coordinates

getCurrentConstraintFor

protected org.eclipse.draw2d.geometry.Rectangle getCurrentConstraintFor(org.eclipse.gef.GraphicalEditPart child)
Retrieves the child's current constraint from the LayoutManager.

Overrides:
getCurrentConstraintFor in class org.eclipse.gef.editpolicies.XYLayoutEditPolicy
Parameters:
child - the child
Returns:
the current constraint

createChangeConstraintCommand

protected org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.EditPart child,
                                                                         java.lang.Object constraint)
Check if the node (child) is always in the diagram bounds

Specified by:
createChangeConstraintCommand in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
ConstrainedLayoutEditPolicy.createChangeConstraintCommand(org.eclipse.gef.EditPart, java.lang.Object)

createChangeConstraintCommand

protected org.eclipse.gef.commands.Command createChangeConstraintCommand(org.eclipse.gef.EditPart child,
                                                                         java.lang.Object constraint,
                                                                         boolean checkConstraint)
Create the command to change the constraints of the EditPart.

Parameters:
child - the EditPart to move
constraint - the new constraints
checkConstraint - if true the command is created only if the bounds are in the parent client area.
Returns:
the ChangeBoundsCommand

isValidConstraint

protected boolean isValidConstraint(org.eclipse.gef.GraphicalEditPart parent,
                                    org.eclipse.draw2d.geometry.Rectangle constraint)
Check if the given constraint location is valid for a child of this editpart

Parameters:
parent - the parent editpart
constraint - the child constraint
Returns:
true if these constraints are valid

createAddCommand

protected org.eclipse.gef.commands.Command createAddCommand(org.eclipse.gef.EditPart child,
                                                            java.lang.Object constraint)
Overrides:
createAddCommand in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
ConstrainedLayoutEditPolicy.createAddCommand(org.eclipse.gef.EditPart, java.lang.Object)

getDeleteDependantCommand

protected org.eclipse.gef.commands.Command getDeleteDependantCommand(org.eclipse.gef.Request request)
Overrides:
getDeleteDependantCommand in class org.eclipse.gef.editpolicies.LayoutEditPolicy
See Also:
LayoutEditPolicy.getDeleteDependantCommand(org.eclipse.gef.Request)

createChildEditPolicy

protected org.eclipse.gef.EditPolicy createChildEditPolicy(org.eclipse.gef.EditPart child)
Overrides:
createChildEditPolicy in class org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy
See Also:
LayoutEditPolicy.createChildEditPolicy(org.eclipse.gef.EditPart)

showLayoutTargetFeedback

protected void showLayoutTargetFeedback(org.eclipse.gef.Request request)
Overrides:
showLayoutTargetFeedback in class org.eclipse.gef.editpolicies.LayoutEditPolicy
See Also:
LayoutEditPolicy.showLayoutTargetFeedback(org.eclipse.gef.Request)

createFeedbackFigure

protected org.eclipse.draw2d.IFigure createFeedbackFigure()
Creates the default feedback figure

Returns:
a new feedback figure

getFeedbackFigure

protected org.eclipse.draw2d.IFigure getFeedbackFigure(org.eclipse.gef.GraphicalEditPart child)
Lazily creates and returns the feedback figure used during drags.

Parameters:
child - the edit part to show the feedback for
Returns:
the feedback figure

eraseLayoutTargetFeedback

protected void eraseLayoutTargetFeedback(org.eclipse.gef.Request request)
Overrides:
eraseLayoutTargetFeedback in class org.eclipse.gef.editpolicies.LayoutEditPolicy
See Also:
LayoutEditPolicy.eraseLayoutTargetFeedback(org.eclipse.gef.Request)

deactivate

public void deactivate()
Specified by:
deactivate in interface org.eclipse.gef.EditPolicy
Overrides:
deactivate in class org.eclipse.gef.editpolicies.LayoutEditPolicy
See Also:
LayoutEditPolicy.deactivate()

Modelers

Copyright (c) 2005 TOPCASED Contributors 2005 - 2007. All rights reserved.