use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPageTest method testOperatorDropdownWhenOperatorCanBeSet.
@Test
public void testOperatorDropdownWhenOperatorCanBeSet() {
final String operatorPlaceholder = "--- please choose ---";
registerFakeProvider();
when(translationService.format(GuidedDecisionTableErraiConstants.OperatorPage_NoOperator)).thenReturn("(no operator)");
when(presenter.getDataModelOracle()).thenReturn(oracle);
when(plugin.getFactField()).thenReturn("factField");
when(plugin.operatorPlaceholder()).thenReturn(operatorPlaceholder);
when(editingCol.getOperator()).thenReturn("");
mockGetOperatorCompletionsToReturn(OperatorsOracle.STANDARD_OPERATORS);
spyOperatorsDropdown();
mockListBox(operatorPlaceholder, "", "equal to");
page.operatorDropdown(widget -> {
assertTrue(widget instanceof CEPOperatorsDropdown);
final CEPOperatorsDropdown dropdown = (CEPOperatorsDropdown) widget;
verify(listBox).setSelectedIndex(1);
verify(listBox).addChangeHandler(any());
verify(dropdown).addPlaceholder(operatorPlaceholder, operatorPlaceholder);
verify(dropdown).insertItem("(no operator)", "", 1);
verify(dropdown.getBox()).setSelectedIndex(1);
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class OperatorPageTest method spyOperatorsDropdown.
private void spyOperatorsDropdown() {
doNothing().when(listBox).setSelectedIndex(anyInt());
doAnswer(answer -> {
final Object firstArgument = answer.getArguments()[0];
final String[] operators = (String[]) firstArgument;
final CEPOperatorsDropdown dropdown = spy(new CEPOperatorsDropdown(operators, editingCol));
when(dropdown.getBox()).thenReturn(listBox);
return dropdown;
}).when(page).newCepOperatorsDropdown(any(), any());
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class Connectives method connectiveOperatorDropDown.
private void connectiveOperatorDropDown(final ConnectiveConstraint cc, final Callback<Widget> callback) {
if (!isReadOnly) {
final String factType = cc.getFactType();
final String fieldName = cc.getFieldName();
this.getDataModelOracle().getConnectiveOperatorCompletions(factType, fieldName, new Callback<String[]>() {
@Override
public void callback(final String[] operators) {
final CEPOperatorsDropdown dropdown = getDropdown(operators, cc);
dropdown.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), "");
dropdown.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {
public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
OperatorSelection selection = event.getValue();
String selected = selection.getValue();
cc.setOperator(selected);
}
});
callback.callback(dropdown);
}
});
} else {
final SmallLabel w = new SmallLabel("<b>" + (cc.getOperator() == null ? GuidedRuleEditorResources.CONSTANTS.pleaseChoose() : HumanReadable.getOperatorDisplayName(cc.getOperator())) + "</b>");
callback.callback(w);
}
}
use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.
the class SingleFieldConstraintOperatorSelector method configure.
public void configure(final SingleFieldConstraint constraint, final Supplier<ConstraintValueEditor> constraintValueEditor, final Function<SingleFieldConstraint, ConstraintValueEditor> constraintValueEditorProducer, final FactPatternWidget parent, final HorizontalPanel placeholderForDropdown, final FlexTable constraintValueEditorWrapper, final int constraintValueEditorRowIndex, final int constraintValueEditorColumnIndex, final AsyncPackageDataModelOracle oracle) {
this.constraint = constraint;
this.constraintValueEditor = constraintValueEditor;
this.constraintValueEditorProducer = constraintValueEditorProducer;
this.parent = parent;
this.placeholderForDropdown = placeholderForDropdown;
this.constraintValueEditorWrapper = constraintValueEditorWrapper;
this.constraintValueEditorRowIndex = constraintValueEditorRowIndex;
this.constraintValueEditorColumnIndex = constraintValueEditorColumnIndex;
this.oracle = oracle;
String fieldName;
String factType;
// Connectives Operators are handled in class Connectives
if (constraint instanceof SingleFieldConstraintEBLeftSide) {
SingleFieldConstraintEBLeftSide sfexp = (SingleFieldConstraintEBLeftSide) constraint;
factType = sfexp.getExpressionLeftSide().getPreviousClassType();
if (factType == null) {
factType = sfexp.getExpressionLeftSide().getClassType();
}
fieldName = sfexp.getExpressionLeftSide().getFieldName();
} else {
factType = constraint.getFactType();
fieldName = constraint.getFieldName();
}
oracle.getOperatorCompletions(factType, fieldName, operators -> {
final CEPOperatorsDropdown operatorsDropdown = getNewOperatorDropdown(operators, constraint);
operatorsDropdown.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), "");
placeholderForDropdown.add(operatorsDropdown);
operatorsDropdown.addValueChangeHandler(event -> onDropDownValueChanged(event));
});
}
Aggregations