This commit is contained in:
Sebastian Stenzel
2020-06-16 15:02:38 +02:00
parent d80605532f
commit d3a6964d8f
3 changed files with 44 additions and 4 deletions

View File

@@ -0,0 +1,32 @@
package org.cryptomator.ui.common;
import javafx.beans.binding.StringBinding;
import javafx.beans.value.ObservableObjectValue;
/**
* Contains a variety of method to create {@link java.util.function.Function#identity() identity}-bindings
* to facilitate the Weak References used internally in JavaFX's Bindings.
*/
public final class WeakBindings {
/**
* Create a new StringBinding that listens to changes from the given observable without being strongly referenced by it.
*
* @param observable The observable
* @return a StringBinding weakly referenced from the given observable
*/
public static StringBinding bindString(ObservableObjectValue<String> observable) {
return new StringBinding() {
{
bind(observable);
}
@Override
protected String computeValue() {
return observable.get();
}
};
}
}

View File

@@ -8,6 +8,7 @@ import javafx.animation.Timeline;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.binding.ObjectBinding;
import javafx.beans.binding.StringBinding;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
@@ -23,6 +24,7 @@ import org.cryptomator.common.vaults.Vault;
import org.cryptomator.keychain.KeychainManager;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.common.UserInteractionLock;
import org.cryptomator.ui.common.WeakBindings;
import org.cryptomator.ui.controls.NiceSecurePasswordField;
import org.cryptomator.ui.forgetPassword.ForgetPasswordComponent;
import org.slf4j.Logger;
@@ -51,7 +53,8 @@ public class UnlockController implements FxController {
private final ObjectBinding<ContentDisplay> unlockButtonContentDisplay;
private final BooleanBinding userInteractionDisabled;
private final BooleanProperty unlockButtonDisabled;
private final StringBinding vaultName;
public NiceSecurePasswordField passwordField;
public CheckBox savePasswordCheckbox;
public ImageView face;
@@ -74,6 +77,7 @@ public class UnlockController implements FxController {
this.unlockButtonContentDisplay = Bindings.createObjectBinding(this::getUnlockButtonContentDisplay, passwordEntryLock.awaitingInteraction());
this.userInteractionDisabled = passwordEntryLock.awaitingInteraction().not();
this.unlockButtonDisabled = new SimpleBooleanProperty();
this.vaultName = WeakBindings.bindString(vault.displayableNameProperty());
this.window.setOnCloseRequest(windowEvent -> cancel());
}
@@ -177,8 +181,12 @@ public class UnlockController implements FxController {
/* Getter/Setter */
public Vault getVault() {
return vault;
public String getVaultName() {
return vaultName.get();
}
public StringBinding vaultNameProperty() {
return vaultName;
}
public ObjectBinding<ContentDisplay> unlockButtonContentDisplayProperty() {

View File

@@ -46,7 +46,7 @@
</ImageView>
</StackPane>
<VBox spacing="6" HBox.hgrow="ALWAYS">
<FormattedLabel format="%unlock.passwordPrompt" arg1="${controller.vault.displayableName}" wrapText="true"/>
<FormattedLabel format="%unlock.passwordPrompt" arg1="${controller.vaultName}" wrapText="true"/>
<NiceSecurePasswordField fx:id="passwordField" disable="${controller.userInteractionDisabled}"/>
<CheckBox fx:id="savePasswordCheckbox" text="%unlock.savePassword" onAction="#didClickSavePasswordCheckbox" disable="${controller.userInteractionDisabled}" visible="${controller.keychainAccessAvailable}"/>
</VBox>