use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode 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.models.guided.dtree.shared.model.nodes.ActionInsertNode in project drools-wb by kiegroup.
the class ActionInsertNodeFactory 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 ActionInsertFactoryHelper anHelper = (ActionInsertFactoryHelper) helper;
final ActionInsertNode node = anHelper.getContext();
// drag proxy. We need to create a new instance of the TypeNode for use in the Decision Tree Widget
return new ActionInsertShape(makeShape(), new ActionInsertNodeImpl(node.getClassName()), anHelper.isReadOnly());
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode in project drools-wb by kiegroup.
the class EditActionInsertPopup method cloneNode.
// Clone node whilst editing to preserve original node should User cancel the edit
private ActionInsertNode cloneNode(final ActionInsertNode node) {
final ActionInsertNode clone = new ActionInsertNodeImpl(node.getClassName());
clone.getFieldValues().addAll(clone(node.getFieldValues()));
clone.setLogicalInsertion(node.isLogicalInsertion());
clone.setParent(node.getParent());
return clone;
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode in project drools by kiegroup.
the class GuidedDecisionTreeModelMarshallingVisitor method generateRuleDRL.
protected void generateRuleDRL(final List<Node> path) {
Node context = null;
final StringBuilder drl = new StringBuilder();
final boolean hasDateFieldValue = hasDateFieldValue(path);
this.varCounter = 0;
drl.append(generateRuleHeaderDRL());
drl.append(INDENTATION).append("when \n");
for (Node node : path) {
if (node instanceof TypeNode) {
generateTypeNodeDRL((TypeNode) node, context, drl);
} else if (node instanceof ConstraintNode) {
generateConstraintNodeDRL((ConstraintNode) node, context, drl);
} else if (node instanceof ActionRetractNode) {
generateActionRetractNodeDRL((ActionRetractNode) node, context, hasDateFieldValue, drl);
} else if (node instanceof ActionUpdateNode) {
generateActionUpdateNodeDRL((ActionUpdateNode) node, context, hasDateFieldValue, drl);
} else if (node instanceof ActionInsertNode) {
generateActionInsertNodeDRL((ActionInsertNode) node, context, hasDateFieldValue, drl);
}
context = node;
}
if (context == null) {
// No previous context to close
} else if (context instanceof ConstraintNode) {
drl.append(")\n").append("then \n").append("end\n");
} else if (context instanceof TypeNode) {
drl.append(")\n").append("then \n").append("end\n");
} else if (context instanceof ActionRetractNode) {
drl.append("end\n");
} else if (context instanceof ActionUpdateNode) {
drl.append("end\n");
} else if (context instanceof ActionInsertNode) {
drl.append("end\n");
}
ruleCount++;
rules.append(drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsertLogical.
@Test
public void testSingleRule_ActionInsertLogical() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( )\n" + "then\n" + " Person $var0 = new Person();\n" + " $var0.setAge( 25 );\n" + " insertLogical( $var0 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
model.setRoot(type);
final ActionInsertNode action = new ActionInsertNodeImpl("Person");
action.setLogicalInsertion(true);
action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations