Search in sources :

Example 6 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class DefaultValueWidgetFactory method getDefaultValueWidget.

// BZ-996932: Added value change notifications.
public static Widget getDefaultValueWidget(final AttributeCol52 ac, final boolean isReadOnly, final DefaultValueChangedEventHandler defaultValueChangedEventHandler) {
    Widget editor = null;
    final String attributeName = ac.getAttribute();
    if (attributeName.equals(RuleAttributeWidget.RULEFLOW_GROUP_ATTR) || attributeName.equals(RuleAttributeWidget.AGENDA_GROUP_ATTR) || attributeName.equals(RuleAttributeWidget.ACTIVATION_GROUP_ATTR) || attributeName.equals(RuleAttributeWidget.TIMER_ATTR) || attributeName.equals(RuleAttributeWidget.CALENDARS_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(""));
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        tb.setValue(defaultValue.getStringValue());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                    editedDefaultValue.setStringValue(tb.getValue());
                    defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                }
            });
        }
        editor = tb;
    } else if (attributeName.equals(RuleAttributeWidget.SALIENCE_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(0));
        } else {
            assertIntegerDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Integer numericValue = (Integer) defaultValue.getNumericValue();
        tb.setValue(numericValue == null ? "" : numericValue.toString());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                    try {
                        editedDefaultValue.setNumericValue(Integer.valueOf(event.getValue()));
                    } catch (NumberFormatException nfe) {
                        editedDefaultValue.setNumericValue(0);
                        tb.setValue("0");
                    } finally {
                        defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                    }
                }
            });
        }
        editor = tb;
    } else if (attributeName.equals(RuleAttributeWidget.DURATION_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(0L));
        } else {
            assertLongDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Long numericValue = (Long) defaultValue.getNumericValue();
        tb.setValue(numericValue == null ? "" : numericValue.toString());
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                    try {
                        editedDefaultValue.setNumericValue(Long.valueOf(event.getValue()));
                    } catch (NumberFormatException nfe) {
                        editedDefaultValue.setNumericValue(0L);
                        tb.setValue("0");
                    } finally {
                        defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                    }
                }
            });
        }
        editor = tb;
    } else if (attributeName.equals(RuleAttributeWidget.NO_LOOP_ATTR) || attributeName.equals(RuleAttributeWidget.LOCK_ON_ACTIVE_ATTR) || attributeName.equals(RuleAttributeWidget.AUTO_FOCUS_ATTR) || attributeName.equals(RuleAttributeWidget.ENABLED_ATTR) || attributeName.equals(GuidedDecisionTable52.NEGATE_RULE_ATTR)) {
        final CheckBox cb = new CheckBox();
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(Boolean.FALSE));
        } else {
            assertBooleanDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final Boolean booleanValue = defaultValue.getBooleanValue();
        cb.setEnabled(!isReadOnly);
        if (booleanValue == null) {
            cb.setValue(false);
            defaultValue.setBooleanValue(Boolean.FALSE);
        } else {
            cb.setValue(booleanValue);
        }
        cb.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                editedDefaultValue.setBooleanValue(cb.getValue());
                defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
            }
        });
        editor = cb;
    } else if (attributeName.equals(RuleAttributeWidget.DATE_EFFECTIVE_ATTR) || attributeName.equals(RuleAttributeWidget.DATE_EXPIRES_ATTR)) {
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(new Date()));
        } else {
            assertDateDefaultValue(ac.getDefaultValue());
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        if (isReadOnly) {
            final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
            tb.setValue(format.format(defaultValue.getDateValue()));
            tb.setEnabled(false);
        } else {
            final DatePicker datePicker = new DatePicker();
            // Wire up update handler
            datePicker.addChangeDateHandler((e) -> {
                DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                editedDefaultValue.setDateValue(datePicker.getValue());
                defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
            });
            final Date dateValue = defaultValue.getDateValue();
            datePicker.setFormat(DATE_FORMAT);
            datePicker.setValue(dateValue);
            editor = datePicker;
        }
    } else if (attributeName.equals(RuleAttributeWidget.DIALECT_ATTR)) {
        final ListBox lb = new ListBox();
        lb.addItem(RuleAttributeWidget.DIALECTS[0]);
        lb.addItem(RuleAttributeWidget.DIALECTS[1]);
        if (ac.getDefaultValue() == null) {
            ac.setDefaultValue(new DTCellValue52(RuleAttributeWidget.DIALECTS[1]));
        }
        final DTCellValue52 defaultValue = ac.getDefaultValue();
        final String stringValue = defaultValue.getStringValue();
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    final int selectedIndex = lb.getSelectedIndex();
                    if (selectedIndex < 0) {
                        return;
                    }
                    DTCellValue52 editedDefaultValue = defaultValue.cloneDefaultValueCell();
                    editedDefaultValue.setStringValue(lb.getValue(selectedIndex));
                    defaultValueChangedEventHandler.onDefaultValueChanged(new DefaultValueChangedEvent(defaultValue, editedDefaultValue));
                }
            });
        }
        if (stringValue == null || stringValue.isEmpty()) {
            lb.setSelectedIndex(1);
            defaultValue.setStringValue(RuleAttributeWidget.DIALECTS[1]);
        } else if (stringValue.equals(RuleAttributeWidget.DIALECTS[0])) {
            lb.setSelectedIndex(0);
        } else if (stringValue.equals(RuleAttributeWidget.DIALECTS[1])) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            defaultValue.setStringValue(RuleAttributeWidget.DIALECTS[1]);
        }
        editor = lb;
    }
    return editor;
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) RuleAttributeWidget(org.drools.workbench.screens.guided.rule.client.editor.RuleAttributeWidget) Widget(com.google.gwt.user.client.ui.Widget) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) Date(java.util.Date) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) CheckBox(org.gwtbootstrap3.client.ui.CheckBox) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 7 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class ValueEditorFactory method getValueEditor.

