Created
November 8, 2012 22:22
-
-
Save bartprokop/4042145 to your computer and use it in GitHub Desktop.
BigTable Email - Vaadin converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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