private static QuerySort fromOrder(PropertySet<?> set, QuerySortOrder order) { Path<?> path = getPathByName(set, order.getSorted()).orElseThrow(() -> new IllegalArgumentException( "No property of the set matches with sort name: " + order.getSorted())); SortDirection direction = (order.getDirection() != null && order.getDirection() == com.vaadin.shared.data.sort.SortDirection.DESCENDING) ? SortDirection.DESCENDING : SortDirection.ASCENDING; return QuerySort.of(path, direction); }
/** * Get a {@link QuerySort} form given {@link QuerySortOrder}, if a {@link Path} property which corresponds to the * ordered property id is available. * <p> * If a {@link PropertySortGenerator} is bound to the property to sort, it will be used to provide the query sort. * </p> * @param order Sort order * @return Optional sort */ protected Optional<QuerySort> sortFromOrder(QuerySortOrder order) { QuerySort sort = null; Optional<PROPERTY> p = getPropertyById(order.getSorted()); if (p.isPresent()) { final PROPERTY property = p.get(); sort = getPropertySortGenerator(property).map(g -> g.getQuerySort(property, order.getDirection() == com.vaadin.shared.data.sort.SortDirection.ASCENDING)).orElse(null); if (sort == null && Path.class.isAssignableFrom(property.getClass())) { sort = QuerySort.of((Path<?>) property, (order.getDirection() == com.vaadin.shared.data.sort.SortDirection.DESCENDING) ? SortDirection.DESCENDING : SortDirection.ASCENDING); } } return Optional.ofNullable(sort); }
QuerySort sort = null; final SortDirection direction = (order.getDirection() != null && order.getDirection() == com.vaadin.shared.data.sort.SortDirection.DESCENDING) ? SortDirection.DESCENDING : SortDirection.ASCENDING;
final int startPage = (int) Math.floor((double) offset / pageSize); final int endPage = (int) Math.floor((double) (offset + pageSize - 1) / pageSize); final Sort.Direction sortDirection = sortOrder.isEmpty() || sortOrder.get(0).getDirection() == SortDirection.ASCENDING ? Sort.Direction.ASC : Sort.Direction.DESC;
@Override protected Stream fetchChildrenFromBackEnd(HierarchicalQuery query) { int offset = query.getOffset(); int limit = query.getLimit(); Account parent = (Account) query.getParent(); Iterator it = query.getSortOrders().iterator(); while (it.hasNext()) { QuerySortOrder order = (QuerySortOrder) it.next(); orders.put(order.getSorted(),order.getDirection() == SortDirection.DESCENDING); } try { return getAllChildren(offset,limit,orders,parent); } catch (Exception e) { getApp().getLog().error(e); return null; } } @Override
public DataProvider getParentDataProvider() { Map<String,Boolean> orders = new HashMap<>(); DataProvider dataProvider = DataProvider.fromCallbacks( (CallbackDataProvider.FetchCallback) query -> { int offset = query.getOffset(); int limit = query.getLimit(); Iterator it = query.getSortOrders().iterator(); while (it.hasNext()) { QuerySortOrder order = (QuerySortOrder) it.next(); orders.put(order.getSorted(),order.getDirection() == SortDirection.DESCENDING); } try { return getPossibleParents(offset,limit,orders); } catch (Exception e) { getApp().getLog().error(e); return null; } }, (CallbackDataProvider.CountCallback<Account, Void>) query -> { try { return getPossibleParentsCount(); } catch (Exception e) { getApp().getLog().error(e); return 0; } }); return dataProvider; }
@Override public DataProvider getDataProvider() { Map<String,Boolean> orders = new HashMap<>(); DataProvider dataProvider = DataProvider.fromCallbacks( (CallbackDataProvider.FetchCallback) query -> { int offset = query.getOffset(); int limit = query.getLimit(); for (Object o : query.getSortOrders()) { QuerySortOrder order = (QuerySortOrder) o; orders.put(order.getSorted(), order.getDirection() == SortDirection.DESCENDING); } User user = (User) query.getFilter().orElse(null); try { return getAll(offset,limit,orders,user); } catch (Exception e) { getApp().getLog().error(e); return null; } }, (CallbackDataProvider.CountCallback) query -> { User user = (User) query.getFilter().orElse(null); try { return getItemCount(user); } catch (Exception e) { getApp().getLog().error(e); return 0; } }); return (ConfigurableFilterDataProvider<Consumer,Void,User>) dataProvider.withConfigurableFilter(); }
@Override public DataProvider getDataProvider() { Map<String,Boolean> orders = new HashMap<>(); DataProvider dataProvider = DataProvider.fromCallbacks( (CallbackDataProvider.FetchCallback) query -> { int offset = query.getOffset(); int limit = query.getLimit(); for (Object o : query.getSortOrders()) { QuerySortOrder order = (QuerySortOrder) o; orders.put(order.getSorted(), order.getDirection() == SortDirection.DESCENDING); } DateRange dateRange = (DateRange) query.getFilter().orElse(null); try { return getAll(offset,limit,orders,defaultJournalId,dateRange); } catch (Exception e) { getApp().getLog().error(e); return null; } }, (CallbackDataProvider.CountCallback) query -> { DateRange dateRange = (DateRange) query.getFilter().orElse(null); try { return getItemCount(defaultJournalId,dateRange); } catch (Exception e) { getApp().getLog().error(e); return 0; } }); return (ConfigurableFilterDataProvider<GLTransaction,Void,DateRange>) dataProvider.withConfigurableFilter(); }