@Override public SortedSet<Integer> tailSet(Integer e) { int index = Collections.binarySearch(intervals, e); if(index < 0) { index = -index - 1; //retrieve the insertion point } IntegerUnion retVal = new IntegerUnion(); if(index % 2 != 0) { retVal.intervals = new ArrayList<>(intervals.subList(index, intervals.size())); retVal.intervals.add(0, e); } else { retVal.intervals = intervals.subList(index, intervals.size()); } return retVal; }
@Override public SortedSet<Integer> tailSet(Integer e) { int index = Collections.binarySearch(intervals, e); if(index < 0) { index = -index - 1; //retrieve the insertion point } IntegerUnion retVal = new IntegerUnion(); if(index % 2 != 0) { retVal.intervals = new ArrayList<>(intervals.subList(index, intervals.size())); retVal.intervals.add(0, e); } else { retVal.intervals = intervals.subList(index, intervals.size()); } return retVal; }
@Override public SortedSet<Integer> getSelectionTableRow() throws EditableElementException { SortedSet<Integer> modelRows = new IntegerUnion(); for (long value : selectedGeometries) { modelRows.add(getRowSet().getRowId(value)); } return modelRows; }
/** * @param zeroBaseDiff JTable selection is 0 based. Set 1 in order to get a 1 based row identifier selection. * @return Select row id */ private IntegerUnion getTableModelSelection(int zeroBaseDiff) { IntegerUnion selectionModelRowId = new IntegerUnion(); for (int viewRowId : table.getSelectedRows()) { selectionModelRowId.add(tableSorter.convertRowIndexToModel(viewRowId) + zeroBaseDiff); } return selectionModelRowId; }
private void writeSelection(OutputStream out) throws IOException { ObjectOutputStream selectionOut = new ObjectOutputStream(out); //Do not save byte consuming selection LongUnion mergedSelection; Set<Long> selection = tableEditableElement.getSelection(); if(selection instanceof LongUnion) { mergedSelection = (LongUnion) selection; } else { mergedSelection = new LongUnion(selection); } if(mergedSelection.getValueRanges().size()>MAX_SELECTION_SERIALISATION_SIZE) { selectionOut.writeObject(new IntegerUnion()); } else { selectionOut.writeObject(mergedSelection); } selectionOut.flush(); selectionOut.close(); }
/** * Invert the current table selection */ public void onMenuReverseSelection() { IntegerUnion invertedSelection = new IntegerUnion(); for(int viewId = 0; viewId<table.getRowCount();viewId++) { if(!table.isRowSelected(viewId)) { invertedSelection.add(viewId); } } setViewRowSelection(invertedSelection); }
/** * Convert index from model to view then update the table selection * @param modelSelection ModelIndex selection * @param zeroBasedDiff JTable selection is 0 based, you can offset the selection row identifier by defining -1 if your selection is 1 based */ private void setRowSelection(Set<Integer> modelSelection, int zeroBasedDiff) { Set<Integer> newSelection; if(tableSorter.isFiltered() || !tableSorter.getSortKeys().isEmpty()) { newSelection = new IntegerUnion(); for(int modelId : modelSelection) { modelId += zeroBasedDiff; int viewRowId = table.convertRowIndexToView(modelId); if(viewRowId!=-1) { newSelection.add(viewRowId); } } } else { newSelection = new IntegerUnion(); for(int modelId : modelSelection) { newSelection.add(modelId + zeroBasedDiff); } } setViewRowSelection(newSelection); }
/** * 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 SortedSet<Integer> getRowNumberFromRowPk(SortedSet<Long> pkSet) throws SQLException { SortedSet<Integer> rowsNum = new IntegerUnion(); if(rowFetchFirstPk == null) { for(long pk : pkSet) {
@Override public void setFilter(Collection<Integer> rowIdSet) { if(rowIdSet != null) { rowFilter = new IntegerUnion(rowIdSet); rowFilterIterator = rowFilter.listIterator(); if(!rowFilter.isEmpty()) { rowId = rowFilter.first() - 1; } else { rowId = 0; } currentRow = null; } else { rowFilter = null; rowFilterIterator = null; } }
@Override public void run(ProgressMonitor pm) { if (model.getRowCount() < 2) { return; } // Retrieve the index if the model have a restricted set of rows if (modelIndex == null) { //Create an array [0 1 ..rows] modelIndex = new IntegerUnion(0, model.getRowCount() - 1); } try(Connection connection = dataSource.getConnection()) { final Collection<Integer> sortedRow = ReadTable.getSortedColumnRowIndex(connection, model.getTableName(), columnSortName, sortRequest.getSortOrder() == SortOrder.ASCENDING, pm); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { //Update the table model on the swing thread eventSortedListeners.callListeners(new SortJobEventSorted(sortRequest, sortedRow, this)); } catch (EventException ex) { //Ignore } } }); } catch (IllegalStateException | SQLException ex) { LOGGER.error(I18N.tr("Driver error"), ex); } }
sortedSet = (SortedSet<Integer>) statisticsRowFilter; } else { sortedSet = new IntegerUnion(statisticsRowFilter);
if(readLock.tryLock(TRY_LOCK_TIME, TimeUnit.MILLISECONDS)) { SortedSet<Integer> modelRows = new IntegerUnion(); for (long value : selection) { modelRows.add(activeLayerRowSet.getRowId(value));
/** * Sort the column in the provided order * * @param sortRequest The key to sort */ public void setSortKey(SortKey sortRequest) { if (sortRequest != null) { //Check if the sort request is not on the geometry column int sortIndex = sortRequest.getColumn(); if(!isSortable(sortIndex)) { //Ignore sort request return; } launchSortProcess(sortRequest); } else { sortedColumns.clear(); if(isFiltered()) { IntegerUnion shownRows = new IntegerUnion(viewToModel); clearIndex(); setRowsFilter(shownRows); } else { clearIndex(); } } }
final IntegerUnion nextViewSelection = new IntegerUnion(); int rowCount = table.getRowCount(); ProgressMonitor viewUpdate = pm.startTask(I18N.tr("Read filter"), rowCount);