+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client.ui.grid;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import com.vaadin.client.ui.grid.renderers.TextRenderer;
-
-/**
- * A column group is a horizontal grouping of columns in a header or footer.
- * Columns groups are added to {@link ColumnGroupRow ColumnGroupRows}.
- *
- * @param <T>
- * The row type of the grid. The row type is the POJO type from where
- * the data is retrieved into the column cells.
- * @since
- * @author Vaadin Ltd
- * @see ColumnGroupRow#addGroup(ColumnGroup...)
- */
-@Deprecated
-public class ColumnGroup<T> {
-
- /**
- * The text shown in the header
- */
- private String header;
-
- /**
- * The text shown in the footer
- */
- private String footer;
-
- /**
- * Renders the header cells for the column group
- */
- private Renderer<String> headerRenderer = new TextRenderer();
-
- /**
- * Renders the footer cells for the column group
- */
- private Renderer<String> footerRenderer = new TextRenderer();
-
- /**
- * The columns included in the group when also accounting for subgroup
- * columns
- */
- private final List<GridColumn<?, T>> columns;
-
- /**
- * The grid associated with the column group
- */
- private final Grid<T> grid;
-
- /**
- * Constructs a new column group
- */
- ColumnGroup(Grid<T> grid, Collection<GridColumn<?, T>> columns) {
- if (columns == null) {
- throw new IllegalArgumentException(
- "columns cannot be null. Pass an empty list instead.");
- }
- this.grid = grid;
- this.columns = Collections
- .unmodifiableList(new ArrayList<GridColumn<?, T>>(columns));
- }
-
- /**
- * Gets the text shown in the header.
- *
- * @return the header text
- */
- public String getHeaderCaption() {
- return header;
- }
-
- /**
- * Sets the text shown in the header.
- *
- * @param caption
- * the caption to set
- */
- public void setHeaderCaption(String caption) {
- this.header = caption;
- grid.refreshHeader();
- }
-
- /**
- * Gets the text shown in the footer.
- *
- * @return the footer text
- */
- public String getFooterCaption() {
- return footer;
- }
-
- /**
- * Sets the text shown in the footer.
- *
- * @param caption
- * the caption to set
- */
- public void setFooterCaption(String caption) {
- this.footer = caption;
- grid.refreshFooter();
- }
-
- /**
- * Returns all columns in this group. This includes columns in all the
- * sub-groups as well.
- *
- * @return an unmodifiable list of columns
- */
- public List<GridColumn<?, T>> getColumns() {
- return columns;
- }
-
- /**
- * Returns the renderer for the header cells.
- *
- * @return the renderer for the header cells
- */
- public Renderer<String> getHeaderRenderer() {
- return headerRenderer;
- }
-
- /**
- * Sets the renderer for the header cells.
- *
- * @param renderer
- * a non-{@code null} renderer to use for the header cells.
- * @throws IllegalArgumentException
- * if {@code renderer} is {@code null}
- */
- public void setHeaderRenderer(Renderer<String> renderer) {
- if (renderer == null) {
- throw new IllegalArgumentException("Renderer cannot be null.");
- }
- this.headerRenderer = renderer;
- grid.refreshHeader();
- }
-
- /**
- * Returns the renderer for the footer cells.
- *
- * @return the renderer for the footer cells
- */
- public Renderer<String> getFooterRenderer() {
- return footerRenderer;
- }
-
- /**
- * Sets the renderer that renders footer cells.
- *
- * @param renderer
- * a non-{@code null} renderer for footer cells.
- * @throws IllegalArgumentException
- * if {@code renderer} is {@code null}
- */
- public void setFooterRenderer(Renderer<String> renderer) {
- if (renderer == null) {
- throw new IllegalArgumentException("Renderer cannot be null.");
- }
- this.footerRenderer = renderer;
- grid.refreshFooter();
- }
-}
+++ /dev/null
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.client.ui.grid;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A column group row represents an additional header or footer row in a
- * {@link Grid}. A column group row contains {@link ColumnGroup ColumnGroups}.
- *
- * @param <T>
- * Row type
- * @since
- * @author Vaadin Ltd
- */
-@Deprecated
-public class ColumnGroupRow<T> {
-
- /**
- * The column groups in this row
- */
- private List<ColumnGroup<T>> groups = new ArrayList<ColumnGroup<T>>();
-
- /**
- * The grid associated with the column row
- */
- private final Grid<T> grid;
-
- /**
- * Is the header shown
- */
- private boolean headerVisible = true;
-
- /**
- * Is the footer shown
- */
- private boolean footerVisible = false;
-
- /**
- * Constructs a new column group row
- *
- * @param grid
- * Grid associated with this column
- *
- */
- ColumnGroupRow(Grid<T> grid) {
- this.grid = grid;
- }
-
- /**
- * Adds a new group of columns to the column group row.
- *
- * @param columns
- * The columns that should be added to the group
- * @return the added columns as a column group
- * @throws IllegalArgumentException
- * if any of {@code columns} already belongs to a group, or if
- * {@code columns} or any of its elements are {@code null}
- */
- public ColumnGroup<T> addGroup(GridColumn<?, T>... columns)
- throws IllegalArgumentException {
-
- if (columns == null) {
- throw new IllegalArgumentException("columns may not be null");
- }
-
- for (GridColumn<?, T> column : columns) {
- if (column == null) {
- throw new IllegalArgumentException(
- "none of the given columns may be null");
- }
-
- if (isColumnGrouped(column)) {
- throw new IllegalArgumentException("Column "
- + String.valueOf(column.getHeaderCaption())
- + " already belongs to another group.");
- }
- }
-
- validateNewGroupProperties(Arrays.asList(columns));
-
- ColumnGroup<T> group = new ColumnGroup<T>(grid, Arrays.asList(columns));
- groups.add(group);
- grid.refreshHeader();
- grid.refreshFooter();
- return group;
- }
-
- private void validateNewGroupProperties(Collection<GridColumn<?, T>> columns) {
-
- int rowIndex = grid.getColumnGroupRows().indexOf(this);
- int parentRowIndex = rowIndex - 1;
-
- // Get the parent row of this row.
- ColumnGroupRow<T> parentRow = null;
- if (parentRowIndex > -1) {
- parentRow = grid.getColumnGroupRows().get(parentRowIndex);
- }
-
- if (parentRow == null) {
- // A parentless row is always valid and is usually the first row
- // added to the grid
- return;
- }
-
- for (GridColumn<?, T> column : columns) {
- if (parentRow.hasColumnBeenGrouped(column)) {
- /*
- * If a property has been grouped in the parent row then all of
- * the properties in the parent group also needs to be included
- * in the child group for the groups to be valid
- */
- ColumnGroup parentGroup = parentRow.getGroupForColumn(column);
- if (!columns.containsAll(parentGroup.getColumns())) {
- throw new IllegalArgumentException(
- "Grouped properties overlaps previous grouping bounderies");
- }
- }
- }
- }
-
- private boolean hasColumnBeenGrouped(GridColumn<?, T> column) {
- return getGroupForColumn(column) != null;
- }
-
- private ColumnGroup<T> getGroupForColumn(GridColumn<?, T> column) {
- for (ColumnGroup<T> group : groups) {
- if (group.getColumns().contains(column)) {
- return group;
- }
- }
- return null;
- }
-
- /**
- * Add a new group to the row by using other already created groups.
- *
- * @param groups
- * the column groups to be further grouped together
- * @return the added column groups as a new single group
- * @throws IllegalArgumentException
- * if any column group already belongs to another group, or if
- * {@code groups} or any of its elements are null
- */
- public ColumnGroup<T> addGroup(ColumnGroup<T>... groups)
- throws IllegalArgumentException {
-
- if (groups == null) {
- throw new IllegalArgumentException("groups may not be null");
- }
-
- Set<GridColumn<?, T>> columns = new HashSet<GridColumn<?, T>>();
- for (ColumnGroup<T> group : groups) {
- if (group == null) {
- throw new IllegalArgumentException(
- "none of the given group may be null");
- }
-
- columns.addAll(group.getColumns());
- }
-
- validateNewGroupProperties(columns);
-
- ColumnGroup<T> group = new ColumnGroup<T>(grid, columns);
- this.groups.add(group);
- grid.refreshHeader();
- grid.refreshFooter();
- return group;
- }
-
- /**
- * Removes a group from the row.
- * <p>
- * <em>Note:</em> this removes only a group in the immediate hierarchy
- * level, and does not search recursively.
- *
- * @param group
- * The group to remove
- * @return {@code true} iff the group was successfully removed
- */
- public boolean removeGroup(ColumnGroup<T> group) {
- boolean removed = groups.remove(group);
- if (removed) {
- grid.refreshHeader();
- grid.refreshFooter();
- }
- return removed;
- }
-
- /**
- * Gets the groups in this row.
- *
- * @return an unmodifiable list of groups in this row
- */
- public List<ColumnGroup<T>> getGroups() {
- return Collections.unmodifiableList(groups);
- }
-
- /**
- * Checks whether the header is visible for the row group or not.
- *
- * @return <code>true</code> iff the header is visible
- */
- public boolean isHeaderVisible() {
- return headerVisible;
- }
-
- /**
- * Sets the visibility of the row group's header.
- *
- * @param visible
- * {@code true} iff the header should be shown
- */
- public void setHeaderVisible(boolean visible) {
- headerVisible = visible;
- grid.refreshHeader();
- }
-
- /**
- * Checks whether the footer is visible for the row or not.
- *
- * @return <code>true</code> iff footer is visible
- */
- public boolean isFooterVisible() {
- return footerVisible;
- }
-
- /**
- * Sets the visibility of the row group's footer.
- *
- * @param visible
- * {@code true} iff the footer should be shown
- */
- public void setFooterVisible(boolean visible) {
- footerVisible = visible;
- grid.refreshFooter();
- }
-
- /**
- * Iterates through all the column groups and checks if the columns already
- * has been added to a group.
- */
- private boolean isColumnGrouped(GridColumn<?, T> column) {
- for (ColumnGroup<T> group : groups) {
- if (group.getColumns().contains(column)) {
- return true;
- }
- }
- return false;
- }
-}
*/
private DataSource<T> dataSource;
- /**
- * The column groups rows added to the grid
- */
- @Deprecated
- private final List<ColumnGroupRow<T>> columnGroupRows = new ArrayList<ColumnGroupRow<T>>();
-
- /**
- * Are the headers for the columns visible
- */
- @Deprecated
- private boolean columnHeadersVisible = true;
-
- /**
- * Are the footers for the columns visible
- */
- @Deprecated
- private boolean columnFootersVisible = false;
-
/**
* The last column frozen counter from the left
*/
}
}
- /**
- * Base class for header / footer escalator updater
- */
- @Deprecated
- protected abstract class HeaderFooterEscalatorUpdater implements
- EscalatorUpdater {
-
- /**
- * The row container which contains the header or footer rows
- */
- private RowContainer rows;
-
- /**
- * Should the index be counted from 0-> or 0<-
- */
- private boolean inverted;
-
- /**
- * Constructs an updater for updating a header / footer
- *
- * @param rows
- * The row container
- * @param inverted
- * Should index counting be inverted
- */
- public HeaderFooterEscalatorUpdater(RowContainer rows, boolean inverted) {
- this.rows = rows;
- this.inverted = inverted;
- }
-
- /**
- * Gets the header/footer caption value
- *
- * @param column
- * The column to get the value for.
- *
- * @return The value that should be rendered for the column caption
- */
- public abstract String getColumnValue(GridColumn<?, T> column);
-
- /**
- * Gets the group caption value
- *
- * @param group
- * The group for with the caption value should be returned
- * @return The value that should be rendered for the column caption
- */
- public abstract String getGroupValue(ColumnGroup<T> group);
-
- /**
- * Is the row visible in the header/footer
- *
- * @param row
- * the row to check
- *
- * @return <code>true</code> if the row should be visible
- */
- public abstract boolean isRowVisible(ColumnGroupRow<T> row);
-
- /**
- * Should the first row be visible
- *
- * @return <code>true</code> if the first row should be visible
- */
- public abstract boolean firstRowIsVisible();
-
- /**
- * The renderer that renders the cell
- *
- * @param column
- * The column for which the cell should be rendered
- *
- * @return renderer used for rendering
- */
- public abstract Renderer<String> getRenderer(GridColumn<?, T> column);
-
- /**
- * The renderer that renders the cell for column groups
- *
- * @param group
- * The group that should be rendered
- * @return renderer used for rendering
- */
- public abstract Renderer<String> getGroupRenderer(ColumnGroup<T> group);
-
- @Override
- public void update(Row row, Iterable<FlyweightCell> cellsToUpdate) {
-
- int rowIndex;
- if (inverted) {
- rowIndex = rows.getRowCount() - row.getRow() - 1;
- } else {
- rowIndex = row.getRow();
- }
- RowContainer container = escalator.findRowContainer(row
- .getElement());
-
- if (firstRowIsVisible() && rowIndex == 0) {
- // column headers
- for (FlyweightCell cell : cellsToUpdate) {
- GridColumn<?, T> column = getColumnFromVisibleIndex(cell
- .getColumn());
- if (column != null) {
- getRenderer(column)
- .render(cell, getColumnValue(column));
- }
-
- activeCellHandler.updateActiveCellStyle(cell, container);
- }
-
- } else if (columnGroupRows.size() > 0) {
- // Adjust for headers
- if (firstRowIsVisible()) {
- rowIndex--;
- }
-
- // Adjust for previous invisible header rows
- ColumnGroupRow<T> groupRow = null;
- for (int i = 0, realIndex = 0; i < columnGroupRows.size(); i++) {
- groupRow = columnGroupRows.get(i);
- if (isRowVisible(groupRow)) {
- if (realIndex == rowIndex) {
- rowIndex = realIndex;
- break;
- }
- realIndex++;
- }
- }
-
- assert groupRow != null;
-
- for (FlyweightCell cell : cellsToUpdate) {
- GridColumn<?, T> column = getColumnFromVisibleIndex(cell
- .getColumn());
- ColumnGroup<T> group = getGroupForColumn(groupRow, column);
- Element cellElement = cell.getElement();
-
- if (group != null) {
- getGroupRenderer(group).render(cell,
- getGroupValue(group));
- cell.setColSpan(group.getColumns().size());
- } else {
- // Cells are reused
- cellElement.setInnerHTML(null);
- cell.setColSpan(1);
-
- activeCellHandler
- .updateActiveCellStyle(cell, container);
- }
- }
- }
- }
-
- @Override
- public void preAttach(Row row, Iterable<FlyweightCell> cellsToAttach) {
- }
-
- @Override
- public void postAttach(Row row, Iterable<FlyweightCell> attachedCells) {
- }
-
- @Override
- public void preDetach(Row row, Iterable<FlyweightCell> cellsToDetach) {
- }
-
- @Override
- public void postDetach(Row row, Iterable<FlyweightCell> detachedCells) {
- }
- }
-
protected class StaticSectionUpdater implements EscalatorUpdater {
private GridStaticSection<?> section;
return columns.get(index);
}
- /**
- * Set the column headers visible.
- *
- * <p>
- * A column header is a single cell header on top of each column reserved
- * for a specific header for that column. The column header can be set by
- * {@link GridColumn#setHeaderCaption(String)} and column headers cannot be
- * merged with other column headers.
- * </p>
- *
- * <p>
- * All column headers occupy the first header row of the grid. If you do not
- * wish to show the column headers in the grid you should hide the row by
- * setting visibility of the header row to <code>false</code>.
- * </p>
- *
- * <p>
- * If you want to merge the column headers into groups you can use
- * {@link ColumnGroupRow}s to group columns together and give them a common
- * header. See {@link #addColumnGroupRow()} for details.
- * </p>
- *
- * <p>
- * The header row is by default visible.
- * </p>
- *
- * @param visible
- * <code>true</code> if header rows should be visible
- */
- @Deprecated
- public void setColumnHeadersVisible(boolean visible) {
- if (visible == isColumnHeadersVisible()) {
- return;
- }
- columnHeadersVisible = visible;
- refreshHeader();
- }
-
- /**
- * Are the column headers visible
- *
- * @return <code>true</code> if they are visible
- */
- @Deprecated
- public boolean isColumnHeadersVisible() {
- return columnHeadersVisible;
- }
-
- /**
- * Set the column footers visible.
- *
- * <p>
- * A column footer is a single cell footer below of each column reserved for
- * a specific footer for that column. The column footer can be set by
- * {@link GridColumn#setFooterCaption(String)} and column footers cannot be
- * merged with other column footers.
- * </p>
- *
- * <p>
- * All column footers occupy the first footer row of the grid. If you do not
- * wish to show the column footers in the grid you should hide the row by
- * setting visibility of the footer row to <code>false</code>.
- * </p>
- *
- * <p>
- * If you want to merge the column footers into groups you can use
- * {@link ColumnGroupRow}s to group columns together and give them a common
- * footer. See {@link #addColumnGroupRow()} for details.
- * </p>
- *
- * <p>
- * The footer row is by default hidden.
- * </p>
- *
- * @param visible
- * <code>true</code> if the footer row should be visible
- */
- @Deprecated
- public void setColumnFootersVisible(boolean visible) {
- if (visible == isColumnFootersVisible()) {
- return;
- }
- columnFootersVisible = visible;
- refreshFooter();
- }
-
- /**
- * Are the column footers visible
- *
- * @return <code>true</code> if they are visible
- *
- */
- @Deprecated
- public boolean isColumnFootersVisible() {
- return columnFootersVisible;
- }
-
- /**
- * Adds a new column group row to the grid.
- *
- * <p>
- * Column group rows are rendered in the header and footer of the grid.
- * Column group rows are made up of column groups which groups together
- * columns for adding a common auxiliary header or footer for the columns.
- * </p>
- *
- * Example usage:
- *
- * <pre>
- * // Add a new column group row to the grid
- * ColumnGroupRow row = grid.addColumnGroupRow();
- *
- * // Group "Column1" and "Column2" together to form a header in the row
- * ColumnGroup column12 = row.addGroup("Column1", "Column2");
- *
- * // Set a common header for "Column1" and "Column2"
- * column12.setHeader("Column 1&2");
- *
- * // Set a common footer for "Column1" and "Column2"
- * column12.setFooter("Column 1&2");
- * </pre>
- *
- * @return a column group row instance you can use to add column groups
- */
- @Deprecated
- public ColumnGroupRow<T> addColumnGroupRow() {
- ColumnGroupRow<T> row = new ColumnGroupRow<T>(this);
- columnGroupRows.add(row);
- refreshHeader();
- refreshFooter();
- return row;
- }
-
- /**
- * Adds a new column group row to the grid at a specific index.
- *
- * @see #addColumnGroupRow() {@link Grid#addColumnGroupRow()} for example
- * usage
- *
- * @param rowIndex
- * the index where the column group row should be added
- * @return a column group row instance you can use to add column groups
- */
- @Deprecated
- public ColumnGroupRow<T> addColumnGroupRow(int rowIndex) {
- ColumnGroupRow<T> row = new ColumnGroupRow<T>(this);
- columnGroupRows.add(rowIndex, row);
- refreshHeader();
- refreshFooter();
- return row;
- }
-
- /**
- * Removes a column group row
- *
- * @param row
- * The row to remove
- */
- @Deprecated
- public void removeColumnGroupRow(ColumnGroupRow<T> row) {
- columnGroupRows.remove(row);
- refreshHeader();
- refreshFooter();
- }
-
- /**
- * Get the column group rows
- *
- * @return a unmodifiable list of column group rows
- *
- */
- @Deprecated
- public List<ColumnGroupRow<T>> getColumnGroupRows() {
- return Collections.unmodifiableList(new ArrayList<ColumnGroupRow<T>>(
- columnGroupRows));
- }
-
- /**
- * Returns the column group for a row and column
- *
- * @param row
- * The row of the column
- * @param column
- * the column to get the group for
- * @return A column group for the row and column or <code>null</code> if not
- * found.
- */
- @Deprecated
- private ColumnGroup<T> getGroupForColumn(ColumnGroupRow<T> row,
- GridColumn<?, T> column) {
- for (ColumnGroup<T> group : row.getGroups()) {
- List<GridColumn<?, T>> columns = group.getColumns();
- if (columns.contains(column)) {
- return group;
- }
- }
- return null;
- }
-
/**
* Returns the header section of this grid. The default header contains a
* single row displaying the column captions.
import com.vaadin.client.ui.grid.sort.SortEventHandler;
import com.vaadin.client.ui.grid.sort.SortOrder;
import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.grid.ColumnGroupRowState;
-import com.vaadin.shared.ui.grid.ColumnGroupState;
import com.vaadin.shared.ui.grid.GridClientRpc;
import com.vaadin.shared.ui.grid.GridColumnState;
import com.vaadin.shared.ui.grid.GridServerRpc;
updateSectionFromState(getWidget().getFooter(), getState().footer);
}
- // Column row groups
- if (stateChangeEvent.hasPropertyChanged("columnGroupRows")) {
- updateColumnGroupsFromStateChangeEvent();
- }
-
if (stateChangeEvent.hasPropertyChanged("lastFrozenColumnId")) {
String frozenColId = getState().lastFrozenColumnId;
if (frozenColId != null) {
}
}
- /**
- * Updates the column groups from a state change
- */
- private void updateColumnGroupsFromStateChangeEvent() {
-
- // FIXME When something changes the header/footer rows will be
- // re-created. At some point we should optimize this so partial updates
- // can be made on the header/footer.
- for (ColumnGroupRow<JSONObject> row : getWidget().getColumnGroupRows()) {
- getWidget().removeColumnGroupRow(row);
- }
-
- for (ColumnGroupRowState rowState : getState().columnGroupRows) {
- ColumnGroupRow<JSONObject> row = getWidget().addColumnGroupRow();
- row.setFooterVisible(rowState.footerVisible);
- row.setHeaderVisible(rowState.headerVisible);
-
- for (ColumnGroupState groupState : rowState.groups) {
- List<GridColumn<Object, JSONObject>> columns = new ArrayList<GridColumn<Object, JSONObject>>();
- for (String columnId : groupState.columns) {
- CustomGridColumn column = columnIdToColumn.get(columnId);
- columns.add(column);
- }
- @SuppressWarnings("unchecked")
- final GridColumn<?, JSONObject>[] gridColumns = columns
- .toArray(new GridColumn[columns.size()]);
- ColumnGroup<JSONObject> group = row.addGroup(gridColumns);
- group.setFooterCaption(groupState.footer);
- group.setHeaderCaption(groupState.header);
- }
- }
- }
-
public void setDataSource(RpcDataSource dataSource) {
this.dataSource = dataSource;
getWidget().setDataSource(this.dataSource);