diff --git a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java index b50b5c7fc86..13694010c73 100644 --- a/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java +++ b/server/src/main/java/com/vaadin/data/provider/BackEndDataProvider.java @@ -17,6 +17,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; /** * A data provider that lazy loads items from a back end. @@ -44,6 +45,22 @@ public interface BackEndDataProvider extends DataProvider { */ void setSortOrders(List sortOrders); + /** + * Sets the sort order to use, given a {@link QuerySortOrderBuilder}. + * Shorthand for {@code setSortOrders(builder.build())}. + * + * @see QuerySortOrderBuilder + * + * @param builder + * the sort builder to retrieve the sort order from + * @throws NullPointerException + * if builder is null + */ + default void setSortOrders(QuerySortOrderBuilder builder) { + Objects.requireNonNull("Sort builder cannot be null."); + setSortOrders(builder.build()); + } + /** * Sets a single sort order to use as the default sorting for this data * provider. This overrides the sorting set by any other method that diff --git a/server/src/main/java/com/vaadin/data/provider/GridSortOrder.java b/server/src/main/java/com/vaadin/data/provider/GridSortOrder.java new file mode 100644 index 00000000000..ffb17d301d7 --- /dev/null +++ b/server/src/main/java/com/vaadin/data/provider/GridSortOrder.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2016 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.data.provider; + +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.ui.Grid.Column; + +/** + * Sorting information for {@link Grid}. + * + * @param + * the grid type + */ +public class GridSortOrder extends SortOrder> { + + /** + * Construct sorting information for usage in a {@link Grid}. + * + * @param column + * the column to be sorted + * @param direction + * sorting direction + */ + public GridSortOrder(Column column, SortDirection direction) { + super(column, direction); + } + + /** + * Gets the column this sorting information is attached to. + * + * @return the column being sorted + */ + @Override + public Column getSorted() { + return super.getSorted(); + } + + /** + * Creates a new grid sort builder with given sorting using ascending sort + * direction. + * + * @param by + * the column to sort by + * @param + * the grid type + * + * @return the grid sort builder + */ + public static GridSortOrderBuilder asc(Column by) { + return new GridSortOrderBuilder().thenAsc(by); + } + + /** + * Creates a new grid sort builder with given sorting using descending sort + * direction. + * + * @param by + * the column to sort by + * @param + * the grid type + * + * @return the grid sort builder + */ + public static GridSortOrderBuilder desc(Column by) { + return new GridSortOrderBuilder().thenDesc(by); + } +} diff --git a/server/src/main/java/com/vaadin/data/provider/GridSortOrderBuilder.java b/server/src/main/java/com/vaadin/data/provider/GridSortOrderBuilder.java new file mode 100644 index 00000000000..3aba2eba6b7 --- /dev/null +++ b/server/src/main/java/com/vaadin/data/provider/GridSortOrderBuilder.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2016 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.data.provider; + +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.ui.Grid.Column; + +/** + * Helper classes with fluent API for constructing {@link GridSortOrder} lists. + * When the sort order is ready to be passed on, calling {@link #build()} will + * create the list of sort orders. + * + * @see GridSortOrder + * @see #thenAsc(Column) + * @see #thenDesc(Column) + * @see #build() + * + * @param + * the type of the grid + */ +public class GridSortOrderBuilder + extends SortOrderBuilder, Column> { + + @Override + public GridSortOrderBuilder thenAsc(Column by) { + return (GridSortOrderBuilder) super.thenAsc(by); + } + + @Override + public GridSortOrderBuilder thenDesc(Column by) { + return (GridSortOrderBuilder) super.thenDesc(by); + } + + @Override + protected GridSortOrder createSortOrder(Column by, + SortDirection direction) { + return new GridSortOrder<>(by, direction); + } +} diff --git a/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java b/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java index ca8d743fae9..7f0a76bf912 100644 --- a/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java +++ b/server/src/main/java/com/vaadin/data/provider/QuerySortOrder.java @@ -45,4 +45,30 @@ public QuerySortOrder(String sorted, SortDirection direction) { public String getSorted() { return super.getSorted(); } + + /** + * Creates a new query sort builder with given sorting using ascending sort + * direction. + * + * @param by + * the string to sort by + * + * @return the query sort builder + */ + public static QuerySortOrderBuilder asc(String by) { + return new QuerySortOrderBuilder().thenAsc(by); + } + + /** + * Creates a new query sort builder with given sorting using descending sort + * direction. + * + * @param by + * the string to sort by + * + * @return the query sort builder + */ + public static QuerySortOrderBuilder desc(String by) { + return new QuerySortOrderBuilder().thenDesc(by); + } } diff --git a/server/src/main/java/com/vaadin/data/provider/QuerySortOrderBuilder.java b/server/src/main/java/com/vaadin/data/provider/QuerySortOrderBuilder.java new file mode 100644 index 00000000000..1f8d1e1aabc --- /dev/null +++ b/server/src/main/java/com/vaadin/data/provider/QuerySortOrderBuilder.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2016 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.data.provider; + +import com.vaadin.shared.data.sort.SortDirection; + +/** + * Helper classes with fluent API for constructing {@link QuerySortOrder} lists. + * When the sort order is ready to be passed on, calling {@link #build()} will + * create the list of sort orders. + * + * @see QuerySortOrder + * @see #thenDesc(String) + * @see #thenDesc(String) + * @see #build() + */ +public class QuerySortOrderBuilder extends SortOrderBuilder { + + @Override + public QuerySortOrderBuilder thenAsc(String by) { + return (QuerySortOrderBuilder) super.thenAsc(by); + } + + @Override + public QuerySortOrderBuilder thenDesc(String by) { + return (QuerySortOrderBuilder) super.thenDesc(by); + } + + @Override + protected QuerySortOrder createSortOrder(String by, + SortDirection direction) { + return new QuerySortOrder(by, direction); + } +} diff --git a/server/src/main/java/com/vaadin/data/provider/SortOrderBuilder.java b/server/src/main/java/com/vaadin/data/provider/SortOrderBuilder.java new file mode 100644 index 00000000000..29488b4415d --- /dev/null +++ b/server/src/main/java/com/vaadin/data/provider/SortOrderBuilder.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2016 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.data.provider; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.vaadin.shared.data.sort.SortDirection; + +/** + * Base class for helper classes with fluent API for constructing sort order + * lists. When the sort order is ready to be passed on, calling {@link #build()} + * will create the list of sort orders. + * + * @param + * the sort order type + * @param + * the sorting type + * + * @see SortOrderBuilder#thenAsc(Object) + * @see SortOrderBuilder#thenDesc(Object) + * @see #build() + */ +public abstract class SortOrderBuilder, V> + implements Serializable { + + private final List sortOrders = new ArrayList<>(); + + /** + * Appends sorting with ascending sort direction. + * + * @param by + * the object to sort by + * @return this sort builder + */ + public SortOrderBuilder thenAsc(V by) { + return append(createSortOrder(by, SortDirection.ASCENDING)); + } + + /** + * Appends sorting with descending sort direction. + * + * @param by + * the object to sort by + * @return this sort builder + */ + public SortOrderBuilder thenDesc(V by) { + return append(createSortOrder(by, SortDirection.DESCENDING)); + } + + /** + * Returns an unmodifiable copy of the list of current sort orders in this + * sort builder. + * + * @return an unmodifiable sort order list + */ + public final List build() { + return Collections.unmodifiableList(new ArrayList<>(sortOrders)); + } + + /** + * Creates a sort order object with the given parameters. + * + * @param by + * the object to sort by + * @param direction + * the sort direction + * + * @return the sort order object + */ + protected abstract T createSortOrder(V by, SortDirection direction); + + /** + * Append a sort order to {@code sortOrders}. + * + * @param sortOrder + * the sort order to append + * @return this + */ + private final SortOrderBuilder append(T sortOrder) { + sortOrders.add(sortOrder); + return this; + } +} diff --git a/server/src/main/java/com/vaadin/event/SortEvent.java b/server/src/main/java/com/vaadin/event/SortEvent.java index b6948fd7114..cca7bbd3b65 100644 --- a/server/src/main/java/com/vaadin/event/SortEvent.java +++ b/server/src/main/java/com/vaadin/event/SortEvent.java @@ -30,15 +30,14 @@ * @see SortListener * @see SortOrder * @param - * the type of the sorting information, usually a String (field id) - * or a {@link java.util.Comparator}. + * the type of the sorting information * * @since 8.0 * @author Vaadin Ltd */ -public class SortEvent extends Component.Event { +public class SortEvent> extends Component.Event { - private final List> sortOrder; + private final List sortOrder; private final boolean userOriginated; /** @@ -52,7 +51,7 @@ public class SortEvent extends Component.Event { * true if event is a result of user interaction, * false if from API call */ - public SortEvent(Component source, List> sortOrder, + public SortEvent(Component source, List sortOrder, boolean userOriginated) { super(source); this.sortOrder = sortOrder; @@ -64,7 +63,7 @@ public SortEvent(Component source, List> sortOrder, * * @return the sort order list */ - public List> getSortOrder() { + public List getSortOrder() { return sortOrder; } @@ -81,11 +80,10 @@ public boolean isUserOriginated() { * Listener for sort order change events. * * @param - * the type of the sorting information, usually a String (field - * id) or a {@link java.util.Comparator}. + * the type of the sorting information */ @FunctionalInterface - public interface SortListener extends Serializable { + public interface SortListener> extends Serializable { /** * Called when the sort order has changed. * @@ -100,10 +98,9 @@ public interface SortListener extends Serializable { * SortEvents}. * * @param - * the type of the sorting information, usually a String (field - * id) or a {@link java.util.Comparator}. + * the type of the sorting information */ - public interface SortNotifier extends Serializable { + public interface SortNotifier> extends Serializable { /** * Adds a sort order change listener that gets notified when the sort * order changes. @@ -113,6 +110,5 @@ public interface SortNotifier extends Serializable { * @return a registration object for removing the listener */ public Registration addSortListener(SortListener listener); - } } diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index b3410c57f07..16e452fbea7 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -46,9 +46,10 @@ import com.vaadin.data.ValueProvider; import com.vaadin.data.provider.DataCommunicator; import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.GridSortOrder; +import com.vaadin.data.provider.GridSortOrderBuilder; import com.vaadin.data.provider.Query; import com.vaadin.data.provider.QuerySortOrder; -import com.vaadin.data.provider.SortOrder; import com.vaadin.event.ConnectorEvent; import com.vaadin.event.ContextClickEvent; import com.vaadin.event.SortEvent; @@ -124,7 +125,7 @@ * the grid bean type */ public class Grid extends AbstractListing implements HasComponents, - HasDataProvider, SortNotifier> { + HasDataProvider, SortNotifier> { @Deprecated private static final Method COLUMN_REORDER_METHOD = ReflectTools.findMethod( @@ -559,11 +560,11 @@ public void sort(String[] columnInternalIds, SortDirection[] directions, assert columnInternalIds.length == directions.length : "Column and sort direction counts don't match."; - List>> list = new ArrayList<>( + List> list = new ArrayList<>( directions.length); for (int i = 0; i < columnInternalIds.length; ++i) { Column column = columnKeys.get(columnInternalIds[i]); - list.add(new SortOrder<>(column, directions[i])); + list.add(new GridSortOrder<>(column, directions[i])); } setSortOrder(list, isUserOriginated); } @@ -1790,7 +1791,7 @@ protected String getInternalIdForColumn(Column column) { private final Map> columnKeys = new HashMap<>(); private final Map> columnIds = new HashMap<>(); - private final List>> sortOrder = new ArrayList<>(); + private final List> sortOrder = new ArrayList<>(); private final DetailsManager detailsManager; private final Set extensionComponents = new HashSet<>(); private StyleGenerator styleGenerator = item -> null; @@ -2783,7 +2784,8 @@ public void sort(Column column) { */ public void sort(Column column, SortDirection direction) { setSortOrder( - Collections.singletonList(new SortOrder<>(column, direction))); + Collections + .singletonList(new GridSortOrder<>(column, direction))); } /** @@ -2803,10 +2805,26 @@ public void clearSortOrder() { * @throws IllegalArgumentException * if order is null */ - public void setSortOrder(List>> order) { + public void setSortOrder(List> order) { setSortOrder(order, false); } + /** + * Sets the sort order to use, given a {@link GridSortOrderBuilder}. + * Shorthand for {@code setSortOrder(builder.build())}. + * + * @see GridSortOrderBuilder + * + * @param builder + * the sort builder to retrieve the sort order from + * @throws NullPointerException + * if builder is null + */ + public void setSortOrder(GridSortOrderBuilder builder) { + Objects.requireNonNull(builder, "Sort builder cannot be null"); + setSortOrder(builder.build()); + } + /** * Adds a sort order change listener that gets notified when the sort order * changes. @@ -2815,7 +2833,8 @@ public void setSortOrder(List>> order) { * the sort order change listener to add */ @Override - public Registration addSortListener(SortListener> listener) { + public Registration addSortListener( + SortListener> listener) { return addListener(SortEvent.class, listener, SORT_ORDER_CHANGE_METHOD); } @@ -2824,7 +2843,7 @@ public Registration addSortListener(SortListener> listener) { * * @return a sort order list */ - public List>> getSortOrder() { + public List> getSortOrder() { return Collections.unmodifiableList(sortOrder); } @@ -3172,7 +3191,7 @@ protected String getInternalIdForColumn(Column column) { return column.getInternalId(); } - private void setSortOrder(List>> order, + private void setSortOrder(List> order, boolean userOriginated) { Objects.requireNonNull(order, "Sort order list cannot be null"); sortOrder.clear(); diff --git a/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java b/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java index ebdcdd105ce..84f011abf82 100644 --- a/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java +++ b/server/src/test/java/com/vaadin/data/provider/DataProviderTestBase.java @@ -82,7 +82,8 @@ public void testSortByComparatorListsDiffer() { .thenComparing(StrBean::getId); List list = dataProvider - .fetch(createQuery(Sort.asc("value").thenAsc("randomNumber") + .fetch(createQuery( + QuerySortOrder.asc("value").thenAsc("randomNumber") .thenAsc("id").build(), comp)) .collect(Collectors.toList()); @@ -104,10 +105,10 @@ public void testSortByComparatorListsDiffer() { public void testDefaultSortWithSpecifiedPostSort() { Comparator comp = Comparator.comparing(StrBean::getValue) .thenComparing(Comparator.comparing(StrBean::getId).reversed()); - setSortOrder(Sort.asc("value").thenDesc("id").build(), comp); + setSortOrder(QuerySortOrder.asc("value").thenDesc("id").build(), comp); List list = dataProvider - .fetch(createQuery(Sort.asc("randomNumber").build(), + .fetch(createQuery(QuerySortOrder.asc("randomNumber").build(), Comparator.comparing(StrBean::getRandomNumber))) .collect(Collectors.toList()); @@ -136,7 +137,7 @@ public void testDefaultSortWithSpecifiedPostSort() { @Test public void testDefaultSortWithFunction() { - setSortOrder(Sort.asc("value").build(), + setSortOrder(QuerySortOrder.asc("value").build(), Comparator.comparing(StrBean::getValue)); List list = dataProvider.fetch(new Query<>()) diff --git a/server/src/test/java/com/vaadin/data/provider/SortOrderBuildersTest.java b/server/src/test/java/com/vaadin/data/provider/SortOrderBuildersTest.java new file mode 100644 index 00000000000..e2896860401 --- /dev/null +++ b/server/src/test/java/com/vaadin/data/provider/SortOrderBuildersTest.java @@ -0,0 +1,66 @@ +package com.vaadin.data.provider; + +import java.time.LocalDate; +import java.util.Arrays; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.renderers.NumberRenderer; + +public class SortOrderBuildersTest { + + @Test + public void gridSortOrderBuilder() { + Grid grid = new Grid<>(); + Column col1 = grid.addColumn(string -> string); + Column col2 = grid.addColumn(string -> 1, + new NumberRenderer()); + Column col3 = grid + .addColumn(string -> LocalDate.of(0, 0, 0)); + + // construct with asc + verifySortOrders( + Arrays.asList( + new GridSortOrder<>(col1, SortDirection.ASCENDING), + new GridSortOrder<>(col2, SortDirection.DESCENDING), + new GridSortOrder<>(col3, SortDirection.ASCENDING)), + GridSortOrder.asc(col1).thenDesc(col2).thenAsc(col3).build()); + // construct with desc + verifySortOrders( + Arrays.asList( + new GridSortOrder<>(col1, SortDirection.DESCENDING), + new GridSortOrder<>(col2, SortDirection.DESCENDING), + new GridSortOrder<>(col3, SortDirection.ASCENDING)), + GridSortOrder.desc(col1).thenDesc(col2).thenAsc(col3).build()); + } + + @Test + public void querySortOrderBuilder() { + verifySortOrders( + Arrays.asList(new QuerySortOrder("a", SortDirection.ASCENDING), + new QuerySortOrder("b", SortDirection.DESCENDING), + new QuerySortOrder("c", SortDirection.ASCENDING)), + QuerySortOrder.asc("a").thenDesc("b").thenAsc("c").build()); + verifySortOrders( + Arrays.asList(new QuerySortOrder("a", SortDirection.DESCENDING), + new QuerySortOrder("b", SortDirection.DESCENDING), + new QuerySortOrder("c", SortDirection.ASCENDING)), + QuerySortOrder.desc("a").thenDesc("b").thenAsc("c").build()); + } + + private > void verifySortOrders(List order1, + List order2) { + Assert.assertEquals(order1.size(), order2.size()); + for (int i = 0; i < order1.size(); i++) { + Assert.assertEquals(order1.get(i).getDirection(), + order2.get(i).getDirection()); + Assert.assertEquals(order1.get(i).getSorted(), + order1.get(i).getSorted()); + } + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java index 73ef2fceebc..601a63115e4 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import com.vaadin.data.ValueProvider; -import com.vaadin.data.provider.SortOrder; +import com.vaadin.data.provider.GridSortOrder; import com.vaadin.event.selection.SelectionEvent; import com.vaadin.shared.data.sort.SortDirection; import com.vaadin.shared.ui.grid.HeightMode; @@ -179,7 +179,7 @@ public void sortByColumn_sortOrderIsAscendingOneColumn() { Column column = grid.getColumns().get(1); grid.sort(column); - SortOrder> sortOrder = grid.getSortOrder().get(0); + GridSortOrder sortOrder = grid.getSortOrder().get(0); Assert.assertEquals(column, sortOrder.getSorted()); Assert.assertEquals(SortDirection.ASCENDING, sortOrder.getDirection()); } @@ -189,7 +189,7 @@ public void sortByColumnDesc_sortOrderIsDescendingOneColumn() { Column column = grid.getColumns().get(1); grid.sort(column, SortDirection.DESCENDING); - SortOrder> sortOrder = grid.getSortOrder().get(0); + GridSortOrder sortOrder = grid.getSortOrder().get(0); Assert.assertEquals(column, sortOrder.getSorted()); Assert.assertEquals(SortDirection.DESCENDING, sortOrder.getDirection()); } @@ -198,12 +198,12 @@ public void sortByColumnDesc_sortOrderIsDescendingOneColumn() { public void setSortOrder() { Column column1 = grid.getColumns().get(1); Column column2 = grid.getColumns().get(2); - List>> order = Arrays.asList( - new SortOrder<>(column2, SortDirection.DESCENDING), - new SortOrder<>(column1, SortDirection.ASCENDING)); + List> order = Arrays.asList( + new GridSortOrder<>(column2, SortDirection.DESCENDING), + new GridSortOrder<>(column1, SortDirection.ASCENDING)); grid.setSortOrder(order); - List>> sortOrder = grid.getSortOrder(); + List> sortOrder = grid.getSortOrder(); Assert.assertEquals(column2, sortOrder.get(0).getSorted()); Assert.assertEquals(SortDirection.DESCENDING, sortOrder.get(0).getDirection()); @@ -228,7 +228,7 @@ public void sortListener_eventIsFired() { Column column1 = grid.getColumns().get(1); Column column2 = grid.getColumns().get(2); - List>> list = new ArrayList<>(); + List> list = new ArrayList<>(); AtomicReference fired = new AtomicReference<>(); grid.addSortListener(event -> { Assert.assertTrue(list.isEmpty()); @@ -241,9 +241,9 @@ public void sortListener_eventIsFired() { Assert.assertEquals(SortDirection.DESCENDING, list.get(0).getDirection()); - List>> order = Arrays.asList( - new SortOrder<>(column2, SortDirection.DESCENDING), - new SortOrder<>(column1, SortDirection.ASCENDING)); + List> order = Arrays.asList( + new GridSortOrder<>(column2, SortDirection.DESCENDING), + new GridSortOrder<>(column1, SortDirection.ASCENDING)); list.clear(); grid.setSortOrder(order);