mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-05-17 10:11:27 +00:00
show stuff in vault list cells
This commit is contained in:
@@ -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> 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<Vault> vaultProperty() {
|
||||
return vault;
|
||||
}
|
||||
|
||||
@@ -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<Vault> 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<Volume> volumeProvider;
|
||||
private final Supplier<String> defaultMountFlags;
|
||||
private final AtomicReference<CryptoFileSystem> cryptoFileSystem = new AtomicReference<>();
|
||||
private final ObjectProperty<State> state = new SimpleObjectProperty<State>(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<State> stateProperty() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static Predicate<Vault> hasState(State state) {
|
||||
return vault -> {
|
||||
return vault.getState() == state;
|
||||
};
|
||||
}
|
||||
|
||||
// ******************************************************************************
|
||||
// Observable Properties
|
||||
// *******************************************************************************
|
||||
|
||||
public ReadOnlyObjectProperty<State> 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<String> 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<String> name() {
|
||||
return EasyBind.map(vaultSettings.path(), Path::getFileName).map(Path::toString);
|
||||
}
|
||||
|
||||
@@ -2,11 +2,24 @@
|
||||
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<VBox xmlns="http://javafx.com/javafx"
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<HBox xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="org.cryptomator.ui.mainwindow.VaultListCellController"
|
||||
prefHeight="50.0" prefWidth="200.0">
|
||||
|
||||
<Label text="${controller.vault}"/>
|
||||
|
||||
</VBox>
|
||||
prefHeight="50.0"
|
||||
prefWidth="200.0"
|
||||
spacing="12"
|
||||
alignment="CENTER_LEFT">
|
||||
<padding>
|
||||
<Insets top="4" right="6" bottom="4" left="6"/>
|
||||
</padding>
|
||||
<children>
|
||||
<FontAwesomeIconView glyphName="${controller.glyph}" HBox.hgrow="NEVER" glyphSize="20"/>
|
||||
<VBox spacing="6" HBox.hgrow="ALWAYS">
|
||||
<Label text="${controller.vault.displayableName}"/>
|
||||
<Label text="${controller.vault.displayablePath}" textOverrun="CENTER_ELLIPSIS"/>
|
||||
</VBox>
|
||||
</children>
|
||||
</HBox>
|
||||
|
||||
Reference in New Issue
Block a user