use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final IPattern p, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (!(p instanceof FactPattern)) {
messages.add(new UnsupportedIPatternParserMessage());
return nodes;
}
final FactPattern fp = (FactPattern) p;
if (fp.isNegated()) {
messages.add(new UnsupportedIPatternParserMessage());
return nodes;
}
if (fp.getWindow().getOperator() != null) {
messages.add(new UnsupportedIPatternParserMessage());
return nodes;
}
final TypeNode node = new TypeNodeImpl(fp.getFactType());
if (fp.isBound()) {
node.setBinding(fp.getBoundName());
}
nodes.add(node);
for (FieldConstraint fc : fp.getFieldConstraints()) {
nodes.addAll(visit(fc, model, dmo, messages));
}
return nodes;
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final FieldConstraint fc, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (fc instanceof CompositeFieldConstraint) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
} else if (fc instanceof SingleFieldConstraintEBLeftSide) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
if (!(fc instanceof SingleFieldConstraint)) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
final SingleFieldConstraint sfc = (SingleFieldConstraint) fc;
if (sfc.getConnectives() != null) {
messages.add(new UnsupportedFieldConstraintParserMessage());
return nodes;
}
ConstraintNode node = null;
final String className = sfc.getFactType();
final String fieldName = sfc.getFieldName();
if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
if (value != null) {
node = new ConstraintNodeImpl(className, fieldName, operator, value);
}
} else {
node = new ConstraintNodeImpl(className, fieldName);
}
} else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_ENUM) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
final Value value = getValue(className, fieldName, model, dmo, messages, sfc.getValue());
if (value != null) {
node = new ConstraintNodeImpl(className, fieldName, operator, value);
}
} else {
node = new ConstraintNodeImpl(className, fieldName);
}
} else if (sfc.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_UNDEFINED) {
final String operator = sfc.getOperator();
final boolean isValueRequired = OperatorsOracle.isValueRequired(operator);
if (isValueRequired) {
node = new ConstraintNodeImpl(className, fieldName);
} else {
node = new ConstraintNodeImpl(className, fieldName, operator, null);
}
} else {
messages.add(new UnsupportedFieldConstraintTypeParserMessage());
return nodes;
}
if (node != null) {
if (sfc.isBound()) {
node.setBinding(sfc.getFieldBinding());
}
nodes.add(node);
}
return nodes;
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private List<Node> visit(final IAction a, final List<TypeNode> types, final GuidedDecisionTree model, final PackageDataModelOracle dmo, final List<ParserMessage> messages) {
final List<Node> nodes = new ArrayList<Node>();
if (a instanceof ActionRetractFact) {
final ActionRetractFact arf = (ActionRetractFact) a;
final String binding = arf.getVariableName();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionRetractNode arn = new ActionRetractNodeImpl(tn);
nodes.add(arn);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionInsertLogicalFact) {
final ActionInsertLogicalFact aif = (ActionInsertLogicalFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionInsertFact) {
final ActionInsertFact aif = (ActionInsertFact) a;
final ActionInsertNode aun = new ActionInsertNodeImpl(aif.getFactType());
aun.setLogicalInsertion(false);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : aif.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(aif.getFactType(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
} else if (a instanceof ActionUpdateField) {
final ActionUpdateField auf = (ActionUpdateField) a;
final String binding = auf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
aun.setModify(true);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : auf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else if (a instanceof ActionSetField) {
final ActionSetField asf = (ActionSetField) a;
final String binding = asf.getVariable();
for (TypeNode tn : types) {
if (tn.isBound()) {
if (tn.getBinding().equals(binding)) {
final ActionUpdateNode aun = new ActionUpdateNodeImpl(tn);
for (org.drools.workbench.models.datamodel.rule.ActionFieldValue afv : asf.getFieldValues()) {
if (afv.getNature() != FieldNatureType.TYPE_LITERAL) {
messages.add(new UnsupportedFieldNatureTypeParserMessage());
return nodes;
}
final String fieldName = afv.getField();
final Value value = getValue(tn.getClassName(), afv.getField(), model, dmo, messages, afv.getValue());
if (value != null) {
final ActionFieldValue _afv = new ActionFieldValueImpl(fieldName, value);
aun.getFieldValues().add(_afv);
}
}
nodes.add(aun);
return nodes;
}
}
}
messages.add(new BindingNotFoundParserMessage(binding));
return nodes;
} else {
messages.add(new UnsupportedIActionParserMessage());
return nodes;
}
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.Node 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.Node in project drools-wb by kiegroup.
the class EditActionRetractPopup 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));
}
});
bindingListBox.setSelectedIndex(selectedIndex);
}
Aggregations