You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/11/07 18:45:44 UTC
[isis] branch v2 updated: ISIS-2030: utilizes the grid facet to
reorder table columns
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 2f8f57c ISIS-2030: utilizes the grid facet to reorder table columns
2f8f57c is described below
commit 2f8f57c32e3a85c54c35c9d73062e8212bb4c8e5
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Nov 7 19:45:32 2018 +0100
ISIS-2030: utilizes the grid facet to reorder table columns
Task-Url: https://issues.apache.org/jira/browse/ISIS-2030
---
.../CollectionContentsAsAjaxTablePanel.java | 114 +++++++++++++--------
1 file changed, 71 insertions(+), 43 deletions(-)
diff --git a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
index 4b4e940..feefca0 100644
--- a/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
+++ b/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/collectioncontents/ajaxtable/CollectionContentsAsAjaxTablePanel.java
@@ -21,6 +21,8 @@ package org.apache.isis.viewer.wicket.ui.components.collectioncontents.ajaxtable
import static org.apache.isis.commons.internal.base._With.mapIfPresentElse;
+import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
@@ -164,6 +166,9 @@ extends PanelAbstract<EntityCollectionModel> implements CollectionCountProvider
private void addPropertyColumnsIfRequired(final List<IColumn<ObjectAdapter,String>> columns) {
final ObjectSpecification typeOfSpec = getModel().getTypeOfSpecification();
+
+ final Comparator<String> propertyIdComparator;
+
// same code also appears in EntityPage.
// we need to do this here otherwise any tables will render the columns in the wrong order until at least
// one object of that type has been rendered via EntityPage.
@@ -172,7 +177,26 @@ extends PanelAbstract<EntityCollectionModel> implements CollectionCountProvider
// the facet should always exist, in fact
// just enough to ask for the metadata.
// This will cause the current ObjectSpec to be updated as a side effect.
- final Grid unused = gridFacet.getGrid();
+ final Grid grid = gridFacet.getGrid();
+
+
+ final Map<String, Integer> propertyIdOrderWithinGrid = new HashMap<>();
+ grid.getAllPropertiesById().forEach((propertyId, __)->{
+ propertyIdOrderWithinGrid.put(propertyId, propertyIdOrderWithinGrid.size());
+ });
+
+ // if propertyId is mentioned within grid, put into first 'half' ordered by
+ // occurrence within grid
+ // if propertyId is not mentioned within grid, put into second 'half' ordered by
+ // propertyId (String) in natural order
+ propertyIdComparator = Comparator
+ .<String>comparingInt(propertyId->
+ propertyIdOrderWithinGrid.getOrDefault(propertyId, Integer.MAX_VALUE))
+ .thenComparing(Comparator.naturalOrder());
+
+
+ } else {
+ propertyIdComparator = null;
}
final Where whereContext =
@@ -186,48 +210,52 @@ extends PanelAbstract<EntityCollectionModel> implements CollectionCountProvider
getPersistenceSession(), getSpecificationLoader()).getSpecification()
: null;
- final Predicate<ObjectAssociation> predicate = ObjectAssociation.Predicates.PROPERTIES
- .and((final ObjectAssociation association)->{
- final Stream<Facet> facets = association.streamFacets()
- .filter((final Facet facet)->
- facet instanceof WhereValueFacet && facet instanceof HiddenFacet);
- return !facets
- .map(facet->(WhereValueFacet) facet)
- .anyMatch(wawF->wawF.where().includes(whereContext));
-
- })
- .and(associationDoesNotReferenceParent(parentSpecIfAny));
-
- final Stream<? extends ObjectAssociation> propertyList =
- typeOfSpec.streamAssociations(Contributed.INCLUDED)
- .filter(predicate);
-
- final Map<String, ObjectAssociation> propertyById = _Maps.newLinkedHashMap();
- propertyList.forEach(property->
- propertyById.put(property.getId(), property));
-
- List<String> propertyIds = _Lists.newArrayList(propertyById.keySet());
-
- // optional SPI to reorder
- final List<TableColumnOrderService> tableColumnOrderServices =
- getServicesInjector().streamServices(TableColumnOrderService.class)
- .collect(Collectors.toList());
-
- for (final TableColumnOrderService tableColumnOrderService : tableColumnOrderServices) {
- final List<String> propertyReorderedIds = reordered(tableColumnOrderService, propertyIds);
- if(propertyReorderedIds != null) {
- propertyIds = propertyReorderedIds;
- break;
- }
- }
-
- for (final String propertyId : propertyIds) {
- final ObjectAssociation property = propertyById.get(propertyId);
- if(property != null) {
- final ColumnAbstract<ObjectAdapter> nopc = createObjectAdapterPropertyColumn(property);
- columns.add(nopc);
- }
- }
+ final Predicate<ObjectAssociation> predicate = ObjectAssociation.Predicates.PROPERTIES
+ .and((final ObjectAssociation association)->{
+ final Stream<Facet> facets = association.streamFacets()
+ .filter((final Facet facet)->
+ facet instanceof WhereValueFacet && facet instanceof HiddenFacet);
+ return !facets
+ .map(facet->(WhereValueFacet) facet)
+ .anyMatch(wawF->wawF.where().includes(whereContext));
+
+ })
+ .and(associationDoesNotReferenceParent(parentSpecIfAny));
+
+ final Stream<? extends ObjectAssociation> propertyList =
+ typeOfSpec.streamAssociations(Contributed.INCLUDED)
+ .filter(predicate);
+
+ final Map<String, ObjectAssociation> propertyById = _Maps.newLinkedHashMap();
+ propertyList.forEach(property->
+ propertyById.put(property.getId(), property));
+
+ List<String> propertyIds = _Lists.newArrayList(propertyById.keySet());
+
+ if(propertyIdComparator!=null) {
+ propertyIds.sort(propertyIdComparator);
+ }
+
+ // optional SPI to reorder
+ final List<TableColumnOrderService> tableColumnOrderServices =
+ getServicesInjector().streamServices(TableColumnOrderService.class)
+ .collect(Collectors.toList());
+
+ for (final TableColumnOrderService tableColumnOrderService : tableColumnOrderServices) {
+ final List<String> propertyReorderedIds = reordered(tableColumnOrderService, propertyIds);
+ if(propertyReorderedIds != null) {
+ propertyIds = propertyReorderedIds;
+ break;
+ }
+ }
+
+ for (final String propertyId : propertyIds) {
+ final ObjectAssociation property = propertyById.get(propertyId);
+ if(property != null) {
+ final ColumnAbstract<ObjectAdapter> nopc = createObjectAdapterPropertyColumn(property);
+ columns.add(nopc);
+ }
+ }
}
private List<String> reordered(