Search in sources :

Example 6 with Node

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools-wb by kiegroup.

the class EditActionUpdatePopup method initialiseBoundTypes.

private void initialiseBoundTypes() {
    // Extract all bindings available on the path to the root
    final Map<String, TypeNode> bindings = new TreeMap<String, TypeNode>();
    Node parent = clone.getParent();
    while (parent != null) {
        if (parent instanceof TypeNode) {
            final TypeNode tn = (TypeNode) parent;
            if (tn.isBound()) {
                bindings.put(tn.getBinding(), tn);
            }
        }
        parent = parent.getParent();
    }
    bindingListBox.setEnabled(!bindings.isEmpty());
    if (bindings.isEmpty()) {
        bindingListBox.addItem(GuidedDecisionTreeConstants.INSTANCE.noBindings());
        return;
    }
    // Add them to the ListBox
    int selectedIndex = 0;
    final BoundNode boundNode = clone.getBoundNode();
    for (String binding : bindings.keySet()) {
        bindingListBox.addItem(binding);
        if (boundNode != null) {
            if (binding.equals(boundNode.getBinding())) {
                selectedIndex = bindingListBox.getItemCount() - 1;
            }
        }
    }
    // Attach event handler before we set the selected index in case we're selecting the first item
    bindingListBox.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(final ChangeEvent event) {
            final String binding = bindingListBox.getItemText(bindingListBox.getSelectedIndex());
            clone.setBoundNode(bindings.get(binding));
            clone.getFieldValues().clear();
            initialiseFieldValues();
        }
    });
    bindingListBox.setSelectedIndex(selectedIndex);
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) BoundNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode) TreeMap(java.util.TreeMap)

Example 7 with Node

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools-wb by kiegroup.

the class ActionUpdateShape method setParentNode.

@Override
public void setParentNode(final WiresBaseTreeNode parent) {
    super.setParentNode(parent);
    // Set binding to first bound parent TypeNode
    if (parent instanceof BaseGuidedDecisionTreeShape) {
        Node node = ((BaseGuidedDecisionTreeShape) parent).getModelNode();
        while (node != null) {
            if (node instanceof TypeNode) {
                final TypeNode tn = (TypeNode) node;
                if (tn.isBound()) {
                    getModelNode().setBoundNode(tn);
                    setNodeLabel(getNodeLabel());
                    break;
                }
            }
            node = node.getParent();
        }
    }
}
Also used : Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) WiresBaseTreeNode(org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)

Example 8 with Node

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools by kiegroup.

the class GuidedDecisionTreeModelMarshallingVisitor method visit.

public String visit(final GuidedDecisionTree model) {
    if (model == null) {
        return "";
    }
    // Append the DRL generated from the model
    if (model.getRoot() != null) {
        baseRuleName = model.getTreeName();
        final List<Node> path = new ArrayList<Node>();
        visit(path, model.getRoot());
    }
    // Append the DRL stored as a result of parsing errors
    for (GuidedDecisionTreeParserError error : model.getParserErrors()) {
        rules.append(error.getOriginalDrl()).append("\n");
    }
    return rules.toString();
}
Also used : GuidedDecisionTreeParserError(org.drools.workbench.models.guided.dtree.shared.model.parser.GuidedDecisionTreeParserError) 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) ArrayList(java.util.ArrayList)

Example 9 with Node

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools by kiegroup.

the class GuidedDecisionTreeModelMarshallingVisitor method visit.

private void visit(final List<Node> path, final Node node) {
    path.add(node);
    // Terminal node; generate the DRL for this path through the tree
    final Iterator<Node> itr = node.iterator();
    if (!itr.hasNext()) {
        generateRuleDRL(path);
    }
    // Process children. Each child creates a new path through the tree
    while (itr.hasNext()) {
        final Node child = itr.next();
        final List<Node> subPath = new ArrayList<Node>(path);
        visit(subPath, child);
    }
}
Also used : 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) ArrayList(java.util.ArrayList)

Example 10 with Node

use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node 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)

Aggregations

Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)14 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)14 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)11 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)11 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)10 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)9 ArrayList (java.util.ArrayList)7 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 WiresBaseTreeNode (org.uberfire.ext.wires.core.trees.client.shapes.WiresBaseTreeNode)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 TreeMap (java.util.TreeMap)2 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)2 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)2 ActionFieldValue (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionFieldValue)2 BoundNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.BoundNode)2 GuidedDecisionTreeParserError (org.drools.workbench.models.guided.dtree.shared.model.parser.GuidedDecisionTreeParserError)2 Value (org.drools.workbench.models.guided.dtree.shared.model.values.Value)2