public class TechTypeTableSortModel implements ISortModel {
- private static final SortDirectionEnum[] NO_DIRECTIONS = {};
- private static final boolean[] NO_BOOLEANS = {};
-
- /**
- * Array that contains the sort direction for every column.
- * Needed to access the current sort state of a column.
- */
- protected SortDirectionEnum[] sortDirections = NO_DIRECTIONS;
-
- /**
- * Array that contains the sorted flags for every column.
- * Needed to access the current sort state of a column.
- */
- protected boolean[] sorted = NO_BOOLEANS;
-
/**
* As this implementation only supports single column sorting,
* this property contains the the column index of the column that
@Override
public boolean isColumnIndexSorted(int columnIndex) {
- if (sorted.length <= columnIndex)
- return false;
- return sorted[columnIndex];
+ return columnIndex == currentSortColumn && !currentSortDirection.equals(SortDirectionEnum.NONE);
}
@Override
public SortDirectionEnum getSortDirection(int columnIndex) {
- if (sortDirections.length <= columnIndex)
- return SortDirectionEnum.NONE;
- return sortDirections[columnIndex];
+ return columnIndex == currentSortColumn ? currentSortDirection : SortDirectionEnum.NONE;
}
@Override
}
@Override
+ @SuppressWarnings("rawtypes")
public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
return Collections.singletonList(AlphanumComparator.COMPARATOR);
}
if (!isColumnIndexSorted(columnIndex)) {
clear();
}
- int columnCount = bodyDataProvider.getColumnCount();
- sortDirections = ensureArraySize(sortDirections, columnCount, SortDirectionEnum.class, SortDirectionEnum.NONE);
-
- sortDirections[columnIndex] = sortDirection;
- sorted[columnIndex] = !sortDirection.equals(SortDirectionEnum.NONE);
currentSortColumn = columnIndex;
currentSortDirection = sortDirection;
+
+ bodyDataProvider.sortBy(columnIndex, sortDirection);
}
@Override
public void clear() {
- Arrays.fill(this.sortDirections, SortDirectionEnum.NONE);
- Arrays.fill(this.sorted, false);
this.currentSortColumn = -1;
this.currentSortDirection = SortDirectionEnum.NONE;
}