Search in sources :

Example 1 with WiresBaseShape

use of org.uberfire.ext.wires.core.api.shapes.WiresBaseShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method setModel.

public void setModel(final GuidedDecisionTree model, final boolean isReadOnly) {
    this.uiRoot = null;
    this.model = model;
    // Clear existing state
    super.clear();
    clearEvent.fire(new ClearEvent());
    // Walk model creating UIModel
    final TypeNode root = model.getRoot();
    if (root != null) {
        final WiresBaseTreeNode uiRoot = typeNodeFactory.getShape(root, isReadOnly);
        this.uiRoot = uiRoot;
        processChildren(root, uiRoot, isReadOnly);
        final Map<WiresBaseShape, Point2D> layout = layoutManager.getLayoutInformation(uiRoot);
        final Rectangle2D canvasBounds = WiresLayoutUtilities.alignLayoutInCanvas(layout);
        for (Map.Entry<WiresBaseShape, Point2D> e : layout.entrySet()) {
            final Point2D destination = new Point2D(e.getValue().getX(), e.getValue().getY());
            e.getKey().setLocation(destination);
        }
        WiresLayoutUtilities.resizeViewPort(canvasBounds, canvasLayer.getViewport());
    }
    if (shapesInCanvas.isEmpty()) {
        showGettingStartedHint();
    }
    canvasLayer.batch();
}
Also used : WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) Point2D(com.ait.lienzo.client.core.types.Point2D) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) Rectangle2D(org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D) ClearEvent(org.uberfire.ext.wires.core.api.events.ClearEvent) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with WiresBaseShape

use of org.uberfire.ext.wires.core.api.shapes.WiresBaseShape 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 3 with WiresBaseShape

use of org.uberfire.ext.wires.core.api.shapes.WiresBaseShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method onShapeSelected.

public void onShapeSelected(@Observes ShapeSelectedEvent event) {
    final WiresBaseShape shape = event.getShape();
    super.selectShape(shape);
}
Also used : WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape)

Example 4 with WiresBaseShape

use of org.uberfire.ext.wires.core.api.shapes.WiresBaseShape in project drools-wb by kiegroup.

the class GuidedDecisionTreeWidget method layout.

void layout() {
    // Get layout information
    final Map<WiresBaseShape, Point2D> layout = layoutManager.getLayoutInformation(uiRoot);
    final Rectangle2D canvasBounds = WiresLayoutUtilities.alignLayoutInCanvas(layout);
    // Run an animation to move WiresBaseTreeNodes from their current position to the target position
    uiRoot.animate(AnimationTweener.EASE_OUT, new AnimationProperties(), ANIMATION_DURATION, new IAnimationCallback() {

        private final Map<WiresBaseShape, Pair<Point2D, Point2D>> transformations = new HashMap<WiresBaseShape, Pair<Point2D, Point2D>>();

        @Override
        public void onStart(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            // Reposition nodes. First we store the WiresBaseTreeNode together with its current position and target position
            transformations.clear();
            for (Map.Entry<WiresBaseShape, Point2D> e : layout.entrySet()) {
                final Point2D origin = e.getKey().getLocation();
                final Point2D destination = new Point2D(e.getValue().getX(), e.getValue().getY());
                transformations.put(e.getKey(), new Pair<Point2D, Point2D>(origin, destination));
            }
            WiresLayoutUtilities.resizeViewPort(canvasBounds, canvasLayer.getViewport());
        }

        @Override
        public void onFrame(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
            // Lienzo's IAnimation.getPercent() passes values > 1.0
            final double pct = iAnimation.getPercent() > 1.0 ? 1.0 : iAnimation.getPercent();
            // Move each descendant along the line between its origin and the target destination
            for (Map.Entry<WiresBaseShape, Pair<Point2D, Point2D>> e : transformations.entrySet()) {
                final Point2D descendantOrigin = e.getValue().getK1();
                final Point2D descendantTarget = e.getValue().getK2();
                final double dx = (descendantTarget.getX() - descendantOrigin.getX()) * pct;
                final double dy = (descendantTarget.getY() - descendantOrigin.getY()) * pct;
                e.getKey().setX(descendantOrigin.getX() + dx);
                e.getKey().setY(descendantOrigin.getY() + dy);
            }
            // Without this call Lienzo doesn't update the Canvas for sub-classes of WiresBaseTreeNode
            uiRoot.getLayer().batch();
        }

        @Override
        public void onClose(final IAnimation iAnimation, final IAnimationHandle iAnimationHandle) {
        // Nothing to do
        }
    });
    canvasLayer.batch();
}
Also used : HashMap(java.util.HashMap) Rectangle2D(org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D) IAnimationHandle(com.ait.lienzo.client.core.animation.IAnimationHandle) WiresBaseShape(org.uberfire.ext.wires.core.api.shapes.WiresBaseShape) AnimationProperties(com.ait.lienzo.client.core.animation.AnimationProperties) Point2D(com.ait.lienzo.client.core.types.Point2D) IAnimation(com.ait.lienzo.client.core.animation.IAnimation) IAnimationCallback(com.ait.lienzo.client.core.animation.IAnimationCallback) Pair(org.uberfire.commons.data.Pair)

Example 5 with WiresBaseShape

use of org.uberfire.ext.wires.core.api.shapes.WiresBaseShape 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)

Aggregations

WiresBaseShape (org.uberfire.ext.wires.core.api.shapes.WiresBaseShape)5 Point2D (com.ait.lienzo.client.core.types.Point2D)2 HashMap (java.util.HashMap)2 BaseGuidedDecisionTreeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)2 Rectangle2D (org.uberfire.ext.wires.core.trees.client.layout.treelayout.Rectangle2D)2 AnimationProperties (com.ait.lienzo.client.core.animation.AnimationProperties)1 IAnimation (com.ait.lienzo.client.core.animation.IAnimation)1 IAnimationCallback (com.ait.lienzo.client.core.animation.IAnimationCallback)1 IAnimationHandle (com.ait.lienzo.client.core.animation.IAnimationHandle)1 Map (java.util.Map)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 Pair (org.uberfire.commons.data.Pair)1 ClearEvent (org.uberfire.ext.wires.core.api.events.ClearEvent)1 ShapeAddedEvent (org.uberfire.ext.wires.core.api.events.ShapeAddedEvent)1 WiresBaseTreeNode (org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode)1