/** * Sets the {@link Comparator} to use with in-memory sorting. * * @param comparator * comparator used to sort data */ public void setInMemorySorting(Comparator<T> comparator) { inMemorySorting = comparator; reset(); }
/** * Creates a new grid without support for creating columns based on property * names. Use an alternative constructor, such as {@link Grid#Grid(Class)}, * to create a grid that automatically sets up columns based on the type of * presented data. * * @see #Grid(Class) * @see #withPropertySet(PropertySet) */ public Grid() { this(new DataCommunicator<>()); }
public DataCommunicator() { addDataGenerator(handler); rpc = getRpcProxy(DataCommunicatorClientRpc.class); registerRpc(createRpc()); keyMapper = createKeyMapper(dataProvider::getId); }
/** * Method for internal reset from a change in the component, requiring a * full data update. */ public void reset() { // Only needed if a full reset is not pending. if (!reset) { beforeClientResponse(true); // Soft reset through client-side re-request. getClientRpc().reset(getDataProviderSize()); } }
/** * Sets a new {@code DataProvider} and refreshes all the internal * structures. * * @param dataProvider * @since 8.1 */ protected void setDataProvider(DataProvider<T, ?> dataProvider) { detachDataProviderListener(); dropAllData(); this.dataProvider = dataProvider; getKeyMapper().setIdentifierGetter(dataProvider::getId); } }
Objects.requireNonNull(dataProvider, "data provider cannot be null"); filter = initialFilter; setDataProvider(dataProvider); setPushRows(Range.between(0, getMinPushSize())); if (isAttached()) { attachDataProviderListener(); markAsDirty(); setFilter(filter); reset(); markAsDirty();
if (getDataProvider() == null) { return; rpc.reset(getDataProviderSize()); int i = 0; for (T data : updatedData) { dataArray.set(i++, getDataObject(data)); Range requestedRows = getPushRows(); boolean triggerReset = false; if (!requestedRows.isEmpty()) { int limit = requestedRows.length(); List<T> rowsToPush = fetchItemsWithRange(offset, limit); pushData(offset, rowsToPush); setPushRows(Range.withLength(0, 0)); reset = triggerReset; updatedData.clear();
/** * Adds the given data generator to this listing. If the generator was * already added, does nothing. * * @param generator * the data generator to add, not null */ protected void addDataGenerator(DataGenerator<T> generator) { getDataCommunicator().addDataGenerator(generator); }
@Override public void attach() { super.attach(); attachDataProviderListener(); }
@Override public void detach() { super.detach(); detachDataProviderListener(); }
@Override public void editRow(int rowNumber) throws IllegalStateException, IllegalArgumentException { if (!isEnabled()) { throw new IllegalStateException("Item editor is not enabled"); } T beanToEdit = getParent().getDataCommunicator() .fetchItemsWithRange(rowNumber, 1).stream().findFirst() .orElseThrow(() -> new IllegalArgumentException( "Row number " + rowNumber + "did not yield any item from data provider")); if (!beanToEdit.equals(edited)) { if (isBuffered() && edited != null) { throw new IllegalStateException("Editing item " + beanToEdit + " failed. Item editor is already editing item " + edited); } else { rpc.bind(rowNumber); } } }
/** * Extends a Grid and makes it's rows draggable. * * @param target * Grid to be extended. */ public GridDragSource(Grid<T> target) { super(target); // Create drag data generator dragDataGenerator = this::generateDragData; // Add drag data generator to Grid target.getDataCommunicator().addDataGenerator(dragDataGenerator); generatorFunctions = new HashMap<>(); // Set default generator function for "text" parameter generatorFunctions.put(DragSourceState.DATA_TYPE_TEXT, defaultGridGenerator); }
/** * Adds a data generator to this data communicator. Data generators can be * used to insert custom data to the rows sent to the client. If the data * generator is already added, does nothing. * * @param generator * the data generator to add, not null */ public void addDataGenerator(DataGenerator<T> generator) { Objects.requireNonNull(generator, "generator cannot be null"); generators.add(generator); // Make sure data gets generated when adding data generators. reset(); }
/** * Creates a new {@code AbstractListing} with a default data communicator. * <p> */ protected AbstractListing() { this(new DataCommunicator<>()); }
/** * Sets the {@link QuerySortOrder}s to use with backend sorting. * * @param sortOrder * list of sort order information to pass to a query */ public void setBackEndSorting(List<QuerySortOrder> sortOrder) { backEndSorting.clear(); backEndSorting.addAll(sortOrder); reset(); }
/** * Creates a grid using a custom {@link PropertySet} implementation for * configuring the initial columns and resolving property names for * {@link #addColumn(String)} and * {@link Column#setEditorComponent(HasValue)}. * * @see #withPropertySet(PropertySet) * * @param propertySet * the property set implementation to use, not <code>null</code>. */ protected Grid(PropertySet<T> propertySet) { this(propertySet, new DataCommunicator<>()); }
/** * Sets the item caption generator that is used to produce the strings shown * in the combo box for each item. By default, * {@link String#valueOf(Object)} is used. * * @param itemCaptionGenerator * the item caption provider to use, not null */ protected void setItemCaptionGenerator( ItemCaptionGenerator<T> itemCaptionGenerator) { Objects.requireNonNull(itemCaptionGenerator, "Item caption generators must not be null"); this.itemCaptionGenerator = itemCaptionGenerator; getDataCommunicator().reset(); }
/** * Creates a new grid that uses reflection based on the provided bean type * to automatically set up an initial set of columns. All columns will be * configured using the same {@link Object#toString()} renderer that is used * by {@link #addColumn(ValueProvider)}. * * @param beanType * the bean type to use, not <code>null</code> * @see #Grid() * @see #withPropertySet(PropertySet) */ public Grid(Class<T> beanType) { this(beanType, new DataCommunicator<>()); }
/** * Sets the item icon generator that is used to produce custom icons for * shown items. The generator can return null for items with no icon. * <p> * Implementations that support item icons make this method public. * * @see IconGenerator * * @param itemIconGenerator * the item icon generator to set, not null * @throws NullPointerException * if {@code itemIconGenerator} is {@code null} */ protected void setItemIconGenerator(IconGenerator<T> itemIconGenerator) { Objects.requireNonNull(itemIconGenerator, "Item icon generator must not be null"); this.itemIconGenerator = itemIconGenerator; getDataCommunicator().reset(); }
/** * Sets the style generator that is used to produce custom class names for * items visible in the popup. The CSS class name that will be added to the * item is <tt>v-filterselect-item-[style name]</tt>. Returning null from * the generator results in no custom style name being set. * * @see StyleGenerator * * @param itemStyleGenerator * the item style generator to set, not null * @throws NullPointerException * if {@code itemStyleGenerator} is {@code null} * @since 8.0 */ public void setStyleGenerator(StyleGenerator<T> itemStyleGenerator) { Objects.requireNonNull(itemStyleGenerator, "Item style generator must not be null"); this.itemStyleGenerator = itemStyleGenerator; getDataCommunicator().reset(); }