Search in sources :

Example 1 with TextBoxBase

use of org.gwtbootstrap3.client.ui.base.TextBoxBase in project kura by eclipse.

the class AbstractServicesUi method createTextBox.

private TextBoxBase createTextBox(final GwtConfigParameter param) {
    if (param.getDescription() != null && param.getDescription().contains("\u200B\u200B\u200B\u200B\u200B")) {
        final TextArea result = createTextArea();
        result.setHeight("120px");
        return result;
    }
    if (isTextArea(param)) {
        return createTextArea();
    }
    return new TextBox();
}
Also used : TextArea(org.gwtbootstrap3.client.ui.TextArea) TextBox(org.gwtbootstrap3.client.ui.TextBox)

Example 2 with TextBoxBase

use of org.gwtbootstrap3.client.ui.base.TextBoxBase in project kura by eclipse.

the class AbstractServicesUi method renderTextField.

// Field Render based on Type
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderTextField(final GwtConfigParameter param, boolean isFirstInstance, final FormGroup formGroup) {
    this.valid.put(param.getId(), true);
    if (isFirstInstance) {
        FormLabel formLabel = new FormLabel();
        formLabel.setText(param.getName());
        if (param.isRequired()) {
            formLabel.setShowRequiredIndicator(true);
        }
        formLabel.setTitle(param.getId());
        formGroup.add(formLabel);
        InlineHelpBlock ihb = new InlineHelpBlock();
        ihb.setIconType(IconType.EXCLAMATION_TRIANGLE);
        formGroup.add(ihb);
        HelpBlock tooltip = new HelpBlock();
        tooltip.setText(getDescription(param));
        formGroup.add(tooltip);
    }
    final TextBoxBase textBox = createTextBox(param);
    String formattedValue = new String();
    // double value as expected
    switch(param.getType()) {
        case LONG:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Long.parseLong(param.getValue()));
            }
            break;
        case DOUBLE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Double.parseDouble(param.getValue()));
            }
            break;
        case FLOAT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Float.parseFloat(param.getValue()));
            }
            break;
        case SHORT:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Short.parseShort(param.getValue()));
            }
            break;
        case BYTE:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Byte.parseByte(param.getValue()));
            }
            break;
        case INTEGER:
            if (param.getValue() != null && !"".equals(param.getValue().trim())) {
                formattedValue = String.valueOf(Integer.parseInt(param.getValue()));
            }
            break;
        default:
            formattedValue = param.getValue();
            break;
    }
    if (param.getValue() != null) {
        textBox.setText(formattedValue);
    } else {
        textBox.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        textBox.setReadOnly(true);
        textBox.setEnabled(false);
    }
    formGroup.add(textBox);
    textBox.setValidateOnBlur(true);
    textBox.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            return validateTextBox(param, textBox, formGroup);
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
// textBox.validate();
}
Also used : InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) ArrayList(java.util.ArrayList) List(java.util.List) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) Editor(com.google.gwt.editor.client.Editor) Validator(org.gwtbootstrap3.client.ui.form.validator.Validator) TextBoxBase(org.gwtbootstrap3.client.ui.base.TextBoxBase)

Example 3 with TextBoxBase

use of org.gwtbootstrap3.client.ui.base.TextBoxBase in project kura by eclipse.

the class AbstractServicesUi method fillUpdatedConfiguration.

