Search in sources :

Example 76 with Pattern52

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

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

the class ActionSetFieldsPage method prepareView.

@Override
public void prepareView() {
    // Setup the available patterns, that could have changed each time this page is visited
    List<Pattern52> availablePatterns = new ArrayList<Pattern52>();
    for (Pattern52 p : model.getPatterns()) {
        if (p.getChildColumns().size() > 0) {
            availablePatterns.add(p);
        } else {
            patternToActionsMap.remove(p);
        }
    }
    view.setAvailablePatterns(availablePatterns);
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ArrayList(java.util.ArrayList)

Example 78 with Pattern52

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

the class ActionSetFieldsPage method initialise.

@Override
public void initialise() {
    view.init(this);
    view.setValidator(getValidator());
    patternToActionsMap.clear();
    // Set-up validator for the pattern-to-action mapping voodoo
    getValidator().setPatternToActionSetFieldsMap(patternToActionsMap);
    // Set-up a factory for value editors
    view.setDTCellValueWidgetFactory(DTCellValueWidgetFactory.getInstance(model, oracle, false, allowEmptyValues()));
    // Existing ActionSetFieldCols (should be empty for a new Decision Table)
    for (ActionCol52 a : model.getActionCols()) {
        if (a instanceof ActionSetFieldCol52) {
            final ActionSetFieldCol52 asf = (ActionSetFieldCol52) a;
            final Pattern52 p = model.getConditionPattern(asf.getBoundName());
            if (!patternToActionsMap.containsKey(p)) {
                patternToActionsMap.put(p, new ArrayList<ActionSetFieldCol52>());
            }
            final List<ActionSetFieldCol52> actions = patternToActionsMap.get(p);
            actions.add(asf);
        }
    }
    view.setChosenFields(new ArrayList<ActionSetFieldCol52>());
    content.setWidget(view);
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ActionCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionCol52) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)

Example 79 with Pattern52

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

the class ActionSetFieldsPage method makeResult.

@Override
public void makeResult(final GuidedDecisionTable52 model) {
    // Copy actions to decision table model. Assertion of bindings occurs in FactPatternsPage
    for (Map.Entry<Pattern52, List<ActionSetFieldCol52>> ps : patternToActionsMap.entrySet()) {
        final Pattern52 p = ps.getKey();
        // Patterns with no conditions don't get created
        if (p.getChildColumns().size() > 0) {
            final String binding = p.getBoundName();
            for (ActionSetFieldCol52 a : ps.getValue()) {
                a.setBoundName(binding);
                model.getActionCols().add(a);
            }
        }
    }
}
Also used : Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ActionSetFieldCol52(org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)

Example 80 with Pattern52

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

the class FactPatternsPageViewImpl method initialiseShufflers.

private void initialiseShufflers() {
    btnMoveUp.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            int index = chosenPatterns.indexOf(chosenPatternSelection);
            final Pattern52 p = chosenPatterns.remove(index);
            chosenPatterns.add(index - 1, p);
            setChosenPatterns(chosenPatterns);
            presenter.setConditionPatterns(chosenPatterns);
        }
    });
    btnMoveDown.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(final ClickEvent event) {
            int index = chosenPatterns.indexOf(chosenPatternSelection);
            final Pattern52 p = chosenPatterns.remove(index);
            chosenPatterns.add(index + 1, p);
            setChosenPatterns(chosenPatterns);
            presenter.setConditionPatterns(chosenPatterns);
        }
    });
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) ClickEvent(com.google.gwt.event.dom.client.ClickEvent)

Aggregations

Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)243 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)184 Test (org.junit.Test)180 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)92 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)66 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)45 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)39 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)34 ArrayList (java.util.ArrayList)31 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)31 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)28 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)27 Path (org.uberfire.backend.vfs.Path)27 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)26 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)26 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)26 StringUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn)25 IntegerUiColumn (org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn)24 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)24 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)24