Example usage for com.google.gwt.i18n.client NumberFormat getCurrencyFormat

List of usage examples for com.google.gwt.i18n.client NumberFormat getCurrencyFormat

Introduction

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

Prototype

public static NumberFormat getCurrencyFormat(String currencyCode) 

Source Link

Document

Provides the standard currency format for the default locale using a specified currency.

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");
        }//  ww w.jav a 2  s. c o m
        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");
    }
}

From source file:org.sigmah.client.ui.view.CreateProjectView.java

License:Open Source License

/**
 * {@inheritDoc}//from  w ww.  java2s.c o  m
 */
@Override
public void initialize() {

    // --
    // -- Builds the form fields.
    // --

    // Project.
    nameField = Forms.text(I18N.CONSTANTS.projectName(), true, EntityConstants.NAME_MAX_LENGTH);
    fullNameField = Forms.text(I18N.CONSTANTS.projectFullName(), true,
            EntityConstants.USER_DATABASE_FULL_NAME_MAX_LENGTH);
    budgetField = Forms.number(
            I18N.CONSTANTS.projectPlannedBudget() + " (" + I18N.CONSTANTS.currencyEuro() + ')', true, false,
            true, NumberFormat.getCurrencyFormat("EUR"));
    orgUnitsField = Forms.combobox(I18N.CONSTANTS.orgunit(), true, OrgUnitDTO.ID, OrgUnitDTO.COMPLETE_NAME,
            I18N.CONSTANTS.orgunitEmptyChoice(), new ListStore<OrgUnitDTO>());
    modelsField = Forms.combobox(I18N.CONSTANTS.projectModel(), true, ProjectModelDTO.ID, ProjectModelDTO.NAME,
            I18N.CONSTANTS.projectModelEmptyChoice(), new ListStore<ProjectModelDTO>());

    // Project model type.
    modelTypeImage = new SimplePanel();
    modelTypeImage.addStyleName(CSS_PROJECT_TYPE_IMAGE);
    modelTypeLabel = new Label();
    modelTypeLabel.addStyleName(CSS_PROJECT_TYPE_LABEL);
    final HorizontalPanel modelTypePanel = new HorizontalPanel();
    modelTypePanel.addStyleName(CSS_PROJECT_TYPE);
    modelTypePanel.add(modelTypeImage);
    modelTypePanel.add(modelTypeLabel);

    // Founding.
    baseProjectBudgetField = Forms.label("");
    amountField = Forms.number(null, false, false, false, NumberFormat.getCurrencyFormat("EUR"));
    percentageField = Forms.label(I18N.CONSTANTS.createProjectPercentage());

    // Tests.
    testProjectsGrid = new Grid<ProjectDTO>(new ListStore<ProjectDTO>(), buildTestProjectsColumnModel());
    testProjectsGrid.setAutoExpandColumn(ProjectDTO.FULL_NAME);
    testProjectsGrid.setHeight(200);
    testProjectsGrid.getView().setForceFit(true);
    testProjectsGrid.getStore().setMonitorChanges(true);

    // Buttons.
    createButton = Forms.button(I18N.CONSTANTS.createProjectCreateButton());

    // Builds the form.
    formPanel = Forms.panel(170);

    formPanel.add(nameField);
    formPanel.add(fullNameField);
    formPanel.add(budgetField);
    formPanel.add(orgUnitsField);
    formPanel.add(modelsField);
    formPanel.add(modelTypePanel);
    formPanel.add(baseProjectBudgetField);
    formPanel.add(amountField);
    formPanel.add(percentageField);
    formPanel.add(testProjectsGrid);
    formPanel.addButton(createButton);

    initPopup(formPanel);

}