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