use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern in project drools-wb by kiegroup.
the class RuleModellerConditionSelectorPopup method addNewFCE.
private void addNewFCE(String type, int position) {
FromCompositeFactPattern p = null;
if (type.equals("from")) {
p = new FromCompositeFactPattern();
} else if (type.equals("from accumulate")) {
p = new FromAccumulateCompositeFactPattern();
} else if (type.equals("from collect")) {
p = new FromCollectCompositeFactPattern();
} else if (type.equals("from entry-point")) {
p = new FromEntryPointFactPattern();
}
this.model.addLhsItem(p, position);
}
use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern in project drools-wb by kiegroup.
the class FromCollectCompositeFactPatternWidget method showRightPatternSelector.
/**
* Pops up the fact selector.
*/
protected void showRightPatternSelector(final Widget w) {
final ListBox box = new ListBox();
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
getFromCollectPattern().setRightPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
final Button freeFormDRLBtn = new Button(GuidedRuleEditorResources.CONSTANTS.FreeFormDrl());
final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
ClickHandler btnsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
Widget sender = (Widget) event.getSource();
if (sender == fromBtn) {
getFromCollectPattern().setRightPattern(new FromCompositeFactPattern());
} else if (sender == fromAccumulateBtn) {
getFromCollectPattern().setRightPattern(new FromAccumulateCompositeFactPattern());
} else if (sender == fromCollectBtn) {
getFromCollectPattern().setRightPattern(new FromCollectCompositeFactPattern());
} else if (sender == freeFormDRLBtn) {
getFromCollectPattern().setRightPattern(new FreeFormLine());
} else if (sender == fromEntryPointBtn) {
getFromCollectPattern().setRightPattern(new FromEntryPointFactPattern());
} else {
throw new IllegalArgumentException("Unknown sender: " + sender);
}
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
};
freeFormDRLBtn.addClickHandler(btnsClickHandler);
fromBtn.addClickHandler(btnsClickHandler);
fromAccumulateBtn.addClickHandler(btnsClickHandler);
fromCollectBtn.addClickHandler(btnsClickHandler);
fromEntryPointBtn.addClickHandler(btnsClickHandler);
popup.addAttribute("", freeFormDRLBtn);
popup.addAttribute("", fromBtn);
popup.addAttribute("", fromAccumulateBtn);
popup.addAttribute("", fromCollectBtn);
popup.addAttribute("", fromEntryPointBtn);
popup.show();
}
use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern in project drools-wb by kiegroup.
the class FromCollectCompositeFactPatternWidget method getCompositeLabel.
@Override
protected Widget getCompositeLabel() {
ClickHandler leftPatternclick = new ClickHandler() {
public void onClick(ClickEvent event) {
showFactTypeSelector();
}
};
ClickHandler rightPatternclick = new ClickHandler() {
public void onClick(ClickEvent event) {
Widget w = (Widget) event.getSource();
showRightPatternSelector(w);
}
};
String lbl = "<div class='form-field'>" + HumanReadable.getCEDisplayName("from collect") + "</div>";
FlexTable panel = new FlexTable();
int r = 0;
if (pattern.getFactPattern() == null) {
panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPatterns() + "</font>", leftPatternclick, !this.readOnly));
}
panel.setWidget(r++, 0, new HTML(lbl));
if (this.getFromCollectPattern().getRightPattern() == null) {
panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPatterns() + "</font>", rightPatternclick, !this.readOnly));
} else {
IPattern rPattern = this.getFromCollectPattern().getRightPattern();
RuleModellerWidget patternWidget = null;
if (rPattern instanceof FactPattern) {
patternWidget = new FactPatternWidget(this.getModeller(), this.getEventBus(), rPattern, true, true, this.readOnly);
} else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
patternWidget = new FromAccumulateCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromAccumulateCompositeFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromCollectCompositeFactPattern) {
patternWidget = new FromCollectCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCollectCompositeFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromEntryPointFactPattern) {
patternWidget = new FromEntryPointFactPatternWidget(this.getModeller(), this.getEventBus(), (FromEntryPointFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromCompositeFactPattern) {
patternWidget = new FromCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCompositeFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FreeFormLine) {
patternWidget = new FreeFormLineWidget(this.getModeller(), this.getEventBus(), (FreeFormLine) rPattern, this.readOnly);
} else {
throw new IllegalArgumentException("Unsupported pattern " + rPattern + " for right side of FROM COLLECT");
}
patternWidget.addOnModifiedCommand(new Command() {
public void execute() {
setModified(true);
}
});
panel.setWidget(r++, 0, addRemoveButton(patternWidget, new ClickHandler() {
public void onClick(ClickEvent event) {
if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveThisBlockOfData())) {
setModified(true);
getFromCollectPattern().setRightPattern(null);
getModeller().refreshWidget();
}
}
}));
}
return panel;
}
use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern in project drools-wb by kiegroup.
the class CompositeFactPatternWidget method showFactTypeSelector.
/**
* Pops up the fact selector.
*/
protected void showFactTypeSelector(final Widget w) {
final ListBox box = new ListBox();
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
pattern.addFactPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
ClickHandler btnsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
Widget sender = (Widget) event.getSource();
if (sender == fromBtn) {
pattern.addFactPattern(new FromCompositeFactPattern());
} else if (sender == fromAccumulateBtn) {
pattern.addFactPattern(new FromAccumulateCompositeFactPattern());
} else if (sender == fromCollectBtn) {
pattern.addFactPattern(new FromCollectCompositeFactPattern());
} else {
throw new IllegalArgumentException("Unknown sender: " + sender);
}
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
};
fromBtn.addClickHandler(btnsClickHandler);
fromAccumulateBtn.addClickHandler(btnsClickHandler);
fromCollectBtn.addClickHandler(btnsClickHandler);
popup.addAttribute("", fromBtn);
popup.addAttribute("", fromAccumulateBtn);
popup.addAttribute("", fromCollectBtn);
popup.show();
}
use of org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testFromAccumulateCompositePattern.
@Test
public void testFromAccumulateCompositePattern() throws Exception {
FactPattern pattern1 = new FactPattern("Person");
SingleFieldConstraint constraint1 = new SingleFieldConstraint("name");
constraint1.setOperator("==");
constraint1.setValue("Toni");
pattern1.addConstraint(constraint1);
FactPattern pattern2 = new FactPattern("Address");
SingleFieldConstraint constraint2 = new SingleFieldConstraint("street");
constraint2.setOperator("!=");
constraint2.setValue("some street");
pattern2.addConstraint(constraint2);
FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern = new FromAccumulateCompositeFactPattern();
fromAccumulateCompositeFactPattern.setSourcePattern(pattern1);
fromAccumulateCompositeFactPattern.setFactPattern(pattern2);
ExpressionFormLine expression = new ExpressionFormLine();
expression.setBinding("person.addresses");
fromAccumulateCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { fromAccumulateCompositeFactPattern };
assertTrue(validator.isValid());
}
Aggregations