diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/AbstractColumn.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/AbstractColumn.java index 57d932745f4..dd2f76d5e3c 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/AbstractColumn.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/AbstractColumn.java @@ -20,6 +20,7 @@ import java.util.stream.Collectors; import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.Synchronize; import com.vaadin.flow.component.grid.Grid.Column; import com.vaadin.flow.internal.HtmlUtils; @@ -31,8 +32,7 @@ * @param * the subclass type */ -abstract class AbstractColumn> extends Component - implements ColumnBase { +abstract class AbstractColumn> extends Component { protected final Grid grid; private boolean headerRenderingScheduled; @@ -70,6 +70,165 @@ public Grid getGrid() { return grid; } + /** + * When set to {@code true}, the column is user-resizable. By default this + * is set to {@code false}. + * + * @param resizable + * whether to allow user resizing of this column + * @return this column, for method chaining + */ + @SuppressWarnings("unchecked") + public T setResizable(boolean resizable) { + getElement().setProperty("resizable", resizable); + return (T) this; + } + + /** + * Gets whether this column is user-resizable. + * + * @return whether this column is user-resizable + */ + @Synchronize("resizable-changed") + public boolean isResizable() { + return getElement().getProperty("resizable", false); + } + + /** + * Sets this column's frozen state. + *

+ * Note: Columns are frozen in-place, freeze columns from + * left to right for a consistent outcome. + * + * @param frozen + * whether to freeze or unfreeze this column + * @return this column, for method chaining + */ + @SuppressWarnings("unchecked") + public T setFrozen(boolean frozen) { + getElement().setProperty("frozen", frozen); + return (T) this; + } + + /** + * Gets the this column's frozen state. + * + * @return whether this column is frozen + */ + @Synchronize("frozen-changed") + public boolean isFrozen() { + return getElement().getProperty("frozen", false); + } + + /** + * Sets this column's frozen state. + *

+ * Note: Columns are frozen in-place, freeze columns from + * right to left for a consistent outcome. + * + * @param frozenToEnd + * whether to freeze or unfreeze this column + * @return this column, for method chaining + * @since 23.1 + */ + @SuppressWarnings("unchecked") + public T setFrozenToEnd(boolean frozenToEnd) { + getElement().setProperty("frozenToEnd", frozenToEnd); + return (T) this; + } + + /** + * Gets the this column's frozen state. + * + * @return whether this column is frozen to end + * @since 23.1 + */ + @Synchronize("frozen-to-end-changed") + public boolean isFrozenToEnd() { + return getElement().getProperty("frozenToEnd", false); + } + + /** + * Sets the column text align. + * + * @param textAlign + * the text alignment of the column. Setting it to + * null resets the alignment to the default value + * {@link ColumnTextAlign#START}. + * @return this column, for method chaining + */ + @SuppressWarnings("unchecked") + public T setTextAlign(ColumnTextAlign textAlign) { + getElement().setProperty("textAlign", + textAlign == null ? null : textAlign.getPropertyValue()); + + // Propagate text align to parent columns + if (getElement().getParent() != null) { + getElement().getParent().getComponent() + .filter(parent -> parent instanceof AbstractColumn + && parent.getChildren().count() == 1) + .map(AbstractColumn.class::cast) + .ifPresent(parent -> parent.setTextAlign(textAlign)); + } + + return (T) this; + } + + /** + * Gets the column text align. The default is {@link ColumnTextAlign#START}. + * + * @return the column text align, not null + */ + @Synchronize("text-align-changed") + public ColumnTextAlign getTextAlign() { + return ColumnTextAlign + .fromPropertyValue(getElement().getProperty("textAlign")); + } + + /** + * Sets a custom part name for the header cell. + * + * @param headerPartName + * the part name to set + * @return this column, for method chaining + */ + @SuppressWarnings("unchecked") + public T setHeaderPartName(String headerPartName) { + getElement().setProperty("headerPartName", headerPartName); + return (T) this; + } + + /** + * Gets the custom part name of the header cell. + * + * @return the part name + */ + public String getHeaderPartName() { + return getElement().getProperty("headerPartName"); + } + + /** + * Sets a custom part name for the footer cell. + * + * @param footerPartName + * the part name to set + * @return this column, for method chaining + */ + @SuppressWarnings("unchecked") + public T setFooterPartName(String footerPartName) { + getElement().setProperty("footerPartName", footerPartName); + return (T) this; + } + + /** + * Gets the custom part name of the footer cell. + * + * @return the part name + */ + public String getFooterPartName() { + return getElement().getProperty("footerPartName"); + } + private void scheduleHeaderRendering() { if (headerRenderingScheduled) { return; diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnBase.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnBase.java deleted file mode 100644 index 7c8d6539f84..00000000000 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnBase.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2000-2026 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.flow.component.grid; - -import com.vaadin.flow.component.HasElement; -import com.vaadin.flow.component.Synchronize; -import com.vaadin.flow.dom.Element; - -/** - * Mixin interface for {@link Grid} columns. - * - * @param - * the subclass type - * - * @author Vaadin Ltd. - */ -interface ColumnBase> extends HasElement { - - /** - * When set to {@code true}, the column is user-resizable. By default this - * is set to {@code false}. - * - * @param resizable - * whether to allow user resizing of this column - * @return this column, for method chaining - */ - @SuppressWarnings("unchecked") - default T setResizable(boolean resizable) { - getElement().setProperty("resizable", resizable); - return (T) this; - } - - /** - * Gets whether this column is user-resizable. - * - * @return whether this column is user-resizable - */ - @Synchronize("resizable-changed") - default boolean isResizable() { - return getElement().getProperty("resizable", false); - } - - /** - * Sets this column's frozen state. - *

- * Note: Columns are frozen in-place, freeze columns from - * left to right for a consistent outcome. - * - * @param frozen - * whether to freeze or unfreeze this column - * @return this column, for method chaining - */ - @SuppressWarnings("unchecked") - default T setFrozen(boolean frozen) { - getElement().setProperty("frozen", frozen); - return (T) this; - } - - /** - * Gets the this column's frozen state. - * - * @return whether this column is frozen - */ - @Synchronize("frozen-changed") - default boolean isFrozen() { - return getElement().getProperty("frozen", false); - } - - /** - * Sets this column's frozen state. - *

- * Note: Columns are frozen in-place, freeze columns from - * right to left for a consistent outcome. - * - * @param frozenToEnd - * whether to freeze or unfreeze this column - * @return this column, for method chaining - * @since 23.1 - */ - @SuppressWarnings("unchecked") - default T setFrozenToEnd(boolean frozenToEnd) { - getElement().setProperty("frozenToEnd", frozenToEnd); - return (T) this; - } - - /** - * Gets the this column's frozen state. - * - * @return whether this column is frozen to end - * @since 23.1 - */ - @Synchronize("frozen-to-end-changed") - default boolean isFrozenToEnd() { - return getElement().getProperty("frozenToEnd", false); - } - - /** - * Sets the column text align. - * - * @param textAlign - * the text alignment of the column. Setting it to - * null resets the alignment to the default value - * {@link ColumnTextAlign#START}. - * @return this column, for method chaining - */ - @SuppressWarnings("unchecked") - default T setTextAlign(ColumnTextAlign textAlign) { - getElement().setProperty("textAlign", - textAlign == null ? null : textAlign.getPropertyValue()); - - // Propagate text align to parent columns - if (getElement().getParent() != null) { - getElement().getParent().getComponent() - .filter(parent -> parent instanceof AbstractColumn - && parent.getChildren().count() == 1) - .map(AbstractColumn.class::cast) - .ifPresent(parent -> parent.setTextAlign(textAlign)); - } - - return (T) this; - } - - /** - * Gets the column text align. The default is {@link ColumnTextAlign#START}. - * - * @return the column text align, not null - */ - @Synchronize("text-align-changed") - default ColumnTextAlign getTextAlign() { - return ColumnTextAlign - .fromPropertyValue(getElement().getProperty("textAlign")); - } - - /** - * Sets a custom part name for the header cell. - * - * @param headerPartName - * the part name to set - * @return this column, for method chaining - */ - @SuppressWarnings("unchecked") - default T setHeaderPartName(String headerPartName) { - getElement().setProperty("headerPartName", headerPartName); - return (T) this; - } - - /** - * Gets the custom part name of the header cell. - * - * @return the part name - */ - default String getHeaderPartName() { - return getElement().getProperty("headerPartName"); - } - - /** - * Sets a custom part name for the footer cell. - * - * @param footerPartName - * the part name to set - * @return this column, for method chaining - */ - @SuppressWarnings("unchecked") - default T setFooterPartName(String footerPartName) { - getElement().setProperty("footerPartName", footerPartName); - return (T) this; - } - - /** - * Gets the custom part name of the footer cell. - * - * @return the part name - */ - default String getFooterPartName() { - return getElement().getProperty("footerPartName"); - } - - /** - * Gets the underlying column element. - *

- * It is highly discouraged to directly use the API exposed by the - * returned element. - * - * @return the root element of this component - */ - @Override - Element getElement(); -} diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnLayer.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnLayer.java index 6351b30cf89..0fb1dc99dde 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnLayer.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnLayer.java @@ -244,7 +244,7 @@ protected void updateSortingIndicators(boolean sortingIndicators) { * the total column ordering, having parent column groups * preceding children (pre-order). */ - protected void updateColumnOrder(List> columnsPreOrder) { + protected void updateColumnOrder(List> columnsPreOrder) { columns.sort(Comparator.comparingInt(columnsPreOrder::indexOf)); setColumns(columns); } diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnTextAlign.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnTextAlign.java index 3580d5c7c50..d5343a08472 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnTextAlign.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/ColumnTextAlign.java @@ -20,7 +20,7 @@ * * @author Vaadin Ltd. * - * @see ColumnBase#setTextAlign(ColumnTextAlign) + * @see Grid.Column#setTextAlign(ColumnTextAlign) * * @since 2.1 */ diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java index 6bbfce9ef64..8a6b6ec02a1 100755 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/Grid.java @@ -3529,11 +3529,11 @@ public void setColumnReorderingAllowed(boolean columnReorderingAllowed) { * * @return top-level columns and/or column groups of this grid */ - private List> getTopLevelColumns() { + private List> getTopLevelColumns() { return getElement().getChildren().map(element -> element.getComponent()) .filter(component -> component.isPresent() - && component.get() instanceof ColumnBase) - .map(component -> (ColumnBase) component.get()) + && component.get() instanceof AbstractColumn) + .map(component -> (AbstractColumn) component.get()) .collect(Collectors.toList()); } @@ -3898,7 +3898,7 @@ private List> fetchChildColumns(ColumnGroup columnGroup) { @SuppressWarnings("unchecked") private void appendChildColumns(List> list, - ColumnBase column) { + AbstractColumn column) { if (column instanceof Column) { list.add((Column) column); } else if (column instanceof ColumnGroup) { diff --git a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/GridColumnOrderHelper.java b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/GridColumnOrderHelper.java index ef8f84982ca..746e8df121c 100644 --- a/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/GridColumnOrderHelper.java +++ b/vaadin-grid-flow-parent/vaadin-grid-flow/src/main/java/com/vaadin/flow/component/grid/GridColumnOrderHelper.java @@ -93,7 +93,7 @@ void setColumnOrder(List> columns) { // update the new column ordering in the column layers as well, // otherwise // any future header/footer cell joining would use old ordering. - final List> columnsPreOrder = getColumnsPreOrder(); + final List> columnsPreOrder = getColumnsPreOrder(); for (ColumnLayer columnLayer : grid.getColumnLayers()) { columnLayer.updateColumnOrder(columnsPreOrder); } @@ -110,14 +110,14 @@ void setColumnOrder(List> columns) { * @return a list of all columns and column groups, ordered with preorder, * never {@code null}. */ - private List> getColumnsPreOrder() { + private List> getColumnsPreOrder() { return getColumnsPreOrder(grid); } - private List> getColumnsPreOrder(Component parent) { - final List> list = new ArrayList<>(); + private List> getColumnsPreOrder(Component parent) { + final List> list = new ArrayList<>(); if (parent instanceof AbstractColumn) { - list.add((ColumnBase) parent); + list.add((AbstractColumn) parent); } parent.getChildren().filter(col -> col instanceof AbstractColumn) .forEach(col -> list.addAll(getColumnsPreOrder(col)));