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(); }
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); } }