protected void fillUpdatedConfiguration(FormGroup fg) {
    GwtConfigParameter param = new GwtConfigParameter();
    List<String> multiFieldValues = new ArrayList<String>();
    int fgwCount = fg.getWidgetCount();
    for (int i = 0; i < fgwCount; i++) {
        logger.fine("Widget: " + fg.getClass());
        if (fg.getWidget(i) instanceof FormLabel) {
            param = this.m_configurableComponent.getParameter(fg.getWidget(i).getTitle());
            logger.fine("Param: " + fg.getTitle() + " -> " + param);
        } else if (fg.getWidget(i) instanceof ListBox || fg.getWidget(i) instanceof Input || fg.getWidget(i) instanceof TextBoxBase) {
            if (param == null) {
                errorLogger.warning("Missing parameter");
                continue;
            }
            String value = getUpdatedFieldConfiguration(param, fg.getWidget(i));
            if (value == null) {
                continue;
            }
            if (param.getCardinality() == 0 || param.getCardinality() == 1 || param.getCardinality() == -1) {
                param.setValue(value);
            } else {
                multiFieldValues.add(value);
            }
        }
    }
    if (!multiFieldValues.isEmpty() && param != null) {
        param.setValues(multiFieldValues.toArray(new String[] {}));
    }
}
Also used : Input(org.gwtbootstrap3.client.ui.Input) GwtConfigParameter(org.eclipse.kura.web.shared.model.GwtConfigParameter) ArrayList(java.util.ArrayList) FormLabel(org.gwtbootstrap3.client.ui.FormLabel) ListBox(org.gwtbootstrap3.client.ui.ListBox) TextBoxBase(org.gwtbootstrap3.client.ui.base.TextBoxBase)

Example 4 with TextBoxBase

use of org.gwtbootstrap3.client.ui.base.TextBoxBase in project kura by eclipse.

the class AbstractServicesUi method getUpdatedFieldConfiguration.

private String getUpdatedFieldConfiguration(GwtConfigParameter param, Widget wg) {
    Map<String, String> options = param.getOptions();
    if (options != null && options.size() > 0) {
        Map<String, String> oMap = param.getOptions();
        if (wg instanceof ListBox) {
            return oMap.get(((ListBox) wg).getSelectedItemText());
        } else {
            return null;
        }
    } else {
        switch(param.getType()) {
            case BOOLEAN:
                return param.getValue();
            case LONG:
            case DOUBLE:
            case FLOAT:
            case SHORT:
            case BYTE:
            case INTEGER:
            case CHAR:
            case STRING:
                TextBoxBase tb = (TextBoxBase) wg;
                String value = tb.getText();
                if (value != null) {
                    return value;
                } else {
                    return null;
                }
            case PASSWORD:
                if (wg instanceof Input) {
                    return ((Input) wg).getValue();
                } else {
                    return null;
                }
            default:
                break;
        }
    }
    return null;
}
Also used : Input(org.gwtbootstrap3.client.ui.Input) ListBox(org.gwtbootstrap3.client.ui.ListBox) TextBoxBase(org.gwtbootstrap3.client.ui.base.TextBoxBase)

Example 5 with TextBoxBase

use of org.gwtbootstrap3.client.ui.base.TextBoxBase in project kura by eclipse.

the class AbstractServicesUi method validateTextBox.

