com.vaadin.data.Result Java Examples

The following examples show how to use com.vaadin.data.Result. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CssColorToColorPickerConverter.java    From gantt with Apache License 2.0 6 votes vote down vote up
@Override
public Result<Color> convertToModel(String value, ValueContext context) {
    if (value == null || value.trim().isEmpty()) {
        return Result.ok(Color.WHITE);
    }
    value = value.trim();
    if (!value.startsWith("#") && !value.startsWith("0x")) {
        value = "#" + value;
    }
    try {
        java.awt.Color c = java.awt.Color.decode(value);
        return Result.ok(new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()));
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return Result.ok(Color.WHITE);
}
 
Example #2
Source File: UserProjectListSelect.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Result<Collection<Integer>> convertToModel(Collection<SimpleProject> value, ValueContext context) {
    if (value == null) {
        return Result.ok(null);
    } else {
        return Result.ok(value.stream().map(project -> project.getId()).collect(Collectors.toSet()));
    }
}
 
Example #3
Source File: BuildCriterionComponent.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private Object getConvertedValue(HasValue<?> component) {
    if (component instanceof Converter) {
        Converter converter = (Converter) component;
        Result result = converter.convertToModel(component.getValue(), null);
        try {
            return result.getOrThrow(SerializableFunction.identity());
        } catch (Throwable throwable) {
            throw new MyCollabException(throwable);
        }
    }
    return component.getValue();
}
 
Example #4
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to model verify dummy impl test.
 */
@Test
public void convertToModelVerifyDummyImplTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final Result<List<?>> convertToModel = new ListPropertyConverter("", null).convertToModel("value", context);
	assertNotNull(convertToModel);
	assertFalse(convertToModel.isError());		
}
 
Example #5
Source File: CubaDateField.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected Result<LocalDate> handleUnparsableDateString(String dateString) {
    if (Objects.equals(dateString, StringUtils.replaceChars(getState(false).dateMask, "#U", "__"))) {
        return Result.ok(null);
    }

    return Result.error(getParseErrorMessage());
}
 
Example #6
Source File: ListPropertyConverter.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public Result<List<?>> convertToModel(final String value, final ValueContext context) {
	return Result.ok(new ArrayList<>());
}
 
Example #7
Source File: SimpleStringConverter.java    From vaadin-grid-util with MIT License 4 votes vote down vote up
@Override
public Result<MODEL> convertToModel(String value, ValueContext context) {
    return null;
}
 
Example #8
Source File: MilestoneComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<Integer> convertToModel(SimpleMilestone value, ValueContext context) {
    return (value != null)? Result.ok(value.getId()) : Result.ok(null);
}
 
Example #9
Source File: ProjectRoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<Integer> convertToModel(SimpleProjectRole role, ValueContext valueContext) {
    return (role != null)? Result.ok(role.getId()) : Result.ok(null);
}
 
Example #10
Source File: ProjectMemberSelectionBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<String> convertToModel(SimpleProjectMember projectMember, ValueContext valueContext) {
    return Result.ok(projectMember.getUsername());
}
 
Example #11
Source File: CubaDateField.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
protected void updateInternal(String newDateString, Map<String, Integer> resolutions) {
    // CAUTION: copied from AbstractDateField
    Set<String> resolutionNames = getResolutions().map(Enum::name)
            .collect(Collectors.toSet());
    resolutionNames.retainAll(resolutions.keySet());
    if (!isReadOnly()
            && (!resolutionNames.isEmpty() || newDateString != null)) {

        // Old and new dates
        final LocalDate oldDate = getValue();

        LocalDate newDate;

        String mask = StringUtils.replaceChars(getState(false).dateMask, "#U", "__");
        if ("".equals(newDateString)
                || mask.equals(newDateString)) {

            newDate = null;
        } else {
            newDate = reconstructDateFromFields(resolutions, oldDate);
        }

        boolean parseErrorWasSet = currentErrorMessage != null;
        boolean hasChanges = !Objects.equals(dateString, newDateString)
                || !Objects.equals(oldDate, newDate)
                || parseErrorWasSet;

        if (hasChanges) {
            dateString = newDateString;
            currentErrorMessage = null;
            if (newDateString == null || newDateString.isEmpty()) {
                boolean valueChanged = setValue(newDate, true);
                if (!valueChanged && parseErrorWasSet) {
                    doSetValue(newDate);
                }
            } else {
                // invalid date string
                if (resolutions.isEmpty()) {
                    Result<LocalDate> parsedDate = handleUnparsableDateString(
                            dateString);
                    parsedDate.ifOk(v -> setValue(v, true));
                    if (parsedDate.isError()) {
                        dateString = null;
                        currentErrorMessage = parsedDate
                                .getMessage().orElse("Parsing error");

                        if (!isDifferentValue(null)) {
                            doSetValue(null);
                        } else {
                            setValue(null, true);
                        }
                    }
                } else {
                    setValue(newDate, true);
                }
            }
        }
    }
}
 
Example #12
Source File: RoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<Integer> convertToModel(SimpleRole simpleRole, ValueContext valueContext) {
    return Result.ok(simpleRole.getId());
}
 
Example #13
Source File: ActiveUserComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<String> convertToModel(SimpleUser value, ValueContext context) {
    return (value != null) ? Result.ok(value.getUsername()) : Result.ok(null);
}
 
Example #14
Source File: StringToEnumConverter.java    From cia with Apache License 2.0 4 votes vote down vote up
@Override
public Result<Enum> convertToModel(final String value, final ValueContext context) {
	return Result.ok(null);
}
 
Example #15
Source File: I18nValueComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<String> convertToModel(T value, ValueContext context) {
    return (value != null) ? Result.ok(value.name()) : Result.ok(null);
}
 
Example #16
Source File: KeyCaptionComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<Integer> convertToModel(Entry entry, ValueContext valueContext) {
    return Result.ok(entry.key);
}
 
Example #17
Source File: AbstractOptionValComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<String> convertToModel(OptionVal value, ValueContext context) {
    return (value != null) ? Result.ok(value.getTypeval()) : Result.ok(null);
}
 
Example #18
Source File: CurrencyComboBoxField.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Result<String> convertToModel(Currency value, ValueContext context) {
    return (value != null) ? Result.ok(value.getCurrencyCode()) : Result.ok(null);
}