com.github.gwtbootstrap.client.ui.BigDecimalBox Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gwt-bootstrap Show documentation
Show all versions of gwt-bootstrap Show documentation
A GWT Library that provides the widgets of Twitter Bootstrap.
The newest version!
package com.github.gwtbootstrap.client.ui;
import java.math.BigDecimal;
import java.text.ParseException;
import com.github.gwtbootstrap.client.ui.base.ValueBoxBase;
import com.google.gwt.dom.client.Document;
import com.google.gwt.text.shared.AbstractRenderer;
import com.google.gwt.text.shared.Parser;
import com.google.gwt.text.shared.Renderer;
/**
* A ValueBox that uses {@link BigDecimalParser} and {@link BigDecimalRenderer}. for Bootstrap
*
* @since 2.2.1.0
* @author Nick Lim
*/
public class BigDecimalBox extends ValueBoxBase {
/**
* Create an empty widget.
*/
public BigDecimalBox() {
super(Document.get().createTextInputElement(), BigDecimalRenderer.instance(),
BigDecimalParser.instance());
}
static class BigDecimalParser implements Parser {
private static BigDecimalParser INSTANCE;
/**
* @return the instance of the no-op renderer
*/
public static Parser instance() {
if (INSTANCE == null) {
INSTANCE = new BigDecimalParser();
}
return INSTANCE;
}
protected BigDecimalParser() {}
public BigDecimal parse(CharSequence object) throws ParseException {
if (object == null || "".equals(object.toString())) {
return null;
}
try {
return new BigDecimal(object.toString());
} catch (NumberFormatException e) {
throw new ParseException(e.getMessage(), 0);
}
}
}
static class BigDecimalRenderer extends AbstractRenderer {
private static BigDecimalRenderer INSTANCE;
/**
* @return the instance
*/
public static Renderer instance() {
if (INSTANCE == null) {
INSTANCE = new BigDecimalRenderer();
}
return INSTANCE;
}
protected BigDecimalRenderer() {}
public String render(BigDecimal object) {
if (object == null) {
return "";
}
return object.toString();
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy