All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xq.gwt.mvc.model.FloatPropertyModel Maven / Gradle / Ivy

Go to download

A framework for implementing the MVP variant of the Model View Controller design pattern in the context of GWT

The newest version!
package xq.gwt.mvc.model;

public class FloatPropertyModel extends AbstractPropertyModel {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3206213233369562042L;
	private Float value;

	public Float getValue() {
		return value;
	}

	public void setValue(Float value) {
		Float oldValue = this.value;
		this.value = value;
		setHasError(false);
		notifyPropertyChanged(oldValue, value);
	}

	@Override
	public String getText() {
		if(getValue() == null)
			return null;
		return String.valueOf(getValue());
	}

	@Override
	public void setText(String text) throws ConversionException {
		setHasError(false);
		if((text == null) ||(text.equals(""))){
			setValue(null);
			return;
		}
		Float floatVal;
		try {
			floatVal = Float.parseFloat(text);
		} catch (Exception e) {
			//Prepare exception
			ConversionException ce = new ConversionException(e.getLocalizedMessage());
			ce.initCause(e);			
			//Try parse as integer
			try {
				Integer intVal = Integer.parseInt(text);
				floatVal = new Float(intVal);
			} catch (Exception ex) {
				setHasError(true);
				throw ce;
			}			
		}
		
		setValue(floatVal);
		
	}
	
	public Object getObjectValue() {		
		return getValue();
	}
	
	public Class getPropertyType() {		
		return Float.class;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy