use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testDSLWithFrom.
/*
* https://issues.jboss.org/browse/DROOLS-1903
*/
@Test
public void testDSLWithFrom() {
final RuleModel m = new RuleModel();
m.name = "testDSLWithFrom";
m.lhs = new IPattern[2];
m.rhs = new IAction[0];
final FromCollectCompositeFactPattern from = new FromCollectCompositeFactPattern();
final FromCompositeFactPattern rightPattern = new FromCompositeFactPattern();
final FactPattern person = new FactPattern("Person");
person.setBoundName("$person");
m.lhs[0] = person;
rightPattern.setFactPattern(new FactPattern("Person"));
rightPattern.setExpression(new ExpressionFormLine(new ExpressionVariable(person.getBoundName(), person.getFactType())));
from.setRightPattern(rightPattern);
from.setFactPattern(new FactPattern("java.util.List"));
m.lhs[1] = from;
final RuleModel modelSpy = spy(m);
doReturn(true).when(modelSpy).hasDSLSentences();
final String drl = ruleModelPersistence.marshal(modelSpy);
final RuleModel tempModel = spy(ruleModelPersistence.unmarshalUsingDSL(drl, null, dmo, ""));
doReturn(true).when(tempModel).hasDSLSentences();
final String newDrl = ruleModelPersistence.marshal(tempModel);
final RuleModel newModel = ruleModelPersistence.unmarshalUsingDSL(newDrl, null, dmo, "");
assertTrue(newModel.lhs[0] instanceof FactPattern);
assertTrue(newModel.lhs[1] instanceof FromCollectCompositeFactPattern);
assertDSLEscaping(newDrl);
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern in project drools-wb by kiegroup.
the class FromAccumulateCompositeFactPatternWidget method getCompositeLabel.
@Override
protected Widget getCompositeLabel() {
ClickHandler leftPatternclick = new ClickHandler() {
public void onClick(ClickEvent event) {
showFactTypeSelector();
}
};
ClickHandler sourcePatternClick = new ClickHandler() {
public void onClick(ClickEvent event) {
showSourcePatternSelector();
}
};
String lbl = "<div class='form-field'>" + HumanReadable.getCEDisplayName("from accumulate") + "</div>";
FlexTable panel = new FlexTable();
int r = 0;
if (pattern.getFactPattern() == null) {
panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPattern() + "</font>", leftPatternclick, !this.readOnly));
}
panel.setWidget(r++, 0, new HTML(lbl));
if (this.getFromAccumulatePattern().getSourcePattern() == null) {
panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPattern() + "</font>", sourcePatternClick, !this.readOnly));
} else {
IPattern rPattern = this.getFromAccumulatePattern().getSourcePattern();
RuleModellerWidget sourcePatternWidget;
if (rPattern instanceof FactPattern) {
sourcePatternWidget = new FactPatternWidget(this.getModeller(), getEventBus(), rPattern, true, true, this.readOnly);
} else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
sourcePatternWidget = new FromAccumulateCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromAccumulateCompositeFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromCollectCompositeFactPattern) {
sourcePatternWidget = new FromCollectCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCollectCompositeFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromEntryPointFactPattern) {
sourcePatternWidget = new FromEntryPointFactPatternWidget(this.getModeller(), this.getEventBus(), (FromEntryPointFactPattern) rPattern, this.readOnly);
} else if (rPattern instanceof FromCompositeFactPattern) {
sourcePatternWidget = new FromCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCompositeFactPattern) rPattern, this.readOnly);
} else {
throw new IllegalArgumentException("Unsupported pattern " + rPattern + " for right side of FROM ACCUMULATE");
}
sourcePatternWidget.addOnModifiedCommand(new Command() {
public void execute() {
setModified(true);
}
});
panel.setWidget(r++, 0, addRemoveButton(sourcePatternWidget, new ClickHandler() {
public void onClick(ClickEvent event) {
if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveThisBlockOfData())) {
setModified(true);
getFromAccumulatePattern().setSourcePattern(null);
getModeller().refreshWidget();
}
}
}));
}
final TabPanel tPanel = new TabPanel() {
{
addStyleName("uf-tabbar-panel");
}
};
final NavTabs navTabs = new NavTabs() {
{
addStyleName("uf-tabbar-panel-nav-tabs");
addStyleName("nav-tabs-pf");
}
};
final TabContent content = new TabContent();
tPanel.add(navTabs);
tPanel.add(content);
FlexTable codeTable = new FlexTable();
int codeTableRow = 0;
int codeTableCol = 0;
codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Init() + ":</div>"));
final TextBox initField = new TextBox();
initField.setTitle(GuidedRuleEditorResources.CONSTANTS.InitCode());
initField.setText(getFromAccumulatePattern().getInitCode());
initField.setEnabled(!this.readOnly);
codeTable.setWidget(codeTableRow++, codeTableCol--, initField);
codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Action() + ":</div>"));
final TextBox actionField = new TextBox();
actionField.setTitle(GuidedRuleEditorResources.CONSTANTS.ActionCode());
actionField.setText(getFromAccumulatePattern().getActionCode());
actionField.setEnabled(!this.readOnly);
codeTable.setWidget(codeTableRow++, codeTableCol--, actionField);
codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Reverse() + ":</div>"));
final TextBox reverseField = new TextBox();
reverseField.setTitle(GuidedRuleEditorResources.CONSTANTS.ReverseCode());
reverseField.setText(getFromAccumulatePattern().getReverseCode());
reverseField.setEnabled(!this.readOnly);
codeTable.setWidget(codeTableRow++, codeTableCol--, reverseField);
codeTable.setWidget(codeTableRow, codeTableCol++, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Result() + ":</div>"));
final TextBox resultField = new TextBox();
resultField.setTitle(GuidedRuleEditorResources.CONSTANTS.ResultCode());
resultField.setText(getFromAccumulatePattern().getResultCode());
resultField.setEnabled(!this.readOnly);
codeTable.setWidget(codeTableRow++, codeTableCol--, resultField);
// panel.setWidget(r++, 0, codeTable);
final ScrollPanel codePanel = new ScrollPanel();
codePanel.add(codeTable);
final TabPane codeTabPane = new TabPane() {
{
add(codePanel);
}
};
final TabListItem codeTabListItem = new TabListItem(GuidedRuleEditorResources.CONSTANTS.CustomCode()) {
{
addStyleName("uf-dropdown-tab-list-item");
setDataTargetWidget(codeTabPane);
getElement().getStyle().setFontSize(12, Style.Unit.PX);
}
};
navTabs.add(codeTabListItem);
content.add(codeTabPane);
FlexTable functionTable = new FlexTable();
functionTable.setWidget(0, 0, new HTML("<div class='form-field'>" + GuidedRuleEditorResources.CONSTANTS.Function() + ":</div>"));
final TextBox functionField = new TextBox();
functionField.setTitle(GuidedRuleEditorResources.CONSTANTS.FunctionCode());
functionField.setText(getFromAccumulatePattern().getFunction());
functionField.setEnabled(!this.readOnly);
functionTable.setWidget(0, 1, functionField);
// panel.setWidget(r++, 0, functionTable);
final ScrollPanel functionPanel = new ScrollPanel();
functionPanel.add(functionTable);
final TabPane functionTabPane = new TabPane() {
{
add(functionPanel);
}
};
final TabListItem functionTabListItem = new TabListItem(GuidedRuleEditorResources.CONSTANTS.Function()) {
{
addStyleName("uf-dropdown-tab-list-item");
setDataTargetWidget(functionTabPane);
getElement().getStyle().setFontSize(12, Style.Unit.PX);
}
};
navTabs.add(functionTabListItem);
content.add(functionTabPane);
ChangeHandler changehandler = new ChangeHandler() {
public void onChange(ChangeEvent event) {
Widget sender = (Widget) event.getSource();
TextBox senderTB = (TextBox) event.getSource();
String code = senderTB.getText();
setModified(true);
if (sender == initField) {
getFromAccumulatePattern().setFunction(null);
functionField.setText("");
getFromAccumulatePattern().setInitCode(code);
} else if (sender == actionField) {
getFromAccumulatePattern().setFunction(null);
functionField.setText("");
getFromAccumulatePattern().setActionCode(code);
} else if (sender == reverseField) {
getFromAccumulatePattern().setFunction(null);
functionField.setText("");
getFromAccumulatePattern().setReverseCode(code);
} else if (sender == resultField) {
getFromAccumulatePattern().setFunction(null);
functionField.setText("");
getFromAccumulatePattern().setResultCode(code);
} else if (sender == functionField) {
getFromAccumulatePattern().clearCodeFields();
initField.setText("");
actionField.setText("");
reverseField.setText("");
resultField.setText("");
getFromAccumulatePattern().setFunction(code);
}
}
};
initField.addChangeHandler(changehandler);
actionField.addChangeHandler(changehandler);
reverseField.addChangeHandler(changehandler);
resultField.addChangeHandler(changehandler);
functionField.addChangeHandler(changehandler);
boolean useFunction = getFromAccumulatePattern().useFunctionOrCode().equals(FromAccumulateCompositeFactPattern.USE_FUNCTION);
if (useFunction) {
functionTabListItem.setActive(true);
functionTabPane.setActive(true);
} else {
codeTabListItem.setActive(true);
codeTabPane.setActive(true);
}
panel.setWidget(r++, 0, tPanel);
return panel;
}
use of org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern 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.FromCollectCompositeFactPattern 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.FromCollectCompositeFactPattern 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;
}
Aggregations