本文整理汇总了Java中com.vaadin.data.util.converter.Converter类的典型用法代码示例。如果您正苦于以下问题:Java Converter类的具体用法?Java Converter怎么用?Java Converter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Converter类属于com.vaadin.data.util.converter包,在下文中一共展示了Converter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Date convertToPresentation(LocalTime value, Class<? extends Date> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value != null) {
final Calendar calendar = Calendar.getInstance(locale);
calendar.set(Calendar.YEAR, 0);
calendar.set(Calendar.MONTH, 0);
calendar.set(Calendar.DAY_OF_MONTH, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, value.getHour());
calendar.set(Calendar.MINUTE, value.getMinute());
calendar.set(Calendar.SECOND, value.getSecond());
return calendar.getTime();
}
return null;
}
示例2: setValue
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public void setValue(Object newValue) throws ReadOnlyException, Converter.ConversionException {
Class propertyType = propertyPath.getMetaProperty().getJavaType();
if (Set.class.isAssignableFrom(propertyType)) {
if (newValue == null) {
newValue = new HashSet();
} else {
if (newValue instanceof Collection) {
newValue = new HashSet<>((Collection<?>) newValue);
} else {
newValue = Collections.singleton(newValue);
}
}
} else if (List.class.isAssignableFrom(propertyType)) {
if (newValue == null) {
newValue = new ArrayList();
} else {
if (newValue instanceof Collection) {
newValue = new ArrayList<>((Collection<?>) newValue);
} else {
newValue = Collections.singletonList(newValue);
}
}
}
super.setValue(newValue);
}
示例3: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(Datatype value,
Class<? extends Object> targetType, Locale locale)
throws Converter.ConversionException {
if (value == null) {
return null;
}
if (targetType.isInstance(String.class) ||
targetType.getName().equals(String.class.getName())) {
return value.getXacmlId();
}
if (targetType.isInstance(Identifier.class) ||
targetType.getName().equals(Identifier.class.getName())) {
return value.getIdentifer();
}
return value.getIdentifer();
}
示例4: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(ConstraintType value,
Class<? extends Object> targetType, Locale locale)
throws Converter.ConversionException {
if (logger.isTraceEnabled()) {
logger.trace("convertToPresentation:" + value + " target " + targetType);
}
if (value == null) {
return null;
}
if (targetType.isAssignableFrom(String.class)) {
return value.getConstraintType();
}
if (targetType.isInstance(Integer.class)) {
return value.getId();
}
return null;
}
示例5: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public String convertToPresentation(Enum availability,
java.lang.Class<? extends String> targetType, Locale locale)
throws Converter.ConversionException {
String text = super.convertToPresentation(availability, targetType,
locale);
String color = "";
if (availability == Availability.AVAILABLE) {
color = "#2dd085";
} else if (availability == Availability.COMING) {
color = "#ffc66e";
} else if (availability == Availability.DISCONTINUED) {
color = "#f54993";
}
String iconCode = "<span class=\"v-icon\" style=\"font-family: "
+ FontAwesome.CIRCLE.getFontFamily() + ";color:" + color
+ "\">&#x"
+ Integer.toHexString(FontAwesome.CIRCLE.getCodepoint())
+ ";</span>";
return iconCode + " " + text;
}
示例6: FieldDescriptor
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
/**
* Constructor for setting values of the FieldDefinition.
* @param id ID of the field.
* @param labelKey Localization key of the field.
* @param fieldClass Field editor component or null.
* @param converter Field converter.
* @param width Width of the field.
* @param valueAlignment Value vertical alignment.
* @param valueType Type of the field value.
* @param defaultValue Default value for field.
* @param readOnly true if field is readonly.
* @param sortable true if field is sortable.
* @param required true if field is required.
*/
public FieldDescriptor(final String id, final String labelKey, final Class<? extends Field> fieldClass,
final Converter<?,?> converter, final int width,
final HorizontalAlignment valueAlignment, final Class<?> valueType,
final Object defaultValue, final boolean readOnly, final boolean sortable, final boolean required) {
super();
this.id = id;
this.labelKey = labelKey;
this.width = width;
this.valueType = valueType;
this.defaultValue = defaultValue;
this.fieldClass = fieldClass;
this.converter = converter;
this.readOnly = readOnly;
this.sortable = sortable;
this.required = required;
if (valueAlignment != null) {
this.valueAlignment = valueAlignment;
}
}
示例7: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(Datatype value,
Class<? extends Object> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
}
if (targetType.isInstance(String.class) ||
targetType.getName().equals(String.class.getName())) {
return value.getXacmlId();
}
if (targetType.isInstance(Identifier.class) ||
targetType.getName().equals(Identifier.class.getName())) {
return value.getIdentifer();
}
return value.getIdentifer();
}
示例8: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(ConstraintType value,
Class<? extends Object> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (logger.isTraceEnabled()) {
logger.trace("convertToPresentation:" + value + " target " + targetType);
}
if (value == null) {
return null;
}
if (targetType.isAssignableFrom(String.class)) {
return value.getConstraintType();
}
if (targetType.isInstance(Integer.class)) {
return value.getId();
}
return null;
}
示例9: convertToModel
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public BigDecimal convertToModel(String value, final Class<? extends BigDecimal> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null || value.isEmpty()) {
return null;
}
// Remove leading and trailing white space
value = value.trim();
// Parse and detect errors. If the full string was not used, it is
// an error.
BigDecimal parsedValue = (BigDecimal) getFormat(locale).parse(value, new ParsePosition(0));
if (parsedValue == null) {
parsedValue = (BigDecimal) getLenientFormat(locale).parse(value, new ParsePosition(0));
}
if (parsedValue == null) {
throw new ConversionException(MessageFormat.format(
"Значение '{0}' не является допустимым числом", value));
}
return parsedValue;
}
示例10: convertToModel
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Age convertToModel(final Object value, final Class<? extends Age> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException
{
Age result = null;
AgeConverter.logger.debug("converToModel: value={} valueType: {} targetType: {}", value,
value != null ? value.getClass() : "null", targetType);
if (value instanceof Object || value instanceof String)
{
result = new Age((String) value);
}
AgeConverter.logger.debug("result: {}", result);
return result;
}
示例11: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(final Age value, final Class<? extends Object> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException
{
String result = "0";
AgeConverter.logger.debug("convertToPresentation: value {} targetType: {}", value, targetType);
if (value != null)
{
result = value.toString();
}
else
{
result = "";
}
AgeConverter.logger.debug("result: {}", result);
return result;
}
示例12: convertToModel
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Period convertToModel(final Object value, final Class<? extends Period> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException
{
Period result = null;
PeriodConverter.logger.debug("converToModel: value: {} valueType: {} targetType: {}", value,
value != null ? value.getClass() : "null", targetType);
if (value instanceof Object || value instanceof String)
{
result = new Period((String) value);
}
PeriodConverter.logger.debug("result: {}", result);
return result;
}
示例13: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(final Period value, final Class<? extends Object> targetType,
final Locale locale) throws com.vaadin.data.util.converter.Converter.ConversionException
{
String result = "0";
PeriodConverter.logger.debug("convertToPresentation: value: {} targetType: {}",
value == null ? "null" : value, targetType);
if (value != null)
{
result = value.toString();
}
else
{
result = "";
}
PeriodConverter.logger.debug("result: {}", result);
return result;
}
示例14: convertToModel
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Phone convertToModel(final Object value, final Class<? extends Phone> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException
{
Phone result = null;
final PhoneDao daoPhone = new DaoFactory().getPhoneDao();
PhoneConverter.logger.debug("converToModel: value: {} valueType: {} targetType: {}", value,
value != null ? value.getClass() : "null", targetType);
if (value instanceof Long)
{
PhoneConverter.logger.debug("Calling findById");
result = daoPhone.findById((Long) value);
}
else if (value instanceof Object || value instanceof String)
{
result = new Phone((String) value);
}
PhoneConverter.logger.debug("result: {}", result);
return result;
}
示例15: convertToPresentation
import com.vaadin.data.util.converter.Converter; //导入依赖的package包/类
@Override
public Object convertToPresentation(final Phone value, final Class<? extends Object> targetType, final Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException
{
String result = "0";
PhoneConverter.logger.debug("convertToPresentation: value: {} targetType: {}", value, targetType);
if (value != null)
{
result = value.getPhoneNo();
}
else
{
result = "";
}
PhoneConverter.logger.debug("result: {}", result);
return result;
}