/** * Update the table selection * @param viewSelection View index selection */ private void setViewRowSelection(Set<Integer> viewSelection) { // Integer union is able to compute range of integer from a set of integer Iterator<Integer> intervals = new IntegerUnion(viewSelection).getValueRanges().iterator(); final int maxRow = table.getRowCount(); try { table.getSelectionModel().setValueIsAdjusting(true); table.clearSelection(); while(intervals.hasNext()) { // If the DataSource here and in other editors is not the same (uncommitted changes) // Then the selected row index may not be the same and can be out of range. // The check is done here. int begin = intervals.next(); int end = Math.min(intervals.next(),maxRow - 1); if(begin < maxRow) { table.addRowSelectionInterval(begin, end); } } }finally { table.getSelectionModel().setValueIsAdjusting(false); } }
@Override public void run() { // Update the table values List<Integer> ranges = nextViewSelection.getValueRanges(); Iterator<Integer> intervals = ranges.iterator(); try { table.getSelectionModel().setValueIsAdjusting(true); table.clearSelection(); ProgressMonitor swingPm = pm.startTask("Apply filter", ranges.size()); while (intervals.hasNext()) { int begin = intervals.next(); int end = intervals.next(); table.addRowSelectionInterval(begin, end); swingPm.endTask(); if (swingPm.isCancelled()) { return; } } } finally { table.getSelectionModel().setValueIsAdjusting(false); } if(!nextViewSelection.isEmpty()) { scrollToRow(nextViewSelection.first(), table); } } });