public Widget getValueEditor(final String className, final String fieldName, final HasValue hasValue, final AsyncPackageDataModelOracle oracle, final boolean isMultipleSelect) {
    String dataType = oracle.getFieldType(className, fieldName);
    // Operators "contained in" and "not contained in" fallback to Strings
    if (isMultipleSelect) {
        dataType = DataType.TYPE_STRING;
    }
    // Fields with enumerations fallback to Strings
    DropDownData dd = null;
    if (oracle.hasEnums(className, fieldName)) {
        final Map<String, String> currentValueMap = getCurrentValueMap();
        dd = oracle.getEnums(className, fieldName, currentValueMap);
    }
    // Ensure Node has a value if needed
    if (hasValue.getValue() == null) {
        final Value value = ValueUtilities.makeEmptyValue(dataType);
        if (value == null) {
            ErrorPopup.showMessage(GuidedDecisionTreeConstants.INSTANCE.dataTypeNotSupported0(dataType));
            return null;
        } else {
            hasValue.setValue(value);
        }
    }
    // Setup the correct widget corresponding to the data type
    if (dataType.equals(DataType.TYPE_DATE)) {
        final DatePicker valueEditor = new DatePicker(false);
        // Wire-up update handler
        valueEditor.addValueChangeHandler(new ValueChangeHandler<Date>() {

            @Override
            public void onValueChange(final ValueChangeEvent<Date> event) {
                hasValue.getValue().setValue(valueEditor.getValue());
            }
        });
        // Set Widget's value
        valueEditor.setFormat(DATE_FORMAT);
        valueEditor.setValue((Date) hasValue.getValue().getValue());
        return valueEditor;
    } else if (dataType.equals(DataType.TYPE_BOOLEAN)) {
        final ListBox valueEditor = new ListBox();
        valueEditor.addItem("true");
        valueEditor.addItem("false");
        // Wire-up update handler
        valueEditor.addClickHandler(new ClickHandler() {

            public void onClick(final ClickEvent event) {
                final String txtValue = valueEditor.getValue(valueEditor.getSelectedIndex());
                final Boolean value = Boolean.valueOf(txtValue);
                hasValue.getValue().setValue(value);
            }
        });
        // Set Widget's value
        valueEditor.setSelectedIndex(hasValue.getValue().getValue().equals(Boolean.TRUE) ? 0 : 1);
        return valueEditor;
    } else {
        // If we have enumeration data show a ListBox
        if (dd != null) {
            final ListBox valueEditor = makeListBox(dd, hasValue, oracle, isMultipleSelect);
            return valueEditor;
        }
        // Otherwise show a TextBox
        final TextBox valueEditor = TextBoxFactory.getTextBox(dataType);
        // Wire-up Handlers before setting value, as invalid values cause the ValueChangeHandler to be invoked
        valueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(final ValueChangeEvent<String> event) {
                hasValue.getValue().setValue(event.getValue());
            }
        });
        // Set Widget's value
        valueEditor.setText(ValueUtilities.convertNodeValue(hasValue.getValue()));
        return valueEditor;
    }
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox) Date(java.util.Date) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) HasValue(org.drools.workbench.models.guided.dtree.shared.model.nodes.HasValue) Value(org.drools.workbench.models.guided.dtree.shared.model.values.Value) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 8 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent 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 9 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class RuleAttributeWidget method getEditorWidget.

