private File getSelectedDirectory() { File directory = getSelectedFile(); if (directory != null && !directory.isDirectory()) directory = directory.getParentFile(); return directory; }
@FXML private void renameButtonClicked(final ActionEvent event) { final File selectedFile = getSelectedFile(); final File parent = selectedFile.getParentFile(); final String newName = showCreateOrRenameDialog( "Rename", "What should be the new name?", parent, selectedFile.getName(), (name) -> !selectedFile.getName().equals(name) && !createFile(parent, name).exists()); if (newName != null) { final File newFile = createFile(parent, newName); if (!selectedFile.renameTo(newFile)) showErrorDialog( "Failed to rename file!", "The file could not be renamed! Maybe you're missing the required permissions?!"); else { refresh(); getSelectedFiles().clear(); getSelectedFiles().add(newFile); } } }
@FXML private void createDirButtonClicked(final ActionEvent event) { final File parent = assertNotNull("getSelectedDirectory()", getSelectedDirectory()); final String dirName = showCreateOrRenameDialog( "Create folder", "What should be the new folder's name?", parent, null, (name) -> !createFile(parent, name).exists()); if (dirName != null) { final File directory = createFile(parent, dirName); directory.mkdirs(); if (!directory.isDirectory()) showErrorDialog( "Failed to create directory!", "The directory could not be created! Maybe you're missing the required permissions?!"); else { refresh(); getSelectedFiles().clear(); getSelectedFiles().add(directory); } } }
public JdbcConnectionFactory(final File localRoot) { this.localRoot = assertNotNull("localRoot", localRoot); if (!localRoot.isDirectory()) throw new IllegalArgumentException( "The given localRoot is not an existing directory: " + localRoot.getAbsolutePath()); initProperties(); initDriverClass(); }
@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); }
private String showCreateOrRenameDialog( final String title, final String headerText, final File parent, final String name, final NameVerifier nameVerifier) { final Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle(title); alert.setHeaderText(headerText); final GridPane contentContainer = new GridPane(); contentContainer.setPadding(new Insets(8)); contentContainer.setHgap(8); contentContainer.setVgap(8); contentContainer.add(new Label("Parent:"), 0, 0); final TextField parentTextField = new TextField(); parentTextField.setEditable(false); parentTextField.setText(parent.getAbsolutePath()); contentContainer.add(parentTextField, 1, 0); contentContainer.add(new Label("Name:"), 0, 1); final TextField dirNameTextField = new TextField(); dirNameTextField.setText(name); GridPane.setHgrow(dirNameTextField, Priority.ALWAYS); contentContainer.add(dirNameTextField, 1, 1); final InvalidationListener updateDisableInvalidationListener = (observable) -> { final String dirName = dirNameTextField.getText(); final Node okButton = alert.getDialogPane().lookupButton(ButtonType.OK); if (isEmpty(dirName)) okButton.setDisable(true); else { final boolean nameAcceptable = nameVerifier.isNameAcceptable(dirName); okButton.setDisable(!nameAcceptable); } }; dirNameTextField.textProperty().addListener(updateDisableInvalidationListener); alert.getDialogPane().setContent(contentContainer); alert.setOnShowing( (event) -> { dirNameTextField.requestFocus(); dirNameTextField.selectAll(); updateDisableInvalidationListener.invalidated(null); }); if (alert.showAndWait().get() == ButtonType.OK) return dirNameTextField.getText(); else return null; }
protected void createAndPersistPreliminaryCollision( final LocalRepoManager localRepoManager, final File file, String localPath, Uid cryptoRepoFileId) { assertNotNull("localRepoManager", localRepoManager); if (localPath == null) assertNotNull("localPath/file", file); logger.debug( "createAndPersistPreliminaryCollision: localRoot='{}' localRepositoryId={} file='{}' localPath='{}' cryptoRepoFileId={}", localRepoManager.getLocalRoot(), getRepositoryId(), (file == null ? "" : file.getAbsolutePath()), (localPath == null ? "" : localPath), cryptoRepoFileId); try (final LocalRepoTransaction tx = localRepoManager.beginWriteTransaction(); ) { if (localPath == null) localPath = '/' + localRepoManager .getLocalRoot() .relativize(file) .replace(FILE_SEPARATOR_CHAR, '/'); final PreliminaryCollisionDao pcDao = tx.getDao(PreliminaryCollisionDao.class); PreliminaryCollision preliminaryCollision = pcDao.getPreliminaryCollision(localPath); if (preliminaryCollision == null) { preliminaryCollision = new PreliminaryCollision(); preliminaryCollision.setPath(localPath); preliminaryCollision = pcDao.makePersistent(preliminaryCollision); } final CryptoRepoFileDao crfDao = tx.getDao(CryptoRepoFileDao.class); if (cryptoRepoFileId != null) { CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(cryptoRepoFileId); preliminaryCollision.setCryptoRepoFile(cryptoRepoFile); } else if (file != null) { final RepoFileDao rfDao = tx.getDao(RepoFileDao.class); final RepoFile repoFile = rfDao.getRepoFile(localRepoManager.getLocalRoot(), file); if (repoFile != null) { final CryptoRepoFile cryptoRepoFile = crfDao.getCryptoRepoFileOrFail(repoFile); preliminaryCollision.setCryptoRepoFile(cryptoRepoFile); } } tx.commit(); } catch (IOException x) { throw new RuntimeException(x); } }
@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."); } }
private UUID readRepositoryIdFromRepositoryPropertiesFile() { final File repositoryPropertiesFile = createFile(getMetaDir(), REPOSITORY_PROPERTIES_FILE_NAME); try { final Properties repositoryProperties = new Properties(); try (InputStream in = repositoryPropertiesFile.createInputStream(); ) { repositoryProperties.load(in); } final String repositoryIdStr = repositoryProperties.getProperty(PROP_REPOSITORY_ID); if (isEmpty(repositoryIdStr)) throw new IllegalStateException( "repositoryProperties.getProperty(PROP_REPOSITORY_ID) is empty!"); final UUID repositoryId = UUID.fromString(repositoryIdStr); return repositoryId; } catch (Exception x) { throw new RuntimeException( "Reading readRepositoryId from '" + repositoryPropertiesFile.getAbsolutePath() + "' failed: " + x, x); } }
public ParentFileEntry(final File parentFile) { this.parentFile = AssertUtil.assertNotNull("parentFile", parentFile); this.lastModified = parentFile.exists() ? parentFile.lastModified() : Long.MIN_VALUE; }