/** * Sends given collection of data objects to the client-side. * * @param firstIndex * first index of pushed data * @param data * data objects to send as an iterable */ protected void pushData(int firstIndex, List<T> data) { JsonArray dataArray = Json.createArray(); int i = 0; for (T item : data) { dataArray.set(i++, getDataObject(item)); } rpc.setData(firstIndex, dataArray); handler.addActiveData(data.stream()); handler.cleanUp(data.stream()); }
/** * Informs the DataProvider that a data object has been updated. * * @param data * updated data object; not {@code null} */ public void refresh(T data) { Objects.requireNonNull(data, "DataCommunicator can not refresh null object"); Object id = getDataProvider().getId(data); // ActiveDataHandler has always the latest data through KeyMapper. Map<Object, T> activeData = getActiveDataHandler().getActiveData(); if (activeData.containsKey(id)) { // Item is currently available at the client-side if (updatedData.isEmpty()) { markAsDirty(); } updatedData.add(activeData.get(id)); } }
/** * Sets the item collapse allowed provider for this * HierarchicalDataCommunicator. The provider should return {@code true} for * any item that the user can collapse. * <p> * <strong>Note:</strong> This callback will be accessed often when sending * data to the client. The callback should not do any costly operations. * * @param provider * the item collapse allowed provider, not {@code null} */ public void setItemCollapseAllowedProvider( ItemCollapseAllowedProvider<T> provider) { Objects.requireNonNull(provider, "Provider can't be null"); itemCollapseAllowedProvider = provider; // Update hierarchy mapper mapper.setItemCollapseAllowedProvider(provider); getActiveDataHandler().getActiveData().values().forEach(this::refresh); }
/** * Triggered when rows have been dropped from the client side cache. * * @param keys * the keys of the rows that have been dropped * @since 8.0.6 */ protected void onDropRows(JsonArray keys) { for (int i = 0; i < keys.length(); ++i) { handler.dropActiveData(keys.getString(i)); } }
/** * Drops all data associated with this data communicator. */ protected void dropAllData() { for (DataGenerator<T> g : generators) { g.destroyAllData(); } handler.destroyAllData(); }