Example usage for com.google.gwt.cell.client DateCell render

List of usage examples for com.google.gwt.cell.client DateCell render

Introduction

In this page you can find the example usage for com.google.gwt.cell.client DateCell render.

Prototype

@Override
    public void render(Context context, Date value, SafeHtmlBuilder sb) 

Source Link

Usage

From source file:org.greatlogic.gxtexamples.client.glgwt.GLGridWidget.java

License:Apache License

private void resizeColumnToFit(final int columnIndex) {
    final ColumnConfig<GLRecord, ?> columnConfig = _grid.getColumnModel().getColumn(columnIndex);
    final TextMetrics textMetrics = TextMetrics.get();
    textMetrics.bind(_grid.getView().getHeader().getAppearance().styles().head());
    int maxWidth = textMetrics.getWidth(columnConfig.getHeader().asString()) + 15; // extra is for the dropdown arrow
    if (_listStore.size() > 0) {
        textMetrics.bind(_grid.getView().getCell(0, 1));
        for (final GLRecord record : _listStore.getAll()) {
            final Object value = columnConfig.getValueProvider().getValue(record);
            if (value != null) {
                String valueAsString;
                if (columnConfig.getCell() instanceof DateCell) {
                    final DateCell dateCell = (DateCell) columnConfig.getCell();
                    final SafeHtmlBuilder sb = new SafeHtmlBuilder();
                    dateCell.render(null, (Date) value, sb);
                    valueAsString = sb.toSafeHtml().asString();
                } else {
                    valueAsString = value.toString();
                }//  w w  w  . j a  v  a2 s  . co  m
                final int width = textMetrics.getWidth(valueAsString) + 12;
                maxWidth = width > maxWidth ? width : maxWidth;
            }
        }
        for (final Store<GLRecord>.Record record : _listStore.getModifiedRecords()) {
            final int width = textMetrics.getWidth(record.getValue(columnConfig.getValueProvider()) //
                    .toString()) + 12;
            maxWidth = width > maxWidth ? width : maxWidth;
        }
    }
    columnConfig.setWidth(maxWidth);
    if (_checkBoxSet.contains(columnConfig)) {
        centerCheckBox(columnConfig);
    }
}