// Copy data from model.
addressEdit.setText(model.address.get());
titleEdit.setText(model.title.get());
descriptionEdit.setText(model.memo.get());
Coin goalCoin = Coin.valueOf(model.goalAmount.get());
if (goalCoin.value != 1) { // 1 satoshi is sentinel value meaning new project.
goalAmountEdit.setText(goalCoin.toPlainString());
}
minPledgeEdit.setPromptText(model.getMinPledgeAmount().toPlainString());
if (model.image.get() == null) {
setupDefaultCoverImage();
} else {
InputStream stream = model.image.get().newInput();
coverImageView.setImage(new Image(stream));
uncheck(stream::close);
}
// Bind UI back to model.
this.model.title.bind(titleEdit.textProperty());
this.model.memo.bind(descriptionEdit.textProperty());
this.model.address.bind(addressEdit.textProperty());
coverPhotoSiteLink.setText(COVERPHOTO_SITE);
ValidationLink goalValid = new ValidationLink(goalAmountEdit, str -> !LHUtils.didThrow(() -> valueOrThrow(str)));
goalAmountEdit.textProperty().addListener((obj, prev, cur) -> {
if (goalValid.isValid.get())
this.model.goalAmount.set(valueOrThrow(cur).value);
});
// Figure out the smallest pledge that is allowed based on the goal divided by number of inputs we can have.
model.minPledgeAmountProperty().addListener(o -> {
minPledgeEdit.setPromptText(model.getMinPledgeAmount().toPlainString());
});
ValidationLink minPledgeValue = new ValidationLink(minPledgeEdit, str -> {
if (str.isEmpty())
return true; // default is used
Coin coin = valueOrNull(str);
if (coin == null) return false;
Coin amount = model.getMinPledgeAmount();
// If min pledge == suggested amount it's ok, or if it's between min amount and goal.
return coin.equals(amount) || (coin.isGreaterThan(amount) && coin.isLessThan(Coin.valueOf(this.model.goalAmount.get())));
});
ValidationLink.autoDisableButton(nextButton,