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 24d08d85f..c747dbc67 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 @@ -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"); diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java index 6fbd13c7a..aa905785c 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/MainWindowModule.java +++ b/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 diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java index 9c624df21..3678ba2ff 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListController.java +++ b/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 selectedVault; private final VaultListCellFactory cellFactory; private final AddVaultWizardComponent.Builder addVaultWizard; + private final RemoveVaultComponent.Builder removeVault; public ListView vaultList; public AnchorPane onboardingOverlay; @Inject - VaultListController(ObservableList vaults, ObjectProperty selectedVault, VaultListCellFactory cellFactory, AddVaultWizardComponent.Builder addVaultWizard) { + VaultListController(ObservableList vaults, ObjectProperty 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."); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVault.java b/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVault.java new file mode 100644 index 000000000..d927fb1c1 --- /dev/null +++ b/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 { + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultComponent.java b/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultComponent.java new file mode 100644 index 000000000..bfa613ef4 --- /dev/null +++ b/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(); + + 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(); + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultController.java b/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultController.java new file mode 100644 index 000000000..ece8309b2 --- /dev/null +++ b/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 vaults; + + @Inject + public RemoveVaultController(@RemoveVault Stage window, @RemoveVault Vault vault, ObservableList 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()); + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultModule.java new file mode 100644 index 000000000..a20ca3f4a --- /dev/null +++ b/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, Provider> 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); +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultScoped.java b/main/ui/src/main/java/org/cryptomator/ui/removevault/RemoveVaultScoped.java new file mode 100644 index 000000000..aa2281541 --- /dev/null +++ b/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 { + +} diff --git a/main/ui/src/main/resources/fxml/remove_vault.fxml b/main/ui/src/main/resources/fxml/remove_vault.fxml new file mode 100644 index 000000000..74fbba97f --- /dev/null +++ b/main/ui/src/main/resources/fxml/remove_vault.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + +