From 536139870943d684907e0d9b93bbda60582b340d Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Thu, 15 Dec 2016 15:57:07 +0200 Subject: [PATCH] Extract interfaces from Grid (#8005) * Extract interfaces from Grid Closes vaadin/framework8-issues#566 --- server/src/main/java/com/vaadin/ui/Grid.java | 661 +----------------- .../grid/AbstractSelectionModel.java | 1 - .../grid/ColumnReorderListener.java | 38 + .../components/grid/ColumnResizeListener.java | 38 + .../grid/ColumnVisibilityChangeListener.java | 38 + .../components/grid/DescriptionGenerator.java | 32 + .../ui/components/grid/DetailsGenerator.java | 33 + .../com/vaadin/ui/components/grid/Editor.java | 158 +++++ .../components/grid/EditorErrorGenerator.java | 52 ++ .../vaadin/ui/components/grid/EditorImpl.java | 2 - .../com/vaadin/ui/components/grid/Footer.java | 18 +- .../vaadin/ui/components/grid/FooterCell.java | 90 +++ .../vaadin/ui/components/grid/FooterRow.java | 82 +++ .../components/grid/GridSelectionModel.java | 46 ++ .../com/vaadin/ui/components/grid/Header.java | 17 +- .../vaadin/ui/components/grid/HeaderCell.java | 90 +++ .../vaadin/ui/components/grid/HeaderRow.java | 83 +++ .../ui/components/grid/ItemClickListener.java | 45 ++ .../components/grid/MultiSelectionModel.java | 68 ++ .../grid/MultiSelectionModelImpl.java | 3 +- .../ui/components/grid/NoSelectionModel.java | 1 - .../components/grid/SingleSelectionModel.java | 68 ++ .../grid/SingleSelectionModelImpl.java | 1 - .../ui/components/grid/SortOrderProvider.java | 48 ++ .../data/GridAsSingleSelectInBinderTest.java | 2 +- .../grid/GridMultiSelectionModelTest.java | 17 +- .../grid/GridNoSelectionModelTest.java | 2 +- .../grid/GridSingleSelectionModelTest.java | 2 +- .../component/grid/GridDeclarativeTest.java | 8 +- .../component/grid/GridDefaultHeaderTest.java | 2 +- .../component/grid/GridHeaderFooterTest.java | 2 +- .../components/grid/basics/GridBasics.java | 14 +- 32 files changed, 1069 insertions(+), 693 deletions(-) create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/Editor.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java create mode 100644 server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index 9f4f00a114..bb48ac56a4 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -33,7 +33,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.BiFunction; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collectors; @@ -44,9 +43,7 @@ import org.jsoup.nodes.Element; import org.jsoup.select.Elements; import com.vaadin.data.Binder; -import com.vaadin.data.BinderValidationStatus; import com.vaadin.data.Listing; -import com.vaadin.data.SelectionModel; import com.vaadin.data.ValueProvider; import com.vaadin.data.provider.DataCommunicator; import com.vaadin.data.provider.DataProvider; @@ -54,7 +51,6 @@ import com.vaadin.data.provider.Query; import com.vaadin.data.provider.SortOrder; import com.vaadin.event.ConnectorEvent; import com.vaadin.event.ContextClickEvent; -import com.vaadin.event.SerializableEventListener; import com.vaadin.event.selection.MultiSelectionListener; import com.vaadin.event.selection.SelectionListener; import com.vaadin.event.selection.SingleSelectionListener; @@ -78,17 +74,30 @@ import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.shared.ui.grid.HeightMode; import com.vaadin.shared.ui.grid.SectionState; -import com.vaadin.ui.Grid.FooterRow; import com.vaadin.ui.Grid.SelectionMode; -import com.vaadin.ui.components.grid.AbstractSelectionModel; +import com.vaadin.ui.components.grid.ColumnReorderListener; +import com.vaadin.ui.components.grid.ColumnResizeListener; +import com.vaadin.ui.components.grid.ColumnVisibilityChangeListener; +import com.vaadin.ui.components.grid.DescriptionGenerator; +import com.vaadin.ui.components.grid.DetailsGenerator; +import com.vaadin.ui.components.grid.Editor; import com.vaadin.ui.components.grid.EditorComponentGenerator; import com.vaadin.ui.components.grid.EditorImpl; import com.vaadin.ui.components.grid.Footer; +import com.vaadin.ui.components.grid.FooterCell; +import com.vaadin.ui.components.grid.FooterRow; +import com.vaadin.ui.components.grid.GridSelectionModel; import com.vaadin.ui.components.grid.Header; import com.vaadin.ui.components.grid.Header.Row; +import com.vaadin.ui.components.grid.HeaderCell; +import com.vaadin.ui.components.grid.HeaderRow; +import com.vaadin.ui.components.grid.ItemClickListener; +import com.vaadin.ui.components.grid.MultiSelectionModel; import com.vaadin.ui.components.grid.MultiSelectionModelImpl; import com.vaadin.ui.components.grid.NoSelectionModel; +import com.vaadin.ui.components.grid.SingleSelectionModel; import com.vaadin.ui.components.grid.SingleSelectionModelImpl; +import com.vaadin.ui.components.grid.SortOrderProvider; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignException; @@ -135,21 +144,6 @@ public class Grid extends AbstractListing "columnVisibilityChanged", ColumnVisibilityChangeEvent.class); - /** - * An event listener for column reorder events in the Grid. - */ - @FunctionalInterface - public interface ColumnReorderListener extends Serializable { - - /** - * Called when the columns of the grid have been reordered. - * - * @param event - * An event providing more information - */ - void columnReorder(ColumnReorderEvent event); - } - /** * Selection mode representing the built-in selection models in grid. *

@@ -209,157 +203,6 @@ public class Grid extends AbstractListing protected abstract GridSelectionModel createModel(); } - /** - * The server-side interface that controls Grid's selection state. - * SelectionModel should extend {@link AbstractGridExtension}. - *

- * - * @param - * the grid bean type - * @see AbstractSelectionModel - * @see SingleSelectionModel - * @see MultiSelectionModel - */ - public interface GridSelectionModel - extends SelectionModel, Extension { - - /** - * Removes this selection model from the grid. - *

- * Must call super {@link Extension#remove()} to detach the extension, - * and fire an selection change event for the selection model (with an - * empty selection). - */ - @Override - public void remove(); - } - - /** - * Single selection model interface for Grid. - * - * @param - * the type of items in grid - */ - public interface SingleSelectionModel extends GridSelectionModel, - com.vaadin.data.SelectionModel.Single { - - /** - * Gets a wrapper to use this single selection model as a single select - * in {@link Binder}. - * - * @return the single select wrapper - */ - SingleSelect asSingleSelect(); - - /** - * {@inheritDoc} - *

- * Use {@link #addSingleSelectionListener(SingleSelectionListener)} for - * more specific single selection event. - * - * @see #addSingleSelectionListener(SingleSelectionListener) - */ - @Override - public default Registration addSelectionListener( - SelectionListener listener) { - return addSingleSelectionListener(e -> listener.selectionChange(e)); - } - - /** - * Adds a single selection listener that is called when the value of - * this select is changed either by the user or programmatically. - * - * @param listener - * the value change listener, not {@code null} - * @return a registration for the listener - */ - public Registration addSingleSelectionListener( - SingleSelectionListener listener); - } - - /** - * Multiselection model interface for Grid. - * - * @param - * the type of items in grid - */ - public interface MultiSelectionModel extends GridSelectionModel, - com.vaadin.data.SelectionModel.Multi { - - /** - * Gets a wrapper to use this multiselection model as a multiselect in - * {@link Binder}. - * - * @return the multiselect wrapper - */ - MultiSelect asMultiSelect(); - - /** - * {@inheritDoc} - *

- * Use {@link #addMultiSelectionListener(MultiSelectionListener)} for - * more specific event on multiselection. - * - * @see #addMultiSelectionListener(MultiSelectionListener) - */ - @Override - public default Registration addSelectionListener( - SelectionListener listener) { - return addMultiSelectionListener(e -> listener.selectionChange(e)); - } - - /** - * Adds a selection listener that will be called when the selection is - * changed either by the user or programmatically. - * - * @param listener - * the value change listener, not {@code null} - * @return a registration for the listener - */ - public Registration addMultiSelectionListener( - MultiSelectionListener listener); - } - - /** - * An event listener for column resize events in the Grid. - */ - @FunctionalInterface - public interface ColumnResizeListener extends Serializable { - - /** - * Called when the columns of the grid have been resized. - * - * @param event - * An event providing more information - */ - void columnResize(ColumnResizeEvent event); - } - - /** - * Generates the sort orders when rows are sorted by a column. - * - * @see Column#setSortOrderProvider - * - * @since 8.0 - * @author Vaadin Ltd - */ - @FunctionalInterface - public interface SortOrderProvider extends - SerializableFunction>> { - - /** - * Generates the sort orders when rows are sorted by a column. - * - * @param sortDirection - * desired sort direction - * - * @return sort information - */ - @Override - public Stream> apply(SortDirection sortDirection); - - } - /** * An event that is fired when the columns are reordered. */ @@ -499,27 +342,6 @@ public class Grid extends AbstractListing } } - /** - * A listener for item click events. - * - * @param - * the grid bean type - * - * @see ItemClick - * @see Registration - */ - @FunctionalInterface - public interface ItemClickListener extends SerializableEventListener { - /** - * Invoked when this listener receives a item click event from a Grid to - * which it has been added. - * - * @param event - * the received event, not null - */ - public void itemClick(ItemClick event); - } - /** * ContextClickEvent for the Grid Component. * @@ -604,22 +426,6 @@ public class Grid extends AbstractListing } } - /** - * An event listener for column visibility change events in the Grid. - * - * @since 7.5.0 - */ - @FunctionalInterface - public interface ColumnVisibilityChangeListener extends Serializable { - - /** - * Called when a column has become hidden or unhidden. - * - * @param event - */ - void columnVisibilityChanged(ColumnVisibilityChangeEvent event); - } - /** * An event that is fired when a column's visibility changes. * @@ -684,28 +490,6 @@ public class Grid extends AbstractListing } } - /** - * A callback interface for generating description texts for an item. - * - * @param - * the grid bean type - */ - @FunctionalInterface - public interface DescriptionGenerator - extends SerializableFunction { - } - - /** - * A callback interface for generating details for a particular row in Grid. - * - * @param - * the grid bean type - */ - @FunctionalInterface - public interface DetailsGenerator - extends SerializableFunction { - } - /** * A helper base class for creating extensions for the Grid component. * @@ -1952,421 +1736,6 @@ public class Grid extends AbstractListing } } - /** - * A header row in a Grid. - */ - public interface HeaderRow extends Serializable { - - /** - * Returns the cell on this row corresponding to the given column id. - * - * @param columnId - * the id of the column whose header cell to get, not null - * @return the header cell - * @throws IllegalArgumentException - * if there is no such column in the grid - */ - public HeaderCell getCell(String columnId); - - /** - * Returns the cell on this row corresponding to the given column. - * - * @param column - * the column whose header cell to get, not null - * @return the header cell - * @throws IllegalArgumentException - * if there is no such column in the grid - */ - public HeaderCell getCell(Column column); - - /** - * Merges column cells in the row. Original cells are hidden, and new - * merged cell is shown instead. The cell has a width of all merged - * cells together, inherits styles of the first merged cell but has - * empty caption. - * - * @param cellsToMerge - * the cells which should be merged. The cells should not be - * merged to any other cell set. - * @return the remaining visible cell after the merge - * - * @see #join(Grid.HeaderCell...) - * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption - */ - HeaderCell join(Set cellsToMerge); - - /** - * Merges column cells in the row. Original cells are hidden, and new - * merged cell is shown instead. The cell has a width of all merged - * cells together, inherits styles of the first merged cell but has - * empty caption. - * - * @param cellsToMerge - * the cells which should be merged. The cells should not be - * merged to any other cell set. - * @return the remaining visible cell after the merge - * - * @see #join(Set) - * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption - */ - HeaderCell join(HeaderCell... cellsToMerge); - - } - - /** - * An individual cell on a Grid header row. - */ - public interface HeaderCell extends Serializable { - - /** - * Returns the textual caption of this cell. - * - * @return the header caption - */ - public String getText(); - - /** - * Sets the textual caption of this cell. - * - * @param text - * the header caption to set, not null - */ - public void setText(String text); - - /** - * Returns the HTML content displayed in this cell. - * - * @return the html - * - */ - public String getHtml(); - - /** - * Sets the HTML content displayed in this cell. - * - * @param html - * the html to set - */ - public void setHtml(String html); - - /** - * Returns the component displayed in this cell. - * - * @return the component - */ - public Component getComponent(); - - /** - * Sets the component displayed in this cell. - * - * @param component - * the component to set - */ - public void setComponent(Component component); - - /** - * Returns the type of content stored in this cell. - * - * @return cell content type - */ - public GridStaticCellType getCellType(); - - /** - * Gets the column id where this cell is. - * - * @return column id for this cell - */ - public String getColumnId(); - } - - /** - * 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 FooterCell getCell(Column column); - - /** - * Merges column cells in the row. Original cells are hidden, and new - * merged cell is shown instead. The cell has a width of all merged - * cells together, inherits styles of the first merged cell but has - * empty caption. - * - * @param cellsToMerge - * the cells which should be merged. The cells should not be - * merged to any other cell set. - * @return the remaining visible cell after the merge - * - * @see #join(Grid.FooterCell...) - * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption - */ - FooterCell join(Set cellsToMerge); - - /** - * Merges column cells in the row. Original cells are hidden, and new - * merged cell is shown instead. The cell has a width of all merged - * cells together, inherits styles of the first merged cell but has - * empty caption. - * - * @param cellsToMerge - * the cells which should be merged. The cells should not be - * merged to any other cell set. - * @return the remaining visible cell after the merge - * - * @see #join(Set) - * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption - */ - FooterCell join(FooterCell... cellsToMerge); - } - - /** - * 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); - - /** - * Returns the HTML content displayed in this cell. - * - * @return the html - * - */ - public String getHtml(); - - /** - * Sets the HTML content displayed in this cell. - * - * @param html - * the html to set - */ - public void setHtml(String html); - - /** - * Returns the component displayed in this cell. - * - * @return the component - */ - public Component getComponent(); - - /** - * Sets the component displayed in this cell. - * - * @param component - * the component to set - */ - public void setComponent(Component component); - - /** - * Returns the type of content stored in this cell. - * - * @return cell content type - */ - public GridStaticCellType getCellType(); - - /** - * Gets the column id where this cell is. - * - * @return column id for this cell - */ - public String getColumnId(); - } - - /** - * Generator for creating editor validation and conversion error messages. - * - * @param - * the bean type - */ - @FunctionalInterface - public interface EditorErrorGenerator extends Serializable, - BiFunction>, BinderValidationStatus, String> { - - /** - * Generates an error message from given validation status object. - * - * @param fieldToColumn - * the map of failed fields and corresponding columns - * @param status - * the binder status object with all failures - * - * @return error message string - */ - @Override - public String apply(Map> fieldToColumn, - BinderValidationStatus status); - } - - /** - * An editor in a Grid. - * - * @param - */ - public interface Editor extends Serializable { - - /** - * Sets the underlying Binder to this Editor. - * - * @param binder - * the binder for updating editor fields; not {@code null} - * @return this editor - */ - public Editor setBinder(Binder binder); - - /** - * Returns the underlying Binder from Editor. - * - * @return the binder; not {@code null} - */ - public Binder getBinder(); - - /** - * Sets the Editor buffered mode. When the editor is in buffered mode, - * edits are only committed when the user clicks the save button. In - * unbuffered mode valid changes are automatically committed. - * - * @param buffered - * {@code true} if editor should be buffered; {@code false} - * if not - * @return this editor - */ - public Editor setBuffered(boolean buffered); - - /** - * Enables or disabled the Editor. A disabled editor cannot be opened. - * - * @param enabled - * {@code true} if editor should be enabled; {@code false} if - * not - * @return this editor - */ - public Editor setEnabled(boolean enabled); - - /** - * Returns whether Editor is buffered or not. - * - * @see #setBuffered(boolean) - * - * @return {@code true} if editor is buffered; {@code false} if not - */ - public boolean isBuffered(); - - /** - * Returns whether Editor is enabled or not. - * - * @return {@code true} if editor is enabled; {@code false} if not - */ - public boolean isEnabled(); - - /** - * Returns whether Editor is open or not. - * - * @return {@code true} if editor is open; {@code false} if not - */ - public boolean isOpen(); - - /** - * Saves any changes from the Editor fields to the edited bean. - * - * @return {@code true} if save succeeded; {@code false} if not - */ - public boolean save(); - - /** - * Close the editor discarding any unsaved changes. - */ - public void cancel(); - - /** - * Sets the caption of the save button in buffered mode. - * - * @param saveCaption - * the save button caption - * @return this editor - */ - public Editor setSaveCaption(String saveCaption); - - /** - * Sets the caption of the cancel button in buffered mode. - * - * @param cancelCaption - * the cancel button caption - * @return this editor - */ - public Editor setCancelCaption(String cancelCaption); - - /** - * Gets the caption of the save button in buffered mode. - * - * @return the save button caption - */ - public String getSaveCaption(); - - /** - * Gets the caption of the cancel button in buffered mode. - * - * @return the cancel button caption - */ - public String getCancelCaption(); - - /** - * Sets the error message generator for this editor. - *

- * The default message is a concatenation of column field validation - * failures and bean validation failures. - * - * @param errorGenerator - * the function to generate error messages; not {@code null} - * @return this editor - * - * @see EditorErrorGenerator - */ - public Editor setErrorGenerator( - EditorErrorGenerator errorGenerator); - - /** - * Gets the error message generator of this editor. - * - * @return the function that generates error messages; not {@code null} - * - * @see EditorErrorGenerator - */ - public EditorErrorGenerator getErrorGenerator(); - } - private class HeaderImpl extends Header { @Override diff --git a/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java index 58fb6bd12a..0371d2be3a 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java @@ -20,7 +20,6 @@ import com.vaadin.shared.ui.grid.AbstractSelectionModelState; import com.vaadin.ui.AbstractListing; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.AbstractGridExtension; -import com.vaadin.ui.Grid.GridSelectionModel; import elemental.json.JsonObject; diff --git a/server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java b/server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java new file mode 100644 index 0000000000..e946e590a2 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java @@ -0,0 +1,38 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.ui.Grid; + +/** + * An event listener for column reorder events in the Grid. + * + * @author Vaadin Ltd + * @since 8.0 + */ +@FunctionalInterface +public interface ColumnReorderListener extends Serializable { + + /** + * Called when the columns of the grid have been reordered. + * + * @param event + * An event providing more information + */ + void columnReorder(Grid.ColumnReorderEvent event); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java b/server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java new file mode 100644 index 0000000000..04efc67f27 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java @@ -0,0 +1,38 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.ui.Grid; + +/** + * An event listener for column resize events in the Grid. + * + * @author Vaadin Ltd + * @since 8.0 + */ +@FunctionalInterface +public interface ColumnResizeListener extends Serializable { + + /** + * Called when the columns of the grid have been resized. + * + * @param event + * An event providing more information + */ + void columnResize(Grid.ColumnResizeEvent event); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java b/server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java new file mode 100644 index 0000000000..db951e58e4 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java @@ -0,0 +1,38 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.ui.Grid; + +/** + * An event listener for column visibility change events in the Grid. + * + * @author Vaadin Ltd + * @since 8.0 + */ +@FunctionalInterface +public interface ColumnVisibilityChangeListener extends Serializable { + + /** + * Called when a column has become hidden or unhidden. + * + * @param event + * the event + */ + void columnVisibilityChanged(Grid.ColumnVisibilityChangeEvent event); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java b/server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java new file mode 100644 index 0000000000..4ec3d72482 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java @@ -0,0 +1,32 @@ +/* + * 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.server.SerializableFunction; + +/** + * A callback interface for generating description texts for an item. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the grid bean type + */ +@FunctionalInterface +public interface DescriptionGenerator + extends SerializableFunction { +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java b/server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java new file mode 100644 index 0000000000..c1da727d1d --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java @@ -0,0 +1,33 @@ +/* + * 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.server.SerializableFunction; +import com.vaadin.ui.Component; + +/** + * A callback interface for generating details for a particular row in Grid. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the grid bean type + */ +@FunctionalInterface +public interface DetailsGenerator + extends SerializableFunction { +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Editor.java b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java new file mode 100644 index 0000000000..823c5cd849 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/Editor.java @@ -0,0 +1,158 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.data.Binder; + +/** + * An editor in a Grid. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + */ +public interface Editor extends Serializable { + + /** + * Sets the underlying Binder to this Editor. + * + * @param binder + * the binder for updating editor fields; not {@code null} + * @return this editor + */ + public Editor setBinder(Binder binder); + + /** + * Returns the underlying Binder from Editor. + * + * @return the binder; not {@code null} + */ + public Binder getBinder(); + + /** + * Sets the Editor buffered mode. When the editor is in buffered mode, edits + * are only committed when the user clicks the save button. In unbuffered + * mode valid changes are automatically committed. + * + * @param buffered + * {@code true} if editor should be buffered; {@code false} if + * not + * @return this editor + */ + public Editor setBuffered(boolean buffered); + + /** + * Enables or disabled the Editor. A disabled editor cannot be opened. + * + * @param enabled + * {@code true} if editor should be enabled; {@code false} if not + * @return this editor + */ + public Editor setEnabled(boolean enabled); + + /** + * Returns whether Editor is buffered or not. + * + * @see #setBuffered(boolean) + * + * @return {@code true} if editor is buffered; {@code false} if not + */ + public boolean isBuffered(); + + /** + * Returns whether Editor is enabled or not. + * + * @return {@code true} if editor is enabled; {@code false} if not + */ + public boolean isEnabled(); + + /** + * Returns whether Editor is open or not. + * + * @return {@code true} if editor is open; {@code false} if not + */ + public boolean isOpen(); + + /** + * Saves any changes from the Editor fields to the edited bean. + * + * @return {@code true} if save succeeded; {@code false} if not + */ + public boolean save(); + + /** + * Close the editor discarding any unsaved changes. + */ + public void cancel(); + + /** + * Sets the caption of the save button in buffered mode. + * + * @param saveCaption + * the save button caption + * @return this editor + */ + public Editor setSaveCaption(String saveCaption); + + /** + * Sets the caption of the cancel button in buffered mode. + * + * @param cancelCaption + * the cancel button caption + * @return this editor + */ + public Editor setCancelCaption(String cancelCaption); + + /** + * Gets the caption of the save button in buffered mode. + * + * @return the save button caption + */ + public String getSaveCaption(); + + /** + * Gets the caption of the cancel button in buffered mode. + * + * @return the cancel button caption + */ + public String getCancelCaption(); + + /** + * Sets the error message generator for this editor. + *

+ * The default message is a concatenation of column field validation + * failures and bean validation failures. + * + * @param errorGenerator + * the function to generate error messages; not {@code null} + * @return this editor + * + * @see EditorErrorGenerator + */ + public Editor setErrorGenerator(EditorErrorGenerator errorGenerator); + + /** + * Gets the error message generator of this editor. + * + * @return the function that generates error messages; not {@code null} + * + * @see EditorErrorGenerator + */ + public EditorErrorGenerator getErrorGenerator(); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java new file mode 100644 index 0000000000..df649f1ea9 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java @@ -0,0 +1,52 @@ +/* + * 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 java.io.Serializable; +import java.util.Map; +import java.util.function.BiFunction; + +import com.vaadin.data.BinderValidationStatus; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; + +/** + * Generator for creating editor validation and conversion error messages. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the bean type + */ +@FunctionalInterface +public interface EditorErrorGenerator extends Serializable, + BiFunction>, BinderValidationStatus, String> { + + /** + * Generates an error message from given validation status object. + * + * @param fieldToColumn + * the map of failed fields and corresponding columns + * @param status + * the binder status object with all failures + * + * @return error message string + */ + @Override + public String apply(Map> fieldToColumn, + BinderValidationStatus status); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java index 7aa3920c3c..56bf4d6414 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java @@ -32,8 +32,6 @@ import com.vaadin.shared.ui.grid.editor.EditorState; import com.vaadin.ui.Component; import com.vaadin.ui.Grid.AbstractGridExtension; import com.vaadin.ui.Grid.Column; -import com.vaadin.ui.Grid.Editor; -import com.vaadin.ui.Grid.EditorErrorGenerator; import elemental.json.JsonObject; 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 index 7d4f45cd1e..ddc36c1efa 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/Footer.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/Footer.java @@ -19,8 +19,6 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import com.vaadin.ui.Grid; - /** * Represents the footer section of a Grid. * @@ -34,13 +32,13 @@ public abstract class Footer extends StaticSection { * A row in a Grid Footer. */ public class Row extends StaticSection.StaticRow - implements Grid.FooterRow { + implements FooterRow { /** * A cell in a Grid footer row. */ public class Cell extends StaticSection.StaticCell - implements Grid.FooterCell { + implements FooterCell { /** * Creates a new footer cell. */ @@ -77,12 +75,12 @@ public abstract class Footer extends StaticSection { * merged to any other cell set. * @return the remaining visible cell after the merge * - * @see #join(Grid.FooterCell...) + * @see #join(FooterCell...) * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption */ @Override - public Grid.FooterCell join(Set cellsToMerge) { - for (Grid.FooterCell cell : cellsToMerge) { + public FooterCell join(Set cellsToMerge) { + for (FooterCell cell : cellsToMerge) { checkIfAlreadyMerged(cell.getColumnId()); } @@ -90,7 +88,7 @@ public abstract class Footer extends StaticSection { Cell newCell = createCell(); Set columnGroup = new HashSet<>(); - for (Grid.FooterCell cell : cellsToMerge) { + for (FooterCell cell : cellsToMerge) { columnGroup.add(cell.getColumnId()); } addMergedCell(newCell, columnGroup); @@ -113,8 +111,8 @@ public abstract class Footer extends StaticSection { * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption */ @Override - public Grid.FooterCell join(Grid.FooterCell... cellsToMerge) { - Set footerCells = new HashSet<>( + public FooterCell join(FooterCell... cellsToMerge) { + Set footerCells = new HashSet<>( Arrays.asList(cellsToMerge)); return join(footerCells); } diff --git a/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java b/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java new file mode 100644 index 0000000000..092637c891 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java @@ -0,0 +1,90 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.shared.ui.grid.GridStaticCellType; +import com.vaadin.ui.Component; + +/** + * An individual cell on a Grid footer row. + * + * @author Vaadin Ltd + * @since 8.0 + */ +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); + + /** + * Returns the HTML content displayed in this cell. + * + * @return the html + * + */ + public String getHtml(); + + /** + * Sets the HTML content displayed in this cell. + * + * @param html + * the html to set + */ + public void setHtml(String html); + + /** + * Returns the component displayed in this cell. + * + * @return the component + */ + public Component getComponent(); + + /** + * Sets the component displayed in this cell. + * + * @param component + * the component to set + */ + public void setComponent(Component component); + + /** + * Returns the type of content stored in this cell. + * + * @return cell content type + */ + public GridStaticCellType getCellType(); + + /** + * Gets the column id where this cell is. + * + * @return column id for this cell + */ + public String getColumnId(); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java b/server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java new file mode 100644 index 0000000000..8d6bd70bf1 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java @@ -0,0 +1,82 @@ +/* + * 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 java.io.Serializable; +import java.util.Set; + +import com.vaadin.ui.Grid; + +/** + * A footer row in a Grid. + * + * @author Vaadin Ltd + * @since 8.0 + */ +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 FooterCell getCell(Grid.Column column); + + /** + * Merges column cells in the row. Original cells are hidden, and new merged + * cell is shown instead. The cell has a width of all merged cells together, + * inherits styles of the first merged cell but has empty caption. + * + * @param cellsToMerge + * the cells which should be merged. The cells should not be + * merged to any other cell set. + * @return the remaining visible cell after the merge + * + * @see #join(FooterCell...) + * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption + */ + FooterCell join(Set cellsToMerge); + + /** + * Merges column cells in the row. Original cells are hidden, and new merged + * cell is shown instead. The cell has a width of all merged cells together, + * inherits styles of the first merged cell but has empty caption. + * + * @param cellsToMerge + * the cells which should be merged. The cells should not be + * merged to any other cell set. + * @return the remaining visible cell after the merge + * + * @see #join(Set) + * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption + */ + FooterCell join(FooterCell... cellsToMerge); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java new file mode 100644 index 0000000000..2913318bf8 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java @@ -0,0 +1,46 @@ +/* + * 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.data.SelectionModel; +import com.vaadin.server.Extension; +import com.vaadin.ui.Grid.AbstractGridExtension; + +/** + * The server-side interface that controls Grid's selection state. + * SelectionModel should extend {@link AbstractGridExtension}. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the grid bean type + * @see AbstractSelectionModel + * @see SingleSelectionModel + * @see MultiSelectionModel + */ +public interface GridSelectionModel extends SelectionModel, Extension { + + /** + * Removes this selection model from the grid. + *

+ * Must call super {@link Extension#remove()} to detach the extension, and + * fire an selection change event for the selection model (with an empty + * selection). + */ + @Override + public void remove(); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Header.java b/server/src/main/java/com/vaadin/ui/components/grid/Header.java index 0991069487..69c23c6818 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/Header.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/Header.java @@ -21,7 +21,6 @@ import java.util.Set; import org.jsoup.nodes.Element; -import com.vaadin.ui.Grid; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; @@ -38,13 +37,13 @@ public abstract class Header extends StaticSection { * A row in a Grid header. */ public class Row extends StaticSection.StaticRow - implements Grid.HeaderRow { + implements HeaderRow { /** * A cell in a Grid header row. */ public class Cell extends StaticSection.StaticCell - implements Grid.HeaderCell { + implements HeaderCell { /** * Creates a new header cell. */ @@ -101,12 +100,12 @@ public abstract class Header extends StaticSection { * merged to any other cell set. * @return the remaining visible cell after the merge * - * @see #join(Grid.HeaderCell...) + * @see #join(HeaderCell...) * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption */ @Override - public Grid.HeaderCell join(Set cellsToMerge) { - for (Grid.HeaderCell cell : cellsToMerge) { + public HeaderCell join(Set cellsToMerge) { + for (HeaderCell cell : cellsToMerge) { checkIfAlreadyMerged(cell.getColumnId()); } @@ -114,7 +113,7 @@ public abstract class Header extends StaticSection { Cell newCell = createCell(); Set columnGroup = new HashSet<>(); - for (Grid.HeaderCell cell : cellsToMerge) { + for (HeaderCell cell : cellsToMerge) { columnGroup.add(cell.getColumnId()); } addMergedCell(newCell, columnGroup); @@ -137,8 +136,8 @@ public abstract class Header extends StaticSection { * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption */ @Override - public Grid.HeaderCell join(Grid.HeaderCell... cellsToMerge) { - Set headerCells = new HashSet<>( + public HeaderCell join(HeaderCell... cellsToMerge) { + Set headerCells = new HashSet<>( Arrays.asList(cellsToMerge)); return join(headerCells); } diff --git a/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java b/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java new file mode 100644 index 0000000000..741ea96617 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java @@ -0,0 +1,90 @@ +/* + * 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 java.io.Serializable; + +import com.vaadin.shared.ui.grid.GridStaticCellType; +import com.vaadin.ui.Component; + +/** + * An individual cell on a Grid header row. + * + * @author Vaadin Ltd + * @since 8.0 + */ +public interface HeaderCell extends Serializable { + + /** + * Returns the textual caption of this cell. + * + * @return the header caption + */ + public String getText(); + + /** + * Sets the textual caption of this cell. + * + * @param text + * the header caption to set, not null + */ + public void setText(String text); + + /** + * Returns the HTML content displayed in this cell. + * + * @return the html + * + */ + public String getHtml(); + + /** + * Sets the HTML content displayed in this cell. + * + * @param html + * the html to set + */ + public void setHtml(String html); + + /** + * Returns the component displayed in this cell. + * + * @return the component + */ + public Component getComponent(); + + /** + * Sets the component displayed in this cell. + * + * @param component + * the component to set + */ + public void setComponent(Component component); + + /** + * Returns the type of content stored in this cell. + * + * @return cell content type + */ + public GridStaticCellType getCellType(); + + /** + * Gets the column id where this cell is. + * + * @return column id for this cell + */ + public String getColumnId(); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java b/server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java new file mode 100644 index 0000000000..19bcb4d111 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java @@ -0,0 +1,83 @@ +/* + * 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 java.io.Serializable; +import java.util.Set; + +import com.vaadin.ui.Grid; + +/** + * A header row in a Grid. + * + * @author Vaadin Ltd + * @since 8.0 + */ +public interface HeaderRow extends Serializable { + + /** + * Returns the cell on this row corresponding to the given column id. + * + * @param columnId + * the id of the column whose header cell to get, not null + * @return the header cell + * @throws IllegalArgumentException + * if there is no such column in the grid + */ + public HeaderCell getCell(String columnId); + + /** + * Returns the cell on this row corresponding to the given column. + * + * @param column + * the column whose header cell to get, not null + * @return the header cell + * @throws IllegalArgumentException + * if there is no such column in the grid + */ + public HeaderCell getCell(Grid.Column column); + + /** + * Merges column cells in the row. Original cells are hidden, and new merged + * cell is shown instead. The cell has a width of all merged cells together, + * inherits styles of the first merged cell but has empty caption. + * + * @param cellsToMerge + * the cells which should be merged. The cells should not be + * merged to any other cell set. + * @return the remaining visible cell after the merge + * + * @see #join(HeaderCell...) + * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption + */ + HeaderCell join(Set cellsToMerge); + + /** + * Merges column cells in the row. Original cells are hidden, and new merged + * cell is shown instead. The cell has a width of all merged cells together, + * inherits styles of the first merged cell but has empty caption. + * + * @param cellsToMerge + * the cells which should be merged. The cells should not be + * merged to any other cell set. + * @return the remaining visible cell after the merge + * + * @see #join(Set) + * @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption + */ + HeaderCell join(HeaderCell... cellsToMerge); + +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java b/server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java new file mode 100644 index 0000000000..2ac3428423 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java @@ -0,0 +1,45 @@ +/* + * 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.event.SerializableEventListener; +import com.vaadin.shared.Registration; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.ItemClick; + +/** + * A listener for item click events. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the grid bean type + * + * @see ItemClick + * @see Registration + */ +@FunctionalInterface +public interface ItemClickListener extends SerializableEventListener { + /** + * Invoked when this listener receives a item click event from a Grid to + * which it has been added. + * + * @param event + * the received event, not null + */ + public void itemClick(Grid.ItemClick event); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java new file mode 100644 index 0000000000..4c5da97a5d --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java @@ -0,0 +1,68 @@ +/* + * 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.data.Binder; +import com.vaadin.event.selection.MultiSelectionListener; +import com.vaadin.event.selection.SelectionListener; +import com.vaadin.shared.Registration; +import com.vaadin.ui.MultiSelect; + +/** + * Multiselection model interface for Grid. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the type of items in grid + */ +public interface MultiSelectionModel + extends GridSelectionModel, com.vaadin.data.SelectionModel.Multi { + + /** + * Gets a wrapper to use this multiselection model as a multiselect in + * {@link Binder}. + * + * @return the multiselect wrapper + */ + MultiSelect asMultiSelect(); + + /** + * {@inheritDoc} + *

+ * Use {@link #addMultiSelectionListener(MultiSelectionListener)} for more + * specific event on multiselection. + * + * @see #addMultiSelectionListener(MultiSelectionListener) + */ + @Override + public default Registration addSelectionListener( + SelectionListener listener) { + return addMultiSelectionListener(e -> listener.selectionChange(e)); + } + + /** + * Adds a selection listener that will be called when the selection is + * changed either by the user or programmatically. + * + * @param listener + * the value change listener, not {@code null} + * @return a registration for the listener + */ + public Registration addMultiSelectionListener( + MultiSelectionListener listener); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java index 764d958dac..41158b6f03 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java @@ -32,7 +32,6 @@ import com.vaadin.event.selection.MultiSelectionListener; import com.vaadin.shared.Registration; import com.vaadin.shared.data.selection.GridMultiSelectServerRpc; import com.vaadin.shared.ui.grid.MultiSelectionModelState; -import com.vaadin.ui.Grid.MultiSelectionModel; import com.vaadin.ui.MultiSelect; /** @@ -200,7 +199,7 @@ public class MultiSelectionModelImpl extends AbstractSelectionModel @Override public boolean isSelected(T item) { return isAllSelected() - || com.vaadin.ui.Grid.MultiSelectionModel.super.isSelected( + || com.vaadin.ui.components.grid.MultiSelectionModel.super.isSelected( item); } diff --git a/server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java index e3f40db2c3..ff51b74cfc 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java @@ -22,7 +22,6 @@ import java.util.Set; import com.vaadin.event.selection.SelectionListener; import com.vaadin.server.AbstractExtension; import com.vaadin.shared.Registration; -import com.vaadin.ui.Grid.GridSelectionModel; /** * Selection model that doesn't allow selecting anything from the grid. diff --git a/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java new file mode 100644 index 0000000000..21b95c102c --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java @@ -0,0 +1,68 @@ +/* + * 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.data.Binder; +import com.vaadin.event.selection.SelectionListener; +import com.vaadin.event.selection.SingleSelectionListener; +import com.vaadin.shared.Registration; +import com.vaadin.ui.SingleSelect; + +/** + * Single selection model interface for Grid. + * + * @author Vaadin Ltd + * @since 8.0 + * + * @param + * the type of items in grid + */ +public interface SingleSelectionModel extends GridSelectionModel, + com.vaadin.data.SelectionModel.Single { + + /** + * Gets a wrapper to use this single selection model as a single select in + * {@link Binder}. + * + * @return the single select wrapper + */ + SingleSelect asSingleSelect(); + + /** + * {@inheritDoc} + *

+ * Use {@link #addSingleSelectionListener(SingleSelectionListener)} for more + * specific single selection event. + * + * @see #addSingleSelectionListener(SingleSelectionListener) + */ + @Override + public default Registration addSelectionListener( + SelectionListener listener) { + return addSingleSelectionListener(e -> listener.selectionChange(e)); + } + + /** + * Adds a single selection listener that is called when the value of this + * select is changed either by the user or programmatically. + * + * @param listener + * the value change listener, not {@code null} + * @return a registration for the listener + */ + public Registration addSingleSelectionListener( + SingleSelectionListener listener); +} diff --git a/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java index 7ca7b583a8..eeb57bab26 100644 --- a/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java +++ b/server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java @@ -28,7 +28,6 @@ import com.vaadin.shared.Registration; import com.vaadin.shared.data.selection.SelectionServerRpc; import com.vaadin.shared.ui.grid.SingleSelectionModelState; import com.vaadin.ui.Component; -import com.vaadin.ui.Grid.SingleSelectionModel; import com.vaadin.ui.SingleSelect; /** diff --git a/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java b/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java new file mode 100644 index 0000000000..c05b37f88a --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java @@ -0,0 +1,48 @@ +/* + * 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 java.util.stream.Stream; + +import com.vaadin.server.SerializableFunction; +import com.vaadin.server.data.SortOrder; +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.ui.Grid.Column; + +/** + * Generates the sort orders when rows are sorted by a column. + * + * @see Column#setSortOrderProvider + * + * @since 8.0 + * @author Vaadin Ltd + */ +@FunctionalInterface +public interface SortOrderProvider + extends SerializableFunction>> { + + /** + * Generates the sort orders when rows are sorted by a column. + * + * @param sortDirection + * desired sort direction + * + * @return sort information + */ + @Override + public Stream> apply(SortDirection sortDirection); + +} diff --git a/server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java b/server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java index 964cf0bc98..9886df43fc 100644 --- a/server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java +++ b/server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java @@ -25,7 +25,7 @@ public class GridAsSingleSelectInBinderTest private class GridWithCustomSingleSelectionModel extends Grid { @Override public void setSelectionModel( - com.vaadin.ui.Grid.GridSelectionModel model) { + com.vaadin.ui.components.grid.GridSelectionModel model) { super.setSelectionModel(model); } } diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java index 21e157c925..8124927ed7 100644 --- a/server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java +++ b/server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java @@ -31,9 +31,9 @@ import com.vaadin.event.selection.MultiSelectionListener; import com.vaadin.shared.Registration; import com.vaadin.tests.util.MockUI; import com.vaadin.ui.Grid; -import com.vaadin.ui.Grid.GridSelectionModel; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.UI; +import com.vaadin.ui.components.grid.GridSelectionModel; import com.vaadin.ui.components.grid.MultiSelectionModelImpl; import com.vaadin.ui.components.grid.MultiSelectionModelImpl.SelectAllCheckBoxVisibility; @@ -633,14 +633,16 @@ public class GridMultiSelectionModelTest { model.getSelectAllCheckBoxVisibility()); // change to explicit NO - model.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.HIDDEN); + model.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.HIDDEN); Assert.assertEquals(SelectAllCheckBoxVisibility.HIDDEN, model.getSelectAllCheckBoxVisibility()); Assert.assertFalse(model.isSelectAllCheckBoxVisible()); // change to explicit YES - model.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE); + model.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.VISIBLE); Assert.assertEquals(SelectAllCheckBoxVisibility.VISIBLE, model.getSelectAllCheckBoxVisibility()); @@ -676,21 +678,24 @@ public class GridMultiSelectionModelTest { model.getSelectAllCheckBoxVisibility()); // change to explicit YES - model.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE); + model.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.VISIBLE); Assert.assertEquals(SelectAllCheckBoxVisibility.VISIBLE, model.getSelectAllCheckBoxVisibility()); Assert.assertTrue(model.isSelectAllCheckBoxVisible()); // change to explicit NO - model.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.HIDDEN); + model.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.HIDDEN); Assert.assertEquals(SelectAllCheckBoxVisibility.HIDDEN, model.getSelectAllCheckBoxVisibility()); Assert.assertFalse(model.isSelectAllCheckBoxVisible()); // change back to depends on data provider - model.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.DEFAULT); + model.setSelectAllCheckBoxVisibility( + SelectAllCheckBoxVisibility.DEFAULT); Assert.assertFalse(model.isSelectAllCheckBoxVisible()); Assert.assertEquals(SelectAllCheckBoxVisibility.DEFAULT, diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java index 442b5009ac..4222b20d15 100644 --- a/server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java +++ b/server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java @@ -10,8 +10,8 @@ import org.junit.Test; import com.vaadin.data.provider.bov.Person; import com.vaadin.ui.Grid; -import com.vaadin.ui.Grid.GridSelectionModel; import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.components.grid.GridSelectionModel; public class GridNoSelectionModelTest { diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java index 9132ecaa22..cded4f878c 100644 --- a/server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java +++ b/server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java @@ -23,8 +23,8 @@ import com.vaadin.event.selection.SingleSelectionEvent; import com.vaadin.event.selection.SingleSelectionListener; import com.vaadin.shared.Registration; import com.vaadin.ui.Grid; -import com.vaadin.ui.Grid.GridSelectionModel; import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.components.grid.GridSelectionModel; import com.vaadin.ui.components.grid.SingleSelectionModelImpl; import elemental.json.JsonObject; diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java index b4d9dc5f29..70e6539a48 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java @@ -34,12 +34,12 @@ import com.vaadin.tests.data.bean.Person; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; -import com.vaadin.ui.Grid.FooterCell; -import com.vaadin.ui.Grid.FooterRow; -import com.vaadin.ui.Grid.HeaderCell; -import com.vaadin.ui.Grid.HeaderRow; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; +import com.vaadin.ui.components.grid.FooterCell; +import com.vaadin.ui.components.grid.FooterRow; +import com.vaadin.ui.components.grid.HeaderCell; +import com.vaadin.ui.components.grid.HeaderRow; import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignException; diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java index 41cdbc8310..bdecc15c35 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java @@ -25,7 +25,7 @@ import org.junit.Test; import com.vaadin.data.ValueProvider; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; -import com.vaadin.ui.Grid.HeaderRow; +import com.vaadin.ui.components.grid.HeaderRow; public class GridDefaultHeaderTest { private Grid grid; diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java index ca6e7dd9f6..5a30325378 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import com.vaadin.data.ValueProvider; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; -import com.vaadin.ui.Grid.HeaderRow; +import com.vaadin.ui.components.grid.HeaderRow; public class GridHeaderFooterTest { diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java index e7ab23961b..63ef591246 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java @@ -29,10 +29,6 @@ import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.Column; -import com.vaadin.ui.Grid.DetailsGenerator; -import com.vaadin.ui.Grid.FooterRow; -import com.vaadin.ui.Grid.HeaderRow; -import com.vaadin.ui.Grid.MultiSelectionModel; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; import com.vaadin.ui.MenuBar; @@ -45,6 +41,12 @@ import com.vaadin.ui.SingleSelect; import com.vaadin.ui.StyleGenerator; import com.vaadin.ui.TextField; import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.components.grid.DetailsGenerator; +import com.vaadin.ui.components.grid.FooterCell; +import com.vaadin.ui.components.grid.FooterRow; +import com.vaadin.ui.components.grid.HeaderCell; +import com.vaadin.ui.components.grid.HeaderRow; +import com.vaadin.ui.components.grid.MultiSelectionModel; import com.vaadin.ui.components.grid.MultiSelectionModelImpl; import com.vaadin.ui.components.grid.MultiSelectionModelImpl.SelectAllCheckBoxVisibility; import com.vaadin.ui.components.grid.SingleSelectionModelImpl; @@ -628,7 +630,7 @@ public class GridBasics extends AbstractTestUIWithLog { int... columnIndexes) { HeaderRow headerRow = grid.getHeaderRow(rowIndex); List> columns = grid.getColumns(); - Set toMerge = new HashSet<>(); + Set toMerge = new HashSet<>(); for (int columnIndex : columnIndexes) { toMerge.add(headerRow.getCell(columns.get(columnIndex))); } @@ -639,7 +641,7 @@ public class GridBasics extends AbstractTestUIWithLog { int... columnIndexes) { FooterRow footerRow = grid.getFooterRow(rowIndex); List> columns = grid.getColumns(); - Set toMerge = new HashSet<>(); + Set toMerge = new HashSet<>(); for (int columnIndex : columnIndexes) { toMerge.add(footerRow.getCell(columns.get(columnIndex))); } -- 2.39.5