Search in sources :

Example 1 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker in project drools-wb by kiegroup.

the class DTCellValueWidgetFactory method makeDateSelector.

private Widget makeDateSelector(final DTCellValue52 value) {
    // If read-only return a label
    if (isReadOnly) {
        Label dateLabel = new Label();
        dateLabel.setText(format.format(value.getDateValue()));
        return dateLabel;
    }
    final DatePicker datePicker = new DatePicker(allowEmptyValues);
    // Wire up update handler
    datePicker.addChangeDateHandler((e) -> value.setDateValue(datePicker.getValue()));
    datePicker.setFormat(DATE_FORMAT);
    datePicker.setValue(value.getDateValue());
    return datePicker;
}
Also used : Label(org.gwtbootstrap3.client.ui.Label) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker)

Example 2 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker 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 3 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker 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 4 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker in project drools-wb by kiegroup.

the class ActionValueEditor method literalEditor.

private Widget literalEditor() {
    if (this.readOnly) {
        return new SmallLabel(assertValue());
    }
    // Date picker
    if (DataType.TYPE_DATE.equals(value.getType())) {
        final DatePicker datePicker = new DatePicker(false);
        // Wire up update handler
        datePicker.addValueChangeHandler(new ValueChangeHandler<Date>() {

            @Override
            public void onValueChange(ValueChangeEvent<Date> event) {
                final Date date = datePicker.getValue();
                final String sDate = (date == null ? null : DATE_FORMATTER.format(datePicker.getValue()));
                value.setValue(sDate);
            }
        });
        datePicker.setFormat(DATE_FORMAT);
        datePicker.setValue(assertDateValue());
        return datePicker;
    }
    // Default editor for all other literals
    final TextBox box = TextBoxFactory.getTextBox(value.getType());
    box.setStyleName("constraint-value-Editor");
    box.addValueChangeHandler(new ValueChangeHandler<String>() {

        public void onValueChange(final ValueChangeEvent<String> event) {
            value.setValue(event.getValue());
            executeOnChangeCommand();
        }
    });
    box.setText(assertValue());
    attachDisplayLengthHandler(box);
    return box;
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) TextBox(org.gwtbootstrap3.client.ui.TextBox) Date(java.util.Date)

Example 5 with DatePicker

use of org.uberfire.ext.widgets.common.client.common.DatePicker in project drools-wb by kiegroup.

the class ConstraintValueEditor method literalEditor.

private Widget literalEditor() {
    // Custom screen
    if (this.constraint instanceof SingleFieldConstraint) {
        final SingleFieldConstraint con = (SingleFieldConstraint) this.constraint;
        CustomFormConfiguration customFormConfiguration = getWorkingSetManager().getCustomFormConfiguration(modeller.getPath(), factType, fieldName);
        if (customFormConfiguration != null) {
            Button btnCustom = new Button(con.getValue(), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    showTypeChoice(constraint);
                }
            });
            btnCustom.setEnabled(!this.readOnly);
            return btnCustom;
        }
    }
    // Label if read-only
    if (this.readOnly) {
        return new SmallLabel(getSanitizedValue());
    }
    // Enumeration (these support multi-select for "in" and "not in", so check before comma separated lists)
    if (this.dropDownData != null) {
        final String operator = constraint.getOperator();
        final boolean multipleSelect = OperatorsOracle.operatorRequiresList(operator);
        EnumDropDown enumDropDown = new EnumDropDown(constraint.getValue(), new DropDownValueChanged() {

            public void valueChanged(String newText, String newValue) {
                // Prevent recursion once value change has been applied
                if (!newValue.equals(constraint.getValue())) {
                    constraint.setValue(newValue);
                    executeOnValueChangeCommand();
                }
            }
        }, dropDownData, multipleSelect, modeller.getPath());
        return enumDropDown;
    }
    // Comma separated value list (this will become a dedicated Widget but for now a TextBox suffices)
    String operator = null;
    if (this.constraint instanceof SingleFieldConstraint) {
        SingleFieldConstraint sfc = (SingleFieldConstraint) this.constraint;
        operator = sfc.getOperator();
    }
    if (OperatorsOracle.operatorRequiresList(operator)) {
        return getNewTextBox(DataType.TYPE_STRING);
    }
    // Date picker
    boolean isCEPOperator = CEPOracle.isCEPOperator((this.constraint).getOperator());
    if (DataType.TYPE_DATE.equals(this.fieldType) || (DataType.TYPE_THIS.equals(this.fieldName) && isCEPOperator)) {
        if (this.readOnly) {
            return new SmallLabel(constraint.getValue());
        }
        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()));
                boolean update = constraint.getValue() == null || !constraint.getValue().equals(sDate);
                constraint.setValue(sDate);
                if (update) {
                    executeOnValueChangeCommand();
                }
            }
        });
        datePicker.setFormat(DATE_FORMAT);
        datePicker.setValue(getSanitizedDateValue());
        return datePicker;
    }
    // Default editor for all other literals
    return getNewTextBox(fieldType);
}
Also used : SmallLabel(org.uberfire.ext.widgets.common.client.common.SmallLabel) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) CustomFormConfiguration(org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration) Date(java.util.Date) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Button(org.gwtbootstrap3.client.ui.Button) EnumDropDown(org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown) DatePicker(org.uberfire.ext.widgets.common.client.common.DatePicker) DropDownValueChanged(org.uberfire.ext.widgets.common.client.common.DropDownValueChanged)

Aggregations

DatePicker (org.uberfire.ext.widgets.common.client.common.DatePicker)6 Date (java.util.Date)5 TextBox (org.gwtbootstrap3.client.ui.TextBox)4 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)3 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)3 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)3 ListBox (org.gwtbootstrap3.client.ui.ListBox)3 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)2 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)2 Widget (com.google.gwt.user.client.ui.Widget)2 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)1 HasValue (org.drools.workbench.models.guided.dtree.shared.model.nodes.HasValue)1 Value (org.drools.workbench.models.guided.dtree.shared.model.values.Value)1 RuleAttributeWidget (org.drools.workbench.screens.guided.rule.client.editor.RuleAttributeWidget)1 EnumDropDown (org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown)1