Search in sources :

Example 1 with DropDownValueChanged

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

the class MethodParameterCallValueEditor method refresh.

private void refresh() {
    root.clear();
    if (enums != null && (enums.getFixedList() != null || enums.getQueryExpression() != null)) {
        root.add(new EnumDropDown(methodParameter.value, new DropDownValueChanged() {

            public void valueChanged(String newText, String newValue) {
                methodParameter.value = newValue;
            }
        }, enums, oracle.getResourcePath()));
    } else {
        if (methodParameter.nature == FieldNatureType.TYPE_UNDEFINED) {
            // we have a blank slate..
            // have to give them a choice
            root.add(choice());
        } else {
            if (methodParameter.nature == FieldNatureType.TYPE_VARIABLE) {
                ListBox list = boundVariable(methodParameter);
                root.add(list);
            } else {
                TextBox box = boundTextBox(this.methodParameter);
                root.add(box);
            }
        }
    }
}
Also used : EnumDropDown(org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown) TextBox(org.gwtbootstrap3.client.ui.TextBox) DropDownValueChanged(org.uberfire.ext.widgets.common.client.common.DropDownValueChanged) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 2 with DropDownValueChanged

use of org.uberfire.ext.widgets.common.client.common.DropDownValueChanged 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)

Example 3 with DropDownValueChanged

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

the class VerifyFieldConstraintEditor method refreshEditor.

private void refreshEditor() {
    String flType = oracle.getFieldType(factType, field.getFieldName());
    panel.clear();
    if (Objects.equals(flType, DataType.TYPE_BOOLEAN)) {
        String[] c = new String[] { "true", "false" };
        panel.add(new EnumDropDown(field.getExpected(), new DropDownValueChanged() {

            public void valueChanged(String newText, String newValue) {
                callback.callback(newValue);
            }
        }, DropDownData.create(c), oracle.getResourcePath()));
    } else if (Objects.equals(flType, DataType.TYPE_DATE)) {
        FieldDatePicker fieldDatePicker = new FieldDatePicker(new FieldDatePickerViewImpl());
        fieldDatePicker.setValue(field.getExpected());
        fieldDatePicker.addValueChangeHandler(new ValueChangeHandler<String>() {

            @Override
            public void onValueChange(ValueChangeEvent<String> event) {
                field.setExpected(event.getValue());
            }
        });
        panel.add(fieldDatePicker);
    } else {
        Map<String, String> currentValueMap = new HashMap<String, String>();
        // TODO fill currentValueMap with values of other VerifyFields (if any)
        DropDownData dropDownData = oracle.getEnums(factType, field.getFieldName(), currentValueMap);
        if (Objects.nonNull(dropDownData)) {
            // Java enum or a literal with a selection list (i.e. Guvnor enum)
            if (Objects.equals(flType, DataType.TYPE_COMPARABLE)) {
                field.setNature(FieldData.TYPE_ENUM);
            } else {
                field.setNature(FieldData.TYPE_LITERAL);
            }
            panel.add(new EnumDropDown(field.getExpected(), new DropDownValueChanged() {

                public void valueChanged(String newText, String newValue) {
                    callback.callback(newValue);
                }
            }, dropDownData, oracle.getResourcePath()));
        } else {
            if (field.getNature() == FieldData.TYPE_UNDEFINED) {
                if (Objects.nonNull(field.getExpected()) && field.getExpected().indexOf('=') == 0) {
                    field.setNature(FieldData.TYPE_VARIABLE);
                } else if (isThereABoundVariableToSet()) {
                    Image clickme = CommonAltedImages.INSTANCE.Edit();
                    clickme.addClickHandler(new ClickHandler() {

                        public void onClick(ClickEvent event) {
                            showTypeChoice(field);
                        }
                    });
                    panel.add(clickme);
                } else {
                    field.setNature(FieldData.TYPE_LITERAL);
                }
            }
            if (field.getNature() == FieldData.TYPE_VARIABLE) {
                panel.add(variableEditor());
            } else if (field.getNature() == FieldData.TYPE_LITERAL) {
                panel.add(textBoxEditor(flType).asWidget());
            }
        }
    }
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) DropDownData(org.kie.soup.project.datamodel.oracle.DropDownData) Image(com.google.gwt.user.client.ui.Image) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) EnumDropDown(org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown) DropDownValueChanged(org.uberfire.ext.widgets.common.client.common.DropDownValueChanged) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

EnumDropDown (org.drools.workbench.screens.guided.rule.client.widget.EnumDropDown)3 DropDownValueChanged (org.uberfire.ext.widgets.common.client.common.DropDownValueChanged)3 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 Image (com.google.gwt.user.client.ui.Image)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)1 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)1 CustomFormConfiguration (org.guvnor.common.services.workingset.client.factconstraints.customform.CustomFormConfiguration)1 Button (org.gwtbootstrap3.client.ui.Button)1 ListBox (org.gwtbootstrap3.client.ui.ListBox)1 TextBox (org.gwtbootstrap3.client.ui.TextBox)1 DropDownData (org.kie.soup.project.datamodel.oracle.DropDownData)1 DatePicker (org.uberfire.ext.widgets.common.client.common.DatePicker)1 SmallLabel (org.uberfire.ext.widgets.common.client.common.SmallLabel)1