Search in sources :

Example 6 with BaseGuidedDecisionTreeShape

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));
    }
}
Also used : WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) ShapeAddedEvent(org.uberfire.ext.wires.core.api.events.ShapeAddedEvent) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape) TypeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape)

Example 7 with BaseGuidedDecisionTreeShape

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();
}
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)

Example 8 with BaseGuidedDecisionTreeShape

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());
}
Also used : BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape) Test(org.junit.Test)

Aggregations

BaseGuidedDecisionTreeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)8 Test (org.junit.Test)3 ShapeDeletedEvent (org.uberfire.ext.wires.core.api.events.ShapeDeletedEvent)2 WiresBaseShape (org.uberfire.ext.wires.core.api.shapes.WiresBaseShape)2 Point2D (com.ait.lienzo.client.core.types.Point2D)1 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)1 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)1 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)1 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)1 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)1 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)1 TypeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape)1 ShapeAddedEvent (org.uberfire.ext.wires.core.api.events.ShapeAddedEvent)1 WiresTreeNodeConnector (org.uberfire.ext.wires.core.trees.client.canvas.WiresTreeNodeConnector)1 WiresBaseTreeNode (org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode)1