implement next window of create new vault workflow

This commit is contained in:
infeo
2019-07-31 15:26:41 +02:00
parent 610460b3e4
commit 37c69f991f
7 changed files with 179 additions and 7 deletions

View File

@@ -76,10 +76,17 @@ public abstract class AddVaultModule {
@Provides
@FxmlScene(FxmlFile.ADDVAULT_NEW_NAME)
@AddVaultWizardScoped
static Scene provideCreateNewVaultScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) {
static Scene provideCreateNewVaultNameScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) {
return fxmlLoaders.createScene("/fxml/addvault_new_name.fxml");
}
@Provides
@FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION)
@AddVaultWizardScoped
static Scene provideCreateNewVaultLocationScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) {
return fxmlLoaders.createScene("/fxml/addvault_new_location.fxml");
}
// ------------------
@Binds
@@ -97,5 +104,9 @@ public abstract class AddVaultModule {
@FxControllerKey(CreateNewVaultNameController.class)
abstract FxController bindCreateNewVaultNameController(CreateNewVaultNameController controller);
@Binds
@IntoMap
@FxControllerKey(CreateNewVaultLocationController.class)
abstract FxController bindCreateNewVaultLocationController(CreateNewVaultLocationController controller);
}

View File

@@ -0,0 +1,122 @@
package org.cryptomator.ui.addvaultwizard;
import dagger.Lazy;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.StringProperty;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.common.FxmlFile;
import org.cryptomator.ui.common.FxmlScene;
import javax.inject.Inject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ResourceBundle;
/**
* TODO: Add trim() filter to vaultName
*/
@AddVaultWizardScoped
public class CreateNewVaultLocationController implements FxController {
private final Stage window;
private final Lazy<Scene> previousScene;
private final ObjectProperty<Path> vaultPath;
private final BooleanBinding vaultPathIsNull;
private final StringProperty vaultName;
private final ResourceBundle resourceBundle;
//TODO: add parameter for next window
@Inject
CreateNewVaultLocationController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy<Scene> previousScene, ObjectProperty<Path> vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) {
this.window = window;
this.previousScene = previousScene;
this.vaultPath = vaultPath;
this.vaultName = vaultName;
this.resourceBundle = resourceBundle;
this.vaultPathIsNull = vaultPath.isNull();
}
@FXML
public void back() {
window.setScene(previousScene.get());
}
@FXML
public void next() {
//TODO: what if there exists already a vault?
if (hasFullAccessToLocation()) {
window.close();
} else {
//TODO error handling
}
}
private boolean hasFullAccessToLocation() {
try {
Path tmp = Files.createFile(vaultPath.get().resolve("tmp"));
Files.delete(tmp);
return true;
} catch (IOException e) {
return false;
}
}
@FXML
public void chooseDirectory() {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle(resourceBundle.getString("addvaultwizard.new.directoryPickerTitle"));
setInitialDirectory(directoryChooser);
final File file = directoryChooser.showDialog(window);
if (file != null) {
vaultPath.setValue(file.toPath().toAbsolutePath());
}
}
private void setInitialDirectory(DirectoryChooser chooser) {
File userHome;
try {
userHome = new File(System.getProperty("user.home"));
} catch (Exception e) {
userHome = null;
}
if (userHome != null) {
chooser.setInitialDirectory(userHome);
}
}
/* Getter/Setter */
public String getVaultName() {
return vaultName.get();
}
public StringProperty vaultNameProperty() {
return vaultName;
}
public Path getVaultPath() {
return vaultPath.get();
}
public ObjectProperty<Path> vaultPathProperty() {
return vaultPath;
}
public boolean isVaultPathIsNull() {
return vaultPathIsNull.get();
}
public BooleanBinding vaultPathIsNullProperty() {
return vaultPathIsNull;
}
}

View File

@@ -26,13 +26,15 @@ public class CreateNewVaultNameController implements FxController {
public TextField textField;
private final Stage window;
private final Lazy<Scene> welcomeScene;
private final Lazy<Scene> nextScene;
private final StringProperty vaultName;
private final ResourceBundle resourceBundle;
@Inject
CreateNewVaultNameController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, StringProperty vaultName, ResourceBundle resourceBundle) {
CreateNewVaultNameController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy<Scene> nextScene, StringProperty vaultName, ResourceBundle resourceBundle) {
this.window = window;
this.welcomeScene = welcomeScene;
this.nextScene = nextScene;
this.vaultName = vaultName;
this.resourceBundle = resourceBundle;
}
@@ -50,7 +52,7 @@ public class CreateNewVaultNameController implements FxController {
@FXML
public void next() {
if (nameIsValid()) {
window.close();
window.setScene(nextScene.get());
} else {
//TODO
}

View File

@@ -5,10 +5,9 @@ public enum FxmlFile {
ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), //
ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), //
ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), //
PREFERENCES("/fxml/preferences.fxml"), //
ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), PREFERENCES("/fxml/preferences.fxml"), //
UNLOCK("/fxml/unlock2.fxml"), // TODO rename
UNLOCK_SUCCESS("/fxml/unlock_success.fxml"),
;
UNLOCK_SUCCESS("/fxml/unlock_success.fxml");
private final String filename;

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
<?import javafx.scene.layout.VBox?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.addvaultwizard.CreateNewVaultLocationController"
prefHeight="400.0" prefWidth="600.0"
alignment="CENTER">
<padding>
<Insets top="12" right="12" bottom="12" left="12"/>
</padding>
<children>
<Region VBox.vgrow="ALWAYS"/>
<Label text="%addvaultwizard.new.selectLocation"/>
<HBox spacing="18">
<TextField promptText="TODO path" text="${controller.vaultPath}" disable="true" HBox.hgrow="ALWAYS"/>
<Button text="TODO directorypicker" onAction="#chooseDirectory" HBox.hgrow="NEVER" prefWidth="120"/>
</HBox>
<Region VBox.vgrow="ALWAYS"/>
<ButtonBar buttonMinWidth="120" buttonOrder="B+X">
<buttons>
<Button text="TODO Back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
<Button text="TODO Next" ButtonBar.buttonData="NEXT_FORWARD" onAction="#next" defaultButton="true" disable="${controller.vaultPathIsNull}"/>
</buttons>
</ButtonBar>
</children>
</VBox>

View File

@@ -1,6 +1,8 @@
addvaultwizard.existing.instruction=Please choose the masterkey.cryptomator file of your existing vault. The directory contain it will be displayed.
addvaultwizard.existing.filePickerTitle=Open Masterkey File
addvaultwizard.new.insertName=Please enter a name for the vault.
addvaultwizard.new.selectLocation=Please pick a directory where your vault is stored:
addvaultwizard.new.directoryPickerTitle=Select Directory
main.closeBtn.tooltip=Close
main.settingsBtn.tooltip=Settings
preferences.title=Preferences

View File

@@ -1,6 +1,8 @@
addvaultwizard.existing.instruction=Please choose the masterkey.cryptomator file of your existing vault. The directory contain it will be displayed.
addvaultwizard.existing.filePickerTitle=Open Masterkey File
addvaultwizard.new.insertName=Please enter a name for the vault.
addvaultwizard.new.selectLocation=Please pick a directory where your vault is stored:
addvaultwizard.new.directoryPickerTitle=Select Directory
main.closeBtn.tooltip=Close
main.settingsBtn.tooltip=Settings
preferences.autoUpdateCheck=Check for updates automatically