@Override
  protected void handleFileTypeCollision(
      LocalRepoTransaction transaction,
      UUID fromRepositoryId,
      File file,
      Class<? extends RepoFileDto> fromFileType) {
    // In contrast to CloudStore, Subshare does not rename the collision-file immediately.
    // Therefore,
    // this method is invoked when a type-collision was already handled somewhere else and we're
    // re-downloading
    // here.

    final RemoteRepository remoteRepository =
        transaction.getDao(RemoteRepositoryDao.class).getRemoteRepositoryOrFail(fromRepositoryId);
    final LastSyncToRemoteRepo lastSyncToRemoteRepo =
        transaction.getDao(LastSyncToRemoteRepoDao.class).getLastSyncToRemoteRepo(remoteRepository);

    final File localRoot = getLocalRepoManager().getLocalRoot();
    final RepoFile repoFile = transaction.getDao(RepoFileDao.class).getRepoFile(localRoot, file);

    if (lastSyncToRemoteRepo != null
        && repoFile.getLocalRevision() <= lastSyncToRemoteRepo.getLocalRepositoryRevisionSynced()) {
      file.deleteRecursively();
      return;
    }
    super.handleFileTypeCollision(transaction, fromRepositoryId, file, fromFileType);
  }
Пример #2
0
  @FXML
  private void deleteButtonClicked(final ActionEvent event) {
    final Set<File> selectedFiles = getSelectedFiles();
    if (selectedFiles.isEmpty()) return;

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Delete");
    alert.setHeaderText("Delete these files?");

    final VBox contentContainer = new VBox();
    contentContainer.setSpacing(8);

    final Text contentText =
        new Text("The following files and folders are about to be deleted (folders recursively!):");
    contentText.setWrappingWidth(400);
    contentContainer.getChildren().add(contentText);

    final ListView<String> fileListView = new ListView<>();
    for (final File file : selectedFiles) fileListView.getItems().add(file.getAbsolutePath());

    fileListView.setPrefSize(400, 200);
    contentContainer.getChildren().add(fileListView);

    alert.getDialogPane().setContent(contentContainer);

    if (alert.showAndWait().get() == ButtonType.OK) {
      final List<File> notDeletedFiles = new ArrayList<>();
      for (final File file : selectedFiles) {
        file.deleteRecursively();
        if (file.exists()) notDeletedFiles.add(file);
      }
      refresh();

      if (!notDeletedFiles.isEmpty())
        showErrorDialog(
            "Deleting failed!",
            "The selected files (or directories) could be not deleted. They may have been deleted partially, though.");
    }
  }