private Widget getEditorWidget(final RuleAttribute at, final int idx, final boolean isReadOnly) {
    Widget editor = null;
    final String attributeName = at.getAttributeName();
    if (attributeName.equals(RULEFLOW_GROUP_ATTR) || attributeName.equals(AGENDA_GROUP_ATTR) || attributeName.equals(ACTIVATION_GROUP_ATTR) || attributeName.equals(TIMER_ATTR) || attributeName.equals(CALENDARS_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(SALIENCE_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_INTEGER);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(DURATION_ATTR)) {
        final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_NUMERIC_LONG);
        tb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            tb.addValueChangeHandler(new ValueChangeHandler<String>() {

                public void onValueChange(ValueChangeEvent<String> event) {
                    at.setValue(tb.getValue());
                }
            });
        }
        tb.setValue(at.getValue());
        editor = tb;
    } else if (attributeName.equals(NO_LOOP_ATTR) || attributeName.equals(LOCK_ON_ACTIVE_ATTR) || attributeName.equals(AUTO_FOCUS_ATTR) || attributeName.equals(ENABLED_ATTR)) {
        editor = checkBoxEditor(at, isReadOnly);
    } else if (attributeName.equals(DATE_EFFECTIVE_ATTR) || attributeName.equals(DATE_EXPIRES_ATTR)) {
        if (isReadOnly) {
            final TextBox tb = TextBoxFactory.getTextBox(DataType.TYPE_STRING);
            tb.setValue(at.getValue());
            tb.setEnabled(false);
        } else {
            final DatePicker datePicker = new DatePicker(false);
            // Wire up update handler
            datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

                @Override
                public void onValueChange(final ValueChangeEvent<Date> event) {
                    final Date date = datePicker.getValue();
                    final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
                    at.setValue(sDate);
                }
            });
            datePicker.setFormat(DATE_FORMAT);
            datePicker.setValue(assertDateValue(at));
            editor = datePicker;
        }
    } else if (attributeName.equals(DIALECT_ATTR)) {
        final ListBox lb = new ListBox();
        lb.addItem(DIALECTS[0]);
        lb.addItem(DIALECTS[1]);
        lb.setEnabled(!isReadOnly);
        if (!isReadOnly) {
            lb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(ChangeEvent event) {
                    final int selectedIndex = lb.getSelectedIndex();
                    if (selectedIndex < 0) {
                        return;
                    }
                    at.setValue(lb.getValue(selectedIndex));
                }
            });
        }
        if (at.getValue() == null || at.getValue().isEmpty()) {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        } else if (at.getValue().equals(DIALECTS[0])) {
            lb.setSelectedIndex(0);
        } else if (at.getValue().equals(DIALECTS[1])) {
            lb.setSelectedIndex(1);
        } else {
            lb.setSelectedIndex(1);
            at.setValue(DIALECTS[1]);
        }
        editor = lb;
    }
    DirtyableHorizontalPane horiz = new DirtyableHorizontalPane();
    if (editor != null) {
        horiz.add(editor);
        if (!isReadOnly) {
            horiz.add(getRemoveIcon(idx));
        }
    }
    return horiz;
}
Also used : IsWidget(com.google.gwt.user.client.ui.IsWidget) Widget(com.google.gwt.user.client.ui.Widget) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) TextBox(org.gwtbootstrap3.client.ui.TextBox) Date(java.util.Date) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 10 with ValueChangeEvent

