Skip to content

Instantly share code, notes, and snippets.

@bartprokop
Created November 8, 2012 22:22
Show Gist options
  • Save bartprokop/4042145 to your computer and use it in GitHub Desktop.
Save bartprokop/4042145 to your computer and use it in GitHub Desktop.
BigTable Email - Vaadin converter
package com.appspot.natanedwin.app;
import com.google.appengine.api.datastore.Email;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.DefaultConverterFactory;
import java.util.Locale;
/**
* @author Bartłomiej Prokop
*/
public class BigTableConverterFactory extends DefaultConverterFactory {
@Override
protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter(Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
if (presentationType == String.class && modelType == Email.class) {
return (Converter<PRESENTATION, MODEL>) new StringToEmail();
}
return super.findConverter(presentationType, modelType);
}
public static class StringToEmail implements Converter<String, Email> {
@Override
public Email convertToModel(String value, Locale locale) throws ConversionException {
return value == null ? null : new Email(value);
}
@Override
public String convertToPresentation(Email value, Locale locale) throws ConversionException {
return value == null ? null : value.getEmail();
}
@Override
public Class<Email> getModelType() {
return Email.class;
}
@Override
public Class<String> getPresentationType() {
return String.class;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment