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);
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations