@Override protected EditPolicy createChildEditPolicy(EditPart child) { BControl control = (BControl) child.getModel(); ResizableEditPolicy policy = new ResizableEditPolicy(); BAttributeWidth atrWidth = (BAttributeWidth) control.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH); BAttributeHeight atrHeight = (BAttributeHeight) control.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT); if (atrWidth.isEditable() && atrHeight.isEditable()) return policy; if (atrWidth.isEditable()) { policy.setResizeDirections(PositionConstants.EAST_WEST); return policy; } if (atrHeight.isEditable()) { policy.setResizeDirections(PositionConstants.NORTH_SOUTH); return policy; } policy.setResizeDirections(0); return policy; }
@Override protected Command getCreateCommand(CreateRequest request) { if (request.getType() == REQ_CREATE && getHost() instanceof AppAbstractEditPart) { if (((BControl) ((AppAbstractEditPart) getHost()).getModel()).canHaveChildren()) { BControl newObj = (BControl) request.getNewObject(); CreateCommand createCmd = new CreateCommand(newObj, (BControl) getHost().getModel()); Rectangle constraint = (Rectangle) getConstraintFor(request); constraint.x = (constraint.x < 0) ? 0 : constraint.x; constraint.y = (constraint.y < 0) ? 0 : constraint.y; BAttributeWidth atrWidth = (BAttributeWidth) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_WIDTH); BAttributeHeight atrHeight = (BAttributeHeight) newObj.getAttributes().get(AttributeConstants.ATTRIBUTE_HEIGHT); if (atrWidth != null) { constraint.width = Integer.valueOf(atrWidth.getValue().toString()); } else { constraint.width = (constraint.width <= 0) ? 100 : constraint.width; } if (atrHeight != null) { constraint.height = Integer.valueOf(atrHeight.getValue().toString()); } else { constraint.height = (constraint.height <= 0) ? 100 : constraint.height; } createCmd.setLayout(constraint); Command cmd = chainGuideAttachmentCommand(request, newObj, createCmd, true); return chainGuideAttachmentCommand(request, newObj, cmd, false); } } return null; }