use of org.vaadin.viritin.grid.GeneratedPropertyListContainer 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;
}
});
}
use of org.vaadin.viritin.grid.GeneratedPropertyListContainer 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);
}
}
use of org.vaadin.viritin.grid.GeneratedPropertyListContainer in project VaadinUtils by rlsutton1.
the class GridHeadingV2PropertySet method wrapGridContainer.
@SuppressWarnings("unchecked")
private GeneratedPropertyListContainer<E> wrapGridContainer(final Class<E> entityClass, final Grid grid) {
final Indexed gridContainer = grid.getContainerDataSource();
if (gridContainer instanceof GeneratedPropertyListContainer) {
return (GeneratedPropertyListContainer<E>) gridContainer;
}
final GeneratedPropertyListContainer<E> gplc = new GeneratedPropertyListContainer<>(entityClass);
gplc.setCollection((Collection<E>) gridContainer.getItemIds());
final Collection<?> containerPropertyIds = gridContainer.getContainerPropertyIds();
if (!containerPropertyIds.isEmpty()) {
gplc.setContainerPropertyIds(containerPropertyIds.toArray(new String[containerPropertyIds.size()]));
}
grid.setContainerDataSource(gplc);
return gplc;
}
Aggregations