Search in sources :

Example 6 with ActionInsertNode

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);
        }
    }
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BaseGuidedDecisionTreeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.BaseGuidedDecisionTreeShape)

Example 7 with ActionInsertNode

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());
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ActionInsertShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.ActionInsertShape) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)

Example 8 with ActionInsertNode

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;
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)

Example 9 with ActionInsertNode

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);
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 10 with ActionInsertNode

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);
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionFieldValueImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl) Test(org.junit.Test)

Aggregations

ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)16 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)13 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)12 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)9 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)8 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)8 Test (org.junit.Test)8 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)5 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)5 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)5 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)5 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)5 Calendar (java.util.Calendar)4 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)4 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)4 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)2 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)2 ArrayList (java.util.ArrayList)1