소스 검색

replaced AddVaultFailureExistingController by AddVaultGenericErrorController

Sebastian Stenzel 5 년 전
부모
커밋
54c0df51d5

+ 0 - 51
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultFailureExistingController.java

@@ -1,51 +0,0 @@
-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 AddVaultFailureExistingController implements FxController {
-
-	private final Stage window;
-	private final Lazy<Scene> previousScene;
-	private final StringBinding vaultName;
-
-	@Inject
-	AddVaultFailureExistingController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_EXISTING) Lazy<Scene> previousScene, ObjectProperty<Path> 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();
-	}
-
-}

+ 48 - 0
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultGenericErrorController.java

@@ -0,0 +1,48 @@
+package org.cryptomator.ui.addvaultwizard;
+
+import javafx.beans.binding.BooleanBinding;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.ReadOnlyObjectProperty;
+import javafx.fxml.FXML;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import org.cryptomator.ui.common.FxController;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+@AddVaultWizardScoped
+public class AddVaultGenericErrorController implements FxController {
+
+	private final Stage window;
+	private final ReadOnlyObjectProperty<Scene> previousScene;
+	private final BooleanBinding returnToPreviousSceneAllowed;
+
+	@Inject
+	AddVaultGenericErrorController(@AddVaultWizardWindow Stage window, @Named("genericErrorReturnScene") ObjectProperty<Scene> previousScene) {
+		this.window = window;
+		this.previousScene = previousScene;
+		this.returnToPreviousSceneAllowed = previousScene.isNotNull();
+	}
+
+	@FXML
+	public void back() {
+		assert previousScene.get() != null; // otherwise button should be disabled
+		window.setScene(previousScene.get());
+	}
+
+	@FXML
+	public void close(){
+		window.close();
+	}
+
+	/* Getter/Setter */
+
+	public BooleanBinding returnToPreviousSceneAllowedProperty() {
+		return returnToPreviousSceneAllowed;
+	}
+
+	public boolean isReturnToPreviousSceneAllowed() {
+		return returnToPreviousSceneAllowed.get();
+	}
+}

+ 30 - 8
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java

@@ -21,6 +21,7 @@ import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlScene;
 import org.cryptomator.ui.common.NewPasswordController;
 import org.cryptomator.ui.common.PasswordStrengthUtil;
+import org.cryptomator.ui.common.StackTraceController;
 import org.cryptomator.ui.mainwindow.MainWindow;
 import org.cryptomator.ui.recoverykey.RecoveryKeyDisplayController;
 
@@ -61,6 +62,20 @@ public abstract class AddVaultModule {
 		return stage;
 	}
 
+	@Provides
+	@Named("genericErrorCause")
+	@AddVaultWizardScoped
+	static ObjectProperty<Throwable> provideGenericErrorCause() {
+		return new SimpleObjectProperty<>();
+	}
+
+	@Provides
+	@Named("genericErrorReturnScene")
+	@AddVaultWizardScoped
+	static ObjectProperty<Scene> provideGenericErrorReturnScene() {
+		return new SimpleObjectProperty<>();
+	}
+
 	@Provides
 	@AddVaultWizardScoped
 	static ObjectProperty<Path> provideVaultPath() {
@@ -105,10 +120,10 @@ public abstract class AddVaultModule {
 	}
 
 	@Provides
-	@FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR)
+	@FxmlScene(FxmlFile.ADDVAULT_GENERIC_ERROR)
 	@AddVaultWizardScoped
-	static Scene provideChooseExistingVaultErrorScene(@AddVaultWizardWindow FXMLLoaderFactory fxmlLoaders) {
-		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_EXISTING_ERROR.getRessourcePathString());
+	static Scene provideGenericErrorScene(@AddVaultWizardWindow FXMLLoaderFactory fxmlLoaders) {
+		return fxmlLoaders.createScene(FxmlFile.ADDVAULT_GENERIC_ERROR.getRessourcePathString());
 	}
 
 	@Provides
