Search in sources :

Example 1 with ComponentRenderer

use of de.datenhahn.vaadin.componentrenderer.ComponentRenderer in project VaadinUtils by rlsutton1.

the class GridHeadingV2PropertySet method addActionColumn.

@SuppressWarnings("unchecked")
private void addActionColumn() {
    ((GeneratedPropertyListContainer<E>) grid.getContainerDataSource()).addGeneratedProperty(ACTION_MENU_PROPERTY_ID, getActionMenuColumnGenerator());
    final Column actionMenuColumn = grid.addColumn(ACTION_MENU_PROPERTY_ID);
    grid.setFrozenColumnCount(1);
    actionMenuColumn.setHeaderCaption("");
    actionMenuColumn.setRenderer(new ComponentRenderer());
    actionMenuColumn.setWidth(40);
    actionMenuColumn.setResizable(false);
    grid.setCellStyleGenerator(new CellStyleGenerator() {

        /**
         */
        private static final long serialVersionUID = 1L;

        @Override
        public String getStyle(CellReference event) {
            String style = "";
            if (event.getPropertyId().equals(ACTION_MENU_PROPERTY_ID)) {
                style = "grid-actionmenu";
            }
            return style;
        }
    });
}
Also used : ComponentRenderer(de.datenhahn.vaadin.componentrenderer.ComponentRenderer) Column(com.vaadin.ui.Grid.Column) CellStyleGenerator(com.vaadin.ui.Grid.CellStyleGenerator) CellReference(com.vaadin.ui.Grid.CellReference) GeneratedPropertyListContainer(org.vaadin.viritin.grid.GeneratedPropertyListContainer)

Example 2 with ComponentRenderer

use of de.datenhahn.vaadin.componentrenderer.ComponentRenderer in project VaadinUtils by rlsutton1.

the class GridHeadingPropertySet method applyToGrid.

/**
 * @param grid
 * @param uniqueId
 *            - an id for this layout/grid combination, it is used to
 *            identify stored column widths in a key value map
 */
public void applyToGrid(final Grid grid, final String uniqueId) {
    this.grid = grid;
    this.uniqueId = uniqueId;
    try {
        // Changing the bound container at this point can cause issues
        // elsewhere, so we avoid it if possible
        Indexed gridContainer = grid.getContainerDataSource();
        for (GridHeadingToPropertyId column : getColumns()) {
            if (column.isGenerated()) {
                gridContainer = wrapGridContainer(grid);
                break;
            }
        }
        final List<String> colsToShow = new LinkedList<>();
        for (GridHeadingToPropertyId column : getColumns()) {
            final String propertyId = column.getPropertyId();
            if (column.isGenerated()) {
                final PropertyValueGenerator<?> columnGenerator = column.getColumnGenerator();
                ((GeneratedPropertyContainer) gridContainer).addGeneratedProperty(propertyId, columnGenerator);
                final Column gridColumn = grid.getColumn(propertyId);
                if (columnGenerator.getType() == String.class && gridColumn.getRenderer() instanceof TextRenderer) {
                    gridColumn.setRenderer(new HtmlRenderer(), null);
                } else if (columnGenerator.getType() == Component.class) {
                    gridColumn.setRenderer(new ComponentRenderer());
                }
            } else {
                Preconditions.checkArgument(grid.getContainerDataSource().getContainerPropertyIds().contains(propertyId), propertyId + " is not a valid property id, valid property ids are " + grid.getContainerDataSource().getContainerPropertyIds().toString());
            }
            colsToShow.add(propertyId);
            final Column gridColumn = grid.getColumn(propertyId);
            if (column.getRenderer() != null) {
                gridColumn.setRenderer(column.getRenderer());
            }
            if (column.getConverter() != null) {
                gridColumn.setConverter(column.getConverter());
            }
            gridColumn.setHeaderCaption(column.getHeader());
            if (column.getWidth() != null) {
                gridColumn.setWidth(column.getWidth());
            } else {
                gridColumn.setExpandRatio(1);
                gridColumn.setMinimumWidth(1);
            }
            if (column.isLocked()) {
                gridColumn.setHidable(false);
            } else {
                gridColumn.setHidable(true);
                if (!column.isVisibleByDefault()) {
                    gridColumn.setHidden(true);
                }
            }
        }
        grid.setColumns(colsToShow.toArray());
        if (eraseSavedConfig) {
            eraseSavedConfig(uniqueId);
        }
        if (!deferLoadSettings) {
            configureSaveColumnWidths(grid, uniqueId);
            configureSaveColumnOrder(grid, uniqueId);
            configureSaveColumnVisible(grid, uniqueId);
        }
    } catch (Exception e) {
        logger.error(e, e);
    }
}
Also used : LinkedList(java.util.LinkedList) ComponentRenderer(de.datenhahn.vaadin.componentrenderer.ComponentRenderer) Column(com.vaadin.ui.Grid.Column) GeneratedPropertyContainer(com.vaadin.data.util.GeneratedPropertyContainer) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Component(com.vaadin.ui.Component) Indexed(com.vaadin.data.Container.Indexed) TextRenderer(com.vaadin.ui.renderers.TextRenderer)

Example 3 with ComponentRenderer

use of de.datenhahn.vaadin.componentrenderer.ComponentRenderer in project VaadinUtils by rlsutton1.

