Search in sources :

Example 1 with CEPOperatorsDropdown

use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.

the class FactPatternConstraintsPageViewImpl method initialiseChosenFields.

private void initialiseChosenFields() {
    chosenConditionsContainer.add(chosenConditionsWidget);
    chosenConditionsWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    chosenConditionsWidget.setMinimumWidth(170);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoChosenFields());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    chosenConditionsWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<ConditionCol52> selectionModel = new MultiSelectionModel<ConditionCol52>(System::identityHashCode);
    chosenConditionsWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            chosenConditionsSelections = new HashSet<ConditionCol52>();
            final Set<ConditionCol52> selections = selectionModel.getSelectedSet();
            for (ConditionCol52 c : selections) {
                chosenConditionsSelections.add(c);
            }
            chosenConditionsSelected(chosenConditionsSelections);
        }

        private void chosenConditionsSelected(final Set<ConditionCol52> cws) {
            btnRemove.setEnabled(true);
            if (cws.size() == 1) {
                chosenConditionsSelection = cws.iterator().next();
                conditionDefinition.setVisible(true);
                validateConditionHeader();
                validateConditionOperator();
                populateConditionDefinition();
                enableMoveUpButton();
                enableMoveDownButton();
            } else {
                chosenConditionsSelection = null;
                conditionDefinition.setVisible(false);
                optLiteral.setEnabled(false);
                optFormula.setEnabled(false);
                optPredicate.setEnabled(false);
                txtColumnHeader.setEnabled(false);
                txtValueList.setEnabled(false);
                defaultValueContainer.setVisible(false);
                btnMoveUp.setEnabled(false);
                btnMoveDown.setEnabled(false);
            }
        }

        private void displayCalculationTypes(final Pattern52 selectedPattern, final ConditionCol52 selectedCondition) {
            final boolean isPredicate = (selectedCondition.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_PREDICATE);
            final boolean hasEnum = presenter.hasEnum(selectedPattern, selectedCondition);
            calculationType.setVisible(!isPredicate);
            optLiteral.setEnabled(!isPredicate);
            optLiteral.setVisible(!isPredicate);
            optFormula.setEnabled(!(isPredicate || hasEnum));
            optFormula.setVisible(!isPredicate);
            operatorContainer.setVisible(!isPredicate);
            optPredicate.setEnabled(isPredicate);
            optPredicate.setVisible(isPredicate);
            txtPredicateExpression.setEnabled(isPredicate);
            predicateExpressionContainer.setVisible(isPredicate);
        }

        private void populateConditionDefinition() {
            // Fields common to all table formats
            txtColumnHeader.setEnabled(true);
            txtColumnHeader.setText(chosenConditionsSelection.getHeader());
            presenter.getOperatorCompletions(availablePatternsSelection, chosenConditionsSelection, new Callback<String[]>() {

                @Override
                public void callback(final String[] ops) {
                    doPopulateConditionDefinition(ops);
                }
            });
        }

        private void doPopulateConditionDefinition(final String[] ops) {
            final CEPOperatorsDropdown ddOperator = new CEPOperatorsDropdown(ops, chosenConditionsSelection);
            ddOperator.addPlaceholder(GuidedRuleEditorResources.CONSTANTS.pleaseChoose(), "");
            ddOperatorContainer.setWidget(ddOperator);
            criteriaExtendedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
            criteriaLimitedEntry.setVisible(presenter.getTableFormat() == GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
            // Fields specific to the table format
            switch(presenter.getTableFormat()) {
                case EXTENDED_ENTRY:
                    txtValueList.setEnabled(!presenter.requiresValueList(availablePatternsSelection, chosenConditionsSelection));
                    txtValueList.setText(chosenConditionsSelection.getValueList());
                    makeDefaultValueWidget();
                    defaultValueContainer.setVisible(validator.doesOperatorNeedValue(chosenConditionsSelection));
                    if (chosenConditionsSelection.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_PREDICATE) {
                        txtPredicateExpression.setText(chosenConditionsSelection.getFactField());
                    }
                    ddOperator.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
                            chosenConditionsSelection.setOperator(event.getValue().getValue());
                            final boolean requiresValueList = presenter.requiresValueList(availablePatternsSelection, chosenConditionsSelection);
                            txtValueList.setEnabled(requiresValueList);
                            if (!requiresValueList) {
                                txtValueList.setText("");
                            } else {
                                txtValueList.setText(chosenConditionsSelection.getValueList());
                            }
                            presenter.stateChanged();
                            validateConditionOperator();
                            makeDefaultValueWidget();
                            defaultValueContainer.setVisible(validator.doesOperatorNeedValue(chosenConditionsSelection));
                        }
                    });
                    switch(chosenConditionsSelection.getConstraintValueType()) {
                        case BaseSingleFieldConstraint.TYPE_LITERAL:
                            optLiteral.setValue(true);
                            displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
                            break;
                        case BaseSingleFieldConstraint.TYPE_RET_VALUE:
                            optFormula.setValue(true);
                            displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
                            break;
                        case BaseSingleFieldConstraint.TYPE_PREDICATE:
                            optPredicate.setValue(true);
                            displayCalculationTypes(availablePatternsSelection, chosenConditionsSelection);
                    }
                    break;
                case LIMITED_ENTRY:
                    calculationType.setVisible(false);
                    makeLimitedValueWidget();
                    // If operator changes the widget used to populate the
                    // value can change
                    ddOperator.addValueChangeHandler(new ValueChangeHandler<OperatorSelection>() {

                        @Override
                        public void onValueChange(ValueChangeEvent<OperatorSelection> event) {
                            chosenConditionsSelection.setOperator(event.getValue().getValue());
                            validateConditionOperator();
                            makeLimitedValueWidget();
                            presenter.stateChanged();
                        }
                    });
                    break;
            }
        }

        private void makeLimitedValueWidget() {
            if (!(chosenConditionsSelection instanceof LimitedEntryConditionCol52)) {
                return;
            }
            final LimitedEntryConditionCol52 lec = (LimitedEntryConditionCol52) chosenConditionsSelection;
            boolean doesOperatorNeedValue = validator.doesOperatorNeedValue(chosenConditionsSelection);
            if (!doesOperatorNeedValue) {
                limitedEntryValueContainer.setVisible(false);
                lec.setValue(null);
                return;
            }
            limitedEntryValueContainer.setVisible(true);
            if (lec.getValue() == null) {
                lec.setValue(factory.makeNewValue(chosenConditionsSelection));
            }
            limitedEntryValueWidgetContainer.setWidget(factory.getWidget(availablePatternsSelection, chosenConditionsSelection, lec.getValue()));
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) Callback(org.uberfire.client.callbacks.Callback) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown) HashSet(java.util.HashSet)

