Quellcode durchsuchen

Extract interfaces from Grid (#8005)

* Extract interfaces from Grid

Closes vaadin/framework8-issues#566
tags/8.0.0.alpha10
Teemu Suo-Anttila vor 7 Jahren
Ursprung
Commit
5361398709
32 geänderte Dateien mit 1069 neuen und 693 gelöschten Zeilen
  1. 15
    646
      server/src/main/java/com/vaadin/ui/Grid.java
  2. 0
    1
      server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java
  3. 38
    0
      server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java
  4. 38
    0
      server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java
  5. 38
    0
      server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java
  6. 32
    0
      server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java
  7. 33
    0
      server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java
  8. 158
    0
      server/src/main/java/com/vaadin/ui/components/grid/Editor.java
  9. 52
    0
      server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java
  10. 0
    2
      server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
  11. 8
    10
      server/src/main/java/com/vaadin/ui/components/grid/Footer.java
  12. 90
    0
      server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java
  13. 82
    0
      server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java
  14. 46
    0
      server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java
  15. 8
    9
      server/src/main/java/com/vaadin/ui/components/grid/Header.java
  16. 90
    0
      server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java
  17. 83
    0
      server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java
  18. 45
    0
      server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java
  19. 68
    0
      server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java
  20. 1
    2
      server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java
  21. 0
    1
      server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java
  22. 68
    0
      server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java
  23. 0
    1
      server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java
  24. 48
    0
      server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java
  25. 1
    1
      server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java
  26. 11
    6
      server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java
  27. 1
    1
      server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java
  28. 1
    1
      server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java
  29. 4
    4
      server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java
  30. 1
    1
      server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java
  31. 1
    1
      server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java
  32. 8
    6
      uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java

+ 15
- 646
server/src/main/java/com/vaadin/ui/Grid.java Datei anzeigen

@@ -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<T> extends AbstractListing<T>
"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.
* <p>
@@ -209,157 +203,6 @@ public class Grid<T> extends AbstractListing<T>
protected abstract <T> GridSelectionModel<T> createModel();
}

/**
* The server-side interface that controls Grid's selection state.
* SelectionModel should extend {@link AbstractGridExtension}.
* <p>
*
* @param <T>
* the grid bean type
* @see AbstractSelectionModel
* @see SingleSelectionModel
* @see MultiSelectionModel
*/
public interface GridSelectionModel<T>
extends SelectionModel<T>, Extension {

/**
* Removes this selection model from the grid.
* <p>
* 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 <T>
* the type of items in grid
*/
public interface SingleSelectionModel<T> extends GridSelectionModel<T>,
com.vaadin.data.SelectionModel.Single<T> {

/**
* Gets a wrapper to use this single selection model as a single select
* in {@link Binder}.
*
* @return the single select wrapper
*/
SingleSelect<T> asSingleSelect();

/**
* {@inheritDoc}
* <p>
* Use {@link #addSingleSelectionListener(SingleSelectionListener)} for
* more specific single selection event.
*
* @see #addSingleSelectionListener(SingleSelectionListener)
*/
@Override
public default Registration addSelectionListener(
SelectionListener<T> 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<T> listener);
}

/**
* Multiselection model interface for Grid.
*
* @param <T>
* the type of items in grid
*/
public interface MultiSelectionModel<T> extends GridSelectionModel<T>,
com.vaadin.data.SelectionModel.Multi<T> {

/**
* Gets a wrapper to use this multiselection model as a multiselect in
* {@link Binder}.
*
* @return the multiselect wrapper
*/
MultiSelect<T> asMultiSelect();

/**
* {@inheritDoc}
* <p>
* Use {@link #addMultiSelectionListener(MultiSelectionListener)} for
* more specific event on multiselection.
*
* @see #addMultiSelectionListener(MultiSelectionListener)
*/
@Override
public default Registration addSelectionListener(
SelectionListener<T> 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<T> 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<SortDirection, Stream<SortOrder<String>>> {

/**
* Generates the sort orders when rows are sorted by a column.
*
* @param sortDirection
* desired sort direction
*
* @return sort information
*/
@Override
public Stream<SortOrder<String>> apply(SortDirection sortDirection);

}

/**
* An event that is fired when the columns are reordered.
*/
@@ -499,27 +342,6 @@ public class Grid<T> extends AbstractListing<T>
}
}

/**
* A listener for item click events.
*
* @param <T>
* the grid bean type
*
* @see ItemClick
* @see Registration
*/
@FunctionalInterface
public interface ItemClickListener<T> 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<T> event);
}

