You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RpcDataSourceConnector.java 9.4KB

Migrating 7.7.1, 7.7.2, 7.7.3 to V8. commit 11c3f8bd9ea65f7a7b8da9a282c31a127bd475a6 - Test and its UI class are added (both V8 and V7). Required functionality should be available via modern GWT version. commit 729dbf96fe76e7627168ab2c9d1d71c4eb7214c8 - About update release notes. No need to be included. commit 675f38349c43ac45dae40cf33a7b1fd0f8f261ca - V8 already contains correct Import-Packages section which uses osgi.javax.servlet.version variable whise version is 3.0.0 at the moment. commit 5da7c052f55cb4703b74f38f5bb19fc3f3fa2a76 - Use Vaadin plugin 7.7.0 from 7.7.0.alpha1. Is not applicable. commit 1df80001ab6c916effa917781dba652d09d01056 - Updated tutorial to Vaadin 7.7.0. Is not applicable. The tutorial already contains correct links and updated source code snippets. commit 8b4f0ed8a894b04902a5d4258119dcdc8e76d1e0 - set-property-fallback name="user.agent" value="safari". Is already there. commit 28ed04e827669cc4dd329331dac9699bd93f70bc - Fix animation end listeners so they are always removed. Is already there. commit 408253bc3f8bd3975f0525ce6832be214a3552e9 - Use servlet context classloader when finding servlet class for websockets. Is already there. commit 7a6f250d89474849648ed2ee96a6bfb78c3b9ca8 - Fire actions before removing menu from the DOM. Is already there. commit 9b66c6eb9bebf657d3f2def8c767e0e9d51cc92c - Do not run test on IE8 as IE8 is broken. Transplanted. commit 3faa43ff39ecda56587b93f0c5e262a2907871a7 - Discard for DateField when the data source contains null. It is not applicable for V8 (There is no anymore discard method in DateField (and no datasource suport in field)). Transplanted for DateField in compatibility. commit e0c1f91a3d6d1884e07ce8d1ba957aff6a9bf29a - Fix ComboBox paging when number of items equals page length. It's already done by another fix which replaced ComboBox in compatibility package to the V7 version. commit 83a1b8a0961cc9b2d43e01757530cefd035b0a22 - Update DOM and update escalator row count in the correct order. Transplanted. commit 45f2fba8ff7a4b62680618a325d4afcebfb7a1e9 - Prevent editor from being canceled while it is being saved. Transplanted to compatibility package. Is not applicable to modern Grid. commit ad67f7f43afb0feec5e029aea90297f2abe4f2c1 - Delete broken stylesheet and revert to default style until a new stylesheet is created. Is already there. commit c970a78d42a2d8f1745df7a11a74f3731f8be9a5 - Always show loading indicator for JavaScript RPC. Transplanted. commit 2aad3416061586f7e2649160bd832eefe03702ad - Make test independent of any converters present in the factory. It's already there. commit c9ad48430be135d18fe9f30868e091dd51c57b94 - Do not include yuicompressor for Sass compiler. Transplanted. Exclusion is added into vaadin/pom.xml commit 52d01a68e91ce73306b3a1747af97e928048ecdf - Test for Firefox download disconnecting push channel. Transplanted. commit 4bc375d1d21f468e6433da3a183150e0bfe0cae4 - Handle encoded URL characters correctly when constructing widget set name. Transplanted. commit 17ba88eaf87e15e6f3c729e5c7f8e875d5f86d8d - Update version to 7.7-SNAPSHOT. Is not applicable. commit 47b7b13e5c959de3bd925693b074d85e7625a87e - Ensure Firefox always updates the grid scrollbar. Transplanted. Made changes in the logic to the test for modern Grid component. commit 4d851ba21d1b8f35685b631d2845731f8fb33252 - Calculate column widths immediately if there is data. Transplanted to both client side modules. commit 8f0b1a1dd026a756912c9f21bd2b34ea46897c7f - Skip Maven enforcer plugin during demo validation. Transplanted (one build file is affected). commit 62815353e1b9d3cd126809f5c818ad35bf913807 - Build demos from 7.7 branch (now for master branch). FW8 demos are added (one build file is affected). commit 815d72115d5aaf3676daefd5642115577e4151ef - Make test pass on all browsers. Transplanted to both V7 and V8 version tests. commit 516c428ca127e3c31b7b4d74220e4b7eed4571be - Use widget set specified by init parameter. Transplanted to the one UIProvider class. commit b00c580ed70f682a42afbfa91f978921bb86c2cd - Use correct column index when calculating min width during resize. Transplanted into both client side classes (main and compatibility) as is. Test for V7 is transplanted as is. Test for V8 is written from scratch based on V7 version. commit 7dd91cf057eb06a09009096a8278f34aad9bd8d9 - Fix regression that broke widget set compilation in 7.7.1. It's already there. commit c665731b0b97b697e80c47955d3558c19f0c81cb - Ensure temporary layout manager state is cleared at the end of a layout phase. Transplanted to the one LayoutManager class. commit 57a965251afdb5ee9ac1913a0101d854d8215aa6 - Fix assertion error when column widths are calculated. Transplanted to both versions of the client Grid widget. commit c5c52684eb30d924cb75a632b526a0f879d5a33c - Format Java files using Eclipse Neon and Vaadin settings. Only formatting changes. Is not transplanted. f5d06d877165bf413ec71c4fc88cf46c8c57a372 - Change javadoc to a style Eclipse formatter can handle. Transplanted to both versions of the client Grid widget. commit 6033e13c20b3d6e8b6f5add0f786d5ab2e1bb3fe - Make initially disabled grid work when enabled. Transplanted to both client side modules. commit a2d6e4fb4b1fd13e9a1b88f2ab1b78d14d8b64a9 - Use requestAnimationFrame when scrolling in Grid. Transplanted to both client side modules. commit fe9438e7b77c606855cfd739dd7e30b3f8cd4165 - Specify branch also for Sampler. Is not applicable for master branch. commit 1ec5d8ef7cb8bbd82bae1c9b79a376a5dca28f48 - Update to Chrome 53. Is already there. commit 961851bfbc4844474299433c34af6c9e4323d891 - Updated link to new step 1 video in tutorial. Is already there. commit 41dc2fe1611adc70d00e6f77debb2a6d4dcdefb0 - Revert "Use widget set specified by init parameter. Transplanted to the one UIProvider class. commit 092b4f7f3192555fe3ae22ac03a89ac2ada2a2dd - Use widget set specified by init parameter. Transplanted to the common server side classes. commit 977cec7e3107c2da306d46449dbf32f6544313be - Fix widget set builder to create widget set in correct location. Transplanted to the one ClassPathExplorer class file. commit 6c12ad89ea1064cd4cc0456baca5ee00ae76d032 - Format project pom files using correct settings. Is not transplanted: only formatting changes for POM files. commit 0aad93ecc1ce743dffc093ce7ae2ef88831f6073 - Add tests for widgetset compilation in different modes. Transplanted. New test projects. commit 0a3a1ef8321ed421be2337034fdb1cae2c434c3d - Use versions-maven-plugin 2.3 to avoid NPE while setting project version. Is already there. Change-Id: Ie3a5088f25de1772f01ea30c4a5eba0b169ee0ab
7 years ago
Migrating 7.7.1, 7.7.2, 7.7.3 to V8. commit 11c3f8bd9ea65f7a7b8da9a282c31a127bd475a6 - Test and its UI class are added (both V8 and V7). Required functionality should be available via modern GWT version. commit 729dbf96fe76e7627168ab2c9d1d71c4eb7214c8 - About update release notes. No need to be included. commit 675f38349c43ac45dae40cf33a7b1fd0f8f261ca - V8 already contains correct Import-Packages section which uses osgi.javax.servlet.version variable whise version is 3.0.0 at the moment. commit 5da7c052f55cb4703b74f38f5bb19fc3f3fa2a76 - Use Vaadin plugin 7.7.0 from 7.7.0.alpha1. Is not applicable. commit 1df80001ab6c916effa917781dba652d09d01056 - Updated tutorial to Vaadin 7.7.0. Is not applicable. The tutorial already contains correct links and updated source code snippets. commit 8b4f0ed8a894b04902a5d4258119dcdc8e76d1e0 - set-property-fallback name="user.agent" value="safari". Is already there. commit 28ed04e827669cc4dd329331dac9699bd93f70bc - Fix animation end listeners so they are always removed. Is already there. commit 408253bc3f8bd3975f0525ce6832be214a3552e9 - Use servlet context classloader when finding servlet class for websockets. Is already there. commit 7a6f250d89474849648ed2ee96a6bfb78c3b9ca8 - Fire actions before removing menu from the DOM. Is already there. commit 9b66c6eb9bebf657d3f2def8c767e0e9d51cc92c - Do not run test on IE8 as IE8 is broken. Transplanted. commit 3faa43ff39ecda56587b93f0c5e262a2907871a7 - Discard for DateField when the data source contains null. It is not applicable for V8 (There is no anymore discard method in DateField (and no datasource suport in field)). Transplanted for DateField in compatibility. commit e0c1f91a3d6d1884e07ce8d1ba957aff6a9bf29a - Fix ComboBox paging when number of items equals page length. It's already done by another fix which replaced ComboBox in compatibility package to the V7 version. commit 83a1b8a0961cc9b2d43e01757530cefd035b0a22 - Update DOM and update escalator row count in the correct order. Transplanted. commit 45f2fba8ff7a4b62680618a325d4afcebfb7a1e9 - Prevent editor from being canceled while it is being saved. Transplanted to compatibility package. Is not applicable to modern Grid. commit ad67f7f43afb0feec5e029aea90297f2abe4f2c1 - Delete broken stylesheet and revert to default style until a new stylesheet is created. Is already there. commit c970a78d42a2d8f1745df7a11a74f3731f8be9a5 - Always show loading indicator for JavaScript RPC. Transplanted. commit 2aad3416061586f7e2649160bd832eefe03702ad - Make test independent of any converters present in the factory. It's already there. commit c9ad48430be135d18fe9f30868e091dd51c57b94 - Do not include yuicompressor for Sass compiler. Transplanted. Exclusion is added into vaadin/pom.xml commit 52d01a68e91ce73306b3a1747af97e928048ecdf - Test for Firefox download disconnecting push channel. Transplanted. commit 4bc375d1d21f468e6433da3a183150e0bfe0cae4 - Handle encoded URL characters correctly when constructing widget set name. Transplanted. commit 17ba88eaf87e15e6f3c729e5c7f8e875d5f86d8d - Update version to 7.7-SNAPSHOT. Is not applicable. commit 47b7b13e5c959de3bd925693b074d85e7625a87e - Ensure Firefox always updates the grid scrollbar. Transplanted. Made changes in the logic to the test for modern Grid component. commit 4d851ba21d1b8f35685b631d2845731f8fb33252 - Calculate column widths immediately if there is data. Transplanted to both client side modules. commit 8f0b1a1dd026a756912c9f21bd2b34ea46897c7f - Skip Maven enforcer plugin during demo validation. Transplanted (one build file is affected). commit 62815353e1b9d3cd126809f5c818ad35bf913807 - Build demos from 7.7 branch (now for master branch). FW8 demos are added (one build file is affected). commit 815d72115d5aaf3676daefd5642115577e4151ef - Make test pass on all browsers. Transplanted to both V7 and V8 version tests. commit 516c428ca127e3c31b7b4d74220e4b7eed4571be - Use widget set specified by init parameter. Transplanted to the one UIProvider class. commit b00c580ed70f682a42afbfa91f978921bb86c2cd - Use correct column index when calculating min width during resize. Transplanted into both client side classes (main and compatibility) as is. Test for V7 is transplanted as is. Test for V8 is written from scratch based on V7 version. commit 7dd91cf057eb06a09009096a8278f34aad9bd8d9 - Fix regression that broke widget set compilation in 7.7.1. It's already there. commit c665731b0b97b697e80c47955d3558c19f0c81cb - Ensure temporary layout manager state is cleared at the end of a layout phase. Transplanted to the one LayoutManager class. commit 57a965251afdb5ee9ac1913a0101d854d8215aa6 - Fix assertion error when column widths are calculated. Transplanted to both versions of the client Grid widget. commit c5c52684eb30d924cb75a632b526a0f879d5a33c - Format Java files using Eclipse Neon and Vaadin settings. Only formatting changes. Is not transplanted. f5d06d877165bf413ec71c4fc88cf46c8c57a372 - Change javadoc to a style Eclipse formatter can handle. Transplanted to both versions of the client Grid widget. commit 6033e13c20b3d6e8b6f5add0f786d5ab2e1bb3fe - Make initially disabled grid work when enabled. Transplanted to both client side modules. commit a2d6e4fb4b1fd13e9a1b88f2ab1b78d14d8b64a9 - Use requestAnimationFrame when scrolling in Grid. Transplanted to both client side modules. commit fe9438e7b77c606855cfd739dd7e30b3f8cd4165 - Specify branch also for Sampler. Is not applicable for master branch. commit 1ec5d8ef7cb8bbd82bae1c9b79a376a5dca28f48 - Update to Chrome 53. Is already there. commit 961851bfbc4844474299433c34af6c9e4323d891 - Updated link to new step 1 video in tutorial. Is already there. commit 41dc2fe1611adc70d00e6f77debb2a6d4dcdefb0 - Revert "Use widget set specified by init parameter. Transplanted to the one UIProvider class. commit 092b4f7f3192555fe3ae22ac03a89ac2ada2a2dd - Use widget set specified by init parameter. Transplanted to the common server side classes. commit 977cec7e3107c2da306d46449dbf32f6544313be - Fix widget set builder to create widget set in correct location. Transplanted to the one ClassPathExplorer class file. commit 6c12ad89ea1064cd4cc0456baca5ee00ae76d032 - Format project pom files using correct settings. Is not transplanted: only formatting changes for POM files. commit 0aad93ecc1ce743dffc093ce7ae2ef88831f6073 - Add tests for widgetset compilation in different modes. Transplanted. New test projects. commit 0a3a1ef8321ed421be2337034fdb1cae2c434c3d - Use versions-maven-plugin 2.3 to avoid NPE while setting project version. Is already there. Change-Id: Ie3a5088f25de1772f01ea30c4a5eba0b169ee0ab
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.v7.client.connectors;
  17. import java.util.ArrayList;
  18. import java.util.Collections;
  19. import java.util.List;
  20. import com.vaadin.client.ServerConnector;
  21. import com.vaadin.client.data.AbstractRemoteDataSource;
  22. import com.vaadin.client.extensions.AbstractExtensionConnector;
  23. import com.vaadin.shared.Range;
  24. import com.vaadin.shared.data.DataProviderRpc;
  25. import com.vaadin.shared.data.DataRequestRpc;
  26. import com.vaadin.shared.ui.Connect;
  27. import com.vaadin.v7.shared.ui.grid.GridState;
  28. import elemental.json.Json;
  29. import elemental.json.JsonArray;
  30. import elemental.json.JsonObject;
  31. /**
  32. * Connects a Vaadin server-side container data source to a Grid. This is
  33. * currently implemented as an Extension hardcoded to support a specific
  34. * connector type. This will be changed once framework support for something
  35. * more flexible has been implemented.
  36. *
  37. * @since 7.4
  38. * @author Vaadin Ltd
  39. */
  40. @Connect(com.vaadin.v7.server.communication.data.RpcDataProviderExtension.class)
  41. public class RpcDataSourceConnector extends AbstractExtensionConnector {
  42. /**
  43. * A callback interface to let {@link GridConnector} know that detail
  44. * visibilities might have changed.
  45. *
  46. * @since 7.5.0
  47. * @author Vaadin Ltd
  48. */
  49. interface DetailsListener {
  50. /**
  51. * A request to verify (and correct) the visibility for a row, given
  52. * updated metadata.
  53. *
  54. * @param rowIndex
  55. * the index of the row that should be checked
  56. * @param row
  57. * the row object to check visibility for
  58. * @see GridState#JSONKEY_DETAILS_VISIBLE
  59. */
  60. void reapplyDetailsVisibility(int rowIndex, JsonObject row);
  61. }
  62. public class RpcDataSource extends AbstractRemoteDataSource<JsonObject> {
  63. protected RpcDataSource() {
  64. registerRpc(DataProviderRpc.class, new DataProviderRpc() {
  65. @Override
  66. public void setRowData(int firstRow, JsonArray rowArray) {
  67. ArrayList<JsonObject> rows = new ArrayList<>(
  68. rowArray.length());
  69. for (int i = 0; i < rowArray.length(); i++) {
  70. JsonObject rowObject = rowArray.getObject(i);
  71. rows.add(rowObject);
  72. }
  73. RpcDataSource.this.setRowData(firstRow, rows);
  74. }
  75. @Override
  76. public void removeRowData(int firstRow, int count) {
  77. RpcDataSource.this.removeRowData(firstRow, count);
  78. }
  79. @Override
  80. public void insertRowData(int firstRow, int count) {
  81. RpcDataSource.this.insertRowData(firstRow, count);
  82. }
  83. @Override
  84. public void resetDataAndSize(int size) {
  85. RpcDataSource.this.resetDataAndSize(size);
  86. }
  87. @Override
  88. public void updateRowData(JsonArray rowArray) {
  89. for (int i = 0; i < rowArray.length(); ++i) {
  90. RpcDataSource.this.updateRowData(rowArray.getObject(i));
  91. }
  92. }
  93. });
  94. }
  95. private DataRequestRpc rpcProxy = getRpcProxy(DataRequestRpc.class);
  96. private DetailsListener detailsListener;
  97. private JsonArray droppedRowKeys = Json.createArray();
  98. @Override
  99. protected void requestRows(int firstRowIndex, int numberOfRows,
  100. RequestRowsCallback<JsonObject> callback) {
  101. if (droppedRowKeys.length() > 0) {
  102. rpcProxy.dropRows(droppedRowKeys);
  103. droppedRowKeys = Json.createArray();
  104. }
  105. /*
  106. * If you're looking at this code because you want to learn how to
  107. * use AbstactRemoteDataSource, please look somewhere else instead.
  108. *
  109. * We're not doing things in the conventional way with the callback
  110. * here since Vaadin doesn't directly support RPC with return
  111. * values. We're instead asking the server to push us some data, and
  112. * when we receive pushed data, we just push it along to the
  113. * underlying cache in the same way no matter if it was a genuine
  114. * push or just a result of us requesting rows.
  115. */
  116. Range cached = getCachedRange();
  117. rpcProxy.requestRows(firstRowIndex, numberOfRows, cached.getStart(),
  118. cached.length());
  119. /*
  120. * Show the progress indicator if there is a pending data request
  121. * and some of the visible rows are being requested. The RPC in
  122. * itself will not trigger the indicator since it might just fetch
  123. * some rows in the background to fill the cache.
  124. *
  125. * The indicator will be hidden by the framework when the response
  126. * is received (unless another request is already on its way at that
  127. * point).
  128. */
  129. if (getRequestedAvailability().intersects(
  130. Range.withLength(firstRowIndex, numberOfRows))) {
  131. getConnection().getLoadingIndicator().ensureTriggered();
  132. }
  133. }
  134. @Override
  135. public void ensureAvailability(int firstRowIndex, int numberOfRows) {
  136. super.ensureAvailability(firstRowIndex, numberOfRows);
  137. /*
  138. * We trigger the indicator already at this point since the actual
  139. * RPC will not be sent right away when waiting for the response to
  140. * a previous request.
  141. *
  142. * Only triggering here would not be enough since the check that
  143. * sets isWaitingForData is deferred. We don't want to trigger the
  144. * loading indicator here if we don't know that there is actually a
  145. * request going on since some other bug might then cause the
  146. * loading indicator to not be hidden.
  147. */
  148. if (isWaitingForData()
  149. && !Range.withLength(firstRowIndex, numberOfRows)
  150. .isSubsetOf(getCachedRange())) {
  151. getConnection().getLoadingIndicator().ensureTriggered();
  152. }
  153. }
  154. @Override
  155. public String getRowKey(JsonObject row) {
  156. if (row.hasKey(GridState.JSONKEY_ROWKEY)) {
  157. return row.getString(GridState.JSONKEY_ROWKEY);
  158. } else {
  159. return null;
  160. }
  161. }
  162. public RowHandle<JsonObject> getHandleByKey(Object key) {
  163. JsonObject row = Json.createObject();
  164. row.put(GridState.JSONKEY_ROWKEY, (String) key);
  165. return new RowHandleImpl(row, key);
  166. }
  167. @Override
  168. protected void unpinHandle(RowHandleImpl handle) {
  169. // Row data is no longer available after it has been unpinned.
  170. String key = getRowKey(handle.getRow());
  171. super.unpinHandle(handle);
  172. if (!handle.isPinned()) {
  173. if (indexOfKey(key) == -1) {
  174. // Row out of view has been unpinned. drop it
  175. droppedRowKeys.set(droppedRowKeys.length(), key);
  176. }
  177. }
  178. }
  179. void setDetailsListener(DetailsListener detailsListener) {
  180. this.detailsListener = detailsListener;
  181. }
  182. @Override
  183. protected void setRowData(int firstRowIndex, List<JsonObject> rowData) {
  184. super.setRowData(firstRowIndex, rowData);
  185. /*
  186. * Intercepting details information from the data source, rerouting
  187. * them back to the GridConnector (as a details listener)
  188. */
  189. for (int i = 0; i < rowData.size(); i++) {
  190. detailsListener.reapplyDetailsVisibility(firstRowIndex + i,
  191. rowData.get(i));
  192. }
  193. }
  194. /**
  195. * Updates row data based on row key.
  196. *
  197. * @since 7.6
  198. * @param row
  199. * new row object
  200. */
  201. protected void updateRowData(JsonObject row) {
  202. int index = indexOfKey(getRowKey(row));
  203. if (index >= 0) {
  204. setRowData(index, Collections.singletonList(row));
  205. }
  206. }
  207. @Override
  208. protected void onDropFromCache(int rowIndex, JsonObject row) {
  209. if (!isPinned(row)) {
  210. droppedRowKeys.set(droppedRowKeys.length(), getRowKey(row));
  211. }
  212. }
  213. @Override
  214. protected boolean canFetchData() {
  215. return isEnabled();
  216. }
  217. }
  218. private final RpcDataSource dataSource = new RpcDataSource();
  219. @Override
  220. protected void extend(ServerConnector target) {
  221. GridConnector gridConnector = (GridConnector) target;
  222. dataSource.setDetailsListener(gridConnector.getDetailsListener());
  223. gridConnector.setDataSource(dataSource);
  224. }
  225. }