Browse Source

adding confirmation dialogue when removing a vault

Armin Schrenk 5 years ago
parent
commit
acda11f110

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

@@ -10,6 +10,7 @@ public enum FxmlFile {
 	MAIN_WINDOW("/fxml/main_window.fxml"), //
 	PREFERENCES("/fxml/preferences.fxml"), //
 	QUIT("/fxml/quit.fxml"),
+	REMOVE_VAULT("/fxml/remove_vault.fxml"), //
 	UNLOCK("/fxml/unlock2.fxml"), // TODO rename
 	UNLOCK_SUCCESS("/fxml/unlock_success.fxml"),
 	VAULT_OPTIONS("/fxml/vault_options.fxml");

+ 2 - 1
main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java

@@ -17,13 +17,14 @@ import org.cryptomator.ui.common.FxController;
 import org.cryptomator.ui.common.FxControllerKey;
 import org.cryptomator.ui.common.FxmlFile;
 import org.cryptomator.ui.common.FxmlScene;
+import org.cryptomator.ui.removevault.RemoveVaultComponent;
 import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
 
 import javax.inject.Provider;
 import java.util.Map;
 import java.util.ResourceBundle;
 
-@Module(subcomponents = {AddVaultWizardComponent.class, VaultOptionsComponent.class, ChangePasswordComponent.class})
+@Module(subcomponents = {AddVaultWizardComponent.class, RemoveVaultComponent.class, VaultOptionsComponent.class, ChangePasswordComponent.class})
 abstract class MainWindowModule {
 
 	@Provides

+ 8 - 6
main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java

@@ -5,9 +5,10 @@ import javafx.beans.property.ObjectProperty;
 import javafx.collections.ObservableList;
 import javafx.scene.control.ListView;
 import javafx.scene.layout.AnchorPane;
+import org.cryptomator.common.vaults.Vault;
 import org.cryptomator.ui.addvaultwizard.AddVaultWizardComponent;
 import org.cryptomator.ui.common.FxController;
-import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.ui.removevault.RemoveVaultComponent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -22,15 +23,17 @@ public class VaultListController implements FxController {
 	private final ObjectProperty<Vault> selectedVault;
 	private final VaultListCellFactory cellFactory;
 	private final AddVaultWizardComponent.Builder addVaultWizard;
+	private final RemoveVaultComponent.Builder removeVault;
 	public ListView<Vault> vaultList;
 	public AnchorPane onboardingOverlay;
 
 	@Inject
-	VaultListController(ObservableList<Vault> vaults, ObjectProperty<Vault> selectedVault, VaultListCellFactory cellFactory, AddVaultWizardComponent.Builder addVaultWizard) {
+	VaultListController(ObservableList<Vault> vaults, ObjectProperty<Vault> selectedVault, VaultListCellFactory cellFactory, AddVaultWizardComponent.Builder addVaultWizard, RemoveVaultComponent.Builder removeVault) {
 		this.vaults = vaults;
 		this.selectedVault = selectedVault;
 		this.cellFactory = cellFactory;
 		this.addVaultWizard = addVaultWizard;
+		this.removeVault = removeVault;
 	}
 
 	public void initialize() {
@@ -45,10 +48,9 @@ public class VaultListController implements FxController {
 	}
 
 	public void didClickRemoveVault() {
-		//TODO: Dialogue
-		if (selectedVault.get() != null) {
-			vaults.remove(selectedVault.get());
-			LOG.debug("Removing vault {}.", selectedVault.get().getDisplayableName());
+		Vault v = selectedVault.get();
+		if (v != null) {
+			removeVault.vault(v).build().showRemoveVault();
 		} else {
 			LOG.debug("Cannot remove a vault if none is selected.");
 		}

+ 14 - 0
main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVault.java

@@ -0,0 +1,14 @@
+package org.cryptomator.ui.removevault;
+
+import javax.inject.Qualifier;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Qualifier
+@Documented
+@Retention(RUNTIME)
+public @interface RemoveVault {
+
+}

+ 38 - 0
main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultComponent.java

@@ -0,0 +1,38 @@
+package org.cryptomator.ui.removevault;
+
+import dagger.BindsInstance;
+import dagger.Lazy;
+import dagger.Subcomponent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+
+@RemoveVaultScoped
+@Subcomponent(modules = {RemoveVaultModule.class})
+public interface RemoveVaultComponent {
+
+	@RemoveVault
+	Stage window();
+
+	@FxmlScene(FxmlFile.REMOVE_VAULT)
+	Lazy<Scene> scene();
+
+	default void showRemoveVault() {
+		Stage stage = window();
+		stage.setScene(scene().get());
+		stage.sizeToScene();
+		stage.show();
+	}
+
+	@Subcomponent.Builder
+	interface Builder {
+
+		@BindsInstance
+		Builder vault(@RemoveVault Vault vault);
+
+		RemoveVaultComponent build();
+	}
+
+}

+ 39 - 0
main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultController.java

@@ -0,0 +1,39 @@
+package org.cryptomator.ui.removevault;
+
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.stage.Stage;
+import org.cryptomator.common.vaults.Vault;
+import org.cryptomator.ui.common.FxController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+
+@RemoveVaultScoped
+public class RemoveVaultController implements FxController {
+
+	private static final Logger LOG = LoggerFactory.getLogger(RemoveVaultController.class);
+
+	private final Stage window;
+	private final Vault vault;
+	private final ObservableList<Vault> vaults;
+
+	@Inject
+	public RemoveVaultController(@RemoveVault Stage window, @RemoveVault Vault vault, ObservableList<Vault> vaults) {
+		this.window = window;
+		this.vault = vault;
+		this.vaults = vaults;
+	}
+
+	@FXML
+	public void close() {
+		window.close();
+	}
+
+	@FXML
+	public void finish() {
+		vaults.remove(vault);
+		LOG.debug("Removing vault {}.", vault.getDisplayableName());
+	}
+}

+ 54 - 0
main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultModule.java

@@ -0,0 +1,54 @@
+package org.cryptomator.ui.removevault;
+
+import dagger.Binds;
+import dagger.Module;
+import dagger.Provides;
+import dagger.multibindings.IntoMap;
+import javafx.scene.Scene;
+import javafx.stage.Modality;
+import javafx.stage.Stage;
+import org.cryptomator.ui.common.FXMLLoaderFactory;
+import org.cryptomator.ui.common.FxController;
+import org.cryptomator.ui.common.FxControllerKey;
+import org.cryptomator.ui.common.FxmlFile;
+import org.cryptomator.ui.common.FxmlScene;
+
+import javax.inject.Provider;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+@Module
+abstract class RemoveVaultModule {
+
+	@Provides
+	@RemoveVault
+	@RemoveVaultScoped
+	static FXMLLoaderFactory provideFxmlLoaderFactory(Map<Class<? extends FxController>, Provider<FxController>> factories, ResourceBundle resourceBundle) {
+		return new FXMLLoaderFactory(factories, resourceBundle);
+	}
+
+	@Provides
+	@RemoveVault
+	@RemoveVaultScoped
+	static Stage provideStage(ResourceBundle resourceBundle) {
+		Stage stage = new Stage();
+		stage.setTitle(resourceBundle.getString("removeVault.title"));
+		stage.setResizable(false);
+		stage.initModality(Modality.APPLICATION_MODAL);
+		return stage;
+	}
+
+	@Provides
+	@FxmlScene(FxmlFile.REMOVE_VAULT)
+	@RemoveVaultScoped
+	static Scene provideUnlockScene(@RemoveVault FXMLLoaderFactory fxmlLoaders) {
+		return fxmlLoaders.createScene("/fxml/remove_vault.fxml"); // TODO rename fxml file
+	}
+
+	// ------------------
+
+	@Binds
+	@IntoMap
+	@FxControllerKey(RemoveVaultController.class)
+	abstract FxController bindRemoveVaultController(RemoveVaultController controller);
+}

+ 13 - 0
main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultScoped.java

@@ -0,0 +1,13 @@
+package org.cryptomator.ui.removevault;
+
+import javax.inject.Scope;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+@Scope
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface RemoveVaultScoped {
+
+}

+ 33 - 0
main/ui/src/main/resources/fxml/remove_vault.fxml

@@ -0,0 +1,33 @@
+<?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.layout.Region?>
+<?import javafx.scene.layout.VBox?>
+<VBox xmlns="http://javafx.com/javafx"
+	  xmlns:fx="http://javafx.com/fxml"
+	  fx:controller="org.cryptomator.ui.removevault.RemoveVaultController"
+	  prefWidth="400.0"
+	  prefHeight="400.0"
+	  spacing="12.0"
+	  alignment="TOP_CENTER">
+	<padding>
+		<Insets top="24" right="24" bottom="24" left="24"/>
+	</padding>
+	<children>
+		<Region prefHeight="24" VBox.vgrow="NEVER"/>
+
+		<Label text="%removeVault.information" labelFor="$confirmButton"/>
+
+		<Region VBox.vgrow="ALWAYS"/>
+
+		<ButtonBar buttonMinWidth="120" buttonOrder="C+I">
+			<buttons>
+				<Button text="%generic.button.back" ButtonBar.buttonData="CANCEL_CLOSE" onAction="#close"/>
+				<Button fx:id="confirmButton" text="%generic.button.confirm" ButtonBar.buttonData="FINISH" onAction="#finish" defaultButton="true"/>
+			</buttons>
+		</ButtonBar>
+	</children>
+</VBox>

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

@@ -34,6 +34,10 @@ addvaultwizard.existing.instruction=Choose the "masterkey.cryptomator" file of y
 addvaultwizard.existing.chooseBtn=Choose…
 addvaultwizard.existing.filePickerTitle=Select Masterkey File
 
+# Remove Vault
+removeVault.title=Remove Vault
+removeVault.information=No files will be delted from your hard drive.
+
 # Change Password
 changepassword.title=Change Password
 changepassword.enterOldPassword=Enter the current password for
@@ -97,3 +101,4 @@ passwordStrength.messageLabel.1=Weak
 passwordStrength.messageLabel.2=Fair
 passwordStrength.messageLabel.3=Strong
 passwordStrength.messageLabel.4=Very strong
+generic.button.confirm=Confirm