From d9677fe7c4a10705cc2dcbf01fc468c3f77d89a2 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Fri, 6 Sep 2019 19:25:25 +0200 Subject: [PATCH] Split up vault detail view --- .../ui/mainwindow/MainWindowModule.java | 15 +++++ .../ui/mainwindow/VaultDetailController.java | 62 +---------------- .../VaultDetailLockedController.java | 46 +++++++++++++ .../VaultDetailNeedsMigrationController.java | 28 ++++++++ .../VaultDetailUnlockedController.java | 66 +++++++++++++++++++ .../src/main/resources/fxml/vault_detail.fxml | 61 +---------------- .../resources/fxml/vault_detail_locked.fxml | 28 ++++++++ .../fxml/vault_detail_needsmigration.fxml | 20 ++++++ .../resources/fxml/vault_detail_unlocked.fxml | 47 +++++++++++++ 9 files changed, 256 insertions(+), 117 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailNeedsMigrationController.java create mode 100644 main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java create mode 100644 main/ui/src/main/resources/fxml/vault_detail_locked.fxml create mode 100644 main/ui/src/main/resources/fxml/vault_detail_needsmigration.fxml create mode 100644 main/ui/src/main/resources/fxml/vault_detail_unlocked.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 673bb82c4..e8a5f3614 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 @@ -85,6 +85,21 @@ abstract class MainWindowModule { @FxControllerKey(VaultDetailController.class) abstract FxController bindVaultDetailController(VaultDetailController controller); + @Binds + @IntoMap + @FxControllerKey(VaultDetailLockedController.class) + abstract FxController bindVaultDetailLockedController(VaultDetailLockedController controller); + + @Binds + @IntoMap + @FxControllerKey(VaultDetailUnlockedController.class) + abstract FxController bindVaultDetailUnlockedController(VaultDetailUnlockedController controller); + + @Binds + @IntoMap + @FxControllerKey(VaultDetailNeedsMigrationController.class) + abstract FxController bindVaultDetailNeedsMigrationController(VaultDetailNeedsMigrationController controller); + @Binds @IntoMap @FxControllerKey(VaultListCellController.class) diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java index c2598d334..dc77d04b5 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailController.java @@ -4,46 +4,30 @@ import javafx.beans.binding.Binding; import javafx.beans.binding.BooleanBinding; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; -import javafx.event.ActionEvent; import javafx.fxml.FXML; import org.cryptomator.common.vaults.Vault; import org.cryptomator.common.vaults.VaultState; -import org.cryptomator.common.vaults.Volume; import org.cryptomator.ui.common.FxController; -import org.cryptomator.ui.common.Tasks; import org.cryptomator.ui.controls.FontAwesome5Icon; import org.cryptomator.ui.fxapp.FxApplication; -import org.cryptomator.ui.migration.MigrationComponent; -import org.cryptomator.ui.vaultoptions.VaultOptionsComponent; import org.fxmisc.easybind.EasyBind; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.inject.Inject; -import java.util.concurrent.ExecutorService; @MainWindowScoped public class VaultDetailController implements FxController { - private static final Logger LOG = LoggerFactory.getLogger(VaultDetailController.class); - private final ReadOnlyObjectProperty vault; + private final FxApplication application; private final Binding glyph; private final BooleanBinding anyVaultSelected; - private final ExecutorService executor; - private final FxApplication application; - private final VaultOptionsComponent.Builder vaultOptionsWindow; - private final MigrationComponent.Builder vaultMigrationWindow; @Inject - VaultDetailController(ObjectProperty vault, ExecutorService executor, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow, MigrationComponent.Builder vaultMigrationWindow) { + VaultDetailController(ObjectProperty vault, FxApplication application) { this.vault = vault; - this.glyph = EasyBind.select(vault).selectObject(Vault::stateProperty).map(this::getGlyphForVaultState).orElse(FontAwesome5Icon.EXCLAMATION_TRIANGLE); - this.executor = executor; this.application = application; - this.vaultOptionsWindow = vaultOptionsWindow; + this.glyph = EasyBind.select(vault).selectObject(Vault::stateProperty).map(this::getGlyphForVaultState).orElse(FontAwesome5Icon.EXCLAMATION_TRIANGLE); this.anyVaultSelected = vault.isNotNull(); - this.vaultMigrationWindow = vaultMigrationWindow; } private FontAwesome5Icon getGlyphForVaultState(VaultState state) { @@ -59,51 +43,11 @@ public class VaultDetailController implements FxController { } } - @FXML - public void unlock() { - application.showUnlockWindow(vault.get()); - } - - @FXML - public void lock() { - Vault v = vault.get(); - v.setState(VaultState.PROCESSING); - Tasks.create(() -> { - v.lock(false); - }).onSuccess(() -> { - LOG.trace("Regular unmount succeeded."); - v.setState(VaultState.LOCKED); - }).onError(Exception.class, e -> { - v.setState(VaultState.UNLOCKED); - LOG.error("Regular unmount failed.", e); - // TODO - }).runOnce(executor); - } - - @FXML - public void showVaultOptions() { - vaultOptionsWindow.vault(vault.get()).build().showVaultOptionsWindow(); - } - - @FXML - public void showVaultMigrator() { - vaultMigrationWindow.vault(vault.get()).build().showMigrationWindow(); - } - @FXML public void revealStorageLocation() { application.getHostServices().showDocument(vault.get().getPath().toUri().toString()); } - @FXML - public void revealAccessLocation() { - try { - vault.get().reveal(); - } catch (Volume.VolumeException e) { - LOG.error("Failed to reveal vault.", e); - } - } - /* Observable Properties */ public ReadOnlyObjectProperty vaultProperty() { diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java new file mode 100644 index 000000000..f5b1d1d3a --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailLockedController.java @@ -0,0 +1,46 @@ +package org.cryptomator.ui.mainwindow; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.fxml.FXML; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.fxapp.FxApplication; +import org.cryptomator.ui.vaultoptions.VaultOptionsComponent; + +import javax.inject.Inject; + +@MainWindowScoped +public class VaultDetailLockedController implements FxController { + + private final ReadOnlyObjectProperty vault; + private final FxApplication application; + private final VaultOptionsComponent.Builder vaultOptionsWindow; + + @Inject + VaultDetailLockedController(ObjectProperty vault, FxApplication application, VaultOptionsComponent.Builder vaultOptionsWindow) { + this.vault = vault; + this.application = application; + this.vaultOptionsWindow = vaultOptionsWindow; + } + + @FXML + public void unlock() { + application.showUnlockWindow(vault.get()); + } + + @FXML + public void showVaultOptions() { + vaultOptionsWindow.vault(vault.get()).build().showVaultOptionsWindow(); + } + + /* Getter/Setter */ + + public ReadOnlyObjectProperty vaultProperty() { + return vault; + } + + public Vault getVault() { + return vault.get(); + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailNeedsMigrationController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailNeedsMigrationController.java new file mode 100644 index 000000000..480c69050 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailNeedsMigrationController.java @@ -0,0 +1,28 @@ +package org.cryptomator.ui.mainwindow; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.fxml.FXML; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.migration.MigrationComponent; + +import javax.inject.Inject; + +@MainWindowScoped +public class VaultDetailNeedsMigrationController implements FxController { + + private final ReadOnlyObjectProperty vault; + private final MigrationComponent.Builder vaultMigrationWindow; + + @Inject + public VaultDetailNeedsMigrationController(ObjectProperty vault, MigrationComponent.Builder vaultMigrationWindow) { + this.vault = vault; + this.vaultMigrationWindow = vaultMigrationWindow; + } + + @FXML + public void showVaultMigrator() { + vaultMigrationWindow.vault(vault.get()).build().showMigrationWindow(); + } +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java new file mode 100644 index 000000000..f2d801679 --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultDetailUnlockedController.java @@ -0,0 +1,66 @@ +package org.cryptomator.ui.mainwindow; + +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.ReadOnlyObjectProperty; +import javafx.fxml.FXML; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.common.vaults.VaultState; +import org.cryptomator.common.vaults.Volume; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.Tasks; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.util.concurrent.ExecutorService; + +@MainWindowScoped +public class VaultDetailUnlockedController implements FxController { + + private static final Logger LOG = LoggerFactory.getLogger(VaultDetailUnlockedController.class); + + private final ReadOnlyObjectProperty vault; + private final ExecutorService executor; + + @Inject + public VaultDetailUnlockedController(ObjectProperty vault, ExecutorService executor) { + this.vault = vault; + this.executor = executor; + } + + @FXML + public void revealAccessLocation() { + try { + vault.get().reveal(); + } catch (Volume.VolumeException e) { + LOG.error("Failed to reveal vault.", e); + } + } + + @FXML + public void lock() { + Vault v = vault.get(); + v.setState(VaultState.PROCESSING); + Tasks.create(() -> { + v.lock(false); + }).onSuccess(() -> { + LOG.trace("Regular unmount succeeded."); + v.setState(VaultState.LOCKED); + }).onError(Exception.class, e -> { + v.setState(VaultState.UNLOCKED); + LOG.error("Regular unmount failed.", e); + // TODO + }).runOnce(executor); + } + + /* Getter/Setter */ + + public ReadOnlyObjectProperty vaultProperty() { + return vault; + } + + public Vault getVault() { + return vault.get(); + } + +} diff --git a/main/ui/src/main/resources/fxml/vault_detail.fxml b/main/ui/src/main/resources/fxml/vault_detail.fxml index 547d48cd2..97604c5b0 100644 --- a/main/ui/src/main/resources/fxml/vault_detail.fxml +++ b/main/ui/src/main/resources/fxml/vault_detail.fxml @@ -1,7 +1,6 @@ - @@ -11,7 +10,6 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/main/ui/src/main/resources/fxml/vault_detail_locked.fxml b/main/ui/src/main/resources/fxml/vault_detail_locked.fxml new file mode 100644 index 000000000..05c3c7400 --- /dev/null +++ b/main/ui/src/main/resources/fxml/vault_detail_locked.fxml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/main/ui/src/main/resources/fxml/vault_detail_needsmigration.fxml b/main/ui/src/main/resources/fxml/vault_detail_needsmigration.fxml new file mode 100644 index 000000000..1c5e9721f --- /dev/null +++ b/main/ui/src/main/resources/fxml/vault_detail_needsmigration.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml b/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml new file mode 100644 index 000000000..4ef8c85c6 --- /dev/null +++ b/main/ui/src/main/resources/fxml/vault_detail_unlocked.fxml @@ -0,0 +1,47 @@ + + + + + + + + + + \ No newline at end of file