Browse Source

Refactored Vault's observable accessPoint property

Sebastian Stenzel 5 years ago
parent
commit
b4bf5415bc

+ 1 - 1
main/commons/src/main/java/org/cryptomator/common/vaults/DokanyVolume.java

@@ -101,7 +101,7 @@ public class DokanyVolume implements Volume {
 	}
 
 	@Override
-	public Optional<Path> getMountPointSafe() {
+	public Optional<Path> getMountPoint() {
 		return Optional.ofNullable(mountPoint);
 	}
 

+ 1 - 1
main/commons/src/main/java/org/cryptomator/common/vaults/FuseVolume.java

@@ -166,7 +166,7 @@ public class FuseVolume implements Volume {
 	}
 
 	@Override
-	public Optional<Path> getMountPointSafe() {
+	public Optional<Path> getMountPoint() {
 		return Optional.ofNullable(mountPoint);
 	}
 

+ 8 - 10
main/commons/src/main/java/org/cryptomator/common/vaults/Vault.java

@@ -13,6 +13,7 @@ import javafx.beans.Observable;
 import javafx.beans.binding.Binding;
 import javafx.beans.binding.Bindings;
 import javafx.beans.binding.BooleanBinding;
+import javafx.beans.binding.ObjectBinding;
 import javafx.beans.binding.StringBinding;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
@@ -59,12 +60,12 @@ public class Vault {
 	private final AtomicReference<CryptoFileSystem> cryptoFileSystem;
 	private final ObjectProperty<VaultState> state;
 	private final VaultStats stats;
-	private final ObjectProperty<Path> accessPoint = new SimpleObjectProperty<>(Path.of(""));
 	private final StringBinding displayableName;
 	private final StringBinding displayablePath;
 	private final BooleanBinding locked;
 	private final BooleanBinding processing;
 	private final BooleanBinding unlocked;
+	private final ObjectBinding<Path> accessPoint;
 
 	private Volume volume;
 
@@ -81,7 +82,7 @@ public class Vault {
 		this.locked = Bindings.createBooleanBinding(this::isLocked, state);
 		this.processing = Bindings.createBooleanBinding(this::isProcessing, state);
 		this.unlocked = Bindings.createBooleanBinding(this::isUnlocked, state);
-		this.state.addListener(this::setAccessPoint);
+		this.accessPoint = Bindings.createObjectBinding(this::getAccessPoint, state);
 	}
 
 	// ******************************************************************************
@@ -220,19 +221,16 @@ public class Vault {
 		return p.getFileName().toString();
 	}
 
-	public ObjectProperty<Path> accessPointProperty() {
+	public ObjectBinding<Path> accessPointProperty() {
 		return accessPoint;
 	}
 
 	public Path getAccessPoint() {
-		return accessPoint.get();
-	}
-
-	private void setAccessPoint(Observable obs) {
-		if (this.getState() == VaultState.UNLOCKED) {
-			accessPoint.setValue(volume.getMountPointSafe().get());
+		if (state.get() == VaultState.UNLOCKED) {
+			assert volume != null;
+			return volume.getMountPoint().orElse(Path.of(""));
 		} else {
-			accessPoint.setValue(Path.of(""));
+			return Path.of("");
 		}
 	}
 

+ 1 - 1
main/commons/src/main/java/org/cryptomator/common/vaults/Volume.java

@@ -30,7 +30,7 @@ public interface Volume {
 
 	void unmount() throws VolumeException;
 
-	Optional<Path> getMountPointSafe();
+	Optional<Path> getMountPoint();
 
 	// optional forced unmounting:
 

+ 1 - 1
main/commons/src/main/java/org/cryptomator/common/vaults/WebDavVolume.java

@@ -97,7 +97,7 @@ public class WebDavVolume implements Volume {
 	}
 
 	@Override
-	public Optional<Path> getMountPointSafe() {
+	public Optional<Path> getMountPoint() {
 		return Optional.ofNullable(mountPoint);
 	}