protected void doGroupSort(CollectionDatasource.Sortable.SortInfo<MetaPropertyPath>[] sortInfo) { if (hasGroups()) { MetaPropertyPath propertyPath = sortInfo[0].getPropertyPath(); boolean asc = CollectionDatasource.Sortable.Order.ASC.equals(sortInfo[0].getOrder()); int index = ArrayUtils.indexOf(groupProperties, propertyPath); if (index > -1) { if (index == 0) { // Sort roots roots.sort(new GroupInfoComparator(asc)); } else { Object parentProperty = groupProperties[index - 1]; for (Map.Entry<GroupInfo, List<GroupInfo>> entry : children.entrySet()) { Object property = entry.getKey().getProperty(); if (property.equals(parentProperty)) { entry.getValue().sort(new GroupInfoComparator(asc)); } } } } else { Set<GroupInfo> groups = parents.keySet(); for (GroupInfo groupInfo : groups) { List<K> items = groupItems.get(groupInfo); if (items != null) { items.sort(new EntityByIdComparator<>(propertyPath, datasource, asc)); } } } } }
protected void setSortDirection(LoadContext.Query q) { boolean asc = Sortable.Order.ASC.equals(sortInfos[0].getOrder()); MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath(); String[] sortProperties = null; if (metadata.getTools().isPersistent(propertyPath)) { sortProperties = getSortPropertiesForPersistentAttribute(propertyPath); } else { // a non-persistent attribute List<String> relProperties = metadata.getTools().getRelatedProperties(propertyPath.getMetaProperty()); if (!relProperties.isEmpty()) { List<String> sortPropertiesList = new ArrayList<>(relProperties.size()); for (String relProp : relProperties) { String[] ppCopy = Arrays.copyOf(propertyPath.getPath(), propertyPath.getPath().length); ppCopy[ppCopy.length - 1] = relProp; MetaPropertyPath relPropertyPath = propertyPath.getMetaProperties()[0].getDomain().getPropertyPath(Joiner.on(".").join(ppCopy)); String[] sortPropertiesForRelProperty = getSortPropertiesForPersistentAttribute(relPropertyPath); if (sortPropertiesForRelProperty != null) Collections.addAll(sortPropertiesList, sortPropertiesForRelProperty); } if (!sortPropertiesList.isEmpty()) sortProperties = sortPropertiesList.toArray(new String[sortPropertiesList.size()]); } } if (sortProperties != null && sortProperties.length != 0) { QueryTransformer transformer = QueryTransformerFactory.createTransformer(q.getQueryString()); transformer.replaceOrderBy(!asc, sortProperties); String jpqlQuery = transformer.getResult(); q.setQueryString(jpqlQuery); } }
protected Comparator<Node<T>> createEntityNodeComparator() { final MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath(); final boolean asc = Order.ASC.equals(sortInfos[0].getOrder()); return new TreeTableNodeComparator<>(propertyPath, asc); } }
protected EntityComparator<T> createEntityComparator() { MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath(); boolean asc = Order.ASC.equals(sortInfos[0].getOrder()); return new EntityComparator<>(propertyPath, asc); }
protected Comparator<T> createEntityComparator() { // In case of generated column the sortInfos can actually contain string as a column identifier. if (sortInfos[0].getPropertyPath() != null) { final MetaPropertyPath propertyPath = sortInfos[0].getPropertyPath(); final boolean asc = Sortable.Order.ASC.equals(sortInfos[0].getOrder()); return new EntityComparator<>(propertyPath, asc); } else { // If we can not sort the datasource, just return the empty comparator. return (o1, o2) -> 0; } }