Search in sources :

Example 6 with LimitedEntryConditionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 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 7 with LimitedEntryConditionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.

the class BaseColumnDefinitionBuilderTest method setupLimitedEntryPatternAndCondition.

protected void setupLimitedEntryPatternAndCondition() {
    final Pattern52 p = new Pattern52();
    p.setFactType("Person");
    p.setBoundName("$p");
    final LimitedEntryConditionCol52 cc = new LimitedEntryConditionCol52();
    cc.setFactField("name");
    cc.setOperator("==");
    cc.setFieldType(DataType.TYPE_STRING);
    cc.setValue(new DTCellValue52("Michael"));
    p.getChildColumns().add(cc);
    model.getConditions().add(p);
    when(dmo.getFieldType(eq("Person"), eq("name"))).thenReturn(DataType.TYPE_STRING);
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)

Example 8 with LimitedEntryConditionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.

the class ValueOptionsPageTest method testCanSetupLimitedValueWhenTableFormatIsNotLimitedEntry.

@Test
public void testCanSetupLimitedValueWhenTableFormatIsNotLimitedEntry() throws Exception {
    when(plugin.editingCol()).thenReturn(new LimitedEntryConditionCol52());
    when(model.getTableFormat()).thenReturn(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);
    when(plugin.doesOperatorNeedValue()).thenReturn(true);
    assertFalse(page.canSetupLimitedValue());
}
Also used : LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) Test(org.junit.Test)

Example 9 with LimitedEntryConditionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools-wb by kiegroup.

the class ValueOptionsPageTest method testCanSetupLimitedValueWhenOperatorNeedsAValue.

@Test
public void testCanSetupLimitedValueWhenOperatorNeedsAValue() throws Exception {
    when(plugin.editingCol()).thenReturn(new LimitedEntryConditionCol52());
    when(plugin.doesOperatorNeedValue()).thenReturn(false);
    assertFalse(page.canSetupLimitedValue());
}
Also used : LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) Test(org.junit.Test)

Example 10 with LimitedEntryConditionCol52

use of org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52 in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testLimitedEntryLHSIsNotNullOperator.

@Test
public void testLimitedEntryLHSIsNotNullOperator() {
    GuidedDecisionTable52 dt = new GuidedDecisionTable52();
    dt.setTableFormat(GuidedDecisionTable52.TableFormat.LIMITED_ENTRY);
    dt.setTableName("limited-entry");
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Smurf");
    dt.getConditions().add(p1);
    LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52();
    cc1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc1.setFieldType(DataType.TYPE_STRING);
    cc1.setFactField("name");
    cc1.setOperator("!= null");
    p1.getChildColumns().add(cc1);
    LimitedEntryConditionCol52 cc2 = new LimitedEntryConditionCol52();
    cc2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    cc2.setFactField("age");
    cc2.setOperator("!= null");
    p1.getChildColumns().add(cc2);
    LimitedEntryConditionCol52 cc3 = new LimitedEntryConditionCol52();
    cc3.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    cc3.setFieldType(DataType.TYPE_DATE);
    cc3.setFactField("dateOfBirth");
    cc3.setOperator("!= null");
    p1.getChildColumns().add(cc3);
    dt.setData(DataUtilities.makeDataLists(new Object[][] { new Object[] { 1l, "desc", true, true, true }, new Object[] { 2l, "desc", false, false, false } }));
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dt);
    int index = -1;
    index = drl.indexOf("Smurf( name != null , age != null , dateOfBirth != null )");
    assertTrue(index > -1);
    index = drl.indexOf("Smurf( )", index + 1);
    assertFalse(index > -1);
}
Also used : GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) Test(org.junit.Test)

Aggregations

LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)20 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)14 Test (org.junit.Test)14 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)10 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)10 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)9 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)3 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 MultiSelectionModel (com.google.gwt.view.client.MultiSelectionModel)1 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)1 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)1 CEPOperatorsDropdown (org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)1