com.vaadin.data.util.converter.Converter Java Examples

The following examples show how to use com.vaadin.data.util.converter.Converter. 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: DatatypeConverter.java    From XACML with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: ConstraintTypeConverter.java    From XACML with MIT License 6 votes vote down vote up
@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;
}
 
Example #3
Source File: CategoryConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Category convertToModel(Object value,
		Class<? extends Category> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	Category category = new Category();
	if (value == null) {
		return category;
	}
	if (value instanceof Identifier) {
		category.setXacmlId(((Identifier)value).stringValue());
	} else {
		category.setXacmlId(value.toString());
	}
	return category;
}
 
Example #4
Source File: CategoryConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Object convertToPresentation(Category value,
		Class<? extends Object> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	if (targetType.getName().equals(String.class.getName())) {
		return value.getXacmlId();
	}
	if (targetType.getName().equals(Identifier.class.getName())) {
		return value.getIdentifer();
	}
	return value.getIdentifer();
}
 
Example #5
Source File: DatatypeConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Datatype convertToModel(Object value,
		Class<? extends Datatype> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	Datatype datatype = new Datatype();
	if (value == null) {
		return datatype;
	}
	if (value instanceof Identifier) {
		datatype.setXacmlId(((Identifier)value).stringValue());
	} else {
		datatype.setXacmlId(value.toString());
	}
	return datatype;
}
 
Example #6
Source File: ConstraintTypeConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public ConstraintType convertToModel(Object value,
		Class<? extends ConstraintType> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	if (logger.isTraceEnabled()) {
		logger.trace("convertToModel:" + value + " target " + targetType);
	}
	ConstraintType constraintValue = new ConstraintType();
	if (value == null) {
		return constraintValue;
	}
	// PLD TODO??
	return constraintValue;
}
 
Example #7
Source File: IdentifierConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Object convertToPresentation(Identifier value,
		Class<? extends Object> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	if (targetType.isInstance(String.class) ||
		targetType.getName().equals(String.class.getName())) {
		return value.stringValue();
	}
	return null;
}
 
Example #8
Source File: ConstraintValueConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public ConstraintValue convertToModel(Object value,
		Class<? extends ConstraintValue> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	if (logger.isTraceEnabled()) {
		logger.trace("convertToModel:" + value + " target " + targetType);
	}
	ConstraintValue newValue = new ConstraintValue();
	if (value == null) {
		return newValue;
	}
	// PLD TODO?
	return newValue;
}
 
Example #9
Source File: ConstraintValueConverter.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Object convertToPresentation(ConstraintValue 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;
	}
	return value.getProperty();
}
 
Example #10
Source File: XacmlConverterFactory.java    From XACML with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
   public <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL>
           createConverter(Class<PRESENTATION> presentationType,
                           Class<MODEL> modelType) {
   	if (logger.isTraceEnabled()) {
   		logger.trace("createConverter: " + presentationType + " from model " + modelType);
   	}
   	//
       // Handle one particular type conversion for Categories
   	//
       if (Category.class == modelType) {
           return (Converter<PRESENTATION, MODEL>) new CategoryConverter();
       }
       //
       // Handle one particular type conversion for Datatypes
       //
       if (Datatype.class == modelType) {
           return (Converter<PRESENTATION, MODEL>) new DatatypeConverter();
       }
       //
       // Handle one particular type conversion for ConstraintType
       //
       if (ConstraintType.class == modelType) {
       	return (Converter<PRESENTATION, MODEL>) new ConstraintTypeConverter();
       }
       //
       // Handle one particular type conversion for ConstraintType
       //
       if (ConstraintValue.class == modelType) {
       	return (Converter<PRESENTATION, MODEL>) new ConstraintValueConverter();
       }
       //
       // Handle one particular type conversion for Identifiers
       //
       if (Identifier.class == modelType) {
       	return (Converter<PRESENTATION, MODEL>) new IdentifierConverter();
       }
       //
       // Default to the supertype
       //
       return super.createConverter(presentationType,
                                    modelType);
   }
 
Example #11
Source File: IdentifierConverter.java    From XACML with MIT License 4 votes vote down vote up
@Override
public Identifier convertToModel(Object value,
		Class<? extends Identifier> targetType, Locale locale)
		throws com.vaadin.data.util.converter.Converter.ConversionException {
	return new IdentifierImpl(value.toString());
}