Search in sources :

Example 1 with BaseGuidedDecisionTreeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method processChildren.

private void processChildren(final Node node, final WiresBaseTreeNode uiNode, final boolean isReadOnly) {
    uiNode.setSelectionManager(this);
    uiNode.setShapesManager(this);
    uiNode.setLayoutManager(layoutManager);
    if (uiNode instanceof BaseGuidedDecisionTreeShape) {
        ((BaseGuidedDecisionTreeShape) uiNode).setPresenter(presenter);
    }
    canvasLayer.add(uiNode);
    shapesInCanvas.add(uiNode);
    final Iterator<Node> itr = node.iterator();
    while (itr.hasNext()) {
        final Node child = itr.next();
        WiresBaseTreeNode uiChildNode = null;
        if (child instanceof TypeNode) {
            uiChildNode = typeNodeFactory.getShape((TypeNode) child, isReadOnly);
        } else if (child instanceof ConstraintNode) {
            uiChildNode = constraintNodeFactory.getShape((ConstraintNode) child, isReadOnly);
        } else if (child instanceof ActionInsertNode) {
            uiChildNode = actionInsertNodeFactory.getShape((ActionInsertNode) child, isReadOnly);
        } else if (child instanceof ActionUpdateNode) {
            uiChildNode = actionUpdateNodeFactory.getShape((ActionUpdateNode) child, isReadOnly);
        } else if (child instanceof ActionRetractNode) {
            uiChildNode = actionRetractNodeFactory.getShape((ActionRetractNode) child, isReadOnly);
        }
        if (uiChildNode != null) {
            uiNode.addChildNode(uiChildNode);
            processChildren(child, uiChildNode, isReadOnly);
        }
    }
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)

Example 2 with BaseGuidedDecisionTreeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method deleteShape.

@Override
public void deleteShape(final WiresBaseShape shape) {
    if (confirmShapeDeletion()) {
        if (uiRoot != null && uiRoot.equals(shape)) {
            uiRoot = null;
            model.setRoot(null);
            shapeDeletedEvent.fire(new ShapeDeletedEvent(shape));
        } else if (shape instanceof BaseGuidedDecisionTreeShape) {
            final BaseGuidedDecisionTreeShape uiChild = (BaseGuidedDecisionTreeShape) shape;
            if (uiChild.getParentNode() instanceof BaseGuidedDecisionTreeShape) {
                final BaseGuidedDecisionTreeShape uiParent = (BaseGuidedDecisionTreeShape) uiChild.getParentNode();
                uiParent.getModelNode().removeChild(uiChild.getModelNode());
            }
            shapeDeletedEvent.fire(new ShapeDeletedEvent(shape));
            layout();
        }
    }
}
Also used : ShapeDeletedEvent(org.uberfire.ext.wires.core.api.events.ShapeDeletedEvent) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)

Example 3 with BaseGuidedDecisionTreeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method getParentNode.

protected BaseGuidedDecisionTreeShape getParentNode(final BaseGuidedDecisionTreeShape uiChild, final double cx, final double cy) {
    BaseGuidedDecisionTreeShape uiProspectiveParent = null;
    double finalDistance = Double.MAX_VALUE;
    for (WiresBaseShape ws : getShapesInCanvas()) {
        if (ws.isVisible()) {
            if (ws instanceof BaseGuidedDecisionTreeShape) {
                final BaseGuidedDecisionTreeShape uiNode = (BaseGuidedDecisionTreeShape) ws;
                if (uiNode.acceptChildNode(uiChild) && !uiNode.hasCollapsedChildren()) {
                    double deltaX = cx - uiNode.getX();
                    double deltaY = cy - uiNode.getY();
                    double distance = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY, 2));
                    if (finalDistance > distance) {
                        finalDistance = distance;
                        uiProspectiveParent = uiNode;
                    }
                }
            }
        }
    }
    // If we're too far away from a parent we might as well not have a parent
    if (finalDistance > MAX_PROXIMITY) {
        uiProspectiveParent = null;
    }
    return uiProspectiveParent;
}
Also used : WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)

Example 4 with BaseGuidedDecisionTreeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidgetTest method testDeleteShapeNotConfirmed.

@Test
public void testDeleteShapeNotConfirmed() {
    doReturn(false).when(widget).confirmShapeDeletion();
    final BaseGuidedDecisionTreeShape shapeToDelete = uiRootShape;
    widget.deleteShape(shapeToDelete);
    verify(shapeDeletedEvent, never()).fire(any(ShapeDeletedEvent.class));
    verify(widget, never()).layout();
    assertEquals(uiRootNode, uiModel.getRoot());
}
Also used : BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape) ShapeDeletedEvent(org.uberfire.ext.wires.core.api.events.ShapeDeletedEvent) Test(org.junit.Test)

Example 5 with BaseGuidedDecisionTreeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidgetTest method testDeleteShapeConfirmedNonRootNode.

@Test
public void testDeleteShapeConfirmedNonRootNode() {
    doReturn(true).when(widget).confirmShapeDeletion();
    final BaseGuidedDecisionTreeShape shapeToDelete = uiChildShape;
    widget.deleteShape(shapeToDelete);
    verify(shapeDeletedEvent).fire(shapeDeletedEventCaptor.capture());
    assertEquals(shapeToDelete, shapeDeletedEventCaptor.getValue().getShape());
    verify(widget).layout();
    assertFalse(uiRootNode.getChildren().contains(uiChildNode));
}
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