/**
* ContextClickEvent for the Grid Component.
*
@@ -604,22 +426,6 @@ public class Grid<T> extends AbstractListing<T>
}
}

/**
* 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<T> extends AbstractListing<T>
}
}

/**
* A callback interface for generating description texts for an item.
*
* @param <T>
* the grid bean type
*/
@FunctionalInterface
public interface DescriptionGenerator<T>
extends SerializableFunction<T, String> {
}

/**
* A callback interface for generating details for a particular row in Grid.
*
* @param <T>
* the grid bean type
*/
@FunctionalInterface
public interface DetailsGenerator<T>
extends SerializableFunction<T, Component> {
}

/**
* A helper base class for creating extensions for the Grid component.
*
@@ -1952,421 +1736,6 @@ public class Grid<T> extends AbstractListing<T>
}
}

/**
* 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<HeaderCell> 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<FooterCell> 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 <T>
* the bean type
*/
@FunctionalInterface
public interface EditorErrorGenerator<T> extends Serializable,
BiFunction<Map<Component, Column<T, ?>>, BinderValidationStatus<T>, 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<Component, Column<T, ?>> fieldToColumn,
BinderValidationStatus<T> status);
}

/**
* An editor in a Grid.
*
* @param <T>
*/
public interface Editor<T> 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<T> setBinder(Binder<T> binder);

/**
* Returns the underlying Binder from Editor.
*
* @return the binder; not {@code null}
*/
public Binder<T> 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<T> 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<T> 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<T> setSaveCaption(String saveCaption);

/**
* Sets the caption of the cancel button in buffered mode.
*
* @param cancelCaption
* the cancel button caption
* @return this editor
*/
public Editor<T> 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.
* <p>
* 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<T> setErrorGenerator(
EditorErrorGenerator<T> errorGenerator);

/**
* Gets the error message generator of this editor.
*
* @return the function that generates error messages; not {@code null}
*
* @see EditorErrorGenerator
*/
public EditorErrorGenerator<T> getErrorGenerator();
}

private class HeaderImpl extends Header {

@Override

+ 0
- 1
server/src/main/java/com/vaadin/ui/components/grid/AbstractSelectionModel.java Datei anzeigen

@@ -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;


+ 38
- 0
server/src/main/java/com/vaadin/ui/components/grid/ColumnReorderListener.java Datei anzeigen

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

+ 38
- 0
server/src/main/java/com/vaadin/ui/components/grid/ColumnResizeListener.java Datei anzeigen

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

+ 38
- 0
server/src/main/java/com/vaadin/ui/components/grid/ColumnVisibilityChangeListener.java Datei anzeigen

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

+ 32
- 0
server/src/main/java/com/vaadin/ui/components/grid/DescriptionGenerator.java Datei anzeigen

@@ -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 <T>
* the grid bean type
*/
@FunctionalInterface
public interface DescriptionGenerator<T>
extends SerializableFunction<T, String> {
}

+ 33
- 0
server/src/main/java/com/vaadin/ui/components/grid/DetailsGenerator.java Datei anzeigen

@@ -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 <T>
* the grid bean type
*/
@FunctionalInterface
public interface DetailsGenerator<T>
extends SerializableFunction<T, Component> {
}

+ 158
- 0
server/src/main/java/com/vaadin/ui/components/grid/Editor.java Datei anzeigen

@@ -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 <T>
*/
public interface Editor<T> 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<T> setBinder(Binder<T> binder);

/**
* Returns the underlying Binder from Editor.
*
* @return the binder; not {@code null}
*/
public Binder<T> 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<T> 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<T> 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<T> setSaveCaption(String saveCaption);

/**
* Sets the caption of the cancel button in buffered mode.
*
* @param cancelCaption
* the cancel button caption
* @return this editor
*/
public Editor<T> 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.
* <p>
* 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<T> setErrorGenerator(EditorErrorGenerator<T> errorGenerator);

/**
* Gets the error message generator of this editor.
*
* @return the function that generates error messages; not {@code null}
*
* @see EditorErrorGenerator
*/
public EditorErrorGenerator<T> getErrorGenerator();
}

+ 52
- 0
server/src/main/java/com/vaadin/ui/components/grid/EditorErrorGenerator.java Datei anzeigen

