From 54d2591391f9a6003454ca84a4899f4c2b8ee590 Mon Sep 17 00:00:00 2001 From: Armin Schrenk Date: Wed, 9 Oct 2019 16:48:07 +0200 Subject: [PATCH] adding error screen for adding existing vault --- .../AddVaultFailureExisitingController.java | 51 +++++++++++++++++++ .../ui/addvaultwizard/AddVaultModule.java | 12 +++++ .../ChooseExistingVaultController.java | 15 +++--- .../org/cryptomator/ui/common/FxmlFile.java | 1 + .../ui/controls/FontAwesome5Icon.java | 1 + .../fxml/addvault_existing_error.fxml | 41 +++++++++++++++ .../main/resources/i18n/strings.properties | 5 ++ .../main/resources/i18n/strings_de.properties | 5 ++ 8 files changed, 124 insertions(+), 7 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExisitingController.java create mode 100644 main/ui/src/main/resources/fxml/addvault_existing_error.fxml diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExisitingController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExisitingController.java new file mode 100644 index 000000000..201f53345 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExisitingController.java @@ -0,0 +1,51 @@ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Lazy; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; +import javafx.beans.property.ObjectProperty; +import javafx.fxml.FXML; +import javafx.scene.Scene; +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.nio.file.Path; + +@AddVaultWizardScoped +public class AddVaultFailureExisitingController implements FxController { + + private final Stage window; + private final Lazy previousScene; + private final StringBinding vaultName; + + @Inject + AddVaultFailureExisitingController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_EXISTING) Lazy previousScene, ObjectProperty pathOfFailedVault){ + this.window = window; + this.previousScene = previousScene; + this.vaultName = Bindings.createStringBinding(() -> pathOfFailedVault.get().getFileName().toString(),pathOfFailedVault); + } + + @FXML + public void close(){ + window.close(); + } + + @FXML + public void back(){ + window.setScene(previousScene.get()); + } + + // Getter & Setter + + public StringBinding vaultNameProperty(){ + return vaultName; + } + + public String getVaultName(){ + return vaultName.get(); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index ef11e9ec7..4eaa1c207 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -94,6 +94,13 @@ public abstract class AddVaultModule { return fxmlLoaders.createScene(FxmlFile.ADDVAULT_EXISTING.getRessourcePathString()); } + @Provides + @FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR) + @AddVaultWizardScoped + static Scene provideChooseExistingVaultErrorScene(@AddVaultWizardWindow FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene(FxmlFile.ADDVAULT_EXISTING_ERROR.getRessourcePathString()); + } + @Provides @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) @AddVaultWizardScoped @@ -141,6 +148,11 @@ public abstract class AddVaultModule { @FxControllerKey(ChooseExistingVaultController.class) abstract FxController bindChooseExistingVaultController(ChooseExistingVaultController controller); + @Binds + @IntoMap + @FxControllerKey(AddVaultFailureExisitingController.class) + abstract FxController bindAddVaultFailureExistingController(AddVaultFailureExisitingController controller); + @Binds @IntoMap @FxControllerKey(CreateNewVaultNameController.class) diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java index 8856dc4cf..8bd11139a 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java @@ -28,16 +28,18 @@ public class ChooseExistingVaultController implements FxController { private final Stage window; private final Lazy welcomeScene; private final Lazy successScene; + private final Lazy errorScene; private final ObjectProperty vaultPath; private final ObjectProperty vault; private final VaultListManager vaultListManager; private final ResourceBundle resourceBundle; @Inject - ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, ObjectProperty vaultPath, @AddVaultWizardWindow ObjectProperty vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) { + ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy successScene, @FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR) Lazy errorScene, ObjectProperty vaultPath, @AddVaultWizardWindow ObjectProperty vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) { this.window = window; this.welcomeScene = welcomeScene; this.successScene = successScene; + this.errorScene = errorScene; this.vaultPath = vaultPath; this.vault = vault; this.vaultListManager = vaultListManager; @@ -51,20 +53,19 @@ public class ChooseExistingVaultController implements FxController { @FXML public void chooseFileAndNext() { - //TODO: error handling & cannot unlock added vault FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(resourceBundle.getString("addvaultwizard.existing.filePickerTitle")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Cryptomator Masterkey", "*.cryptomator")); - File file = fileChooser.showOpenDialog(window); - if (file != null) { - vaultPath.setValue(file.toPath().toAbsolutePath().getParent()); + File masterkeyFile = fileChooser.showOpenDialog(window); + if (masterkeyFile != null) { + vaultPath.setValue(masterkeyFile.toPath().toAbsolutePath().getParent()); try { Vault newVault = vaultListManager.add(vaultPath.get()); vault.set(newVault); window.setScene(successScene.get()); } catch (NoSuchFileException e) { - LOG.error("Nope", e); - // TODO + LOG.error("Failed to open existing vault.", e); + window.setScene(errorScene.get()); } } } diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 80f958813..553e70bef 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -3,6 +3,7 @@ package org.cryptomator.ui.common; public enum FxmlFile { ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), // ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), // + ADDVAULT_EXISTING_ERROR("/fxml/addvault_existing_error.fxml"), ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), // ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), // ADDVAULT_NEW_PASSWORD("/fxml/addvault_new_password.fxml"), // diff --git a/main/ui/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java b/main/ui/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java index 070f4519d..f5b62ae2b 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java +++ b/main/ui/src/main/java/org/cryptomator/ui/controls/FontAwesome5Icon.java @@ -9,6 +9,7 @@ public enum FontAwesome5Icon { CHECK("\uF00C"), // COG("\uF013"), // COGS("\uF085"), // + EXCLAMATION("\uF12A"), EXCLAMATION_TRIANGLE("\uF071"), // EYE("\uF06E"), // EYE_SLASH("\uF070"), // diff --git a/main/ui/src/main/resources/fxml/addvault_existing_error.fxml b/main/ui/src/main/resources/fxml/addvault_existing_error.fxml new file mode 100644 index 000000000..c145b6283 --- /dev/null +++ b/main/ui/src/main/resources/fxml/addvault_existing_error.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +