Search in sources :

Example 1 with Column

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());
        }
    }
}
Also used : Column(com.vaadin.ui.Grid.Column) ListPropertyConverter(com.hack23.cia.web.impl.ui.application.views.common.converters.ListPropertyConverter)

Example 2 with Column

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);
            }
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ColumnResizeListener(com.vaadin.ui.Grid.ColumnResizeListener) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComponentResizeListener(com.ejt.vaadin.sizereporter.ComponentResizeListener) Column(com.vaadin.ui.Grid.Column) SizeReporter(com.ejt.vaadin.sizereporter.SizeReporter) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ColumnResizeEvent(com.vaadin.ui.Grid.ColumnResizeEvent) ComponentResizeEvent(com.ejt.vaadin.sizereporter.ComponentResizeEvent)

Example 3 with Column

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);
            }
        }
    });
}
Also used : Column(com.vaadin.ui.Grid.Column) ColumnReorderEvent(com.vaadin.ui.Grid.ColumnReorderEvent) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ColumnReorderListener(com.vaadin.ui.Grid.ColumnReorderListener)

Example 4 with Column

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);
        }
    });
}
Also used : Column(com.vaadin.ui.Grid.Column) ColumnVisibilityChangeEvent(com.vaadin.ui.Grid.ColumnVisibilityChangeEvent) ColumnVisibilityChangeListener(com.vaadin.ui.Grid.ColumnVisibilityChangeListener)

Example 5 with Column

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;
        }
    });
}
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)

Aggregations

Column (com.vaadin.ui.Grid.Column)16 ArrayList (java.util.ArrayList)7 LinkedList (java.util.LinkedList)6 ColumnVisibilityChangeEvent (com.vaadin.ui.Grid.ColumnVisibilityChangeEvent)4 ColumnVisibilityChangeListener (com.vaadin.ui.Grid.ColumnVisibilityChangeListener)4 List (java.util.List)4 ColumnReorderEvent (com.vaadin.ui.Grid.ColumnReorderEvent)3 ColumnReorderListener (com.vaadin.ui.Grid.ColumnReorderListener)3 ComponentRenderer (de.datenhahn.vaadin.componentrenderer.ComponentRenderer)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ComponentResizeEvent (com.ejt.vaadin.sizereporter.ComponentResizeEvent)2 ComponentResizeListener (com.ejt.vaadin.sizereporter.ComponentResizeListener)2 SizeReporter (com.ejt.vaadin.sizereporter.SizeReporter)2 Indexed (com.vaadin.data.Container.Indexed)2 Component (com.vaadin.ui.Component)2 ColumnResizeEvent (com.vaadin.ui.Grid.ColumnResizeEvent)2 ColumnResizeListener (com.vaadin.ui.Grid.ColumnResizeListener)2 HtmlRenderer (com.vaadin.ui.renderers.HtmlRenderer)2 TextRenderer (com.vaadin.ui.renderers.TextRenderer)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2