@@ -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 <T>
* the bean type
*/
@FunctionalInterface
public interface EditorErrorGenerator<T> extends Serializable,
BiFunction<Map<Component, Grid.Column<T, ?>>, BinderValidationStatus<T>, 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<Component, Grid.Column<T, ?>> fieldToColumn,
BinderValidationStatus<T> status);
}

+ 0
- 2
server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java Datei anzeigen

@@ -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;


+ 8
- 10
server/src/main/java/com/vaadin/ui/components/grid/Footer.java Datei anzeigen

@@ -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<Footer.Row> {
* A row in a Grid Footer.
*/
public class Row extends StaticSection.StaticRow<Row.Cell>
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<Footer.Row> {
* 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<Grid.FooterCell> cellsToMerge) {
for (Grid.FooterCell cell : cellsToMerge) {
public FooterCell join(Set<FooterCell> cellsToMerge) {
for (FooterCell cell : cellsToMerge) {
checkIfAlreadyMerged(cell.getColumnId());
}

@@ -90,7 +88,7 @@ public abstract class Footer extends StaticSection<Footer.Row> {
Cell newCell = createCell();

Set<String> 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<Footer.Row> {
* @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption
*/
@Override
public Grid.FooterCell join(Grid.FooterCell... cellsToMerge) {
Set<Grid.FooterCell> footerCells = new HashSet<>(
public FooterCell join(FooterCell... cellsToMerge) {
Set<FooterCell> footerCells = new HashSet<>(
Arrays.asList(cellsToMerge));
return join(footerCells);
}

+ 90
- 0
server/src/main/java/com/vaadin/ui/components/grid/FooterCell.java Datei anzeigen

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

+ 82
- 0
server/src/main/java/com/vaadin/ui/components/grid/FooterRow.java Datei anzeigen

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

+ 46
- 0
server/src/main/java/com/vaadin/ui/components/grid/GridSelectionModel.java Datei anzeigen

@@ -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 <T>
* the grid bean type
* @see AbstractSelectionModel
* @see SingleSelectionModel
* @see MultiSelectionModel
*/
public interface GridSelectionModel<T> extends SelectionModel<T>, Extension {

/**
* Removes this selection model from the grid.
* <p>
* 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();
}

+ 8
- 9
server/src/main/java/com/vaadin/ui/components/grid/Header.java Datei anzeigen

@@ -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<Header.Row> {
* A row in a Grid header.
*/
public class Row extends StaticSection.StaticRow<Row.Cell>
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<Header.Row> {
* 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<Grid.HeaderCell> cellsToMerge) {
for (Grid.HeaderCell cell : cellsToMerge) {
public HeaderCell join(Set<HeaderCell> cellsToMerge) {
for (HeaderCell cell : cellsToMerge) {
checkIfAlreadyMerged(cell.getColumnId());
}

@@ -114,7 +113,7 @@ public abstract class Header extends StaticSection<Header.Row> {
Cell newCell = createCell();

Set<String> 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<Header.Row> {
* @see com.vaadin.ui.AbstractComponent#setCaption(String) setCaption
*/
@Override
public Grid.HeaderCell join(Grid.HeaderCell... cellsToMerge) {
Set<Grid.HeaderCell> headerCells = new HashSet<>(
public HeaderCell join(HeaderCell... cellsToMerge) {
Set<HeaderCell> headerCells = new HashSet<>(
Arrays.asList(cellsToMerge));
return join(headerCells);
}

+ 90
- 0
server/src/main/java/com/vaadin/ui/components/grid/HeaderCell.java Datei anzeigen

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

+ 83
- 0
server/src/main/java/com/vaadin/ui/components/grid/HeaderRow.java Datei anzeigen

@@ -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<HeaderCell> 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);

}

+ 45
- 0
server/src/main/java/com/vaadin/ui/components/grid/ItemClickListener.java Datei anzeigen

@@ -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 <T>
* the grid bean type
*
* @see ItemClick
* @see Registration
*/
@FunctionalInterface
public interface ItemClickListener<T> 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<T> event);
}

+ 68
- 0
server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModel.java Datei anzeigen

@@ -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 <T>
* the type of items in grid
*/
public interface MultiSelectionModel<T>
extends GridSelectionModel<T>, com.vaadin.data.SelectionModel.Multi<T> {

/**
* Gets a wrapper to use this multiselection model as a multiselect in
* {@link Binder}.
*
* @return the multiselect wrapper
*/
MultiSelect<T> asMultiSelect();

/**
* {@inheritDoc}
* <p>
* Use {@link #addMultiSelectionListener(MultiSelectionListener)} for more
* specific event on multiselection.
*
* @see #addMultiSelectionListener(MultiSelectionListener)
*/
@Override
public default Registration addSelectionListener(
SelectionListener<T> 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<T> listener);
}

+ 1
- 2
server/src/main/java/com/vaadin/ui/components/grid/MultiSelectionModelImpl.java Datei anzeigen

@@ -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<T> extends AbstractSelectionModel<T>
@Override
public boolean isSelected(T item) {
return isAllSelected()
|| com.vaadin.ui.Grid.MultiSelectionModel.super.isSelected(
|| com.vaadin.ui.components.grid.MultiSelectionModel.super.isSelected(
item);
}


+ 0
- 1
server/src/main/java/com/vaadin/ui/components/grid/NoSelectionModel.java Datei anzeigen

@@ -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.

+ 68
- 0
server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModel.java Datei anzeigen

@@ -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 <T>
* the type of items in grid
*/
public interface SingleSelectionModel<T> extends GridSelectionModel<T>,
com.vaadin.data.SelectionModel.Single<T> {

/**
* Gets a wrapper to use this single selection model as a single select in
* {@link Binder}.
*
* @return the single select wrapper
*/
SingleSelect<T> asSingleSelect();

/**
* {@inheritDoc}
* <p>
* Use {@link #addSingleSelectionListener(SingleSelectionListener)} for more
* specific single selection event.
*
* @see #addSingleSelectionListener(SingleSelectionListener)
*/
@Override
public default Registration addSelectionListener(
SelectionListener<T> 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<T> listener);
}

+ 0
- 1
server/src/main/java/com/vaadin/ui/components/grid/SingleSelectionModelImpl.java Datei anzeigen

@@ -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;

/**

+ 48
- 0
server/src/main/java/com/vaadin/ui/components/grid/SortOrderProvider.java Datei anzeigen

@@ -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<SortDirection, Stream<SortOrder<String>>> {

/**
* Generates the sort orders when rows are sorted by a column.
*
* @param sortDirection
* desired sort direction
*
* @return sort information
*/
@Override
public Stream<SortOrder<String>> apply(SortDirection sortDirection);

}

+ 1
- 1
server/src/test/java/com/vaadin/data/GridAsSingleSelectInBinderTest.java Datei anzeigen

@@ -25,7 +25,7 @@ public class GridAsSingleSelectInBinderTest
private class GridWithCustomSingleSelectionModel extends Grid<Sex> {
@Override
public void setSelectionModel(
com.vaadin.ui.Grid.GridSelectionModel<Sex> model) {
com.vaadin.ui.components.grid.GridSelectionModel<Sex> model) {
super.setSelectionModel(model);
}
}

+ 11
- 6
server/src/test/java/com/vaadin/tests/components/grid/GridMultiSelectionModelTest.java Datei anzeigen

@@ -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,

+ 1
- 1
server/src/test/java/com/vaadin/tests/components/grid/GridNoSelectionModelTest.java Datei anzeigen

@@ -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 {


+ 1
- 1
server/src/test/java/com/vaadin/tests/components/grid/GridSingleSelectionModelTest.java Datei anzeigen

@@ -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;

+ 4
- 4
server/src/test/java/com/vaadin/tests/server/component/grid/GridDeclarativeTest.java Datei anzeigen

@@ -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;


+ 1
- 1
server/src/test/java/com/vaadin/tests/server/component/grid/GridDefaultHeaderTest.java Datei anzeigen

@@ -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<String> grid;

+ 1
- 1
server/src/test/java/com/vaadin/tests/server/component/grid/GridHeaderFooterTest.java Datei anzeigen

@@ -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 {


+ 8
- 6
uitest/src/main/java/com/vaadin/tests/components/grid/basics/GridBasics.java Datei anzeigen

@@ -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<Column<DataObject, ?>> columns = grid.getColumns();
Set<Grid.HeaderCell> toMerge = new HashSet<>();
Set<HeaderCell> 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<Column<DataObject, ?>> columns = grid.getColumns();
Set<Grid.FooterCell> toMerge = new HashSet<>();
Set<FooterCell> toMerge = new HashSet<>();
for (int columnIndex : columnIndexes) {
toMerge.add(footerRow.getCell(columns.get(columnIndex)));
}

Laden…
Abbrechen
Speichern