private Sorter createSorter() { final List<ItemPoolSorter<InventoryItem>> oneColSorters = new ArrayList<ItemPoolSorter<InventoryItem>>(maxSortDepth); for (final ItemColumn col : this.colsToSort) { oneColSorters.add( new ItemPoolSorter<InventoryItem>( col.getFnSort(), col.getConfig().getSortState().equals(SortState.ASC) ? true : false)); } return new Sorter(oneColSorters); }
// Adds a column to sort cascade list. // If column is first in the cascade, inverts direction of sort. // Otherwise, sorts in ascending direction. public void add(final ItemColumn col0, final boolean forSetup) { this.sorter = null; if (forSetup) { // just add column unmodified if setting up sort columns this.colsToSort.add(0, col0); } else { if (colsToSort.size() > 0 && colsToSort.get(0).equals(col0)) { // if column already at top level, just invert col0.getConfig().setSortPriority(1); col0.getConfig() .setSortState( col0.getConfig().getSortState() == SortState.ASC ? SortState.DESC : SortState.ASC); } else { // otherwise move column to top level and move others down this.colsToSort.remove(col0); col0.getConfig().setSortPriority(1); col0.getConfig().setSortState(col0.getConfig().getDefaultSortState()); this.colsToSort.add(0, col0); } // decrement sort priority on remaining columns for (int i = 1; i < maxSortDepth; i++) { if (colsToSort.size() == i) { break; } if (colsToSort.get(i).getConfig().getSortPriority() != 0) { colsToSort.get(i).getConfig().setSortPriority(i + 1); } } } // unset and remove boundary columns. if (this.colsToSort.size() > maxSortDepth) { this.colsToSort.get(maxSortDepth).getConfig().setSortPriority(0); this.colsToSort.remove(maxSortDepth); } }