use of org.jboss.tools.hibernate.ui.diagram.editors.command.ShapeSetConstraintCommand in project jbosstools-hibernate by jbosstools.
the class ShapesXYLayoutEditPolicy method createChangeConstraintCommand.
/**
* @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChangeConstraintCommand(org.eclipse.gef.EditPart, java.lang.Object)
*/
protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
if (!(child instanceof OrmShapeEditPart && constraint instanceof Rectangle)) {
return super.createChangeConstraintCommand(request, child, constraint);
}
OrmShape part = (OrmShape) child.getModel();
Command result = new ShapeSetConstraintCommand(part, request, ((Rectangle) constraint).getLocation());
if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_HORIZONTAL_GUIDE);
if (guidePos != null) {
result = chainGuideAttachmentCommand(request, part, result, true);
} else if (part.getHorizontalGuide() != null) {
// SnapToGuides didn't provide a horizontal guide, but this part is attached
// to a horizontal guide. Now we check to see if the part is attached to
// the guide along the edge being resized. If that is the case, we need to
// detach the part from the guide; otherwise, we leave it alone.
int alignment = part.getHorizontalGuide().getAlignment(part);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
result = result.chain(new ChangeGuideCommand(part, true));
}
}
}
if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
Integer guidePos = (Integer) request.getExtendedData().get(SnapToGuides.KEY_VERTICAL_GUIDE);
if (guidePos != null) {
result = chainGuideAttachmentCommand(request, part, result, false);
} else if (part.getVerticalGuide() != null) {
int alignment = part.getVerticalGuide().getAlignment(part);
int edgeBeingResized = 0;
if ((request.getResizeDirection() & PositionConstants.WEST) != 0) {
edgeBeingResized = -1;
} else {
edgeBeingResized = 1;
}
if (alignment == edgeBeingResized) {
result = result.chain(new ChangeGuideCommand(part, false));
}
}
}
if (request.getType().equals(REQ_MOVE_CHILDREN) || request.getType().equals(REQ_ALIGN_CHILDREN)) {
result = chainGuideAttachmentCommand(request, part, result, true);
result = chainGuideAttachmentCommand(request, part, result, false);
result = chainGuideDetachmentCommand(request, part, result, true);
result = chainGuideDetachmentCommand(request, part, result, false);
}
return result;
}
Aggregations