// Validates all the entered values
// TODO: validation should be done like in the old web ui: cleaner approach
private List<EditorError> validateTextBox(GwtConfigParameter param, TextBoxBase box, FormGroup group) {
    group.setValidationState(ValidationState.NONE);
    this.valid.put(param.getName(), true);
    List<EditorError> result = new ArrayList<EditorError>();
    if (param.isRequired() && (box.getText().trim() == null || "".equals(box.getText().trim()))) {
        this.valid.put(param.getId(), false);
        result.add(new BasicEditorError(box, box.getText(), MSGS.formRequiredParameter()));
    }
    if (box.getText().trim() != null && !"".equals(box.getText().trim())) {
        if (param.getType().equals(GwtConfigParameterType.CHAR)) {
            if (box.getText().trim().length() > 1) {
                this.valid.put(param.getId(), false);
                result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(Integer.toString(box.getText().trim().length()), box.getText())));
            }
            if (param.getMin() != null && param.getMin().charAt(0) > box.getText().trim().charAt(0)) {
                this.valid.put(param.getId(), false);
                result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin().charAt(0))));
            }
            if (param.getMax() != null && param.getMax().charAt(0) < box.getText().trim().charAt(0)) {
                this.valid.put(param.getId(), false);
                result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax().charAt(0))));
            }
        } else if (param.getType().equals(GwtConfigParameterType.STRING)) {
            int configMinValue = 0;
            int configMaxValue = Integer.MAX_VALUE;
            try {
                configMinValue = Integer.parseInt(param.getMin());
            } catch (NumberFormatException nfe) {
                errorLogger.log(Level.FINE, "Configuration min value error! Applying UI defaults...");
            }
            try {
                configMaxValue = Integer.parseInt(param.getMax());
            } catch (NumberFormatException nfe) {
                errorLogger.log(Level.FINE, "Configuration max value error! Applying UI defaults...");
            }
            if (String.valueOf(box.getText().trim()).length() < configMinValue) {
                this.valid.put(param.getName(), false);
                result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, configMinValue)));
            }
            if (String.valueOf(box.getText().trim()).length() > configMaxValue) {
                this.valid.put(param.getName(), false);
                result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, configMaxValue)));
            }
        } else {
            try {
                // numeric value
                if (param.getType().equals(GwtConfigParameterType.FLOAT)) {
                    Float uiValue = Float.parseFloat(box.getText().trim());
                    if (param.getMin() != null && Float.parseFloat(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Float.parseFloat(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                } else if (param.getType().equals(GwtConfigParameterType.INTEGER)) {
                    Integer uiValue = Integer.parseInt(box.getText().trim());
                    if (param.getMin() != null && Integer.parseInt(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Integer.parseInt(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                } else if (param.getType().equals(GwtConfigParameterType.SHORT)) {
                    Short uiValue = Short.parseShort(box.getText().trim());
                    if (param.getMin() != null && Short.parseShort(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Short.parseShort(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                } else if (param.getType().equals(GwtConfigParameterType.BYTE)) {
                    Byte uiValue = Byte.parseByte(box.getText().trim());
                    if (param.getMin() != null && Byte.parseByte(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Byte.parseByte(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                } else if (param.getType().equals(GwtConfigParameterType.LONG)) {
                    Long uiValue = Long.parseLong(box.getText().trim());
                    if (param.getMin() != null && Long.parseLong(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Long.parseLong(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                } else if (param.getType().equals(GwtConfigParameterType.DOUBLE)) {
                    Double uiValue = Double.parseDouble(box.getText().trim());
                    if (param.getMin() != null && Double.parseDouble(param.getMin()) > uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MIN_VALUE, param.getMin())));
                    }
                    if (param.getMax() != null && Double.parseDouble(param.getMax()) < uiValue) {
                        this.valid.put(param.getId(), false);
                        result.add(new BasicEditorError(box, box.getText(), MessageUtils.get(CONFIG_MAX_VALUE, param.getMax())));
                    }
                }
            } catch (NumberFormatException e) {
                this.valid.put(param.getId(), false);
                result.add(new BasicEditorError(box, box.getText(), e.getLocalizedMessage()));
            }
        }
    }
    return result;
}
Also used : BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) EditorError(com.google.gwt.editor.client.EditorError) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)3 TextBoxBase (org.gwtbootstrap3.client.ui.base.TextBoxBase)3 FormLabel (org.gwtbootstrap3.client.ui.FormLabel)2 Input (org.gwtbootstrap3.client.ui.Input)2 ListBox (org.gwtbootstrap3.client.ui.ListBox)2 Editor (com.google.gwt.editor.client.Editor)1 EditorError (com.google.gwt.editor.client.EditorError)1 List (java.util.List)1 GwtConfigParameter (org.eclipse.kura.web.shared.model.GwtConfigParameter)1 HelpBlock (org.gwtbootstrap3.client.ui.HelpBlock)1 InlineHelpBlock (org.gwtbootstrap3.client.ui.InlineHelpBlock)1 TextArea (org.gwtbootstrap3.client.ui.TextArea)1 TextBox (org.gwtbootstrap3.client.ui.TextBox)1 BasicEditorError (org.gwtbootstrap3.client.ui.form.error.BasicEditorError)1 Validator (org.gwtbootstrap3.client.ui.form.validator.Validator)1