shapeDragController = new ShapePickupDragController(boundaryPanel, true, Diagram.this);
shapeDragController.setBehaviorDragStartSensitivity(2);
shapeDragController.setBehaviorConstrainedToBoundaryPanel(true);
shapeDragController.setBehaviorMultipleSelection(true);
shapeDragController.addDragHandler(new DragHandlerAdapter() {
@Override
public void onDragStart(DragStartEvent event) {
int startX =
Diagram.this.boundaryPanel.getWidgetLeft(event.getContext().draggable)
- Diagram.this.boundaryPanel.getAbsoluteLeft();
int startY =
Diagram.this.boundaryPanel.getWidgetTop(event.getContext().draggable)
- Diagram.this.boundaryPanel.getAbsoluteTop();
Diagram.this.onElementDrag(new ElementDragEvent(event.getContext().draggable, startX, startY,
ElementDragEvent.DragEventType.DRAG_START));
}
@Override
public void onDragEnd(DragEndEvent event) {
Widget widget = event.getContext().draggable;
if (event.getContext().vetoException != null) {
if (event.getContext().draggable instanceof Shape) {
Shape draggable = (Shape) event.getContext().draggable;
draggable.updateConnectors();
}
}
if (widget instanceof Shape) {
Shape shape = (Shape) event.getContext().draggable;
if (!ctrlPressed) {
fixShapePosition(shape);
for (ConnectionPoint cp : shape.connectionPoints) {
for (EndPoint ep : cp.gluedEndPoints) {
// connector between two dragged shapes
if (ep.connector.startEndPoint.gluedConnectionPoint != null
&& ep.connector.endEndPoint.gluedConnectionPoint != null
&& ep.connector.startEndPoint.gluedConnectionPoint.getParentWidget() != null
&& ep.connector.endEndPoint.gluedConnectionPoint.getParentWidget() != null
&& selectedWidgets.contains(ep.connector.startEndPoint.gluedConnectionPoint.getParentWidget())
&& selectedWidgets.contains(ep.connector.endEndPoint.gluedConnectionPoint.getParentWidget())) {
ep.connector.moveOffsetFromStartPos(shape.getTranslationX(), shape.getTranslationY());
} else {
ep.connector.updateCornerPoints();
}
}
}
fixLineSections(shape);
} else {
fixShapePosition(shape);
for (Connector c : shape.getConnectedConnectors()) {
if (c.startEndPoint.gluedConnectionPoint != null && c.endEndPoint.gluedConnectionPoint != null
&& c.startEndPoint.gluedConnectionPoint.getParentWidget() != null
&& c.endEndPoint.gluedConnectionPoint.getParentWidget() != null
&& selectedWidgets.contains(c.startEndPoint.gluedConnectionPoint.getParentWidget())
&& selectedWidgets.contains(c.endEndPoint.gluedConnectionPoint.getParentWidget())) {
c.moveOffsetFromStartPos(shape.getTranslationX(), shape.getTranslationY());
} else {
c.fixEndSectionDirection(c.endEndPoint);
c.fixEndSectionDirection(c.startEndPoint);
c.fixLineSections(c.getCorners());
c.drawSections();
}
}
}
}
int endX =
Diagram.this.boundaryPanel.getWidgetLeft(event.getContext().draggable)
- Diagram.this.boundaryPanel.getAbsoluteLeft();
int endY =
Diagram.this.boundaryPanel.getWidgetTop(event.getContext().draggable)
- Diagram.this.boundaryPanel.getAbsoluteTop();
Diagram.this.onElementDrag(new ElementDragEvent(event.getContext().draggable, endX, endY,
ElementDragEvent.DragEventType.DRAG_END));
}
});
// Create drag controller to control end point dragging
endPointDragController = new EndPointDragController(this.boundaryPanel, true, Diagram.this);
endPointDragController.setBehaviorConstrainedToBoundaryPanel(true);
endPointDragController.setBehaviorDragStartSensitivity(4);
endPointDragController.addDragHandler(new DragHandlerAdapter() {
@Override
public void onDragStart(DragStartEvent event) {
endPointDragging = true;
if (event != null) {