Search in sources :

Example 6 with CEPOperatorsDropdown

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);
    });
}
Also used : CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown) Test(org.junit.Test)

Example 7 with CEPOperatorsDropdown

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());
}
Also used : CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)

Example 8 with CEPOperatorsDropdown

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);
    }
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) OperatorSelection(org.drools.workbench.screens.guided.rule.client.editor.OperatorSelection) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)

Example 9 with CEPOperatorsDropdown

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));
    });
}
Also used : SingleFieldConstraintEBLeftSide(org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide) CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)

Aggregations

CEPOperatorsDropdown (org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)9 Test (org.junit.Test)3 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)2 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)2 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)1 MultiSelectionModel (com.google.gwt.view.client.MultiSelectionModel)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)1 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)1 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)1 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)1 OperatorSelection (org.drools.workbench.screens.guided.rule.client.editor.OperatorSelection)1 Label (org.gwtbootstrap3.client.ui.Label)1 ListBox (org.gwtbootstrap3.client.ui.ListBox)1 Callback (org.uberfire.client.callbacks.Callback)1 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)1 WizardPageStatusChangeEvent (org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent)1