private void renameDestination() { SaveFileDialog dialog = new SaveFileDialog(mainApp.getPrimaryStage(), recording, userPrefs); if (dialog.showAndWait()) { if (destinationExistsOrIsDuplicate(recording)) { recording.setFileExistsAction(Recording.FileExistsAction.REPLACE); } else { recording.setFileExistsAction(Recording.FileExistsAction.OK); } } setActiveButton(); }
/** * Return true if @recording's destination already exists or is a duplicate of another queued * recording */ private boolean destinationExistsOrIsDuplicate(Recording recording) { if (Files.exists(recording.getDestination())) { return true; } for (Recording earlierRecording : recordings) { if (earlierRecording == recording) { break; } else { if (recording.getDestination().equals(earlierRecording.getDestination())) { return true; } } } return false; }
public static List<Recording> getRecordingsWithDuplicateDestination(List<Recording> recordings) { Set<Path> seen = new HashSet<>(); Set<Path> duplicatePaths = new HashSet<>(); for (Recording recording : recordings) { Path destination = recording.getDestination(); if (seen.contains(destination)) { duplicatePaths.add(destination); } else { seen.add(destination); } } return recordings .stream() .filter(recording -> duplicatePaths.contains(recording.getDestination())) .collect(Collectors.toList()); }
private GridPane buildRecordingGrid(Recording recording) { GridPane grid = new GridPane(); grid.setHgap(5); grid.setVgap(5); Label status = new Label(); status.setAlignment(Pos.CENTER); status.setMinWidth(STATUS_MIN_WIDTH); updateStatusIcon(recording, status); recording .fileExistsActionProperty() .addListener(observable -> updateStatusIcon(recording, status)); Label title = new Label(); title.setMinWidth(TITLE_MIN_WIDTH); title.textProperty().bind(recording.fullTitleProperty()); Label destination = new Label(); destination.getStyleClass().add("destination"); destination.textProperty().bind(recording.destinationProperty().asString()); LocalDate dateArchived = recording.getDateArchived(); if (dateArchived != null) { String dateArchivedText = String.format("Archived %s", DateUtils.formatArchivedOnDate(dateArchived)); Tooltip tooltip = new Tooltip(dateArchivedText); title.setTooltip(tooltip); destination.setTooltip(tooltip); } ReplaceOrRenameActionBar actionBar = new ReplaceOrRenameActionBar(recording, userPrefs); actionBar.setMinWidth(ACTION_BAR_MIN_WIDTH); GridPane.setHalignment(actionBar, HPos.RIGHT); GridPane.setHgrow(actionBar, Priority.ALWAYS); GridPane.setMargin(actionBar, new Insets(0, 0, 0, 10)); grid.add(status, 0, 0, 1, 2); grid.add(title, 1, 0); grid.add(destination, 1, 1); grid.add(actionBar, 2, 0, 1, 2); return grid; }
private void setActiveButton() { switch (recording.getFileExistsAction()) { case OK: rename.setSelected(true); break; case REPLACE: replace.setSelected(true); break; case CANCEL: cancel.setSelected(true); break; } }
private void updateStatusIcon(Recording recording, Label status) { switch (recording.getFileExistsAction()) { case OK: status.setGraphic(mainApp.getGlyph(FontAwesome.Glyph.CHECK)); break; case REPLACE: status.setGraphic(mainApp.getGlyph(FontAwesome.Glyph.EXCLAMATION_CIRCLE)); break; case CANCEL: status.setGraphic(mainApp.getGlyph(FontAwesome.Glyph.CLOSE)); break; } }
private void initDialog() { dialog.initOwner(mainApp.getPrimaryStage()); dialog.initModality(Modality.APPLICATION_MODAL); dialog.initStyle(StageStyle.DECORATED); dialog.setResizable(true); dialog.setTitle("Recordings Already Exist"); dialog.setHeaderText("Replace or rename recordings?"); dialog.getDialogPane().setPadding(new Insets(10)); VBox vbox = new VBox(); vbox.setSpacing(10); dialog.getDialogPane().setContent(vbox); Label label = new Label( "Archiving the following recordings will replace files on your computer unless you rename them:"); vbox.getChildren().add(label); VBox recordingBox = new VBox(); recordingBox.setSpacing(20); for (Recording recording : recordingsToDisplay) { recording.setFileExistsAction(Recording.FileExistsAction.REPLACE); recordingBox.getChildren().add(buildRecordingGrid(recording)); } ScrollPane scrollPane = new ScrollPane(); scrollPane.getStyleClass().add("recording-exists-list"); scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); scrollPane.setFitToWidth(true); scrollPane.setFitToHeight(true); scrollPane.setContent(recordingBox); scrollPane.setPadding(new Insets(10)); vbox.getChildren().add(scrollPane); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); }
private void cancelArchive() { recording.setFileExistsAction(Recording.FileExistsAction.CANCEL); cancel.setSelected(true); }
private void replace() { recording.setFileExistsAction(Recording.FileExistsAction.REPLACE); replace.setSelected(true); }