@@ -158,11 +173,6 @@ public abstract class AddVaultModule {
 	@FxControllerKey(ChooseExistingVaultController.class)
 	abstract FxController bindChooseExistingVaultController(ChooseExistingVaultController controller);
 
-	@Binds
-	@IntoMap
-	@FxControllerKey(AddVaultFailureExistingController.class)
-	abstract FxController bindAddVaultFailureExistingController(AddVaultFailureExistingController controller);
-
 	@Binds
 	@IntoMap
 	@FxControllerKey(CreateNewVaultNameController.class)
@@ -201,4 +211,16 @@ public abstract class AddVaultModule {
 	@IntoMap
 	@FxControllerKey(AddVaultSuccessController.class)
 	abstract FxController bindAddVaultSuccessController(AddVaultSuccessController controller);
+
+	@Binds
+	@IntoMap
+	@FxControllerKey(AddVaultGenericErrorController.class)
+	abstract FxController bindAddVaultGenericErrorController(AddVaultGenericErrorController controller);
+
+	@Provides
+	@IntoMap
+	@FxControllerKey(StackTraceController.class)
+	static FxController provideStackTraceController(@Named("genericErrorCause") ObjectProperty<Throwable> errorCause) {
+		return new StackTraceController(errorCause.get());
+	}
 }

+ 8 - 4
main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/ChooseExistingVaultController.java

@@ -15,6 +15,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
+import javax.inject.Named;
 import java.io.File;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;
@@ -28,18 +29,20 @@ public class ChooseExistingVaultController implements FxController {
 	private final Stage window;
 	private final Lazy<Scene> welcomeScene;
 	private final Lazy<Scene> successScene;
-	private final Lazy<Scene> errorScene;
+	private final Lazy<Scene> genericErrorScene;
+	private final ObjectProperty<Throwable> genericErrorCause;
 	private final ObjectProperty<Path> vaultPath;
 	private final ObjectProperty<Vault> vault;
 	private final VaultListManager vaultListManager;
 	private final ResourceBundle resourceBundle;
 
 	@Inject
-	ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, @FxmlScene(FxmlFile.ADDVAULT_EXISTING_ERROR) Lazy<Scene> errorScene, ObjectProperty<Path> vaultPath, @AddVaultWizardWindow ObjectProperty<Vault> vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) {
+	ChooseExistingVaultController(@AddVaultWizardWindow Stage window, @FxmlScene(FxmlFile.ADDVAULT_WELCOME) Lazy<Scene> welcomeScene, @FxmlScene(FxmlFile.ADDVAULT_SUCCESS) Lazy<Scene> successScene, @FxmlScene(FxmlFile.ADDVAULT_GENERIC_ERROR) Lazy<Scene> genericErrorScene, @Named("genericErrorCause") ObjectProperty<Throwable> genericErrorCause, ObjectProperty<Path> vaultPath, @AddVaultWizardWindow ObjectProperty<Vault> vault, VaultListManager vaultListManager, ResourceBundle resourceBundle) {
 		this.window = window;
 		this.welcomeScene = welcomeScene;
 		this.successScene = successScene;
-		this.errorScene = errorScene;
+		this.genericErrorScene = genericErrorScene;
+		this.genericErrorCause = genericErrorCause;
 		this.vaultPath = vaultPath;
 		this.vault = vault;
 		this.vaultListManager = vaultListManager;
@@ -65,7 +68,8 @@ public class ChooseExistingVaultController implements FxController {
 				window.setScene(successScene.get());
 			} catch (NoSuchFileException e) {
 				LOG.error("Failed to open existing vault.", e);
-				window.setScene(errorScene.get());
+				genericErrorCause.set(e);
+				window.setScene(genericErrorScene.get());
 			}
 		}
 	}

+ 2 - 2
main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java

@@ -1,14 +1,14 @@
 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_GENERIC_ERROR("/fxml/addvault_generic_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"), //
 	ADDVAULT_NEW_RECOVERYKEY("/fxml/addvault_new_recoverykey.fxml"), //
 	ADDVAULT_SUCCESS("/fxml/addvault_success.fxml"), //
+	ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), //
 	CHANGEPASSWORD("/fxml/changepassword.fxml"), //
 	FORGET_PASSWORD("/fxml/forget_password.fxml"), //
 	MAIN_WINDOW("/fxml/main_window.fxml"), //

+ 0 - 41
main/ui/src/main/resources/fxml/addvault_existing_error.fxml

