diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-10-18 17:31:37 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2016-10-19 11:32:25 +0000 |
commit | 5bc6d1802e2da2c600fb8559474e86ec1b3b4bf7 (patch) | |
tree | a94fe6dfff1074069633f34ad8788f28a9730016 /server/src/main/java/com/vaadin | |
parent | 5fc90cda4c27402414fd31c1b87194968321a2fa (diff) | |
download | vaadin-framework-5bc6d1802e2da2c600fb8559474e86ec1b3b4bf7.tar.gz vaadin-framework-5bc6d1802e2da2c600fb8559474e86ec1b3b4bf7.zip |
Implement basic footer support for Grid
Change-Id: I3db51521320767a28bc3acd9586b1453764a15bc
Diffstat (limited to 'server/src/main/java/com/vaadin')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 189 | ||||
-rw-r--r-- | server/src/main/java/com/vaadin/ui/components/grid/Footer.java | 70 |
2 files changed, 259 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 843db35e16..b904565a64 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -54,6 +54,8 @@ import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.shared.ui.grid.SectionState; import com.vaadin.shared.util.SharedUtil; +import com.vaadin.ui.Grid.FooterRow; +import com.vaadin.ui.components.grid.Footer; import com.vaadin.ui.components.grid.Header; import com.vaadin.ui.components.grid.Header.Row; import com.vaadin.ui.renderers.AbstractRenderer; @@ -1562,6 +1564,57 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { public void setText(String text); } + /** + * A footer row in a Grid. + */ + public interface FooterRow extends Serializable { + + /** + * Returns the cell on this row corresponding to the given column id. + * + * @param columnId + * the id of the column whose footer cell to get, not null + * @return the footer cell + * @throws IllegalArgumentException + * if there is no such column in the grid + */ + public FooterCell getCell(String columnId); + + /** + * Returns the cell on this row corresponding to the given column. + * + * @param column + * the column whose footer cell to get, not null + * @return the footer cell + * @throws IllegalArgumentException + * if there is no such column in the grid + */ + public default FooterCell getCell(Column<?, ?> column) { + return getCell(column.getId()); + } + } + + /** + * An individual cell on a Grid footer row. + */ + public interface FooterCell extends Serializable { + + /** + * Returns the textual caption of this cell. + * + * @return the footer caption + */ + public String getText(); + + /** + * Sets the textual caption of this cell. + * + * @param text + * the footer caption to set, not null + */ + public void setText(String text); + } + private class HeaderImpl extends Header { @Override @@ -1575,6 +1628,19 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { } }; + private class FooterImpl extends Footer { + + @Override + protected SectionState getState(boolean markAsDirty) { + return Grid.this.getState(markAsDirty).footer; + } + + @Override + protected Collection<Column<T, ?>> getColumns() { + return Grid.this.getColumns(); + } + }; + private Set<Column<T, ?>> columnSet = new LinkedHashSet<>(); private Map<String, Column<T, ?>> columnKeys = new HashMap<>(); @@ -1585,6 +1651,7 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { private DescriptionGenerator<T> descriptionGenerator; private Header header = new HeaderImpl(); + private Footer footer = new FooterImpl(); private int counter = 0; @@ -2156,6 +2223,128 @@ public class Grid<T> extends AbstractSingleSelect<T> implements HasComponents { } /** + * Returns the footer row at the given index. + * + * @param index + * the index of the row, where the topmost row has index zero + * @return the footer row at the index + * @throws IndexOutOfBoundsException + * if {@code rowIndex < 0 || rowIndex >= getFooterRowCount()} + */ + public FooterRow getFooterRow(int index) { + return getFooter().getRow(index); + } + + /** + * Gets the number of rows in the footer section. + * + * @return the number of footer rows + */ + public int getFooterRowCount() { + return getFooter().getRowCount(); + } + + /** + * Inserts a new row at the given position to the footer section. Shifts the + * row currently at that position and any subsequent rows down (adds one to + * their indices). Inserting at {@link #getFooterRowCount()} appends the row + * at the bottom of the footer. + * + * @param index + * the index at which to insert the row, where the topmost row + * has index zero + * @return the inserted footer row + * + * @throws IndexOutOfBoundsException + * if {@code rowIndex < 0 || rowIndex > getFooterRowCount()} + * + * @see #appendFooterRow() + * @see #prependFooterRow() + * @see #removeFooterRow(FooterRow) + * @see #removeFooterRow(int) + */ + public FooterRow addFooterRowAt(int index) { + return getFooter().addRowAt(index); + } + + /** + * Adds a new row at the bottom of the footer section. + * + * @return the appended footer row + * + * @see #prependFooterRow() + * @see #addFooterRowAt(int) + * @see #removeFooterRow(FooterRow) + * @see #removeFooterRow(int) + */ + public FooterRow appendFooterRow() { + return addFooterRowAt(getFooterRowCount()); + } + + /** + * Adds a new row at the top of the footer section. + * + * @return the prepended footer row + * + * @see #appendFooterRow() + * @see #addFooterRowAt(int) + * @see #removeFooterRow(FooterRow) + * @see #removeFooterRow(int) + */ + public FooterRow prependFooterRow() { + return addFooterRowAt(0); + } + + /** + * Removes the given row from the footer section. Removing a default row + * sets the Grid to have no default row. + * + * @param row + * the footer row to be removed, not null + * + * @throws IllegalArgumentException + * if the footer does not contain the row + * + * @see #removeFooterRow(int) + * @see #addFooterRowAt(int) + * @see #appendFooterRow() + * @see #prependFooterRow() + */ + public void removeFooterRow(FooterRow row) { + getFooter().removeRow(row); + } + + /** + * Removes the row at the given position from the footer section. + * + * @param index + * the index of the row to remove, where the topmost row has + * index zero + * + * @throws IndexOutOfBoundsException + * if {@code index < 0 || index >= getFooterRowCount()} + * + * @see #removeFooterRow(FooterRow) + * @see #addFooterRowAt(int) + * @see #appendFooterRow() + * @see #prependFooterRow() + */ + public void removeFooterRow(int index) { + getFooter().removeRow(index); + } + + /** + * Returns the footer section of this grid. The default footer contains a + * single row, set as the {@linkplain #setDefaultFooterRow(FooterRow) + * default row}. + * + * @return the footer section + */ + protected Footer getFooter() { + return footer; + } + + /** * Registers a new column reorder listener. * * @param listener diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Footer.java b/server/src/main/java/com/vaadin/ui/components/grid/Footer.java new file mode 100644 index 0000000000..9423e2d842 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/Footer.java @@ -0,0 +1,70 @@ +/* + * Copyright 2000-2016 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.ui.components.grid; + +import com.vaadin.ui.Grid; + +/** + * Represents the footer section of a Grid. + * + * @author Vaadin Ltd. + * + * @since 8.0 + */ +public abstract class Footer extends StaticSection<Footer.Row> { + + /** + * A row in a Grid Footer. + */ + public class Row extends StaticSection.StaticRow<Row.Cell> + implements Grid.FooterRow { + + /** + * A cell in a Grid footer row. + */ + public class Cell extends StaticSection.StaticCell + implements Grid.FooterCell { + /** + * Creates a new footer cell. + */ + protected Cell() { + super(Row.this); + } + } + + /** + * Creates a new footer row. + */ + protected Row() { + super(Footer.this); + } + + @Override + protected Cell createCell() { + return new Cell(); + } + + @Override + protected String getCellTagName() { + return "td"; + } + } + + @Override + public Row createRow() { + return new Row(); + } +} |