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