Search in sources :

Example 1 with WiresTreeNodeConnector

use of org.uberfire.ext.wires.core.trees.client.canvas.WiresTreeNodeConnector 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();
}
Also used : Point2D(com.ait.lienzo.client.core.types.Point2D) WiresTreeNodeConnector(org.uberfire.ext.wires.core.trees.client.canvas.WiresTreeNodeConnector) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)

Aggregations

Point2D (com.ait.lienzo.client.core.types.Point2D)1 BaseGuidedDecisionTreeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)1 WiresTreeNodeConnector (org.uberfire.ext.wires.core.trees.client.canvas.WiresTreeNodeConnector)1