Example usage for com.google.gwt.i18n.client CurrencyList get

List of usage examples for com.google.gwt.i18n.client CurrencyList get

Introduction

In this page you can find the example usage for com.google.gwt.i18n.client CurrencyList get.

Prototype

public static CurrencyList get() 

Source Link

Document

Return the singleton instance of CurrencyList.

Usage

From source file:org.broadleafcommerce.openadmin.client.datasource.dynamic.ListGridDataSource.java

License:Apache License

protected void setupDecimalFormatters(ListGridField gridField, DataSourceField field) {
    String fieldType = field.getAttribute("fieldType");
    if (fieldType != null && SupportedFieldType.MONEY.toString().equals(fieldType)) {
        String currencyCodeField = null;
        if (field.getAttribute("currencyCodeField") != null
                && !field.getAttribute("currencyCodeField").equals("")) {
            currencyCodeField = field.getAttribute("currencyCodeField");
        }//from  ww  w. j  a  v  a  2s .c om
        final String formatCodeField = currencyCodeField;
        gridField.setCellFormatter(new CellFormatter() {
            @Override
            public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                if (value == null) {
                    return "";
                }
                String formatCodeFieldTemp = formatCodeField;
                if (formatCodeFieldTemp == null) {
                    formatCodeFieldTemp = getAttribute("currencyCodeField");
                }
                String currencyCode = null;
                if (formatCodeFieldTemp != null) {
                    currencyCode = record.getAttribute(formatCodeFieldTemp);
                }
                if (currencyCode == null) {
                    currencyCode = getAttribute("blcCurrencyCode");
                }
                Number formatValue;
                if (value.getClass().getName().equals(String.class.getName())) {
                    formatValue = Double.parseDouble((String) value);
                } else {
                    formatValue = (Number) value;
                }
                if (CurrencyList.get().lookup(currencyCode) == null) {
                    //This must not be a known currency code
                    return String.valueOf(value);
                }
                try {
                    return NumberFormat.getCurrencyFormat(currencyCode).format(formatValue);
                } catch (Exception e) {
                    return String.valueOf(value);
                }
            }
        });
        gridField.setAttribute("type", "localMoneyDecimal");
    }
    if (fieldType != null && SupportedFieldType.DECIMAL.toString().equals(fieldType)) {
        gridField.setAttribute("type", "localDecimal");
    }
}