diff --git a/src/main/java/io/github/dsheirer/gui/calls/CallsView.java b/src/main/java/io/github/dsheirer/gui/calls/CallsView.java index 14b655f4..48314f7c 100644 --- a/src/main/java/io/github/dsheirer/gui/calls/CallsView.java +++ b/src/main/java/io/github/dsheirer/gui/calls/CallsView.java @@ -33,6 +33,7 @@ import io.github.dsheirer.database.call.CallType; import io.github.dsheirer.database.call.RecordingState; import io.github.dsheirer.gui.table.ColumnConfigurationButton; import io.github.dsheirer.gui.table.TableColumnMonitor; +import io.github.dsheirer.gui.table.TableRowCopy; import io.github.dsheirer.protocol.Protocol; import io.github.dsheirer.sample.Listener; import javafx.animation.KeyFrame; @@ -89,6 +90,9 @@ import java.util.prefs.Preferences; * * The table shows one page of search results, newest first. On the first page, new calls that match the search * criteria are added at the top as they start, and the duration of calls in progress counts up. + * + * Rows can be selected (Ctrl+A selects the page) and copied to the clipboard as tab separated text (Ctrl+C or the + * context menu), which pastes into a spreadsheet. */ public class CallsView extends VBox { @@ -178,13 +182,18 @@ public class CallsView extends VBox createColumns(); mTableColumnMonitor = new TableColumnMonitor<>(mTableView, TABLE_KEY); mTableView.setPlaceholder(new Label("No calls")); - mTableView.getSelectionModel().setSelectionMode(javafx.scene.control.SelectionMode.SINGLE); + mTableView.getSelectionModel().setSelectionMode(javafx.scene.control.SelectionMode.MULTIPLE); mTableView.setRowFactory(table -> createRow()); mTableView.setOnKeyPressed(event -> { if(event.getCode() == KeyCode.ENTER) { play(mTableView.getSelectionModel().getSelectedItem()); } + else if(TableRowCopy.isCopy(event)) + { + copySelected(); + event.consume(); + } }); VBox.setVgrow(mTableView, Priority.ALWAYS); @@ -527,12 +536,17 @@ public class CallsView extends VBox status.setSortable(false); status.setCellValueFactory(cdf -> new ReadOnlyObjectWrapper<>(cdf.getValue())); status.setCellFactory(column -> new StatusCell()); + TableRowCopy.setCopyText(status, CallsView::getStatusText); TableColumn playing = new TableColumn<>("Playing"); playing.setId("playing"); playing.setPrefWidth(70); playing.setCellValueFactory(cdf -> new ReadOnlyObjectWrapper<>(cdf.getValue())); playing.setCellFactory(column -> new PlayingCell()); + TableRowCopy.setCopyText(playing, call -> { + ChannelPlayback playback = getPlayback(call); + return playback != null ? playback.channelName() : ""; + }); mTableView.getColumns().add(start); mTableView.getColumns().add(duration); @@ -727,7 +741,12 @@ public class CallsView extends VBox row.setOnContextMenuRequested(event -> { if(!row.isEmpty()) { - mTableView.getSelectionModel().select(row.getIndex()); + //Keep a multiple selection when the click is on one of the selected rows + if(!mTableView.getSelectionModel().isSelected(row.getIndex())) + { + mTableView.getSelectionModel().clearAndSelect(row.getIndex()); + } + createContextMenu(row.getItem()).show(row, event.getScreenX(), event.getScreenY()); event.consume(); } @@ -790,9 +809,85 @@ public class CallsView extends VBox }); menu.getItems().add(copy); + int selected = mTableView.getSelectionModel().getSelectedIndices().size(); + MenuItem copyRows = new MenuItem(selected > 1 ? "Copy " + selected + " Selected Rows" : "Copy Selected Row"); + copyRows.setOnAction(event -> copySelected()); + MenuItem selectAll = new MenuItem("Select All Rows on This Page"); + selectAll.setOnAction(event -> mTableView.getSelectionModel().selectAll()); + menu.getItems().addAll(new SeparatorMenuItem(), copyRows, selectAll); + return menu; } + /** + * Copies the selected rows to the clipboard as tab separated text with a header line, using the visible columns + * in their displayed order. + */ + void copySelected() + { + int count = TableRowCopy.copySelected(mTableView); + + if(count > 0) + { + mStatusLabel.setText("Copied " + count + (count == 1 ? " call" : " calls") + " to the clipboard"); + } + } + + /** + * Applies a change to the rows and keeps the selected calls selected. + */ + private void preserveSelection(Runnable change) + { + TableRowCopy.preserveSelection(mTableView, CallsView::getKeys, change); + } + + /** + * Identity keys of a call row: the live call key and the database row id + */ + private static List getKeys(CallRecord call) + { + List keys = new ArrayList<>(2); + + if(call.getCallKey() != 0) + { + keys.add("K" + call.getCallKey()); + } + + if(call.getId() != 0) + { + keys.add("I" + call.getId()); + } + + return keys; + } + + /** + * Status text of a call, for copying the status column + */ + static String getStatusText(CallRecord call) + { + String status; + + if(call.isActive()) + { + status = "In progress"; + } + else if(call.isPlayable()) + { + status = "Recorded"; + } + else if(call.isEncrypted()) + { + status = "Encrypted"; + } + else + { + status = call.getRecordingState().toString(); + } + + return call.isDuplicate() ? status + " (duplicate)" : status; + } + /** * Menu label suffix for the audio channel, empty for a mono output. */ @@ -841,7 +936,7 @@ public class CallsView extends VBox if(candidate.isPlayable()) { - mTableView.getSelectionModel().select(x); + mTableView.getSelectionModel().clearAndSelect(x); mTableView.scrollTo(Math.max(0, x - 3)); play(candidate); return; @@ -926,7 +1021,6 @@ public class CallsView extends VBox return; } - CallRecord selected = mTableView.getSelectionModel().getSelectedItem(); List calls = new ArrayList<>(); if(offset == 0) @@ -969,19 +1063,9 @@ public class CallsView extends VBox } } - mCalls.setAll(calls); + preserveSelection(() -> mCalls.setAll(calls)); mTotal = result.total(); updatePaging(); - - if(selected != null) - { - int index = indexOf(selected); - - if(index >= 0) - { - mTableView.getSelectionModel().select(index); - } - } })); } @@ -1025,10 +1109,11 @@ public class CallsView extends VBox } int index = indexOf(call); + final CallRecord update = call; if(index >= 0) { - mCalls.set(index, call); + preserveSelection(() -> mCalls.set(index, update)); } else if(mOffset == 0 && mCriteria.matches(call)) { @@ -1040,13 +1125,16 @@ public class CallsView extends VBox insert++; } - mCalls.add(insert, call); - mTotal++; + final int position = insert; + preserveSelection(() -> { + mCalls.add(position, update); - if(mCalls.size() > mPageSize) - { - mCalls.removeLast(); - } + if(mCalls.size() > mPageSize) + { + mCalls.removeLast(); + } + }); + mTotal++; updatePaging(); } @@ -1077,7 +1165,7 @@ public class CallsView extends VBox if(index >= 0) { - mCalls.set(index, updated); + preserveSelection(() -> mCalls.set(index, updated)); } } } @@ -1092,7 +1180,8 @@ public class CallsView extends VBox { CallRecord updated = row.copy(); updated.setId(saved.getId()); - mCalls.set(x, updated); + final int position = x; + preserveSelection(() -> mCalls.set(position, updated)); break; } }