/** * Adds a context click listener that gets notified when a context click * happens. * * @param listener * the context click listener to add, not null actual event * provided to the listener is {@link GridContextClickEvent} * @return a registration object for removing the listener * * @since 8.1 * @see #addItemClickListener * @see Registration */ @Override public Registration addContextClickListener( ContextClickEvent.ContextClickListener listener) { return super.addContextClickListener(listener); }
/** * Creates a new {@code AbstractListing} with the given custom data * communicator. * <p> * <strong>Note:</strong> This method is for creating an * {@code AbstractListing} with a custom communicator. In the common case * {@link AbstractListing#AbstractListing()} should be used. * <p> * * @param dataCommunicator * the data communicator to use, not null */ protected AbstractListing(DataCommunicator<T> dataCommunicator) { Objects.requireNonNull(dataCommunicator, "dataCommunicator cannot be null"); this.dataCommunicator = dataCommunicator; addExtension(dataCommunicator); }
@Override protected T deserializeDeclarativeRepresentation(String item) { if (item == null) { return super.deserializeDeclarativeRepresentation( UUID.randomUUID().toString()); } return super.deserializeDeclarativeRepresentation(new String(item)); }
/** * Reads the listing specific state from the given design. * <p> * This method is separated from {@link #readDesign(Element, DesignContext)} * to be overridable in subclasses that need to replace this, but still must * be able to call {@code super.readDesign(...)}. * * @see #doWriteDesign(Element, DesignContext) * * @param design * The element to obtain the state from * @param context * The DesignContext instance used for parsing the design */ protected void doReadDesign(Element design, DesignContext context) { Attributes attr = design.attributes(); if (attr.hasKey("readonly")) { setReadOnly(DesignAttributeHandler.readAttribute("readonly", attr, Boolean.class)); } setItemCaptionGenerator( new DeclarativeCaptionGenerator<>(getItemCaptionGenerator())); setItemIconGenerator( new DeclarativeIconGenerator<>(getItemIconGenerator())); readItems(design, context); }
T item = deserializeDeclarativeRepresentation(serializedItem); ItemCaptionGenerator<T> captionGenerator = getItemCaptionGenerator(); if (captionGenerator instanceof DeclarativeCaptionGenerator) { ((DeclarativeCaptionGenerator) captionGenerator).setCaption(item, IconGenerator<T> iconGenerator = getItemIconGenerator(); if (child.hasAttr("icon")) { if (iconGenerator instanceof DeclarativeIconGenerator) {
/** * Writes a data source Item to a design. Hierarchical select components * should override this method to recursively write any child items as well. * * @param design * the element into which to insert the item * @param item * the item to write * @param context * the DesignContext instance used in writing * @return a JSOUP element representing the {@code item} */ protected Element writeItem(Element design, T item, DesignContext context) { Element element = design.appendElement("option"); String caption = getItemCaptionGenerator().apply(item); if (caption != null) { element.html(DesignFormatter.encodeForTextNode(caption)); } else { element.html(DesignFormatter.encodeForTextNode(item.toString())); } element.attr("item", serializeDeclarativeRepresentation(item)); Resource icon = getItemIconGenerator().apply(item); if (icon != null) { DesignAttributeHandler.writeAttribute("icon", element.attributes(), icon, null, Resource.class, context); } return element; }
/** * 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 protected Collection<String> getCustomAttributes() { Collection<String> attributes = super.getCustomAttributes(); // "value" is not an attribute for the component. "selected" attribute // is used in "option"'s tag to mark selection which implies value for // single select component attributes.add("value"); return attributes; }
@Override public ItemCaptionGenerator<T> getItemCaptionGenerator() { return super.getItemCaptionGenerator(); }
/** * Adds this extension to the given parent listing. * * @param listing * the parent component to add to */ public void extend(AbstractListing<T> listing) { super.extend(listing); listing.addDataGenerator(this); }
@Override public void writeDesign(Element design, DesignContext designContext) { super.writeDesign(design, designContext); doWriteDesign(design, designContext); }
@Override public void readDesign(Element design, DesignContext context) { super.readDesign(design, context); doReadDesign(design, context); }
@Override public void beforeClientResponse(boolean initial) { super.beforeClientResponse(initial); if (initial && editor.isOpen()) { // Re-attaching grid. Any old editor should be closed. editor.cancel(); } }
/** * Removes the given data generator from this listing. If this listing does * not have the generator, does nothing. * * @param generator * the data generator to remove, not null */ protected void removeDataGenerator(DataGenerator<T> generator) { getDataCommunicator().removeDataGenerator(generator); }
@Override protected Collection<String> getCustomAttributes() { Collection<String> attributes = super.getCustomAttributes(); // "value" is not an attribute for the component. "selected" attribute // is used in "option"'s tag to mark selection which implies value for // multiselect component attributes.add("value"); return attributes; }
protected <F> SerializableConsumer<F> internalSetDataProvider( DataProvider<T, F> dataProvider, F initialFilter) { return getDataCommunicator().setDataProvider(dataProvider, initialFilter); }
@Override protected Collection<String> getCustomAttributes() { Collection<String> result = super.getCustomAttributes(); // "rename" for frozen column count result.add("frozen-column-count"); result.add("frozen-columns"); // "rename" for height-mode result.add("height-by-rows"); result.add("rows"); // add a selection-mode attribute result.add("selection-mode"); return result; }
protected DataProvider<T, ?> internalGetDataProvider() { return getDataCommunicator().getDataProvider(); }
/** * 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(); }
/** * 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(); }