Search in sources :

Example 1 with TypeShape

use of org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape 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 2 with TypeShape

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

the class TypeNodeFactory method getShape.

/**
 * This returns a new Shape following a drag operation from the palette
 * @param helper
 * @return
 */
@Override
public WiresBaseShape getShape(final FactoryHelper helper) {
    final TypeFactoryHelper tnHelper = (TypeFactoryHelper) helper;
    final TypeNode node = tnHelper.getContext();
    // We need to create a new instance of the TypeNode for use in the Decision Tree Widget
    return new TypeShape(makeShape(), new TypeNodeImpl(node.getClassName()), tnHelper.isReadOnly());
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) TypeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape)

Aggregations

TypeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape)2 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)1 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)1 BaseGuidedDecisionTreeShape (org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)1 ShapeAddedEvent (org.uberfire.ext.wires.core.api.events.ShapeAddedEvent)1 WiresBaseShape (org.uberfire.ext.wires.core.api.shapes.WiresBaseShape)1