Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GridSortOrder and SortOrderBuilders (#8338)
- Loading branch information
Showing
11 changed files
with
441 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
server/src/main/java/com/vaadin/data/provider/GridSortOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 <T> | |||
* the grid type | |||
*/ | |||
public class GridSortOrder<T> extends SortOrder<Column<T, ?>> { | |||
|
|||
/** | |||
* Construct sorting information for usage in a {@link Grid}. | |||
* | |||
* @param column | |||
* the column to be sorted | |||
* @param direction | |||
* sorting direction | |||
*/ | |||
public GridSortOrder(Column<T, ?> column, SortDirection direction) { | |||
super(column, direction); | |||
} | |||
|
|||
/** | |||
* Gets the column this sorting information is attached to. | |||
* | |||
* @return the column being sorted | |||
*/ | |||
@Override | |||
public Column<T, ?> 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 <T> | |||
* the grid type | |||
* | |||
* @return the grid sort builder | |||
*/ | |||
public static <T> GridSortOrderBuilder<T> asc(Column<T, ?> by) { | |||
return new GridSortOrderBuilder<T>().thenAsc(by); | |||
} | |||
|
|||
/** | |||
* Creates a new grid sort builder with given sorting using descending sort | |||
* direction. | |||
* | |||
* @param by | |||
* the column to sort by | |||
* @param <T> | |||
* the grid type | |||
* | |||
* @return the grid sort builder | |||
*/ | |||
public static <T> GridSortOrderBuilder<T> desc(Column<T, ?> by) { | |||
return new GridSortOrderBuilder<T>().thenDesc(by); | |||
} | |||
} |
52 changes: 52 additions & 0 deletions
52
server/src/main/java/com/vaadin/data/provider/GridSortOrderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 <T> | |||
* the type of the grid | |||
*/ | |||
public class GridSortOrderBuilder<T> | |||
extends SortOrderBuilder<GridSortOrder<T>, Column<T, ?>> { | |||
|
|||
@Override | |||
public GridSortOrderBuilder<T> thenAsc(Column<T, ?> by) { | |||
return (GridSortOrderBuilder<T>) super.thenAsc(by); | |||
} | |||
|
|||
@Override | |||
public GridSortOrderBuilder<T> thenDesc(Column<T, ?> by) { | |||
return (GridSortOrderBuilder<T>) super.thenDesc(by); | |||
} | |||
|
|||
@Override | |||
protected GridSortOrder<T> createSortOrder(Column<T, ?> by, | |||
SortDirection direction) { | |||
return new GridSortOrder<>(by, direction); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
server/src/main/java/com/vaadin/data/provider/QuerySortOrderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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<QuerySortOrder, String> { | |||
|
|||
@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); | |||
} | |||
} |
99 changes: 99 additions & 0 deletions
99
server/src/main/java/com/vaadin/data/provider/SortOrderBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 <T> | |||
* the sort order type | |||
* @param <V> | |||
* the sorting type | |||
* | |||
* @see SortOrderBuilder#thenAsc(Object) | |||
* @see SortOrderBuilder#thenDesc(Object) | |||
* @see #build() | |||
*/ | |||
public abstract class SortOrderBuilder<T extends SortOrder<V>, V> | |||
implements Serializable { | |||
|
|||
private final List<T> sortOrders = new ArrayList<>(); | |||
|
|||
/** | |||
* Appends sorting with ascending sort direction. | |||
* | |||
* @param by | |||
* the object to sort by | |||
* @return this sort builder | |||
*/ | |||
public SortOrderBuilder<T, V> 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<T, V> 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<T> 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<T, V> append(T sortOrder) { | |||
sortOrders.add(sortOrder); | |||
return this; | |||
} | |||
} |
Oops, something went wrong.