use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape 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));
}
}
use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.
the class GuidedDecisionTreeWidget method onDragPreviewHandler.
public void onDragPreviewHandler(@Observes ShapeDragPreviewEvent shapeDragPreviewEvent) {
// We can only connect WiresTreeNodes to each other
if (!(shapeDragPreviewEvent.getShape() instanceof BaseGuidedDecisionTreeShape)) {
dropContext.setContext(null);
return;
}
// Find a Parent Node to attach the Shape to
final double cx = getX(shapeDragPreviewEvent.getX());
final double cy = getY(shapeDragPreviewEvent.getY());
final BaseGuidedDecisionTreeShape uiChild = (BaseGuidedDecisionTreeShape) shapeDragPreviewEvent.getShape();
final BaseGuidedDecisionTreeShape uiProspectiveParent = getParentNode(uiChild, cx, cy);
// If there is a prospective parent show the line between child and parent
if (uiProspectiveParent != null) {
if (connector == null) {
connector = new WiresTreeNodeConnector();
canvasLayer.add(connector);
connector.moveToBottom();
}
connector.getPoints().get(0).set(uiProspectiveParent.getLocation());
connector.getPoints().get(1).set(new Point2D(cx, cy));
} else if (connector != null) {
canvasLayer.remove(connector);
connector = null;
}
dropContext.setContext(uiProspectiveParent);
canvasLayer.batch();
}
use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.
the class GuidedDecisionTreeWidgetTest method testDeleteShapeConfirmedRootNode.
@Test
public void testDeleteShapeConfirmedRootNode() {
doReturn(true).when(widget).confirmShapeDeletion();
final BaseGuidedDecisionTreeShape shapeToDelete = uiRootShape;
widget.deleteShape(shapeToDelete);
verify(shapeDeletedEvent).fire(shapeDeletedEventCaptor.capture());
assertEquals(shapeToDelete, shapeDeletedEventCaptor.getValue().getShape());
verify(widget, never()).layout();
assertNull(uiModel.getRoot());
}
Aggregations