]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/techtype/table/TechTypeTableSortModel.java
Sorting support for tech type table columns
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / techtype / table / TechTypeTableSortModel.java
index f6a02f4a6c8990e5ac3eed2673f548905b73546e..95c9008e48336d2b8320acbc3c674279be07e529 100644 (file)
@@ -13,21 +13,6 @@ import org.simantics.utils.strings.AlphanumComparator;
 
 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
@@ -61,16 +46,12 @@ public class TechTypeTableSortModel implements ISortModel  {
 
     @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
@@ -79,6 +60,7 @@ public class TechTypeTableSortModel implements ISortModel  {
     }
 
     @Override
+    @SuppressWarnings("rawtypes")
     public List<Comparator> getComparatorsForColumnIndex(int columnIndex) {
         return Collections.singletonList(AlphanumComparator.COMPARATOR);
     }
@@ -94,20 +76,15 @@ public class TechTypeTableSortModel implements ISortModel  {
         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;
     }