use of org.uberfire.ext.wires.core.api.events.ShapeAddedEvent in project drools-wb by kiegroup.
the class GuidedDecisionTreeWidget method onDragCompleteHandler.
public void onDragCompleteHandler(@Observes ShapeDragCompleteEvent shapeDragCompleteEvent) {
final WiresBaseShape wiresShape = shapeDragCompleteEvent.getShape();
// Hide the temporary connector
if (connector != null) {
canvasLayer.remove(connector);
canvasLayer.batch();
connector = null;
}
// If there's no Shape to add then exit
if (wiresShape == null) {
dropContext.setContext(null);
return;
}
// If the Shape is not intended for the Guided Decision Tree widget then exit
if (!(wiresShape instanceof BaseGuidedDecisionTreeShape)) {
dropContext.setContext(null);
return;
}
final BaseGuidedDecisionTreeShape uiChild = (BaseGuidedDecisionTreeShape) wiresShape;
// Get Shape's co-ordinates relative to the Canvas
final double cx = getX(shapeDragCompleteEvent.getX());
final double cy = getY(shapeDragCompleteEvent.getY());
// If the Shape was dropped outside the bounds of the Canvas then exit
if (cx < 0 || cy < 0) {
dropContext.setContext(null);
return;
}
final int scrollWidth = getElement().getScrollWidth();
final int scrollHeight = getElement().getScrollHeight();
if (cx > scrollWidth || cy > scrollHeight) {
dropContext.setContext(null);
return;
}
// Add the new Node to it's parent (unless this is the first node)
final BaseGuidedDecisionTreeShape uiParent = dropContext.getContext();
boolean addShape = ((getShapesInCanvas().size() == 0 && (uiChild instanceof TypeShape)) || (getShapesInCanvas().size() > 0 && uiParent != null));
boolean addChildToParent = uiParent != null;
if (addShape) {
uiChild.setX(cx);
uiChild.setY(cy);
if (addChildToParent) {
uiParent.addChildNode(uiChild);
uiParent.getModelNode().addChild(uiChild.getModelNode());
} else if (uiChild instanceof TypeShape) {
uiRoot = uiChild;
model.setRoot(((TypeShape) uiChild).getModelNode());
}
addShape(uiChild);
// Notify other Panels of a Shape being added
shapeAddedEvent.fire(new ShapeAddedEvent(uiChild));
}
}
Aggregations