From 5af2a392eadb685cd8df71ecc1f707fd9e37b3b6 Mon Sep 17 00:00:00 2001 From: Sebastian Stenzel Date: Tue, 23 Jul 2019 14:21:08 +0200 Subject: [PATCH] show stuff in vault list cells --- .../mainwindow/VaultListCellController.java | 35 +++++++++- .../java/org/cryptomator/ui/model/Vault.java | 66 +++++++++++++++---- .../main/resources/fxml/vault_list_cell.fxml | 25 +++++-- 3 files changed, 106 insertions(+), 20 deletions(-) diff --git a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListCellController.java b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListCellController.java index dba8ec5e1..0232aed88 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListCellController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/mainwindow/VaultListCellController.java @@ -1,5 +1,7 @@ package org.cryptomator.ui.mainwindow; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; import org.cryptomator.ui.common.FxController; @@ -9,14 +11,43 @@ import javax.inject.Inject; // unscoped because each cell needs its own controller public class VaultListCellController implements FxController { - + private final ObjectProperty vault = new SimpleObjectProperty<>(); + private final StringBinding glyph; @Inject - VaultListCellController() {} + VaultListCellController() { + this.glyph = Bindings.createStringBinding(this::getGlyphForVault, vault); + } + + private String getGlyphForVault() { + Vault v = vault.get(); + if (v == null) { + return "WARNING"; + } else { + switch (v.getState()) { + case LOCKED: + return "LOCK"; + case UNLOCKED: + return "UNLOCK"; + case PROCESSING: + return "SPINNER"; + default: + return "WARNING"; + } + } + } /* Getter/Setter */ + public StringBinding glyphProperty() { + return glyph; + } + + public String getGlyph() { + return glyph.get(); + } + public ObjectProperty vaultProperty() { return vault; } diff --git a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java index 42f5d0748..24f5f7626 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java +++ b/main/ui/src/main/java/org/cryptomator/ui/model/Vault.java @@ -12,6 +12,8 @@ import com.google.common.base.Strings; import javafx.application.Platform; import javafx.beans.Observable; import javafx.beans.binding.Binding; +import javafx.beans.binding.Bindings; +import javafx.beans.binding.StringBinding; import javafx.beans.property.ObjectProperty; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.SimpleObjectProperty; @@ -51,12 +53,15 @@ public class Vault { public static final Predicate NOT_LOCKED = hasState(State.LOCKED).negate(); private static final Logger LOG = LoggerFactory.getLogger(Vault.class); private static final String MASTERKEY_FILENAME = "masterkey.cryptomator"; + private static final Path HOME_DIR = Paths.get(SystemUtils.USER_HOME); private final VaultSettings vaultSettings; private final Provider volumeProvider; private final Supplier defaultMountFlags; private final AtomicReference cryptoFileSystem = new AtomicReference<>(); private final ObjectProperty state = new SimpleObjectProperty(State.LOCKED); + private final StringBinding displayableName; + private final StringBinding displayablePath; private Volume volume; @@ -69,6 +74,9 @@ public class Vault { this.vaultSettings = vaultSettings; this.volumeProvider = volumeProvider; this.defaultMountFlags = defaultMountFlags; + + this.displayableName = Bindings.createStringBinding(this::getDisplayableName, vaultSettings.path()); + this.displayablePath = Bindings.createStringBinding(this::getDisplayablePath, vaultSettings.path()); } // ****************************************************************************** @@ -167,24 +175,52 @@ public class Vault { volume.reveal(); } - // ****************************************************************************** - // Getter/Setter - // *******************************************************************************/ - - public State getState() { - return state.get(); - } - - public ReadOnlyObjectProperty stateProperty() { - return state; - } - public static Predicate hasState(State state) { return vault -> { return vault.getState() == state; }; } + // ****************************************************************************** + // Observable Properties + // ******************************************************************************* + + public ReadOnlyObjectProperty stateProperty() { + return state; + } + + public State getState() { + return state.get(); + } + + public StringBinding displayableNameProperty() { + return displayableName; + } + + public String getDisplayableName() { + Path p = vaultSettings.path().get(); + return p.getFileName().toString(); + } + + public StringBinding displayablePathProperty() { + return displayablePath; + } + + public String getDisplayablePath() { + Path p = vaultSettings.path().get(); + if (p.startsWith(HOME_DIR)) { + Path relativePath = HOME_DIR.relativize(p); + String homePrefix = SystemUtils.IS_OS_WINDOWS ? "~\\" : "~/"; + return homePrefix + relativePath.toString(); + } else { + return p.toString(); + } + } + + // ****************************************************************************** + // Getter/Setter + // *******************************************************************************/ + public Observable[] observables() { return new Observable[]{state}; } @@ -197,6 +233,10 @@ public class Vault { return vaultSettings.path().getValue(); } + /** + * @deprecated use displayablePathProperty() instead + */ + @Deprecated(forRemoval = true, since = "1.5.0") public Binding displayablePath() { Path homeDir = Paths.get(SystemUtils.USER_HOME); return EasyBind.map(vaultSettings.path(), p -> { @@ -212,7 +252,9 @@ public class Vault { /** * @return Directory name without preceeding path components and file extension + * @deprecated use nameProperty() instead */ + @Deprecated(forRemoval = true, since = "1.5.0") public Binding name() { return EasyBind.map(vaultSettings.path(), Path::getFileName).map(Path::toString); } diff --git a/main/ui/src/main/resources/fxml/vault_list_cell.fxml b/main/ui/src/main/resources/fxml/vault_list_cell.fxml index 5d41aa709..af1582206 100644 --- a/main/ui/src/main/resources/fxml/vault_list_cell.fxml +++ b/main/ui/src/main/resources/fxml/vault_list_cell.fxml @@ -2,11 +2,24 @@ - + + + - - + prefHeight="50.0" + prefWidth="200.0" + spacing="12" + alignment="CENTER_LEFT"> + + + + + + + + +