use of com.vaadin.ui.Grid.Column in project cia by Hack23.
the class GridFactoryImpl method setColumnConverters.
/**
* Sets the column converters.
*
* @param collectionPropertyConverter
* the collection property converter
* @param grid
* the grid
*/
private static void setColumnConverters(final ListPropertyConverter[] collectionPropertyConverter, final Grid grid) {
if (collectionPropertyConverter != null) {
for (final ListPropertyConverter converter : collectionPropertyConverter) {
grid.removeColumn(converter.getColumn());
Column column = grid.addColumn(converter);
column.setCaption(WordUtils.capitalize(converter.getColumn()));
column.setId(converter.getColumn());
}
}
}
use of com.vaadin.ui.Grid.Column in project VaadinUtils by rlsutton1.
the class GridHeadingPropertySet method configureDynamicColumnWidth.
private void configureDynamicColumnWidth() {
final AtomicBoolean resizing = new AtomicBoolean(false);
final AtomicInteger gridWidth = new AtomicInteger();
final SizeReporter sizeReporter = new SizeReporter(grid);
sizeReporter.addResizeListener(new ComponentResizeListener() {
private static final long serialVersionUID = 1L;
@Override
public void sizeChanged(ComponentResizeEvent event) {
final int newGridWidth = event.getWidth();
gridWidth.set(newGridWidth);
if (newGridWidth > 1) {
final List<Column> gridColumns = grid.getColumns();
double columnsTotalWidth = 0;
for (Column column : gridColumns) {
columnsTotalWidth += column.getWidth();
}
final double widthDiscrepancy = gridWidth.get() - columnsTotalWidth;
if (widthDiscrepancy != 0) {
final double perColumnChange = widthDiscrepancy / gridColumns.size();
for (Column column : gridColumns) {
resizing.set(true);
column.setWidth(column.getWidth() + perColumnChange);
resizing.set(false);
}
}
}
}
});
grid.addColumnResizeListener(new ColumnResizeListener() {
private static final long serialVersionUID = 1L;
@Override
public void columnResize(ColumnResizeEvent event) {
if (gridWidth.get() > 0 && !resizing.get()) {
resizing.set(true);
final List<Column> gridColumns = grid.getColumns();
final int totalColumns = gridColumns.size();
final Column resizedColumn = event.getColumn();
final double resizedColumnWidth = resizedColumn.getWidth();
final int resizedColumnIndex = gridColumns.indexOf(resizedColumn);
// availableWidth = grid width - width of column being
// resized - widths of columns to the left
double availableWidth = gridWidth.get() - resizedColumnWidth;
for (int i = 0; i < resizedColumnIndex; i++) {
availableWidth -= gridColumns.get(i).getWidth();
}
// columnsToResize = total columns - column being resized -
// number of columns to the right
final int columnsToResize = totalColumns - resizedColumnIndex - 1;
final double perColumnWidth = availableWidth / columnsToResize;
for (int i = (resizedColumnIndex + 1); i < totalColumns; i++) {
gridColumns.get(i).setWidth(perColumnWidth);
}
resizing.set(false);
}
}
});
}
use of com.vaadin.ui.Grid.Column in project VaadinUtils by rlsutton1.
the class GridHeadingPropertySet method configureSaveColumnOrder.
private void configureSaveColumnOrder(final Grid grid, final String uniqueId) {
final String keyStub = uniqueId + "-order";
final List<Column> availableColumns = grid.getColumns();
final String columns = UserSettingsStorageFactory.getUserSettingsStorage().get(keyStub);
if (availableColumns.size() > 0 && columns != null && !columns.isEmpty()) {
final Object[] parsedColumns = columns.split(", ?");
if (parsedColumns.length > 0) {
grid.setColumns(calculateColumnOrder(availableColumns, parsedColumns));
}
}
grid.addColumnReorderListener(new ColumnReorderListener() {
private static final long serialVersionUID = -2810298692555333890L;
@Override
public void columnReorder(ColumnReorderEvent event) {
final List<Column> columns = ((Grid) event.getSource()).getColumns();
if (columns.size() > 0) {
String parsedColumns = "";
for (Column column : columns) {
parsedColumns += column.getPropertyId() + ", ";
}
parsedColumns = parsedColumns.substring(0, parsedColumns.length() - 2);
UserSettingsStorageFactory.getUserSettingsStorage().store(keyStub, "" + parsedColumns);
}
}
});
}
use of com.vaadin.ui.Grid.Column in project VaadinUtils by rlsutton1.
the class GridHeadingV2PropertySet method configureSaveColumnVisible.
private void configureSaveColumnVisible(final Grid grid) {
final String keyStub = uniqueId + "-visible";
for (GridHeadingV2ToPropertyId id : getColumns()) {
final String setVisible = UserSettingsStorageFactory.getUserSettingsStorage().get(keyStub + "-" + id.getPropertyId());
if (setVisible != null && !setVisible.isEmpty()) {
grid.getColumn(id.getPropertyId()).setHidden(!Boolean.parseBoolean(setVisible));
}
}
grid.addColumnVisibilityChangeListener(new ColumnVisibilityChangeListener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void columnVisibilityChanged(ColumnVisibilityChangeEvent event) {
final Column column = event.getColumn();
final boolean isVisible = !column.isHidden();
UserSettingsStorageFactory.getUserSettingsStorage().store(keyStub + "-" + column.getPropertyId(), "" + isVisible);
}
});
}
use of com.vaadin.ui.Grid.Column 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;
}
});
}
Aggregations