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

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

Introduction

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

Prototype

public String format(Number number) 

Source Link

Document

This method formats a Number to produce a string.

Usage

From source file:org.roda.wui.common.client.tools.Humanize.java

/**
 * Format a value in milliseconds as a string
 * //  w  w w  .  j av a 2 s  . co m
 * @param value
 * @param showMillis
 * @return a formatted string for time duration
 */
public static String formatValueMilliseconds(long value, boolean showMillis) {
    long hours = value / 3600000;
    long minutes = (value % 3600000) / 60000;
    long seconds = ((value % 3600000) % 60000) / 1000;
    long millis = value % 1000;

    NumberFormat numberFormat = NumberFormat.getFormat("00");
    NumberFormat millisFormat = NumberFormat.getFormat("000");

    if (showMillis) {
        return numberFormat.format(hours) + ":" + numberFormat.format(minutes) + ":"
                + numberFormat.format(seconds) + "." + millisFormat.format(millis);
    } else {
        return numberFormat.format(hours) + ":" + numberFormat.format(minutes) + ":"
                + numberFormat.format(seconds);
    }
}

From source file:org.roda.wui.common.client.widgets.wcag.AccessibleSimplePager.java

@Override
protected String createText() {
    // Default text is 1 based.
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();/* w  w  w.  j  a  v  a  2  s. c o  m*/
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    boolean exact = display.isRowCountExact();
    return formatter.format(pageStart) + "-" + formatter.format(endIndex) + " "
            + (exact ? messages.of() : messages.ofOver()) + " " + formatter.format(dataSize);
}

From source file:org.sakaiproject.gradebook.gwt.client.gxt.custom.widget.grid.ItemTreeGridView.java

License:Educational Community License

@Override
protected String getRenderedValue(ColumnData data, int rowIndex, int colIndex, ModelData m, String property) {
    GridCellRenderer<ModelData> r = cm.getRenderer(colIndex);
    if (r != null) {
        Object o = r.render(ds.getAt(rowIndex), property, data, rowIndex, colIndex, ds, grid);
        if (o instanceof Widget || r instanceof WidgetTreeGridCellRenderer) {
            return "";
        } else {//  ww w.j  a  v a 2  s.c om
            if (o == null)
                return "";
            return o.toString();
        }
    }
    Object val = m.get(property);

    ColumnConfig c = cm.getColumn(colIndex);

    if (val != null && c.getNumberFormat() != null) {
        Number n = (Number) val;
        NumberFormat nf = cm.getColumn(colIndex).getNumberFormat();
        val = nf.format(n.doubleValue());
    } else if (val != null && c.getDateTimeFormat() != null) {
        DateTimeFormat dtf = c.getDateTimeFormat();
        val = dtf.format((Date) val);
    }

    String text = null;
    if (val != null) {
        text = val.toString();
    }
    return text == null || text.equals("") ? "&#160;" : text;
}

From source file:org.sigmah.client.ui.view.project.indicator.ProjectIndicatorManagementView.java

License:Open Source License

/**
 * Format the value <code>property</code> of the given indicator.
 * /*from  www  . j a va  2  s.co m*/
 * @param indicator Indicator to use.
 * @param property The property to retrieve.
 * 
 * @return The value formatted according to the aggregation mode of the given indicator.
 */
private String formatIndicatorValue(final IndicatorDTO indicator, String property) {
    final Double value = indicator.get(property);

    if (value == null) {
        return "";
    }

    final NumberFormat numberFormat = IndicatorNumberFormats.getNumberFormat(indicator);

    return numberFormat.format(value);
}

From source file:org.sigmah.client.ui.view.project.indicator.SiteColumnModelBuilder.java

License:Open Source License

protected ColumnConfig createIndicatorColumn(IndicatorDTO indicator, String header) {

    final NumberFormat format = IndicatorNumberFormats.getNumberFormat(indicator);

    NumberField indicatorField = new NumberField();

    ColumnConfig indicatorColumn = new ColumnConfig(indicator.getPropertyName(), header, 50);

    indicatorColumn.setNumberFormat(format);
    indicatorColumn.setEditor(new CellEditor(indicatorField));
    indicatorColumn.setAlignment(Style.HorizontalAlignment.RIGHT);

    // For SUM indicators, don't show ZEROs in the Grid
    // (it looks better if we don't)
    if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SUM) {
        indicatorColumn.setRenderer(new GridCellRenderer() {
            @Override/*w ww  .j a v  a  2 s . c  o m*/
            public Object render(ModelData model, String property, ColumnData config, int rowIndex,
                    int colIndex, ListStore listStore, Grid grid) {
                Double value = model.get(property);
                if (value != null && value != 0) {
                    return format.format(value);
                } else {
                    return "";
                }
            }
        });
    }

    return indicatorColumn;
}

From source file:org.ssgwt.client.ui.datagrid.SSPager.java

License:Apache License

/**
 * Get the text to display in the pager that reflects the state of the
 * pager. This will show the range of records that are displayed
 * /*  w ww  . j av  a2  s  .  c o  m*/
 * @return the text
 */
protected String createText() {
    // Default text is 1 based.
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    return formatter.format(pageStart) + "-" + formatter.format(endIndex);
}

From source file:org.ssgwt.client.ui.datagrid.SSPager.java

