Search in sources :

Example 1 with EditorError

use of com.google.gwt.editor.client.EditorError in project kura by eclipse.

the class AbstractServicesUi method renderPasswordField.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void renderPasswordField(final GwtConfigParameter param, boolean isFirstInstance, 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);
        if (param.getDescription() != null) {
            HelpBlock toolTip = new HelpBlock();
            toolTip.setText(getDescription(param));
            formGroup.add(toolTip);
        }
    }
    final Input input = new Input();
    input.setType(InputType.PASSWORD);
    if (param.getValue() != null) {
        input.setText(param.getValue());
    } else {
        input.setText("");
    }
    if (param.getMin() != null && param.getMin().equals(param.getMax())) {
        input.setReadOnly(true);
        input.setEnabled(false);
    }
    input.setValidateOnBlur(true);
    input.addValidator(new Validator() {

        @Override
        public List<EditorError> validate(Editor editor, Object value) {
            setDirty(true);
            List<EditorError> result = new ArrayList<EditorError>();
            if ((input.getText() == null || "".equals(input.getText().trim())) && param.isRequired()) {
                // null in required field
                result.add(new BasicEditorError(input, input.getText(), MSGS.formRequiredParameter()));
                AbstractServicesUi.this.valid.put(param.getName(), false);
            } else {
                param.setValue(input.getText());
                AbstractServicesUi.this.valid.put(param.getName(), true);
            }
            return result;
        }

        @Override
        public int getPriority() {
            return 0;
        }
    });
    formGroup.add(input);
}
Also used : BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) Input(org.gwtbootstrap3.client.ui.Input) InlineHelpBlock(org.gwtbootstrap3.client.ui.InlineHelpBlock) HelpBlock(org.gwtbootstrap3.client.ui.HelpBlock) BasicEditorError(org.gwtbootstrap3.client.ui.form.error.BasicEditorError) EditorError(com.google.gwt.editor.client.EditorError) 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)

Example 2 with EditorError

use of com.google.gwt.editor.client.EditorError in project gwt-material by GwtMaterialDesign.

the class ValidatorMixin method validate.

/**
 * {@inheritDoc}
 */
@Override
public boolean validate(boolean show) {
    Boolean oldValid = valid;
    valid = true;
    if (errorHandler != null && !validators.isEmpty()) {
        List<EditorError> errors = new ArrayList<>();
        for (ValidatorWrapper<V> wrapper : validators) {
            Validator<V> validator = wrapper.getValidator();
            List<EditorError> result = validator.validate(inputWidget, inputWidget.getValue());
            if (result != null && !result.isEmpty()) {
                errors.addAll(result);
                valid = false;
            }
        }
        if (show) {
            if (errors.size() > 0) {
                errorHandler.showErrors(errors);
            } else {
                errorHandler.clearErrors();
            }
        }
    }
    if (valid != oldValid) {
        eventBus.fireEvent(new ValidationChangedEvent(valid));
    }
    return valid;
}
Also used : ValidationChangedEvent(gwt.material.design.client.base.validator.ValidationChangedEvent) EditorError(com.google.gwt.editor.client.EditorError) ArrayList(java.util.ArrayList)

Example 3 with EditorError

use of com.google.gwt.editor.client.EditorError in project gerrit by GerritCodeReview.

the class ValueEditor method showErrors.

@Override
public void showErrors(List<EditorError> errors) {
    StringBuilder buf = new StringBuilder();
    for (EditorError error : errors) {
        if (error.getEditor().equals(editProxy)) {
            buf.append("\n");
            if (error.getUserData() instanceof ParseException) {
                buf.append(((ParseException) error.getUserData()).getMessage());
            } else {
                buf.append(error.getMessage());
            }
        }
    }
    if (0 < buf.length()) {
        errorLabel.setInnerText(buf.substring(1));
        errorLabel.getStyle().setDisplay(Display.BLOCK);
    } else {
        errorLabel.setInnerText("");
        errorLabel.getStyle().setDisplay(Display.NONE);
    }
}
Also used : EditorError(com.google.gwt.editor.client.EditorError) ParseException(java.text.ParseException)

Example 4 with EditorError

use of com.google.gwt.editor.client.EditorError in project gwt-material by GwtMaterialDesign.

the class AbstractValidator method createErrorList.

/**
 * Creates the error list.
 *
 * @param editor     the editor
 * @param value      the value
 * @param messageKey the message key
 * @return the list
 */
public List<EditorError> createErrorList(Editor<T> editor, T value, String messageKey) {
    List<EditorError> result = new ArrayList<>();
    result.add(new BasicEditorError(editor, value, getInvalidMessage(messageKey)));
    return result;
}
Also used : BasicEditorError(gwt.material.design.client.base.error.BasicEditorError) BasicEditorError(gwt.material.design.client.base.error.BasicEditorError) EditorError(com.google.gwt.editor.client.EditorError) ArrayList(java.util.ArrayList)

Example 5 with EditorError

use of com.google.gwt.editor.client.EditorError 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

EditorError (com.google.gwt.editor.client.EditorError)5 ArrayList (java.util.ArrayList)4 BasicEditorError (org.gwtbootstrap3.client.ui.form.error.BasicEditorError)2 Editor (com.google.gwt.editor.client.Editor)1 BasicEditorError (gwt.material.design.client.base.error.BasicEditorError)1 ValidationChangedEvent (gwt.material.design.client.base.validator.ValidationChangedEvent)1 ParseException (java.text.ParseException)1 List (java.util.List)1 FormLabel (org.gwtbootstrap3.client.ui.FormLabel)1 HelpBlock (org.gwtbootstrap3.client.ui.HelpBlock)1 InlineHelpBlock (org.gwtbootstrap3.client.ui.InlineHelpBlock)1 Input (org.gwtbootstrap3.client.ui.Input)1 Validator (org.gwtbootstrap3.client.ui.form.validator.Validator)1