Merge pull request #2505 from cryptomator/feature/javafx-19

This commit is contained in:
Sebastian Stenzel
2022-10-28 22:09:29 +02:00
committed by GitHub
21 changed files with 147 additions and 167 deletions
+1 -1
View File
@@ -43,7 +43,7 @@
<easybind.version>2.2</easybind.version>
<guava.version>31.1-jre</guava.version>
<gson.version>2.9.1</gson.version>
<javafx.version>18.0.2</javafx.version>
<javafx.version>19</javafx.version>
<jwt.version>4.2.1</jwt.version>
<nimbus-jose.version>9.25.4</nimbus-jose.version>
<logback.version>1.4.4</logback.version>
@@ -23,6 +23,7 @@ import javax.inject.Named;
import javax.inject.Singleton;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import java.net.InetSocketAddress;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -130,16 +131,16 @@ public abstract class CommonsModule {
@Provides
@Singleton
static Binding<InetSocketAddress> provideServerSocketAddressBinding(Settings settings) {
return Bindings.createObjectBinding(() -> {
static ObservableValue<InetSocketAddress> provideServerSocketAddressBinding(Settings settings) {
return settings.port().map(port -> {
String host = SystemUtils.IS_OS_WINDOWS ? "127.0.0.1" : "localhost";
return InetSocketAddress.createUnresolved(host, settings.port().intValue());
}, settings.port());
});
}
@Provides
@Singleton
static WebDavServer provideWebDavServer(Binding<InetSocketAddress> serverSocketAddressBinding) {
static WebDavServer provideWebDavServer(ObservableValue<InetSocketAddress> serverSocketAddressBinding) {
WebDavServer server = WebDavServer.create();
// no need to unsubscribe eventually, because server is a singleton
EasyBind.subscribe(serverSocketAddressBinding, server::bind);
@@ -10,6 +10,7 @@ import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import java.util.Optional;
@Singleton
@@ -18,7 +19,7 @@ public class LicenseHolder {
private final Settings settings;
private final LicenseChecker licenseChecker;
private final ObjectProperty<DecodedJWT> validJwtClaims;
private final StringBinding licenseSubject;
private final ObservableValue<String> licenseSubject;
private final BooleanBinding validLicenseProperty;
@Inject
@@ -26,7 +27,7 @@ public class LicenseHolder {
this.settings = settings;
this.licenseChecker = licenseChecker;
this.validJwtClaims = new SimpleObjectProperty<>();
this.licenseSubject = Bindings.createStringBinding(this::getLicenseSubject, validJwtClaims);
this.licenseSubject = validJwtClaims.map(DecodedJWT::getSubject);
this.validLicenseProperty = validJwtClaims.isNotNull();
Optional<DecodedJWT> claims = licenseChecker.check(settings.licenseKey().get());
@@ -55,17 +56,12 @@ public class LicenseHolder {
}
}
public StringBinding licenseSubjectProperty() {
public ObservableValue<String> licenseSubjectProperty() {
return licenseSubject;
}
public String getLicenseSubject() {
DecodedJWT claims = validJwtClaims.get();
if (claims != null) {
return claims.getSubject();
} else {
return null;
}
return licenseSubject.getValue();
}
public BooleanBinding validLicenseProperty() {
@@ -12,6 +12,7 @@ import com.google.common.io.BaseEncoding;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
@@ -20,6 +21,7 @@ import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import java.nio.file.Path;
import java.util.Objects;
import java.util.Optional;
@@ -56,11 +58,11 @@ public class VaultSettings {
private final ObjectProperty<WhenUnlocked> actionAfterUnlock = new SimpleObjectProperty<>(DEFAULT_ACTION_AFTER_UNLOCK);
private final BooleanProperty autoLockWhenIdle = new SimpleBooleanProperty(DEFAULT_AUTOLOCK_WHEN_IDLE);
private final IntegerProperty autoLockIdleSeconds = new SimpleIntegerProperty(DEFAULT_AUTOLOCK_IDLE_SECONDS);
private final StringBinding mountName;
private final StringExpression mountName;
public VaultSettings(String id) {
this.id = Objects.requireNonNull(id);
this.mountName = Bindings.createStringBinding(this::normalizeDisplayName, displayName);
this.mountName = StringExpression.stringExpression(displayName.map(VaultSettings::normalizeDisplayName).orElse(""));
}
Observable[] observables() {
@@ -78,8 +80,7 @@ public class VaultSettings {
}
//visible for testing
String normalizeDisplayName() {
var original = displayName.getValueSafe();
static String normalizeDisplayName(String original) {
if (original.isBlank() || ".".equals(original) || "..".equals(original)) {
return "_";
}
@@ -105,7 +106,7 @@ public class VaultSettings {
return displayName;
}
public StringBinding mountName() {
public StringExpression mountName() {
return mountName;
}
@@ -34,6 +34,7 @@ import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.beans.property.SimpleBooleanProperty;
import java.io.IOException;
import java.nio.file.Path;
@@ -60,7 +61,6 @@ public class Vault {
private final ObjectProperty<Exception> lastKnownException;
private final VaultConfigCache configCache;
private final VaultStats stats;
private final StringBinding displayName;
private final StringBinding displayablePath;
private final BooleanBinding locked;
private final BooleanBinding processing;
@@ -84,7 +84,6 @@ public class Vault {
this.state = state;
this.lastKnownException = lastKnownException;
this.stats = stats;
this.displayName = Bindings.createStringBinding(this::getDisplayName, vaultSettings.displayName());
this.displayablePath = Bindings.createStringBinding(this::getDisplayablePath, vaultSettings.path());
this.locked = Bindings.createBooleanBinding(this::isLocked, state);
this.processing = Bindings.createBooleanBinding(this::isProcessing, state);
@@ -266,8 +265,8 @@ public class Vault {
return state.get() == VaultState.Value.ERROR;
}
public StringBinding displayNameProperty() {
return displayName;
public ReadOnlyStringProperty displayNameProperty() {
return vaultSettings.displayName();
}
public String getDisplayName() {
@@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Named;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.StringBinding;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
@@ -68,7 +69,7 @@ public class VaultModule {
@DefaultMountFlags
public StringBinding provideDefaultMountFlags(Settings settings, VaultSettings vaultSettings) {
ObjectProperty<VolumeImpl> preferredVolumeImpl = settings.preferredVolumeImpl();
StringBinding mountName = vaultSettings.mountName();
StringExpression mountName = vaultSettings.mountName();
BooleanProperty readOnly = vaultSettings.usesReadOnlyMode();
return Bindings.createStringBinding(() -> {
@@ -88,7 +89,7 @@ public class VaultModule {
}
// see: https://github.com/osxfuse/osxfuse/wiki/Mount-options
private String getMacFuseDefaultMountFlags(StringBinding mountName, ReadOnlyBooleanProperty readOnly) {
private String getMacFuseDefaultMountFlags(StringExpression mountName, ReadOnlyBooleanProperty readOnly) {
assert SystemUtils.IS_OS_MAC_OSX;
StringBuilder flags = new StringBuilder();
if (readOnly.get()) {
@@ -139,7 +140,7 @@ public class VaultModule {
// see https://github.com/billziss-gh/winfsp/blob/5d0b10d0b643652c00ebb4704dc2bb28e7244973/src/dll/fuse/fuse_main.c#L53-L62 for syntax guide
// see https://github.com/billziss-gh/winfsp/blob/5d0b10d0b643652c00ebb4704dc2bb28e7244973/src/dll/fuse/fuse.c#L295-L319 for options (-o <...>)
// see https://github.com/billziss-gh/winfsp/wiki/Frequently-Asked-Questions/5ba00e4be4f5e938eaae6ef1500b331de12dee77 (FUSE 4.) on why the given defaults were chosen
private String getWindowsFuseDefaultMountFlags(StringBinding mountName, ReadOnlyBooleanProperty readOnly) {
private String getWindowsFuseDefaultMountFlags(StringExpression mountName, ReadOnlyBooleanProperty readOnly) {
assert SystemUtils.IS_OS_WINDOWS;
StringBuilder flags = new StringBuilder();
@@ -102,7 +102,7 @@ public class CreateNewVaultPasswordController implements FxController {
this.masterkeyFileAccess = masterkeyFileAccess;
this.processing = new SimpleBooleanProperty();
this.readyToCreateVault = new SimpleBooleanProperty();
this.createVaultButtonState = Bindings.createObjectBinding(this::getCreateVaultButtonState, processing);
this.createVaultButtonState = Bindings.when(processing).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
}
@FXML
@@ -231,6 +231,6 @@ public class CreateNewVaultPasswordController implements FxController {
}
public ContentDisplay getCreateVaultButtonState() {
return processing.get() ? ContentDisplay.LEFT : ContentDisplay.TEXT_ONLY;
return createVaultButtonState.get();
}
}
@@ -1,6 +1,5 @@
package org.cryptomator.ui.common;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.ui.controls.FontAwesome5IconView;
import org.cryptomator.ui.controls.NiceSecurePasswordField;
@@ -42,7 +41,7 @@ public class NewPasswordController implements FxController {
passwordStrength.bind(Bindings.createIntegerBinding(() -> strengthRater.computeRate(passwordField.getCharacters()), passwordField.textProperty()));
passwordStrengthLabel.graphicProperty().bind(Bindings.createObjectBinding(this::getIconViewForPasswordStrengthLabel, passwordField.textProperty(), passwordStrength));
passwordStrengthLabel.textProperty().bind(EasyBind.map(passwordStrength, strengthRater::getStrengthDescription));
passwordStrengthLabel.textProperty().bind(passwordStrength.map(strengthRater::getStrengthDescription));
BooleanBinding passwordsMatch = Bindings.createBooleanBinding(this::passwordFieldsMatch, passwordField.textProperty(), reenterField.textProperty());
BooleanBinding reenterFieldNotEmpty = reenterField.textProperty().isNotEmpty();
@@ -46,7 +46,7 @@ public class NiceSecurePasswordField extends StackPane {
nonPrintableCharsIcon.managedProperty().bind(passwordField.containingNonPrintableCharsProperty());
revealPasswordIcon.setGlyph(FontAwesome5Icon.EYE);
revealPasswordIcon.glyphProperty().bind(Bindings.createObjectBinding(this::getRevealPasswordGlyph, revealPasswordButton.selectedProperty()));
revealPasswordIcon.glyphProperty().bind(Bindings.when(revealPasswordButton.selectedProperty()).then(FontAwesome5Icon.EYE_SLASH).otherwise(FontAwesome5Icon.EYE));
revealPasswordIcon.setGlyphSize(ICON_SIZE);
revealPasswordButton.setContentDisplay(ContentDisplay.LEFT);
@@ -61,10 +61,6 @@ public class NiceSecurePasswordField extends StackPane {
disabledProperty().addListener(this::disabledChanged);
}
private FontAwesome5Icon getRevealPasswordGlyph() {
return revealPasswordButton.isSelected() ? FontAwesome5Icon.EYE_SLASH : FontAwesome5Icon.EYE;
}
private void disabledChanged(@SuppressWarnings("unused") Observable observable) {
revealPasswordButton.setSelected(false);
}
@@ -3,12 +3,12 @@ package org.cryptomator.ui.health;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.EasyObservableList;
import com.tobiasdiez.easybind.Subscription;
import com.tobiasdiez.easybind.optional.OptionalBinding;
import org.cryptomator.cryptofs.health.api.DiagnosticResult;
import org.cryptomator.ui.common.FxController;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
@@ -22,15 +22,15 @@ public class CheckDetailController implements FxController {
private final EasyObservableList<Result> results;
private final ObjectProperty<Check> check;
private final OptionalBinding<Check.CheckState> checkState;
private final Binding<String> checkName;
private final Binding<Boolean> checkRunning;
private final Binding<Boolean> checkScheduled;
private final Binding<Boolean> checkFinished;
private final Binding<Boolean> checkSkipped;
private final Binding<Boolean> checkSucceeded;
private final Binding<Boolean> checkFailed;
private final Binding<Boolean> checkCancelled;
private final ObservableValue<Check.CheckState> checkState;
private final ObservableValue<String> checkName;
private final BooleanExpression checkRunning;
private final BooleanExpression checkScheduled;
private final BooleanExpression checkFinished;
private final BooleanExpression checkSkipped;
private final BooleanExpression checkSucceeded;
private final BooleanExpression checkFailed;
private final BooleanExpression checkCancelled;
private final Binding<Number> countOfWarnSeverity;
private final Binding<Number> countOfCritSeverity;
private final Binding<Boolean> warnOrCritsExist;
@@ -44,15 +44,15 @@ public class CheckDetailController implements FxController {
this.resultListCellFactory = resultListCellFactory;
this.results = EasyBind.wrapList(FXCollections.observableArrayList());
this.check = selectedTask;
this.checkState = EasyBind.wrapNullable(selectedTask).mapObservable(Check::stateProperty);
this.checkName = EasyBind.wrapNullable(selectedTask).map(Check::getName).orElse("");
this.checkRunning = checkState.map(Check.CheckState.RUNNING::equals).orElse(false);
this.checkScheduled = checkState.map(Check.CheckState.SCHEDULED::equals).orElse(false);
this.checkSkipped = checkState.map(Check.CheckState.SKIPPED::equals).orElse(false);
this.checkSucceeded = checkState.map(Check.CheckState.SUCCEEDED::equals).orElse(false);
this.checkFailed = checkState.map(Check.CheckState.ERROR::equals).orElse(false);
this.checkCancelled = checkState.map(Check.CheckState.CANCELLED::equals).orElse(false);
this.checkFinished = EasyBind.combine(checkSucceeded, checkFailed, checkCancelled, (a, b, c) -> a || b || c);
this.checkState = selectedTask.flatMap(Check::stateProperty);
this.checkName = selectedTask.map(Check::getName).orElse("");
this.checkRunning = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.RUNNING::equals).orElse(false));
this.checkScheduled = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SCHEDULED::equals).orElse(false));
this.checkSkipped =BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SKIPPED::equals).orElse(false));
this.checkSucceeded = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.SUCCEEDED::equals).orElse(false));
this.checkFailed = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.ERROR::equals).orElse(false));
this.checkCancelled = BooleanExpression.booleanExpression(checkState.map(Check.CheckState.CANCELLED::equals).orElse(false));
this.checkFinished = checkSucceeded.or(checkFailed).or(checkCancelled);
this.countOfWarnSeverity = results.reduce(countSeverity(DiagnosticResult.Severity.WARN));
this.countOfCritSeverity = results.reduce(countSeverity(DiagnosticResult.Severity.CRITICAL));
this.warnOrCritsExist = EasyBind.combine(checkSucceeded, countOfWarnSeverity, countOfCritSeverity, (suceeded, warns, crits) -> suceeded && (warns.longValue() > 0 || crits.longValue() > 0) );
@@ -84,7 +84,7 @@ public class CheckDetailController implements FxController {
return checkName.getValue();
}
public Binding<String> checkNameProperty() {
public ObservableValue<String> checkNameProperty() {
return checkName;
}
@@ -108,7 +108,7 @@ public class CheckDetailController implements FxController {
return checkRunning.getValue();
}
public Binding<Boolean> checkRunningProperty() {
public BooleanExpression checkRunningProperty() {
return checkRunning;
}
@@ -116,7 +116,7 @@ public class CheckDetailController implements FxController {
return checkFinished.getValue();
}
public Binding<Boolean> checkFinishedProperty() {
public BooleanExpression checkFinishedProperty() {
return checkFinished;
}
@@ -124,7 +124,7 @@ public class CheckDetailController implements FxController {
return checkScheduled.getValue();
}
public Binding<Boolean> checkScheduledProperty() {
public BooleanExpression checkScheduledProperty() {
return checkScheduled;
}
@@ -132,7 +132,7 @@ public class CheckDetailController implements FxController {
return checkSkipped.getValue();
}
public Binding<Boolean> checkSkippedProperty() {
public BooleanExpression checkSkippedProperty() {
return checkSkipped;
}
@@ -140,7 +140,7 @@ public class CheckDetailController implements FxController {
return checkSucceeded.getValue();
}
public Binding<Boolean> checkSucceededProperty() {
public BooleanExpression checkSucceededProperty() {
return checkSucceeded;
}
@@ -148,7 +148,7 @@ public class CheckDetailController implements FxController {
return checkFailed.getValue();
}
public Binding<Boolean> checkFailedProperty() {
public BooleanExpression checkFailedProperty() {
return checkFailed;
}
@@ -164,7 +164,7 @@ public class CheckDetailController implements FxController {
return warnOrCritsExist.getValue();
}
public Binding<Boolean> checkCancelledProperty() {
public BooleanExpression checkCancelledProperty() {
return checkCancelled;
}
@@ -1,21 +1,20 @@
package org.cryptomator.ui.health;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.ui.common.FxController;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;
public class CheckListCellController implements FxController {
private final ObjectProperty<Check> check;
private final Binding<String> checkName;
private final Binding<Boolean> checkRunnable;
private final ObservableValue<Boolean> checkRunnable;
private final ObservableValue<String> checkName;
/* FXML */
public CheckBox checkbox;
@@ -23,8 +22,8 @@ public class CheckListCellController implements FxController {
@Inject
public CheckListCellController() {
check = new SimpleObjectProperty<>();
checkRunnable = EasyBind.wrapNullable(check).mapObservable(Check::stateProperty).map(Check.CheckState.RUNNABLE::equals).orElse(false);
checkName = EasyBind.wrapNullable(check).map(Check::getName).orElse("");
checkRunnable = check.flatMap(Check::stateProperty).map(Check.CheckState.RUNNABLE::equals).orElse(false);
checkName = check.map(Check::getName).orElse("");
}
public void initialize() {
@@ -50,7 +49,7 @@ public class CheckListCellController implements FxController {
check.set(c);
}
public Binding<String> checkNameProperty() {
public ObservableValue<String> checkNameProperty() {
return checkName;
}
@@ -58,7 +57,7 @@ public class CheckListCellController implements FxController {
return checkName.getValue();
}
public Binding<Boolean> checkRunnableProperty() {
public ObservableValue<Boolean> checkRunnableProperty() {
return checkRunnable;
}
@@ -13,13 +13,12 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.application.Platform;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableObjectValue;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.Tooltip;
import javafx.util.Duration;
@@ -38,10 +37,10 @@ public class ResultListCellController implements FxController {
private final Logger LOG = LoggerFactory.getLogger(ResultListCellController.class);
private final ObjectProperty<Result> result;
private final ObservableObjectValue<DiagnosticResult.Severity> severity;
private final Binding<String> description;
private final ObservableValue<DiagnosticResult.Severity> severity;
private final ObservableValue<String> description;
private final ResultFixApplier fixApplier;
private final ObservableObjectValue<Result.FixState> fixState;
private final ObservableValue<Result.FixState> fixState;
private final ObjectBinding<FontAwesome5Icon> severityGlyph;
private final ObjectBinding<FontAwesome5Icon> fixGlyph;
private final BooleanBinding fixable;
@@ -62,10 +61,10 @@ public class ResultListCellController implements FxController {
@Inject
public ResultListCellController(ResultFixApplier fixApplier, ResourceBundle resourceBundle) {
this.result = new SimpleObjectProperty<>(null);
this.severity = EasyBind.wrapNullable(result).map(r -> r.diagnosis().getSeverity()).asOrdinary();
this.description = EasyBind.wrapNullable(result).map(Result::getDescription).orElse("");
this.severity = result.map(Result::diagnosis).map(DiagnosticResult::getSeverity);
this.description = result.map(Result::getDescription).orElse("");
this.fixApplier = fixApplier;
this.fixState = EasyBind.wrapNullable(result).mapObservable(Result::fixState).asOrdinary();
this.fixState = result.flatMap(Result::fixState);
this.severityGlyph = Bindings.createObjectBinding(this::getSeverityGlyph, result);
this.fixGlyph = Bindings.createObjectBinding(this::getFixGlyph, fixState);
this.fixable = Bindings.createBooleanBinding(this::isFixable, fixState);
@@ -83,14 +82,15 @@ public class ResultListCellController implements FxController {
@FXML
public void initialize() {
// see getGlyph() for relevant glyphs:
subscriptions.addAll(List.of(EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-muted", Bindings.equal(severity, DiagnosticResult.Severity.INFO)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-primary", Bindings.equal(severity, DiagnosticResult.Severity.GOOD)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-orange", Bindings.equal(severity, DiagnosticResult.Severity.WARN)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-red", Bindings.equal(severity, DiagnosticResult.Severity.CRITICAL)) //
subscriptions.addAll(List.of(EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-muted", severity.map(DiagnosticResult.Severity.INFO::equals).orElse(false)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-primary", severity.map(DiagnosticResult.Severity.GOOD::equals).orElse(false)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-orange", severity.map(DiagnosticResult.Severity.WARN::equals).orElse(false)), //
EasyBind.includeWhen(severityView.getStyleClass(), "glyph-icon-red", severity.map(DiagnosticResult.Severity.CRITICAL::equals).orElse(false)) //
));
var animation = Animations.createDiscrete360Rotation(fixView);
this.fixRunningRotator = AutoAnimator.animate(animation) //
.onCondition(Bindings.equal(fixState, Result.FixState.FIXING)) //
.onCondition(fixing) //
.afterStop(() -> fixView.setRotate(0)) //
.build();
}
@@ -127,7 +127,7 @@ public class ResultListCellController implements FxController {
return result;
}
public Binding<String> descriptionProperty() {
public ObservableValue<String> descriptionProperty() {
return description;
}
@@ -173,7 +173,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixable() {
return Result.FixState.FIXABLE.equals(fixState.get());
return Result.FixState.FIXABLE.equals(fixState.getValue());
}
public BooleanBinding fixingProperty() {
@@ -181,7 +181,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixing() {
return Result.FixState.FIXING.equals(fixState.get());
return Result.FixState.FIXING.equals(fixState.getValue());
}
public BooleanBinding fixedProperty() {
@@ -189,7 +189,7 @@ public class ResultListCellController implements FxController {
}
public boolean isFixed() {
return Result.FixState.FIXED.equals(fixState.get());
return Result.FixState.FIXED.equals(fixState.getValue());
}
public BooleanBinding fixFailedProperty() {
@@ -197,7 +197,7 @@ public class ResultListCellController implements FxController {
}
public Boolean isFixFailed() {
return Result.FixState.FIX_FAILED.equals(fixState.get());
return Result.FixState.FIX_FAILED.equals(fixState.getValue());
}
public BooleanBinding fixRunningOrDoneProperty() {
@@ -50,7 +50,7 @@ public class PassphraseEntryController implements FxController {
private final KeychainManager keychain;
private final StringBinding vaultName;
private final BooleanProperty unlockInProgress = new SimpleBooleanProperty();
private final ObjectBinding<ContentDisplay> unlockButtonContentDisplay = Bindings.createObjectBinding(this::getUnlockButtonContentDisplay, unlockInProgress);
private final ObjectBinding<ContentDisplay> unlockButtonContentDisplay = Bindings.when(unlockInProgress).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
private final BooleanProperty unlockButtonDisabled = new SimpleBooleanProperty();
/* FXML */
@@ -186,7 +186,7 @@ public class PassphraseEntryController implements FxController {
}
public ContentDisplay getUnlockButtonContentDisplay() {
return unlockInProgress.get() ? ContentDisplay.LEFT : ContentDisplay.TEXT_ONLY;
return unlockButtonContentDisplay.get();
}
public ReadOnlyBooleanProperty userInteractionDisabledProperty() {
@@ -46,7 +46,7 @@ public class ResizeController implements FxController {
ResizeController(@MainWindow Stage window, Settings settings) {
this.window = window;
this.settings = settings;
this.showResizingArrows = Bindings.createBooleanBinding(this::isShowResizingArrows, window.fullScreenProperty());
this.showResizingArrows = window.fullScreenProperty().not();
}
@FXML
@@ -181,8 +181,7 @@ public class ResizeController implements FxController {
}
public boolean isShowResizingArrows() {
//If in fullscreen resizing is not be possible;
return !window.isFullScreen();
return showResizingArrows.get();
}
}
@@ -1,6 +1,5 @@
package org.cryptomator.ui.mainwindow;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.ui.common.Animations;
@@ -11,10 +10,10 @@ import org.cryptomator.ui.controls.FontAwesome5IconView;
import javax.inject.Inject;
import javafx.application.Application;
import javafx.beans.binding.Binding;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
@MainWindowScoped
@@ -22,7 +21,7 @@ public class VaultDetailController implements FxController {
private final ReadOnlyObjectProperty<Vault> vault;
private final Application application;
private final Binding<FontAwesome5Icon> glyph;
private final ObservableValue<FontAwesome5Icon> glyph;
private final BooleanBinding anyVaultSelected;
private AutoAnimator spinAnimation;
@@ -35,15 +34,13 @@ public class VaultDetailController implements FxController {
VaultDetailController(ObjectProperty<Vault> vault, Application application) {
this.vault = vault;
this.application = application;
this.glyph = EasyBind.select(vault) //
.selectObject(Vault::stateProperty) //
.map(this::getGlyphForVaultState);
this.glyph = vault.flatMap(Vault::stateProperty).map(this::getGlyphForVaultState);
this.anyVaultSelected = vault.isNotNull();
}
public void initialize() {
this.spinAnimation = AutoAnimator.animate(Animations.createDiscrete360Rotation(vaultStateView)) //
.onCondition(EasyBind.select(vault).selectObject(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals)) //
.onCondition(vault.flatMap(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals).orElse(false)) //
.afterStop(() -> vaultStateView.setRotate(0)) //
.build();
}
@@ -77,7 +74,7 @@ public class VaultDetailController implements FxController {
return vault.get();
}
public Binding<FontAwesome5Icon> glyphProperty() {
public ObservableValue<FontAwesome5Icon> glyphProperty() {
return glyph;
}
@@ -1,6 +1,5 @@
package org.cryptomator.ui.mainwindow;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.common.keychain.KeychainManager;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.ui.common.FxController;
@@ -9,10 +8,10 @@ import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab;
import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
import javax.inject.Inject;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.stage.Stage;
@@ -24,7 +23,7 @@ public class VaultDetailLockedController implements FxController {
private final VaultOptionsComponent.Factory vaultOptionsWindow;
private final KeychainManager keychain;
private final Stage mainWindow;
private final BooleanExpression passwordSaved;
private final ObservableValue<Boolean> passwordSaved;
@Inject
VaultDetailLockedController(ObjectProperty<Vault> vault, FxApplicationWindows appWindows, VaultOptionsComponent.Factory vaultOptionsWindow, KeychainManager keychain, @MainWindow Stage mainWindow) {
@@ -34,7 +33,7 @@ public class VaultDetailLockedController implements FxController {
this.keychain = keychain;
this.mainWindow = mainWindow;
if (keychain.isSupported() && !keychain.isLocked()) {
this.passwordSaved = BooleanExpression.booleanExpression(EasyBind.select(vault).selectObject(v -> keychain.getPassphraseStoredProperty(v.getId())));
this.passwordSaved = vault.flatMap(v -> keychain.getPassphraseStoredProperty(v.getId())).orElse(false);
} else {
this.passwordSaved = new SimpleBooleanProperty(false);
}
@@ -65,13 +64,11 @@ public class VaultDetailLockedController implements FxController {
return vault.get();
}
public BooleanExpression passwordSavedProperty() {
public ObservableValue<Boolean> passwordSavedProperty() {
return passwordSaved;
}
public boolean isPasswordSaved() {
if (keychain.isSupported() && vault.get() != null) {
return keychain.getPassphraseStoredProperty(vault.get().getId()).get();
} else return false;
return passwordSaved.getValue();
}
}
@@ -1,6 +1,5 @@
package org.cryptomator.ui.mainwindow;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
import org.cryptomator.ui.common.Animations;
@@ -10,15 +9,15 @@ import org.cryptomator.ui.controls.FontAwesome5Icon;
import org.cryptomator.ui.controls.FontAwesome5IconView;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
// unscoped because each cell needs its own controller
public class VaultListCellController implements FxController {
private final ObjectProperty<Vault> vault = new SimpleObjectProperty<>();
private final Binding<FontAwesome5Icon> glyph;
private final ObservableValue<FontAwesome5Icon> glyph;
private AutoAnimator spinAnimation;
@@ -27,14 +26,12 @@ public class VaultListCellController implements FxController {
@Inject
VaultListCellController() {
this.glyph = EasyBind.select(vault) //
.selectObject(Vault::stateProperty) //
.map(this::getGlyphForVaultState);
this.glyph = vault.flatMap(Vault::stateProperty).map(this::getGlyphForVaultState);
}
public void initialize() {
this.spinAnimation = AutoAnimator.animate(Animations.createDiscrete360Rotation(vaultStateView)) //
.onCondition(EasyBind.select(vault).selectObject(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals)) //
.onCondition(vault.flatMap(Vault::stateProperty).map(VaultState.Value.PROCESSING::equals).orElse(false)) //
.afterStop(() -> vaultStateView.setRotate(0)) //
.build();
}
@@ -55,7 +52,7 @@ public class VaultListCellController implements FxController {
/* Getter/Setter */
public Binding<FontAwesome5Icon> glyphProperty() {
public ObservableValue<FontAwesome5Icon> glyphProperty() {
return glyph;
}
@@ -1,8 +1,5 @@
package org.cryptomator.ui.mainwindow;
import com.tobiasdiez.easybind.EasyBind;
import com.tobiasdiez.easybind.optional.ObservableOptionalValue;
import com.tobiasdiez.easybind.optional.OptionalBinding;
import org.cryptomator.common.keychain.KeychainManager;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.common.vaults.VaultState;
@@ -14,33 +11,39 @@ import org.cryptomator.ui.vaultoptions.SelectedVaultOptionsTab;
import org.cryptomator.ui.vaultoptions.VaultOptionsComponent;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.stage.Stage;
import java.util.EnumSet;
import java.util.Objects;
import static org.cryptomator.common.vaults.VaultState.Value.*;
import static org.cryptomator.common.vaults.VaultState.Value.ERROR;
import static org.cryptomator.common.vaults.VaultState.Value.LOCKED;
import static org.cryptomator.common.vaults.VaultState.Value.MISSING;
import static org.cryptomator.common.vaults.VaultState.Value.NEEDS_MIGRATION;
import static org.cryptomator.common.vaults.VaultState.Value.UNLOCKED;
@MainWindowScoped
public class VaultListContextMenuController implements FxController {
private final ObservableOptionalValue<Vault> selectedVault;
private final ReadOnlyObjectProperty<Vault> selectedVault;
private final Stage mainWindow;
private final FxApplicationWindows appWindows;
private final VaultService vaultService;
private final KeychainManager keychain;
private final RemoveVaultComponent.Builder removeVault;
private final VaultOptionsComponent.Factory vaultOptionsWindow;
private final OptionalBinding<VaultState.Value> selectedVaultState;
private final Binding<Boolean> selectedVaultPassphraseStored;
private final Binding<Boolean> selectedVaultRemovable;
private final Binding<Boolean> selectedVaultUnlockable;
private final Binding<Boolean> selectedVaultLockable;
private final ObservableValue<VaultState.Value> selectedVaultState;
private final ObservableValue<Boolean> selectedVaultPassphraseStored;
private final ObservableValue<Boolean> selectedVaultRemovable;
private final ObservableValue<Boolean> selectedVaultUnlockable;
private final ObservableValue<Boolean> selectedVaultLockable;
@Inject
VaultListContextMenuController(ObjectProperty<Vault> selectedVault, @MainWindow Stage mainWindow, FxApplicationWindows appWindows, VaultService vaultService, KeychainManager keychain, RemoveVaultComponent.Builder removeVault, VaultOptionsComponent.Factory vaultOptionsWindow) {
this.selectedVault = EasyBind.wrapNullable(selectedVault);
this.selectedVault = selectedVault;
this.mainWindow = mainWindow;
this.appWindows = appWindows;
this.vaultService = vaultService;
@@ -48,8 +51,8 @@ public class VaultListContextMenuController implements FxController {
this.removeVault = removeVault;
this.vaultOptionsWindow = vaultOptionsWindow;
this.selectedVaultState = this.selectedVault.mapObservable(Vault::stateProperty);
this.selectedVaultPassphraseStored = this.selectedVault.map(this::isPasswordStored).orElse(false);
this.selectedVaultState = selectedVault.flatMap(Vault::stateProperty).orElse(null);
this.selectedVaultPassphraseStored = selectedVault.map(this::isPasswordStored).orElse(false);
this.selectedVaultRemovable = selectedVaultState.map(EnumSet.of(LOCKED, MISSING, ERROR, NEEDS_MIGRATION)::contains).orElse(false);
this.selectedVaultUnlockable = selectedVaultState.map(LOCKED::equals).orElse(false);
this.selectedVaultLockable = selectedVaultState.map(UNLOCKED::equals).orElse(false);
@@ -61,40 +64,37 @@ public class VaultListContextMenuController implements FxController {
@FXML
public void didClickRemoveVault() {
selectedVault.ifValuePresent(v -> {
removeVault.vault(v).build().showRemoveVault();
});
var vault = Objects.requireNonNull(selectedVault.get());
removeVault.vault(vault).build().showRemoveVault();
}
@FXML
public void didClickShowVaultOptions() {
selectedVault.ifValuePresent(v -> {
vaultOptionsWindow.create(v).showVaultOptionsWindow(SelectedVaultOptionsTab.ANY);
});
var vault = Objects.requireNonNull(selectedVault.get());
vaultOptionsWindow.create(vault).showVaultOptionsWindow(SelectedVaultOptionsTab.ANY);
}
@FXML
public void didClickUnlockVault() {
selectedVault.ifValuePresent(v -> {
appWindows.startUnlockWorkflow(v, mainWindow);
});
var vault = Objects.requireNonNull(selectedVault.get());
appWindows.startUnlockWorkflow(vault, mainWindow);
}
@FXML
public void didClickLockVault() {
selectedVault.ifValuePresent(v -> {
appWindows.startLockWorkflow(v, mainWindow);
});
var vault = Objects.requireNonNull(selectedVault.get());
appWindows.startLockWorkflow(vault, mainWindow);
}
@FXML
public void didClickRevealVault() {
selectedVault.ifValuePresent(vaultService::reveal);
var vault = Objects.requireNonNull(selectedVault.get());
vaultService.reveal(vault);
}
// Getter and Setter
public Binding<Boolean> selectedVaultUnlockableProperty() {
public ObservableValue<Boolean> selectedVaultUnlockableProperty() {
return selectedVaultUnlockable;
}
@@ -102,7 +102,7 @@ public class VaultListContextMenuController implements FxController {
return selectedVaultUnlockable.getValue();
}
public Binding<Boolean> selectedVaultLockableProperty() {
public ObservableValue<Boolean> selectedVaultLockableProperty() {
return selectedVaultLockable;
}
@@ -110,7 +110,7 @@ public class VaultListContextMenuController implements FxController {
return selectedVaultLockable.getValue();
}
public Binding<Boolean> selectedVaultRemovableProperty() {
public ObservableValue<Boolean> selectedVaultRemovableProperty() {
return selectedVaultRemovable;
}
@@ -118,7 +118,7 @@ public class VaultListContextMenuController implements FxController {
return selectedVaultRemovable.getValue();
}
public Binding<Boolean> selectedVaultPassphraseStoredProperty() {
public ObservableValue<Boolean> selectedVaultPassphraseStoredProperty() {
return selectedVaultPassphraseStored;
}
@@ -83,7 +83,7 @@ public class MigrationRunController implements FxController {
this.appWindows = appWindows;
this.startScene = startScene;
this.successScene = successScene;
this.migrateButtonContentDisplay = Bindings.createObjectBinding(this::getMigrateButtonContentDisplay, vault.stateProperty());
this.migrateButtonContentDisplay = Bindings.when(vault.processingProperty()).then(ContentDisplay.LEFT).otherwise(ContentDisplay.TEXT_ONLY);
this.capabilityErrorScene = capabilityErrorScene;
this.migrationButtonDisabled = new SimpleBooleanProperty();
this.migrationProgress = new SimpleDoubleProperty(volatileMigrationProgress);
@@ -211,10 +211,7 @@ public class MigrationRunController implements FxController {
}
public ContentDisplay getMigrateButtonContentDisplay() {
return switch (vault.getState()) {
case PROCESSING -> ContentDisplay.LEFT;
default -> ContentDisplay.TEXT_ONLY;
};
return migrateButtonContentDisplay.get();
}
public ReadOnlyDoubleProperty migrationProgressProperty() {
@@ -2,7 +2,6 @@ package org.cryptomator.ui.vaultoptions;
import org.cryptomator.common.keychain.KeychainManager;
import org.cryptomator.common.vaults.Vault;
import org.cryptomator.integrations.keychain.KeychainAccessException;
import org.cryptomator.ui.changepassword.ChangePasswordComponent;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.forgetPassword.ForgetPasswordComponent;
@@ -11,9 +10,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.stage.Stage;
@@ -28,7 +26,7 @@ public class MasterkeyOptionsController implements FxController {
private final RecoveryKeyComponent.Builder recoveryKeyWindow;
private final ForgetPasswordComponent.Builder forgetPasswordWindow;
private final KeychainManager keychain;
private final BooleanExpression passwordSaved;
private final ObservableValue<Boolean> passwordSaved;
@Inject
@@ -40,7 +38,7 @@ public class MasterkeyOptionsController implements FxController {
this.forgetPasswordWindow = forgetPasswordWindow;
this.keychain = keychain;
if (keychain.isSupported() && !keychain.isLocked()) {
this.passwordSaved = Bindings.createBooleanBinding(this::isPasswordSaved, keychain.getPassphraseStoredProperty(vault.getId()));
this.passwordSaved = keychain.getPassphraseStoredProperty(vault.getId()).orElse(false);
} else {
this.passwordSaved = new SimpleBooleanProperty(false);
}
@@ -67,13 +65,11 @@ public class MasterkeyOptionsController implements FxController {
forgetPasswordWindow.vault(vault).owner(window).build().showForgetPassword();
}
public BooleanExpression passwordSavedProperty() {
public ObservableValue<Boolean> passwordSavedProperty() {
return passwordSaved;
}
public boolean isPasswordSaved() {
if (keychain.isSupported() && !keychain.isLocked() && vault != null) {
return keychain.getPassphraseStoredProperty(vault.getId()).get();
} else return false;
return passwordSaved.getValue();
}
}
@@ -15,12 +15,17 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class VaultSettingsTest {
@ParameterizedTest
@CsvSource({"a\u000Fa,a_a", ": \\,_ _", "汉语,汉语", "..,_", "a\ta,a\u0020a", "\t\n\r,_"})
@ParameterizedTest(name = "VaultSettings.normalizeDisplayName({0}) = {1}")
@CsvSource(value = {
"a\u000Fa,a_a",
": \\,_ _",
"汉语,汉语",
"..,_",
"a\ta,a\u0020a",
"'\t\n\r',_"
})
public void testNormalize(String test, String expected) {
VaultSettings settings = new VaultSettings("id");
settings.displayName().setValue(test);
assertEquals(expected, settings.normalizeDisplayName());
assertEquals(expected, VaultSettings.normalizeDisplayName(test));
}
}