use of com.vaadin.data.util.converter.StringToBooleanConverter 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);
}
}
Aggregations