use of org.openforis.collect.metamodel.SurveySummarySortField in project collect by openforis.
the class SurveySelectVM method reloadSurveySummaries.
private void reloadSurveySummaries(Binder binder) {
Listheader lastSortedHeader = null;
boolean lastSortDirectionDescending = true;
if (binder != null) {
Component view = binder.getView();
Iterable<Component> listHeaders = view.queryAll("listheader");
for (Component headerComp : listHeaders) {
Listheader listHeader = (Listheader) headerComp;
String sortDirection = listHeader.getSortDirection();
if (!"natural".equals(sortDirection)) {
lastSortedHeader = listHeader;
lastSortDirectionDescending = "descending".equals(sortDirection);
break;
}
}
}
List<SurveySummarySortField> sortFields;
if (lastSortedHeader == null) {
sortFields = Arrays.asList(new SurveySummarySortField(Sortable.MODIFIED_DATE, true), new SurveySummarySortField(Sortable.NAME));
} else {
String id = lastSortedHeader.getId();
Sortable sortableField;
if ("surveysListNameHeader".equals(id)) {
sortableField = Sortable.NAME;
} else if ("surveysListProjectNameHeader".equals(id)) {
sortableField = Sortable.PROJECT_NAME;
} else if ("surveysListLastModifiedDateHeader".equals(id)) {
sortableField = Sortable.MODIFIED_DATE;
} else if ("surveysListTargetHeader".equals(id)) {
sortableField = Sortable.TARGET;
} else if ("surveysListModifiedHeader".equals(id)) {
sortableField = Sortable.MODIFIED;
} else if ("surveysListPublishedHeader".equals(id)) {
sortableField = Sortable.PUBLISHED;
} else {
throw new IllegalStateException("Unsupported sorting for column with header id " + id);
}
sortFields = Arrays.asList(new SurveySummarySortField(sortableField, lastSortDirectionDescending), new SurveySummarySortField(Sortable.NAME, lastSortDirectionDescending));
}
summaries = loadSurveySummaries(sortFields);
notifyChange("surveySummaries");
if (lastSortedHeader != null) {
lastSortedHeader.sort(!lastSortDirectionDescending);
}
}
Aggregations