the class GridHeadingV2PropertySet method applyToGrid.

/**
 * @param grid
 * @param uniqueId
 *            - an id for this layout/grid combination, it is used to
 *            identify stored column widths in a key value map
 */
@Override
@SuppressWarnings("unchecked")
public void applyToGrid(final Class<E> entityClass, final Grid grid, final String uniqueId) {
    this.grid = grid;
    this.uniqueId = uniqueId;
    final List<String> columnsToShow = new LinkedList<>();
    try {
        // Avoid changing the container data source if we can
        Indexed gridContainer = grid.getContainerDataSource();
        if (actionColumnEnabled && actionMenuProvider != null) {
            gridContainer = wrapGridContainer(entityClass, grid);
            addActionColumn();
            columnsToShow.add(ACTION_MENU_PROPERTY_ID);
        } else {
            for (GridHeadingV2ToPropertyId column : getColumns()) {
                if (column.isGenerated()) {
                    gridContainer = wrapGridContainer(entityClass, grid);
                    break;
                }
            }
        }
        for (GridHeadingV2ToPropertyId column : getColumns()) {
            final String propertyId = column.getPropertyId();
            if (column.isGenerated()) {
                final PropertyValueGenerator<?> columnGenerator = column.getColumnGenerator();
                ((GeneratedPropertyListContainer<E>) gridContainer).addGeneratedProperty(propertyId, columnGenerator);
                // already exists, then we shouldn't try to add it again
                if (grid.getColumn(propertyId) == null) {
                    grid.addColumn(propertyId);
                }
                final Column gridColumn = grid.getColumn(propertyId);
                if (columnGenerator.getType() == String.class && gridColumn.getRenderer() instanceof TextRenderer) {
                    gridColumn.setRenderer(new HtmlRenderer(), null);
                } else if (columnGenerator.getType() == Component.class) {
                    gridColumn.setRenderer(new ComponentRenderer());
                }
            } else {
                Preconditions.checkArgument(grid.getContainerDataSource().getContainerPropertyIds().contains(propertyId), propertyId + " is not a valid property id, valid property ids are " + grid.getContainerDataSource().getContainerPropertyIds().toString());
            }
            columnsToShow.add(propertyId);
            final Column gridColumn = grid.getColumn(propertyId);
            if (column.getRenderer() != null) {
                gridColumn.setRenderer(column.getRenderer(), null);
            } else if (gridContainer.getType(propertyId) == Boolean.class) {
                // Show a tick/cross if column is a boolean
                gridColumn.setRenderer(new HtmlRenderer(), new StringToBooleanConverter(FontAwesome.CHECK.getHtml(), FontAwesome.TIMES.getHtml()));
            }
            gridColumn.setHeaderCaption(column.getHeader());
            columnWidthTypes.put(propertyId, column.getWidthType());
            if (column.getWidth() != null) {
                setColumnWidth(gridColumn, column.getWidth());
                if (column.getWidthType().equals(WidthType.FIXED)) {
                    gridColumn.setResizable(false);
                }
            } else {
                gridColumn.setExpandRatio(1);
                gridColumn.setMinimumWidth(1);
            }
            if (column.isVisibilityLocked()) {
                gridColumn.setHidable(false);
            } else {
                gridColumn.setHidable(true);
                if (!column.isVisible()) {
                    gridColumn.setHidden(true);
                }
            }
        }
        grid.setColumns(columnsToShow.toArray());
        if (eraseSavedConfig) {
            eraseSavedConfig(uniqueId);
        }
        if (!deferLoadSettings) {
            configureSaveColumnWidths(grid);
            configureSaveColumnOrder(grid);
            configureSaveColumnVisible(grid);
        }
    } catch (Exception e) {
        logger.error(e, e);
    }
}
Also used : LinkedList(java.util.LinkedList) GeneratedPropertyListContainer(org.vaadin.viritin.grid.GeneratedPropertyListContainer) StringToBooleanConverter(com.vaadin.data.util.converter.StringToBooleanConverter) ComponentRenderer(de.datenhahn.vaadin.componentrenderer.ComponentRenderer) Column(com.vaadin.ui.Grid.Column) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Component(com.vaadin.ui.Component) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Indexed(com.vaadin.data.Container.Indexed) TextRenderer(com.vaadin.ui.renderers.TextRenderer)

Aggregations

Column (com.vaadin.ui.Grid.Column)3 ComponentRenderer (de.datenhahn.vaadin.componentrenderer.ComponentRenderer)3 Indexed (com.vaadin.data.Container.Indexed)2 Component (com.vaadin.ui.Component)2 HtmlRenderer (com.vaadin.ui.renderers.HtmlRenderer)2 TextRenderer (com.vaadin.ui.renderers.TextRenderer)2 LinkedList (java.util.LinkedList)2 GeneratedPropertyListContainer (org.vaadin.viritin.grid.GeneratedPropertyListContainer)2 GeneratedPropertyContainer (com.vaadin.data.util.GeneratedPropertyContainer)1 StringToBooleanConverter (com.vaadin.data.util.converter.StringToBooleanConverter)1 CellReference (com.vaadin.ui.Grid.CellReference)1 CellStyleGenerator (com.vaadin.ui.Grid.CellStyleGenerator)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1