Search in sources :

Example 1 with MultiSelectionModel

use of com.google.gwt.view.client.MultiSelectionModel in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPageViewImpl method initialiseChosenPatterns.

private void initialiseChosenPatterns() {
    chosenPatternsContainer.add(chosenPatternsWidget);
    chosenPatternsWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    chosenPatternsWidget.setMinimumWidth(130);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoChosenPatterns());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    chosenPatternsWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<ActionInsertFactFieldsPattern> selectionModel = new MultiSelectionModel<ActionInsertFactFieldsPattern>(System::identityHashCode);
    chosenPatternsWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            chosenPatternsSelections = selectionModel.getSelectedSet();
            chosenPatternsSelected(chosenPatternsSelections);
        }

        private void chosenPatternsSelected(final Set<ActionInsertFactFieldsPattern> cps) {
            btnRemoveFactTypes.setEnabled(cps.size() > 0);
            fieldDefinition.setVisible(false);
            if (cps.size() == 1) {
                chosenPatternsSelection = cps.iterator().next();
                presenter.selectPattern(chosenPatternsSelection);
                patternDefinition.setVisible(true);
                validateBinding();
                txtBinding.setEnabled(true);
                txtBinding.setVisible(true);
                txtBinding.setText(chosenPatternsSelection.getBoundName());
                chkLogicalInsert.setEnabled(true);
                chkLogicalInsert.setVisible(true);
                chkLogicalInsert.setValue(chosenPatternsSelection.isInsertedLogically());
            } else {
                chosenPatternsSelection = null;
                setAvailableFields(new ArrayList<AvailableField>());
                setChosenFields(new ArrayList<ActionInsertFactCol52>());
                patternDefinition.setVisible(false);
                txtBinding.setEnabled(false);
                txtBinding.setVisible(false);
                txtBinding.setText("");
                chkLogicalInsert.setEnabled(false);
                chkLogicalInsert.setVisible(false);
            }
        }
    });
}
Also used : ActionInsertFactFieldsPattern(org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern) MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) ArrayList(java.util.ArrayList) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 2 with MultiSelectionModel

use of com.google.gwt.view.client.MultiSelectionModel in project drools-wb by kiegroup.

the class ActionInsertFactFieldsPageViewImpl method initialiseAvailableFactTypes.

private void initialiseAvailableFactTypes() {
    availableFactTypesContainer.add(availableFactTypesWidget);
    availableFactTypesWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    availableFactTypesWidget.setMinimumWidth(130);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoAvailablePatterns());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    availableFactTypesWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<String> selectionModel = new MultiSelectionModel<String>();
    availableFactTypesWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            availableFactTypesSelections = selectionModel.getSelectedSet();
            btnAddFactTypes.setEnabled(availableFactTypesSelections.size() > 0);
        }
    });
}
Also used : MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 3 with MultiSelectionModel

use of com.google.gwt.view.client.MultiSelectionModel in project drools-wb by kiegroup.

the class FactPatternConstraintsPageViewImpl method initialiseAvailableFields.

private void initialiseAvailableFields() {
    availableFieldsContainer.add(availableFieldsWidget);
    availableFieldsWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    availableFieldsWidget.setMinimumWidth(170);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoAvailableFields());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    availableFieldsWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<AvailableField> selectionModel = new MultiSelectionModel<AvailableField>();
    availableFieldsWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            availableFieldsSelections = selectionModel.getSelectedSet();
            btnAdd.setEnabled(availableFieldsSelections.size() > 0);
        }
    });
}
Also used : MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Example 4 with MultiSelectionModel

use of com.google.gwt.view.client.MultiSelectionModel 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 5 with MultiSelectionModel

use of com.google.gwt.view.client.MultiSelectionModel in project drools-wb by kiegroup.

the class FactPatternsPageViewImpl method initialiseAvailableTypes.

private void initialiseAvailableTypes() {
    availableTypesContainer.add(availableTypesWidget);
    availableTypesWidget.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    availableTypesWidget.setMinimumWidth(270);
    final Label lstEmpty = new Label(GuidedDecisionTableConstants.INSTANCE.DecisionTableWizardNoAvailablePatterns());
    lstEmpty.setStyleName(WizardCellListResources.INSTANCE.cellListStyle().cellListEmptyItem());
    availableTypesWidget.setEmptyListWidget(lstEmpty);
    final MultiSelectionModel<String> selectionModel = new MultiSelectionModel<String>();
    availableTypesWidget.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(final SelectionChangeEvent event) {
            availableTypesSelections = selectionModel.getSelectedSet();
            btnAdd.setEnabled(availableTypesSelections.size() > 0);
        }
    });
}
Also used : MultiSelectionModel(com.google.gwt.view.client.MultiSelectionModel) Label(org.gwtbootstrap3.client.ui.Label) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent)

Aggregations

MultiSelectionModel (com.google.gwt.view.client.MultiSelectionModel)10 SelectionChangeEvent (com.google.gwt.view.client.SelectionChangeEvent)10 Label (org.gwtbootstrap3.client.ui.Label)10 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)2 Callback (org.uberfire.client.callbacks.Callback)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 ArrayList (java.util.ArrayList)1 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)1 ActionInsertFactFieldsPattern (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactFieldsPattern)1 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)1 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)1 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)1 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)1 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)1 CEPOperatorsDropdown (org.drools.workbench.screens.guided.rule.client.editor.CEPOperatorsDropdown)1