@Override public void generateData(T item, JsonObject jsonObject) { if (generator == null || !visibleDetails.contains(item)) { return; } if (!components.containsKey(item)) { Component detailsComponent = generator.apply(item); Objects.requireNonNull(detailsComponent, "Details generator can't create null components"); if (detailsComponent.getParent() != null) { throw new IllegalStateException( "Details component was already attached"); } addComponentToGrid(detailsComponent); components.put(item, detailsComponent); } jsonObject.put(GridState.JSONKEY_DETAILS_VISIBLE, components.get(item).getConnectorId()); }
/** * Sets the visibility of details component for given item. * * @param item * the item to show details for * @param visible * {@code true} if details component should be visible; * {@code false} if it should be hidden */ public void setDetailsVisible(T item, boolean visible) { boolean refresh = false; if (!visible) { refresh = visibleDetails.remove(item); if (components.containsKey(item)) { removeComponentFromGrid(components.remove(item)); } } else { refresh = visibleDetails.add(item); } if (refresh) { refresh(item); } }
/** * Sets the details component generator. * * @param generator * the generator for details components */ public void setDetailsGenerator(DetailsGenerator<T> generator) { if (this.generator != generator) { removeAllComponents(); } this.generator = generator; visibleDetails.forEach(this::refresh); }
setSelectionModel(new SingleSelectionModelImpl<>()); detailsManager = new DetailsManager<>(); addExtension(detailsManager); addDataGenerator(detailsManager);
@Override public void remove() { removeAllComponents(); super.remove(); }
/** * Returns the visibility of details component for given item. * * @param item * the item to show details for * * @return {@code true} if details component should be visible; * {@code false} if it should be hidden */ public boolean isDetailsVisible(T item) { return detailsManager.isDetailsVisible(item); }
/** * Sets the details component generator. * * @param generator * the generator for details components */ public void setDetailsGenerator(DetailsGenerator<T> generator) { this.detailsManager.setDetailsGenerator(generator); }
/** * Sets the visibility of details component for given item. * * @param item * the item to show details for * @param visible * {@code true} if details component should be visible; * {@code false} if it should be hidden */ public void setDetailsVisible(T item, boolean visible) { detailsManager.setDetailsVisible(item, visible); }