Example usage for com.vaadin.ui Grid.Column setStyleGenerator

List of usage examples for com.vaadin.ui Grid.Column setStyleGenerator

Introduction

In this page you can find the example usage for com.vaadin.ui Grid.Column setStyleGenerator.

Prototype

public void setStyleGenerator(StyleGenerator<T> styleGenerator) 

Source Link

Document

Sets the style generator that is used for generating class names for rows in this grid.

Usage

From source file:org.jpos.qi.minigl.AccountsView.java

License:Open Source License

public void formatGrid() {
    setGridGetters();// w  w  w .j av a 2 s .  c o m

    TreeGrid<Account> grid = (TreeGrid) getGrid();

    //Delete not visible columns
    //Use columnId as caption
    //Set sorting for every column.
    DecimalFormat nf = new DecimalFormat();
    nf.setGroupingUsed(false);

    grid.setStyleGenerator(styleGen -> {
        if (styleGen.isDebit()) {
            return "debit-color";
        } else {
            return "credit-color";
        }
    });

    Iterator<Grid.Column<Account, ?>> it = grid.getColumns().iterator();
    while (it.hasNext()) {
        Grid.Column c = it.next();
        String columnId = c.getId();
        if (!Arrays.asList(getVisibleColumns()).contains(columnId)) {
            grid.removeColumn(columnId);
        } else {
            c.setCaption(getCaptionFromId(columnId)).setSortProperty(columnId).setSortable(false)
                    .setHidable(false);
            c.setStyleGenerator(obj -> {
                Object value = c.getValueProvider().apply(obj);
                if (value instanceof BigDecimal) {
                    return "align-right";
                }
                return null;
            });
        }

    }
    //fix for when a manual resize is done, the last column takes the empty space.
    grid.addColumnResizeListener(event -> {
        int lastColumnIndex = grid.getColumns().size() - 1;
        ((Grid.Column) grid.getColumns().get(lastColumnIndex)).setWidth(1500);
    });
    //expand root account
    Account a = (Account) getEntityByParam("5");
    grid.expand(a);
}

From source file:org.jpos.qi.QIEntityView.java

License:Open Source License

public void formatGrid() {
    setGridGetters();//  w  ww .  j  a  v a 2  s . c  om

    //Delete not visible columns
    //Use columnId as caption
    //Set sorting for every column.
    DecimalFormat nf = new DecimalFormat();
    nf.setGroupingUsed(false);

    Iterator<Grid.Column> it = grid.getColumns().iterator();
    while (it.hasNext()) {
        Grid.Column c = it.next();
        String columnId = c.getId();
        if (!Arrays.asList(getVisibleColumns()).contains(columnId)) {
            grid.removeColumn(columnId);
        } else {
            c.setCaption(getCaptionFromId("column." + columnId)).setSortProperty(columnId).setSortable(true)
                    .setHidable(true);

            ViewConfig.FieldConfig config = viewConfig.getFields().get(c.getId());
            if (config != null) {
                if (config.getExpandRatio() != -1)
                    c.setExpandRatio(config.getExpandRatio());
            }
            c.setStyleGenerator(obj -> {
                Object value = c.getValueProvider().apply(obj);
                if (value instanceof BigDecimal && !c.getId().equals("id")) {
                    return "align-right";
                }
                return null;
            });
        }

    }
    //fix for when a manual resize is done, the last column takes the empty space.
    grid.addColumnResizeListener(event -> {
        int lastColumnIndex = grid.getColumns().size() - 1;
        ((Grid.Column) grid.getColumns().get(lastColumnIndex)).setWidth(1500);
    });
    grid.setSizeFull();
}