License:Apache License

/**
 * Get the text to display in the pager that reflects the state of the
 * pager. This will show the total amount of records
 * //from  w  w  w  .ja  v  a2 s.com
 * @return the text
 */
protected String createTextOf() {
    // Default text is 1 based.
    NumberFormat formatter = NumberFormat.getFormat("#,###");
    HasRows display = getDisplay();
    Range range = display.getVisibleRange();
    int pageStart = range.getStart() + 1;
    int pageSize = range.getLength();
    int dataSize = display.getRowCount();
    int endIndex = Math.min(dataSize, pageStart + pageSize - 1);
    endIndex = Math.max(pageStart, endIndex);
    boolean exact = display.isRowCountExact();
    return (exact ? " of " : " of over ") + formatter.format(dataSize);
}

From source file:org.talend.mdm.webapp.browserecords.client.rest.ExplainRestServiceHandler.java

License:Open Source License

private String getScoreValue(JSONValue jsonValue) {
    String value = null;// w ww  .j a  va 2  s  .c  o  m
    if (jsonValue != null && jsonValue.isNumber() != null) {
        NumberFormat numberFormat = NumberFormat.getFormat("0.00"); //$NON-NLS-1$
        value = numberFormat.format(jsonValue.isNumber().doubleValue() * 100) + "%"; //$NON-NLS-1$
    }
    return value;
}

From source file:org.talend.mdm.webapp.browserecords.client.util.FormatUtil.java

License:Open Source License

public static String changeNumberToFormatedValue(String value) {
    StringBuilder pattern = new StringBuilder("###0.");
    if (value == null || value.equals("")) {
        return "";
    }//from   w  ww  . j  ava 2  s  .  c o  m
    if (value.contains(",")) {
        value = value.replace(",", ".");
    }
    int fractionDigits = 0;
    if (value.contains(".")) {
        fractionDigits = value.trim().split("\\.")[1].length();
    }

    if (fractionDigits == 0) {
        pattern.append("######");
    }

    for (int i = 0; i < fractionDigits; i++) {
        pattern.append("0");
    }
    NumberFormat nf = NumberFormat.getFormat(pattern.toString());
    return nf.format(Double.valueOf(value));
}

From source file:org.talend.mdm.webapp.stagingarea.control.client.view.StagingContainerSummaryView.java

License:Open Source License

@Override
public void onModelEvent(ModelEvent e) {
    GwtEvent.Type<ModelEventHandler> type = e.getAssociatedType();
    if (type == ModelEvent.Types.CONTAINER_MODEL_CHANGED.getType()) {
        StagingContainerModel stagingContainerModel = e.getModel();
        // Updates summary
        int waiting = stagingContainerModel.getWaitingValidationRecords();
        int valid = stagingContainerModel.getValidRecords();
        int invalid = stagingContainerModel.getInvalidRecords();
        Element titleEl = detailPanel.getElementById(STAGING_AREA_TITLE);
        titleEl.setInnerHTML(messages.total_desc("<b>" + stagingContainerModel.getTotalRecords() + "</b>")); //$NON-NLS-1$ //$NON-NLS-2$
        Element waitingEl = detailPanel.getElementById(STAGING_AREA_WAITING);
        waitingEl.setInnerHTML(messages.waiting_desc("<b>" + waiting + "</b>")); //$NON-NLS-1$ //$NON-NLS-2$
        Element invalidEl = detailPanel.getElementById(STAGING_AREA_INVALID);
        invalidEl.setInnerHTML(messages.invalid_desc(
                "<span id=\"open_invalid_record\" style=\"color:red; text-decoration:underline; cursor:pointer;\">", //$NON-NLS-1$
                "<b>" + invalid + "</b>", "</span>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Element open_invalid_record = detailPanel.getElementById("open_invalid_record"); //$NON-NLS-1$
        addClickForRecord(2, open_invalid_record);
        Element validEl = detailPanel.getElementById(STAGING_AREA_VALID);
        validEl.setInnerHTML(messages.valid_desc(
                "<span id=\"open_valid_record\" style=\"color:green; text-decoration:underline; cursor:pointer;\">", //$NON-NLS-1$
                "<b>" + valid + "</b>", "</span>")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        Element open_valid_record = detailPanel.getElementById("open_valid_record"); //$NON-NLS-1$
        addClickForRecord(3, open_valid_record);
        // Update gauge bar
        int total = valid + invalid + waiting;
        if (total == 0) {
            gaugeBar.reset();/*from  w ww. j  a v  a 2 s  .c om*/
            return;
        }
        double percentage = valid * 1D / total;
        NumberFormat format = NumberFormat.getFormat("#0.00"); //$NON-NLS-1$
        final double validPercentage = format.parse(format.format(valid * 100D / total));
        if (gaugeBar.getValue() < 1.0 || totalRecordCount != total) {
            gaugeBar.updateProgress(percentage, messages.percentage(valid, total, validPercentage));
        }
        totalRecordCount = total;
    } else if (type == ModelEvent.Types.VALIDATION_END.getType()
            || type == ModelEvent.Types.VALIDATION_CANCEL.getType()) {
        startValidate.enable();
    } else if (type == ModelEvent.Types.VALIDATION_START.getType()) {
        startValidate.disable();
    }
}