private void addComponent(Object item, Component component) { if (activeComponents.containsKey(item)) { if (activeComponents.get(item).equals(component)) { // Reusing old component return; } removeComponent(item); } activeComponents.put(item, component); getGrid().addExtensionComponent(component); }
private void removeComponent(Object item) { Component component = activeComponents.remove(item); if (component != null) { getGrid().removeExtensionComponent(component); } }
/** * Checks if column is attached and throws an * {@link IllegalStateException} if it is not. * * @throws IllegalStateException * if the column is no longer attached to any grid */ protected void checkColumnIsAttached() throws IllegalStateException { if (getGrid() == null) { throw new IllegalStateException( "Column is no longer attached to a grid."); } }
getGrid().markAsDirty();
getGrid().getDataCommunicator().reset();
if (expandRatio != getExpandRatio()) { getState().expandRatio = expandRatio; getGrid().markAsDirty();
/** * Sets a component and setter to use for editing values of this column * in the editor row. This is a shorthand for use in simple cases where * no validator or converter is needed. Use * {@link #setEditorBinding(Binding)} to support more complex cases. * <p> * <strong>Note:</strong> The same component cannot be used for multiple * columns. * * @param editorComponent * the editor component * @param setter * a setter that stores the component value in the row item * @return this column * * @see #setEditorBinding(Binding) * @see Grid#getEditor() * @see Binder#bind(HasValue, ValueProvider, Setter) */ public <C extends HasValue<V> & Component> Column<T, V> setEditorComponent( C editorComponent, Setter<T, V> setter) { Objects.requireNonNull(editorComponent, "Editor component cannot be null"); Objects.requireNonNull(setter, "Setter cannot be null"); Binding<T, V> binding = getGrid().getEditor().getBinder() .bind(editorComponent, valueProvider::apply, setter); return setEditorBinding(binding); }
/** * Sets the minimum width for this column. * <p> * This defines the minimum guaranteed pixel width of the column * <em>when it is set to expand</em>. * * @param pixels * the minimum width for the column * @throws IllegalStateException * if the column is no longer attached to any grid * @see #setExpandRatio(int) * @return the column itself */ public Column<T, V> setMinimumWidth(double pixels) throws IllegalStateException { checkColumnIsAttached(); final double maxwidth = getMaximumWidth(); if (pixels >= 0 && pixels > maxwidth && maxwidth >= 0) { throw new IllegalArgumentException("New minimum width (" + pixels + ") was greater than maximum width (" + maxwidth + ")"); } getState().minWidth = pixels; getGrid().markAsDirty(); return this; }
/** * Sets the user-defined identifier to map this column. The identifier * can be used for example in {@link Grid#getColumn(String)}. * <p> * The id is also used as the {@link #setSortProperty(String...) backend * sort property} for this column if no sort property or sort order * provider has been set for this column. * * @see #setSortProperty(String...) * @see #setSortOrderProvider(SortOrderProvider) * * @param id * the identifier string * @return this column */ public Column<T, V> setId(String id) { Objects.requireNonNull(id, "Column identifier cannot be null"); if (userId != null) { throw new IllegalStateException( "Column identifier cannot be changed"); } userId = id; getGrid().setColumnId(id, this); updateSortable(); return this; }
/** * Sets the description generator that is used for generating * descriptions for cells in this column. This method uses the given * content mode. * * @see #setDescriptionGenerator(DescriptionGenerator) * * @param cellDescriptionGenerator * the cell description generator to set, or {@code null} to * remove a previously set generator * @param tooltipContentMode * the content mode for tooltips * @return this column * * @since 8.2 */ public Column<T, V> setDescriptionGenerator( DescriptionGenerator<T> cellDescriptionGenerator, ContentMode tooltipContentMode) { this.descriptionGenerator = cellDescriptionGenerator; getState().tooltipContentMode = tooltipContentMode; getGrid().getDataCommunicator().reset(); return this; }
/** * Sets the maximum width for this column. * <p> * This defines the maximum allowed pixel width of the column <em>when * it is set to expand</em>. * * @param pixels * the maximum width * @throws IllegalStateException * if the column is no longer attached to any grid * @see #setExpandRatio(int) */ public Column<T, V> setMaximumWidth(double pixels) { checkColumnIsAttached(); final double minwidth = getMinimumWidth(); if (pixels >= 0 && pixels < minwidth && minwidth >= 0) { throw new IllegalArgumentException("New maximum width (" + pixels + ") was less than minimum width (" + minwidth + ")"); } getState().maxWidth = pixels; getGrid().markAsDirty(); return this; }
/** * Hides or shows the column. By default columns are visible before * explicitly hiding them. * * @since 7.5.0 * @param hidden * <code>true</code> to hide the column, <code>false</code> * to show * @return this column * @throws IllegalStateException * if the column is no longer attached to any grid */ public Column<T, V> setHidden(boolean hidden) { checkColumnIsAttached(); if (hidden != isHidden()) { getState().hidden = hidden; getGrid().fireColumnVisibilityChangeEvent(this, hidden, false); } return this; }
/** * Sets the style generator that is used for generating class names for * cells in this column. Returning null from the generator results in no * custom style name being set. * * Note: The style generator is applied only to the body cells, not to * the Editor. * * @param cellStyleGenerator * the cell style generator to set, not null * @return this column * @throws NullPointerException * if {@code cellStyleGenerator} is {@code null} */ public Column<T, V> setStyleGenerator( StyleGenerator<T> cellStyleGenerator) { Objects.requireNonNull(cellStyleGenerator, "Cell style generator must not be null"); this.styleGenerator = cellStyleGenerator; getGrid().getDataCommunicator().reset(); return this; }
/** * Sets the header caption for this column. * * @param caption * the header caption, not null * * @return this column */ public Column<T, V> setCaption(String caption) { Objects.requireNonNull(caption, "Header caption can't be null"); if (caption.equals(getState(false).caption)) { return this; } getState().caption = caption; HeaderRow row = getGrid().getDefaultHeaderRow(); if (row != null) { row.getCell(this).setText(caption); } return this; }
/** * Sets whether this column can be resized by the user. * * @since 7.6 * @param resizable * {@code true} if this column should be resizable, * {@code false} otherwise * @throws IllegalStateException * if the column is no longer attached to any grid */ public Column<T, V> setResizable(boolean resizable) { checkColumnIsAttached(); if (resizable != isResizable()) { getState().resizable = resizable; getGrid().markAsDirty(); } return this; }
/** * Marks the column width as undefined. An undefined width means the * grid is free to resize the column based on the cell contents and * available space in the grid. * * @return the column itself */ public Column<T, V> setWidthUndefined() { checkColumnIsAttached(); if (!isWidthUndefined()) { getState().width = -1; getGrid().markAsDirty(); getGrid().fireColumnResizeEvent(this, false); } return this; }
@Override public void destroyData(T item) { removeComponent(getGrid().getDataProvider().getId(item)); }
@SuppressWarnings("unchecked") private <P> JsonValue generateRendererValue(T item, ValueProvider<V, P> presentationProvider, Connector renderer) { P presentationValue = presentationProvider .apply(valueProvider.apply(item)); // Make Grid track components. if (renderer instanceof ComponentRenderer && presentationValue instanceof Component) { addComponent(getGrid().getDataProvider().getId(item), (Component) presentationValue); } return ((Renderer<P>) renderer).encode(presentationValue); }
private void updateSortable() { boolean inMemory = getGrid().getDataProvider().isInMemory(); boolean hasSortOrder = getSortOrder(SortDirection.ASCENDING) .count() != 0; getState().sortable = this.sortable && (inMemory || hasSortOrder); }