com.vaadin.data.ValueContext Java Examples

The following examples show how to use com.vaadin.data.ValueContext. 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: CssColorToColorPickerConverter.java    From gantt with Apache License 2.0 5 votes vote down vote up
@Override
public String convertToPresentation(Color value, ValueContext context) {
    if (value != null) {
        return value.getCSS();
    }
    return null;
}
 
Example #3
Source File: ListPropertyConverter.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public String convertToPresentation(final List value, final ValueContext context) {
	final StringBuilder stringBuilder = new StringBuilder();

	if (value != null) {
		stringBuilder.append(START_TAG);
		for (final Object object : value) {
			appendObjectPresentation(stringBuilder, object);
		}
		stringBuilder.append(END_TAG);
	}


	return stringBuilder.toString();
}
 
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: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation fallback no value test.
 */
@Test
public void convertToPresentationFallbackNoValueTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("partyId", "partyId","partyName").convertToPresentation(Arrays.asList(new ViewRiksdagenParty()), context);
	assertEquals("[ ]",emptyString);
}
 
Example #6
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation fallback test.
 */
@Test
public void convertToPresentationFallbackTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("partyId", "partyId","partyName").convertToPresentation(Arrays.asList(new ViewRiksdagenParty().withPartyName("PartyName")), context);
	assertEquals("[PartyName ]",emptyString);
}
 
Example #7
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation no value test.
 */
@Test
public void convertToPresentationNoValueTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("partyId", "partyId").convertToPresentation(Arrays.asList(new ViewRiksdagenParty()), context);
	assertEquals("[ ]",emptyString);
}
 
Example #8
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation null value failure test.
 */
@Test
public void convertToPresentationNullValueFailureTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("", null).convertToPresentation(null, context);
	assertEquals("",emptyString);
}
 
Example #9
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation test.
 */
@Test
public void convertToPresentationTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("partyId", "partyId").convertToPresentation(Arrays.asList(new ViewRiksdagenParty().withPartyId("partyId")), context);
	assertEquals("[partyId ]",emptyString);
}
 
Example #10
Source File: ListPropertyConverterTest.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Convert to presentation wrong path method value failure test.
 */
@Test
public void convertToPresentationWrongPathMethodValueFailureTest() {
	final ValueContext context = new ValueContext(Locale.ENGLISH);
	final String emptyString = new ListPropertyConverter("party", "party").convertToPresentation(Arrays.asList(new ViewRiksdagenCommittee()), context);
	assertEquals("[ ]",emptyString);
}
 
Example #11
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 #12
Source File: I18nValueComboBox.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public T convertToPresentation(String value, ValueContext context) {
    if (value == null) {
        return getValue();
    }
    return Enum.valueOf(eClass, value);
}
 
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: ProjectMemberSelectionBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SimpleProjectMember convertToPresentation(String memberName, ValueContext valueContext) {
    return members.stream().filter(member -> member.getUsername().equals(memberName)).findFirst().get();
}
 
Example #15
Source File: ActiveUserComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SimpleUser convertToPresentation(String value, ValueContext context) {
    return users.stream().filter(user -> user.getUsername().equals(value)).findFirst().orElse(null);
}
 
Example #16
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 #17
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 #18
Source File: KeyCaptionComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Entry convertToPresentation(Integer key, ValueContext valueContext) {
    return Arrays.stream(entries).filter(entry -> entry.key == key).findFirst().get();
}
 
Example #19
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 #20
Source File: AbstractOptionValComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public OptionVal convertToPresentation(String value, ValueContext context) {
    return options.stream().filter(option -> option.getTypeval().equals(value)).findFirst().orElse(null);
}
 
Example #21
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);
}
 
Example #22
Source File: CurrencyComboBoxField.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Currency convertToPresentation(String value, ValueContext context) {
    return (value == null) ? null : Currency.getInstance(value);
}
 
Example #23
Source File: RoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SimpleRole convertToPresentation(Integer id, ValueContext valueContext) {
    Optional<SimpleRole> result = roles.stream().filter(role -> role.getId() == id).findFirst();
    return result.orElse(null);
}
 
Example #24
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 #25
Source File: UserProjectListSelect.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Collection<SimpleProject> convertToPresentation(Collection<Integer> value, ValueContext context) {
    return null;
}
 
Example #26
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 #27
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 #28
Source File: ProjectRoleComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SimpleProjectRole convertToPresentation(Integer roleId, ValueContext valueContext) {
    return roles.stream().filter(role -> role.getId() == roleId).findFirst().orElse(null);
}
 
Example #29
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 #30
Source File: MilestoneComboBox.java    From mycollab with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public SimpleMilestone convertToPresentation(Integer value, ValueContext context) {
    if (milestones == null) return null;
    return milestones.stream().filter(milestone -> milestone.getId() == value).findFirst().orElse(null);
}