if (!encryptResult) {
this.beanPathAdapter.bindBidirectional(this.modelKey.getKey(),
tf.textProperty());
} else {
try {
final StringProperty msp = new SimpleStringProperty(
tf.getText()) {
@Override
public void set(final String value) {
super.set(value);
if (value == null || value.isEmpty()) {
tf.setText(value);
return;
}
encrypt = false;
try {
final String clearText = getEncryptionProvider()
.decrypt(value);
tf.setText(clearText);
} catch (final Throwable t) {
throw new RuntimeException("Unable to decrypt", t);
} finally {
encrypt = true;
}
}
};
this.beanPathAdapter.bindBidirectional(this.modelKey.getKey(),
msp);
tf.focusedProperty().addListener(new ChangeListener<Boolean>() {
private String ltv = tf.getText();
@Override
public void changed(
final ObservableValue<? extends Boolean> observable,
final Boolean oldValue, final Boolean newValue) {
if (encrypt && (newValue == null || !newValue)
&& tf.getText() != null
&& !tf.getText().isEmpty()
&& !tf.getText().equals(ltv)) {
try {
final String encrypted = getEncryptionProvider()
.encrypt(tf.getText());
ltv = tf.getText();
msp.set(encrypted);
} catch (final Throwable t) {
throw new RuntimeException("Unable to encrypt",
t);
}
}