@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<?import javafx.geometry.Insets?>
-<?import javafx.scene.control.Button?>
-<?import javafx.scene.control.ButtonBar?>
-<?import javafx.scene.layout.HBox?>
-<?import javafx.scene.layout.StackPane?>
-<?import javafx.scene.layout.VBox?>
-<?import javafx.scene.shape.Circle?>
-<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
-<?import org.cryptomator.ui.controls.FormattedLabel?>
-<VBox xmlns="http://javafx.com/javafx"
-	  xmlns:fx="http://javafx.com/fxml"
-	  fx:controller="org.cryptomator.ui.addvaultwizard.AddVaultFailureExistingController"
-	  minWidth="450"
-	  maxWidth="450"
-	  minHeight="145"
-	  spacing="12">
-	<padding>
-		<Insets topRightBottomLeft="12"/>
-	</padding>
-	<children>
-		<HBox spacing="12" alignment="CENTER_LEFT" VBox.vgrow="ALWAYS">
-			<StackPane alignment="CENTER" HBox.hgrow="NEVER">
-				<Circle styleClass="glyph-icon-primary" radius="24"/>
-				<FontAwesome5IconView styleClass="glyph-icon-white" glyph="EXCLAMATION" glyphSize="24"/>
-			</StackPane>
-			<FormattedLabel format="%addvaultwizard.existing.error" arg1="${controller.vaultName}" wrapText="true"/>
-		</HBox>
-
-		<VBox alignment="BOTTOM_CENTER" VBox.vgrow="ALWAYS">
-			<ButtonBar buttonMinWidth="120" buttonOrder="B+C">
-				<buttons>
-					<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back"/>
-					<Button text="%generic.button.cancel" ButtonBar.buttonData="CANCEL_CLOSE" defaultButton="true" cancelButton="true" onAction="#close"/>
-				</buttons>
-			</ButtonBar>
-		</VBox>
-	</children>
-</VBox>
-

+ 30 - 0
main/ui/src/main/resources/fxml/addvault_generic_error.fxml

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.geometry.Insets?>
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.ButtonBar?>
+<?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.AddVaultGenericErrorController"
+	  prefWidth="450"
+	  prefHeight="450"
+	  spacing="12"
+	  alignment="TOP_CENTER">
+	<padding>
+		<Insets topRightBottomLeft="24"/>
+	</padding>
+	<children>
+		<fx:include source="/fxml/stacktrace.fxml"/>
+		
+		<Region VBox.vgrow="ALWAYS"/>
+
+		<ButtonBar buttonMinWidth="120" buttonOrder="B+C">
+			<buttons>
+				<Button text="%generic.button.back" ButtonBar.buttonData="BACK_PREVIOUS" onAction="#back" visible="${controller.returnToPreviousSceneAllowed}"/>
+				<Button text="%generic.button.cancel" ButtonBar.buttonData="CANCEL_CLOSE" onAction="#close"/>
+			</buttons>
+		</ButtonBar>
+	</children>
+</VBox>

+ 0 - 2
main/ui/src/main/resources/i18n/strings.properties

@@ -43,7 +43,6 @@ addvaultwizard.new.directoryPickerButton=Choose…
 addvaultwizard.new.directoryPickerTitle=Select Directory
 addvaultwizard.new.fileAlreadyExists=Vault can not be created at this path because some object already exists.
 addvaultwizard.new.invalidName=Invalid vault name. Please consider a regular directory name.
-addvaultwizard.new.ioException=Selected directory failed a basic test. Make sure to have the appropriate access rights and nothing interferes with Cryptomator.
 ### Password
 addvaultwizard.new.createVaultBtn=Create Vault
 addvaultwizard.new.generateRecoveryKeyChoice=You won't be able to access your data without your password. Do you want a recovery key for the case you lose your password?
@@ -70,7 +69,6 @@ addvault.new.readme.accessLocation.4=Feel free to remove this file.
 addvaultwizard.existing.instruction=Choose the "masterkey.cryptomator" file of your existing vault.
 addvaultwizard.existing.chooseBtn=Choose…
 addvaultwizard.existing.filePickerTitle=Select Masterkey File
-addvaultwizard.existing.error=Unable to add vault "%s": Not a valid vault. Please look into the log for more information.
 ## Success
 addvaultwizard.success.nextStepsInstructions=Added vault "%s".\nYou need to unlock this vault to access or add contents. Alternatively you can unlock it at any later point in time.
 addvaultwizard.success.unlockNow=Unlock Now