use of org.drools.workbench.models.datamodel.rule.IAction in project drools-wb by kiegroup.
the class GuidedRuleModelVisitor method getConsumedModelClasses.
public Set<String> getConsumedModelClasses() {
final Set<String> factTypes = new HashSet<String>();
// Extract Fact Types from model
if (model.lhs != null) {
for (int i = 0; i < model.lhs.length; i++) {
IPattern pattern = model.lhs[i];
factTypes.addAll(visit(pattern));
}
}
if (model.rhs != null) {
for (int i = 0; i < model.rhs.length; i++) {
IAction action = model.rhs[i];
factTypes.addAll(visit(action));
}
}
// Convert Fact Types into Fully Qualified Class Names
final Set<String> fullyQualifiedClassNames = new HashSet<String>();
for (String factType : factTypes) {
fullyQualifiedClassNames.add(convertToFullyQualifiedClassName(factType));
}
return fullyQualifiedClassNames;
}
use of org.drools.workbench.models.datamodel.rule.IAction in project drools-wb by kiegroup.
the class RuleModeller method renderRhs.
/**
* Do all the widgets for the RHS.
*/
private void renderRhs(final RuleModel model) {
for (int i = 0; i < model.rhs.length; i++) {
DirtyableVerticalPane widget = new DirtyableVerticalPane();
widget.setWidth("100%");
IAction action = model.rhs[i];
// if lockRHS() set the widget RO, otherwise let them decide.
Boolean readOnly = this.lockRHS() ? true : null;
RuleModellerWidget w = getWidgetFactory().getWidget(this, eventBus, action, readOnly);
w.addOnModifiedCommand(this.onWidgetModifiedCommand);
widget.add(wrapRHSWidget(model, i, w));
widget.add(spacerWidget());
layout.setWidget(currentLayoutRow, 0, new DirtyableHorizontalPane());
layout.setWidget(currentLayoutRow, 1, new DirtyableHorizontalPane());
layout.setWidget(currentLayoutRow, 2, this.wrapLineNumber(i + 1, false));
layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 2, HasVerticalAlignment.ALIGN_MIDDLE);
layout.setWidget(currentLayoutRow, 3, widget);
layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 3, HasHorizontalAlignment.ALIGN_LEFT);
layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 3, HasVerticalAlignment.ALIGN_TOP);
layout.getFlexCellFormatter().setWidth(currentLayoutRow, 3, "100%");
layout.getRowFormatter().addStyleName(currentLayoutRow, (i % 2 == 0 ? GuidedRuleEditorResources.INSTANCE.css().evenRow() : GuidedRuleEditorResources.INSTANCE.css().oddRow()));
if (!w.isFactTypeKnown()) {
addInvalidPatternIcon();
addFactTypeKnownValueChangeHandler(w, currentLayoutRow);
}
final int index = i;
if (!(this.lockRHS() || w.isReadOnly())) {
this.addActionsButtonsToLayout(GuidedRuleEditorResources.CONSTANTS.AddAnActionBelow(), new ClickHandler() {
public void onClick(ClickEvent event) {
showActionSelector(index + 1);
}
}, new ClickHandler() {
public void onClick(ClickEvent event) {
model.moveRhsItemDown(index);
refreshWidget();
}
}, new ClickHandler() {
public void onClick(ClickEvent event) {
model.moveRhsItemUp(index);
refreshWidget();
}
});
}
this.rhsWidgets.add(w);
currentLayoutRow++;
}
}
use of org.drools.workbench.models.datamodel.rule.IAction in project drools-wb by kiegroup.
the class RuleModellerActionSelectorPopup method addCustomActionPlugins.
private void addCustomActionPlugins() {
if (actionPlugins != null) {
for (RuleModellerActionPlugin actionPlugin : actionPlugins) {
final IAction iAction = actionPlugin.createIAction(ruleModeller);
actionPlugin.addPluginToActionList(ruleModeller, () -> {
choices.addItem(actionPlugin.getActionAddDescription(), actionPlugin.getId());
cmds.put(actionPlugin.getId(), () -> {
model.addRhsItem(iAction, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
hide();
});
});
}
}
}
use of org.drools.workbench.models.datamodel.rule.IAction in project drools by kiegroup.
the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.
private GuidedDecisionTree visit(final String drl, final String baseFileName, final List<String> globals, final PackageDataModelOracle dmo) {
PortablePreconditions.checkNotNull("drl", drl);
PortablePreconditions.checkNotNull("baseFileName", baseFileName);
PortablePreconditions.checkNotNull("globals", globals);
PortablePreconditions.checkNotNull("dmo", dmo);
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName(baseFileName);
// De-serialize Package name
final String packageName = PackageNameParser.parsePackageName(drl);
model.setPackageName(packageName);
// De-serialize imports
final Imports imports = ImportsParser.parseImports(drl);
for (Import item : imports.getImports()) {
model.getImports().addImport(item);
}
// Split DRL into separate rules
final List<String> rules = new ArrayList<String>();
final Pattern pattern = Pattern.compile("\\s?rule\\s(.+?)\\send\\s?", Pattern.DOTALL);
final Matcher matcher = pattern.matcher(drl);
while (matcher.find()) {
rules.add(matcher.group());
}
// Build a linear Path of Nodes for each rule
final List<GuidedDecisionTreeParserExtendedError> rulesParserContent = new ArrayList<GuidedDecisionTreeParserExtendedError>();
for (String rule : rules) {
final GuidedDecisionTreeParserExtendedError ruleParserContent = new GuidedDecisionTreeParserExtendedError();
rulesParserContent.add(ruleParserContent);
try {
final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule, globals, dmo);
ruleParserContent.setOriginalRuleName(rm.name);
ruleParserContent.setOriginalDrl(rule);
for (IPattern p : rm.lhs) {
ruleParserContent.getNodes().addAll(visit(p, model, dmo, ruleParserContent.getMessages()));
}
for (IAction a : rm.rhs) {
ruleParserContent.getNodes().addAll(visit(a, getTypesOnPath(ruleParserContent.getNodes()), model, dmo, ruleParserContent.getMessages()));
}
} catch (Exception e) {
ruleParserContent.getMessages().add(new DefaultParserMessage(e.getMessage()));
}
}
// Combine Paths into a single tree.
for (GuidedDecisionTreeParserExtendedError ruleParserContent : rulesParserContent) {
Node activeModelNode = null;
boolean error = !ruleParserContent.getMessages().isEmpty();
for (int index = 0; !error && index < ruleParserContent.getNodes().size(); index++) {
final Node node = ruleParserContent.getNodes().get(index);
switch(index) {
case 0:
if (!(node instanceof TypeNode)) {
ruleParserContent.getMessages().add(new InvalidRootParserMessage());
error = true;
break;
}
final TypeNode root = (TypeNode) node;
if (model.getRoot() == null) {
model.setRoot(root);
} else if (!root.equals(model.getRoot())) {
ruleParserContent.getMessages().add(new AmbiguousRootParserMessage(root.getClassName()));
error = true;
break;
}
activeModelNode = model.getRoot();
break;
default:
if (!activeModelNode.getChildren().contains(node)) {
// If the active node in the Model doesn't contain the child add it as a new child
activeModelNode.addChild(node);
activeModelNode = node;
} else {
// Otherwise swap out the Node in the Path for the existing one in the Model
activeModelNode = activeModelNode.getChildren().get(activeModelNode.getChildren().indexOf(node));
}
}
}
if (!ruleParserContent.getMessages().isEmpty()) {
model.getParserErrors().add(new GuidedDecisionTreeParserError(ruleParserContent.getOriginalRuleName(), ruleParserContent.getOriginalDrl(), ruleParserContent.getMessages()));
}
}
return model;
}
use of org.drools.workbench.models.datamodel.rule.IAction in project drools by kiegroup.
the class BRLActionColumnTest method testDiffAll.
@Test
public void testDiffAll() {
List<IAction> definition1 = Arrays.asList(new ActionRetractFact("var1"));
column1.setDefinition(definition1);
List<BRLActionVariableColumn> childColumns1 = Arrays.asList(new BRLActionVariableColumn("var1", "FieldType1"));
column1.setChildColumns(childColumns1);
column1.setHeader("header1");
column1.setHideColumn(false);
List<IAction> definition2 = Arrays.asList(new ActionRetractFact("var2"));
column2.setDefinition(definition2);
List<BRLActionVariableColumn> childColumns2 = Arrays.asList(new BRLActionVariableColumn("var2", "FieldType2"));
column2.setChildColumns(childColumns2);
column2.setHeader("header2");
column2.setHideColumn(true);
List<BaseColumnFieldDiff> diff = column1.diff(column2);
assertNotNull(diff);
assertEquals(5, diff.size());
assertEquals(FIELD_HIDE_COLUMN, diff.get(0).getFieldName());
assertEquals(false, diff.get(0).getOldValue());
assertEquals(true, diff.get(0).getValue());
assertEquals(FIELD_HEADER, diff.get(1).getFieldName());
assertEquals("header1", diff.get(1).getOldValue());
assertEquals("header2", diff.get(1).getValue());
assertEquals(FIELD_DEFINITION, diff.get(2).getFieldName());
assertEquals(definition1, diff.get(2).getOldValue());
assertEquals(definition2, diff.get(2).getValue());
assertEquals(FIELD_VAR_NAME, diff.get(3).getFieldName());
assertEquals("var1", diff.get(3).getOldValue());
assertEquals("var2", diff.get(3).getValue());
assertEquals(FIELD_FIELD_TYPE, diff.get(4).getFieldName());
assertEquals("FieldType1", diff.get(4).getOldValue());
assertEquals("FieldType2", diff.get(4).getValue());
}
Aggregations