diff options
author | Patrik Lindström <patrik@vaadin.com> | 2014-02-11 15:36:24 +0200 |
---|---|---|
committer | Henrik Paul <henrik@vaadin.com> | 2014-02-18 15:47:40 +0000 |
commit | d2027d8344313b048bf3b82e2a988ab40b0bb596 (patch) | |
tree | c387db0400b72af93bcb4205e241229e44a4cb29 /server | |
parent | 0ad5587c2f5dba0678995402dab482e81867f366 (diff) | |
download | vaadin-framework-d2027d8344313b048bf3b82e2a988ab40b0bb596.tar.gz vaadin-framework-d2027d8344313b048bf3b82e2a988ab40b0bb596.zip |
Implement programmatic scrolling (#13327)
Further changes required for this, included in the same patch:
- created GridClientRpc interface
- created test case UI for server-side controlled Grid programmatic
scrolling
- refactored getScrollPos logic into Escalator and moved
ScrollDestination enum to shared package
Change-Id: Ibf72a4f75831807d83fb5941597a6ce3fda08e17
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/components/grid/Grid.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/components/grid/Grid.java b/server/src/com/vaadin/ui/components/grid/Grid.java index 08685874c1..4126ec6d93 100644 --- a/server/src/com/vaadin/ui/components/grid/Grid.java +++ b/server/src/com/vaadin/ui/components/grid/Grid.java @@ -42,10 +42,12 @@ import com.vaadin.data.Property.ValueChangeNotifier; import com.vaadin.data.RpcDataProviderExtension; import com.vaadin.server.KeyMapper; import com.vaadin.shared.ui.grid.ColumnGroupRowState; +import com.vaadin.shared.ui.grid.GridClientRpc; import com.vaadin.shared.ui.grid.GridColumnState; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.Range; +import com.vaadin.shared.ui.grid.ScrollDestination; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Component; @@ -804,4 +806,56 @@ public class Grid extends AbstractComponent { public Object getLastFrozenPropertyId() { return columnKeys.get(getState().lastFrozenColumnId); } + + /** + * Scrolls to a certain item, using {@link ScrollDestination#ANY}. + * + * @param itemId + * id of item to scroll to. + * @throws IllegalArgumentException + * if the provided id is not recognized by the data source. + */ + public void scrollToItem(Object itemId) throws IllegalArgumentException { + scrollToItem(itemId, ScrollDestination.ANY); + } + + /** + * Scrolls to a certain item, using user-specified scroll destination. + * + * @param itemId + * id of item to scroll to. + * @param destination + * value specifying desired position of scrolled-to row. + * @throws IllegalArgumentException + * if the provided id is not recognized by the data source. + */ + public void scrollToItem(Object itemId, ScrollDestination destination) + throws IllegalArgumentException { + + int row = datasource.indexOfId(itemId); + + if (row == -1) { + throw new IllegalArgumentException( + "Item with specified ID does not exist in data source"); + } + + GridClientRpc clientRPC = getRpcProxy(GridClientRpc.class); + clientRPC.scrollToRow(row, destination); + } + + /** + * Scrolls to the beginning of the first data row. + */ + public void scrollToStart() { + GridClientRpc clientRPC = getRpcProxy(GridClientRpc.class); + clientRPC.scrollToStart(); + } + + /** + * Scrolls to the end of the last data row. + */ + public void scrollToEnd() { + GridClientRpc clientRPC = getRpcProxy(GridClientRpc.class); + clientRPC.scrollToEnd(); + } } |