/** This method will select all objects in {@link #selectedFiles}.<br> */ private void handleMulitpleSelection() { HashSet fileSet = new HashSet(selectedFiles); affected.getSelectionModel().setValueIsAdjusting(true); affected.getSelectionModel().clearSelection(); for (int i = 0; !fileSet.isEmpty() && i < model.getRowCount(); i++) { File current = model.getFileAt(sorter.modelIndex(i)); if (fileSet.contains(current)) { fileSet.remove(current); affected.getSelectionModel().addSelectionInterval(i, i); } } affected.getSelectionModel().setValueIsAdjusting(false); }
/** * Creates and instance which stores the selection data. * * @param table the table to get the selected objects from. * @param tableSorterModel the sorting table model of entagged tag editor. * @param tableModel the table model of entagged tag editor. */ public SelectionRecord( JTable table, TableSorter tableSorterModel, TagEditorTableModel tableModel) { if (table == null || tableSorterModel == null || tableModel == null) { throw new IllegalArgumentException("argument must not be null!"); } this.affected = table; this.sorter = tableSorterModel; this.model = tableModel; int[] selectedRows = table.getSelectedRows(); if (selectedRows != null && selectedRows.length > 0) { for (int i = 0; i < selectedRows.length; i++) { selectedFiles.add(tableModel.getFileAt(sorter.modelIndex(selectedRows[i]))); singleFileIndex = selectedRows[i]; } } }
/** * This method will handle the selection change, if just one row has been selected on this records * creation.<br> */ private void applySingleSelection() { affected.getSelectionModel().setValueIsAdjusting(true); affected.getSelectionModel().clearSelection(); File searchFor = (File) selectedFiles.get(0); for (int i = 0; i < model.getRowCount(); i++) { if (model.getFileAt(sorter.modelIndex(i)).equals(searchFor)) { int newIndex = -1; if (i <= singleFileIndex) { newIndex = singleFileIndex + 1; if (newIndex >= model.getRowCount()) { newIndex = model.getRowCount() - 1; } } else { newIndex = singleFileIndex; } affected.changeSelection(newIndex, 0, false, false); break; } } affected.getSelectionModel().setValueIsAdjusting(false); }