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