Refactored Vault's observable accessPoint property

This commit is contained in:
Sebastian Stenzel
2019-09-05 15:42:45 +02:00
parent c8e22fe2e3
commit b4bf5415bc
5 changed files with 12 additions and 14 deletions

View File

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

View File

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

View File

@@ -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("");
}
}

View File

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

View File

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