Example 2 with CEPOperatorsDropdown

use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.

the class OperatorPageTest method testOperatorDropdownSelectedNotFirstItem.

@Test
public void testOperatorDropdownSelectedNotFirstItem() {
    registerFakeProvider();
    when(plugin.getFactField()).thenReturn("factField");
    when(plugin.operatorPlaceholder()).thenReturn("please choose");
    when(editingCol.getOperator()).thenReturn("not equal to");
    mockGetOperatorCompletionsToReturn(OperatorsOracle.STANDARD_OPERATORS);
    spyOperatorsDropdown();
    mockListBox("please choose", "equal to", "not equal to");
    page.operatorDropdown(widget -> {
        assertTrue(widget instanceof CEPOperatorsDropdown);
        final CEPOperatorsDropdown operatorsDropdown = (CEPOperatorsDropdown) widget;
        verify(operatorsDropdown.getBox()).setSelectedIndex(2);
    });
}
Also used : CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown) Test(org.junit.Test)

Example 3 with CEPOperatorsDropdown

use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.

the class OperatorPage method newCepOperatorsDropdown.

private CEPOperatorsDropdown newCepOperatorsDropdown(final String[] operatorsArray) {
    final CEPOperatorsDropdown dropdown = newCepOperatorsDropdown(operatorsArray, editingCol());
    dropdown.addPlaceholder(plugin().operatorPlaceholder(), plugin().operatorPlaceholder());
    dropdown.insertItem(translate(GuidedDecisionTableErraiConstants.OperatorPage_NoOperator), "", 1);
    return dropdown;
}
Also used : CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)

Example 4 with CEPOperatorsDropdown

use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.

the class OperatorPage method cepOperatorsDropdown.

private void cepOperatorsDropdown(final Consumer<IsWidget> widgetSupplier) {
    getOperatorCompletions(options -> {
        final String[] operatorsArray = filterOptionsForConstraintTypeLiteral(options);
        final CEPOperatorsDropdown dropdown = newCepOperatorsDropdown(operatorsArray);
        final ListBox box = dropdown.getBox();
        final int currentValueIndex = getCurrentIndexFromList(getOperator(), box);
        box.addChangeHandler((ChangeEvent valueChangeEvent) -> setOperator(box.getValue(box.getSelectedIndex())));
        if (currentValueIndex != box.getSelectedIndex()) {
            box.setSelectedIndex(currentValueIndex);
        }
        widgetSupplier.accept(dropdown);
    });
}
Also used : ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) WizardPageStatusChangeEvent(org.uberfire.ext.widgets.core.client.wizards.WizardPageStatusChangeEvent) CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown) ListBox(org.gwtbootstrap3.client.ui.ListBox) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 5 with CEPOperatorsDropdown

use of org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown in project drools-wb by kiegroup.

the class OperatorPageTest method testOperatorPlaceholderSelectedWhenNothingSelectedPreviously.

@Test
public void testOperatorPlaceholderSelectedWhenNothingSelectedPreviously() {
    registerFakeProvider();
    when(plugin.getFactField()).thenReturn("factField");
    when(plugin.operatorPlaceholder()).thenReturn("please choose");
    mockGetOperatorCompletionsToReturn(OperatorsOracle.STANDARD_OPERATORS);
    spyOperatorsDropdown();
    mockListBox("please choose", "equal to");
    page.operatorDropdown(widget -> {
        assertTrue(widget instanceof CEPOperatorsDropdown);
        final CEPOperatorsDropdown operatorsDropdown = (CEPOperatorsDropdown) widget;
        verify(operatorsDropdown.getBox()).setSelectedIndex(0);
    });
}
Also used : CEPOperatorsDropdown(org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown) Test(org.junit.Test)

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