use of com.google.gwt.event.logical.shared.ValueChangeEvent in project drools-wb by kiegroup.

the class ExpressionBuilder method createWidgetForExpression.

// Render Widgets for the Expression. ExpressionMethodParameter and ExpressionText parts
// are represented by a TextBox to allow the User to edit the values, Updates are
// reflected in the model.
private Widget createWidgetForExpression() {
    final HorizontalPanel container = new HorizontalPanel();
    container.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    container.setStylePrimaryName(GuidedRuleEditorResources.INSTANCE.css().container());
    for (ExpressionPart expressionPart : expression.getParts()) {
        if (expressionPart instanceof ExpressionUnboundFact) {
            continue;
        } else if (this.readOnly) {
            container.add(new Label(expressionPart.getName()));
        } else if (expressionPart instanceof ExpressionMethod) {
            container.add(new Label(expressionPart.getName()));
            container.add(new Label("("));
            final ExpressionMethod em = (ExpressionMethod) expressionPart;
            final List<ExpressionFormLine> emParams = em.getOrderedParams();
            for (int index = 0; index < emParams.size(); index++) {
                final ExpressionFormLine paramValueHolder = emParams.get(index);
                final String paramDataType = em.getParameterDataType(paramValueHolder);
                final ExpressionMethodParameter paramValue = ((ExpressionMethodParameter) paramValueHolder.getRootExpression());
                final TextBox paramValueEditor = TextBoxFactory.getTextBox(paramDataType);
                paramValueEditor.addValueChangeHandler(new ValueChangeHandler<String>() {

                    @Override
                    public void onValueChange(ValueChangeEvent<String> event) {
                        paramValue.setText(event.getValue());
                    }
                });
                paramValueEditor.setText(paramValue.getName());
                container.add(paramValueEditor);
                if (index < emParams.size() - 1) {
                    container.add(new Label(", "));
                }
            }
            container.add(new Label(")"));
        } else if (!(expressionPart instanceof ExpressionText)) {
            container.add(new Label(expressionPart.getName()));
        } else {
            final TextBox tb = new TextBox();
            final ExpressionText expressionTextPart = (ExpressionText) expressionPart;
            tb.setText(expressionTextPart.getName());
            tb.addChangeHandler(new ChangeHandler() {

                @Override
                public void onChange(final ChangeEvent changeEvent) {
                    expressionTextPart.setText(tb.getText());
                }
            });
            container.add(tb);
        }
        container.add(new Label("."));
    }
    return container;
}
Also used : ExpressionMethodParameter(org.drools.workbench.models.datamodel.rule.ExpressionMethodParameter) ExpressionPart(org.drools.workbench.models.datamodel.rule.ExpressionPart) Label(com.google.gwt.user.client.ui.Label) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel) SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ExpressionText(org.drools.workbench.models.datamodel.rule.ExpressionText) TextBox(org.gwtbootstrap3.client.ui.TextBox) ExpressionUnboundFact(org.drools.workbench.models.datamodel.rule.ExpressionUnboundFact) ExpressionMethod(org.drools.workbench.models.datamodel.rule.ExpressionMethod) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ExpressionTypeChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeEvent) ExpressionChangeEvent(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeEvent) ExpressionChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionChangeHandler) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) ExpressionTypeChangeHandler(org.drools.workbench.screens.guided.rule.client.editor.ExpressionTypeChangeHandler) HorizontalPanel(com.google.gwt.user.client.ui.HorizontalPanel)

Aggregations

ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)20 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)18 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)10 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)10 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)6 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)6 TextBox (org.gwtbootstrap3.client.ui.TextBox)5 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)4 Widget (com.google.gwt.user.client.ui.Widget)3 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 DatePicker (org.uberfire.ext.widgets.common.client.common.DatePicker)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 HorizontalPanel (com.google.gwt.user.client.ui.HorizontalPanel)2 Image (com.google.gwt.user.client.ui.Image)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)2 Label (com.google.gwt.user.client.ui.Label)2