mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
fix bugs with bindings
This commit is contained in:
parent
29ad94c4d9
commit
c8699dd66b
@ -43,10 +43,13 @@ public class CodeBehind<T extends PresentationModel> implements Initializable {
|
||||
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
|
||||
// we got removed from the scene
|
||||
// lets terminate
|
||||
if (oldValue != null && newValue == null) terminate();
|
||||
if (oldValue != null && newValue == null)
|
||||
terminate();
|
||||
|
||||
});
|
||||
|
||||
presentationModel.initialized();
|
||||
presentationModel.activate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,8 +58,10 @@ public class CodeBehind<T extends PresentationModel> implements Initializable {
|
||||
*/
|
||||
public void terminate() {
|
||||
log.trace("Lifecycle: terminate " + this.getClass().getSimpleName());
|
||||
if (childController != null) childController.terminate();
|
||||
if (childController != null)
|
||||
childController.terminate();
|
||||
|
||||
presentationModel.deactivate();
|
||||
presentationModel.terminate();
|
||||
}
|
||||
|
||||
|
@ -30,9 +30,10 @@ import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.*;
|
||||
import javafx.scene.control.*;
|
||||
@ -49,6 +50,7 @@ public class TradeController extends CachedViewController {
|
||||
protected CreateOfferCB createOfferCodeBehind;
|
||||
protected TakeOfferController takeOfferController;
|
||||
protected GuiceFXMLLoader orderBookLoader;
|
||||
private Node createOfferView;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -77,8 +79,24 @@ public class TradeController extends CachedViewController {
|
||||
// Textfield focus out triggers validation, use runLater as quick fix...
|
||||
|
||||
//TODO update to new verison
|
||||
((TabPane) root).getSelectionModel().selectedIndexProperty().addListener((observableValue) ->
|
||||
Platform.runLater(InputTextField::hideErrorMessageDisplay));
|
||||
((TabPane) root).getSelectionModel().selectedIndexProperty().addListener((observableValue, oldValue,
|
||||
newValue) ->
|
||||
{
|
||||
InputTextField.hideErrorMessageDisplay();
|
||||
}
|
||||
);
|
||||
|
||||
// We want to get informed when a tab get closed
|
||||
((TabPane) root).getTabs().addListener((ListChangeListener<Tab>) change -> {
|
||||
change.next();
|
||||
List<? extends Tab> removedTabs = change.getRemoved();
|
||||
if (removedTabs.size() == 1 && createOfferView.equals(removedTabs.get(0).getContent())) {
|
||||
if (createOfferCodeBehind != null) {
|
||||
createOfferCodeBehind.terminate();
|
||||
createOfferCodeBehind = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -114,11 +132,12 @@ public class TradeController extends CachedViewController {
|
||||
// in different graphs
|
||||
GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
|
||||
try {
|
||||
final Parent view = loader.load();
|
||||
createOfferView = loader.load();
|
||||
createOfferCodeBehind = loader.getController();
|
||||
log.debug("####### loader.getController() " + createOfferCodeBehind);
|
||||
createOfferCodeBehind.setParentController(this);
|
||||
final Tab tab = new Tab("Create offer");
|
||||
tab.setContent(view);
|
||||
tab.setContent(createOfferView);
|
||||
tabPane.getTabs().add(tab);
|
||||
tabPane.getSelectionModel().select(tabPane.getTabs().size() - 1);
|
||||
return createOfferCodeBehind;
|
||||
@ -159,8 +178,6 @@ public class TradeController extends CachedViewController {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void onCreateOfferViewRemoved() {
|
||||
createOfferCodeBehind = null;
|
||||
|
||||
orderBookController.onCreateOfferViewRemoved();
|
||||
}
|
||||
|
||||
|
@ -78,22 +78,20 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
|
||||
balanceTextField.setup(presentationModel.getWalletFacade(), presentationModel.address.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
super.activate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deactivate() {
|
||||
super.deactivate();
|
||||
|
||||
//TODO check that again
|
||||
if (parentController != null) ((TradeController) parentController).onCreateOfferViewRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void terminate() {
|
||||
super.terminate();
|
||||
|
||||
// Used to re-enable createOfferButton in OrderBookController
|
||||
if (parentController != null) ((TradeController) parentController).onCreateOfferViewRemoved();
|
||||
}
|
||||
|
||||
|
||||
@ -174,13 +172,15 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
presentationModel.requestPlaceOfferFailed.addListener((o, oldValue, newValue) -> {
|
||||
if (newValue) {
|
||||
Popups.openErrorPopup("Error", "An error occurred when placing the offer.\n" +
|
||||
presentationModel.requestPlaceOfferErrorMessage);
|
||||
presentationModel.requestPlaceOfferErrorMessage.get());
|
||||
presentationModel.requestPlaceOfferFailed.set(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setupBindings() {
|
||||
|
@ -74,7 +74,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
|
||||
final BooleanProperty isCloseButtonVisible = new SimpleBooleanProperty();
|
||||
final BooleanProperty isPlaceOfferButtonVisible = new SimpleBooleanProperty(true);
|
||||
final BooleanProperty isPlaceOfferButtonDisabled = new SimpleBooleanProperty();
|
||||
final BooleanProperty isPlaceOfferButtonDisabled = new SimpleBooleanProperty(true);
|
||||
final BooleanProperty showWarningAdjustedVolume = new SimpleBooleanProperty();
|
||||
final BooleanProperty showWarningInvalidFiatDecimalPlaces = new SimpleBooleanProperty();
|
||||
final BooleanProperty showWarningInvalidBtcDecimalPlaces = new SimpleBooleanProperty();
|
||||
@ -206,7 +206,6 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
}
|
||||
|
||||
void onFocusOutMinAmountTextField(Boolean oldValue, Boolean newValue, String userInput) {
|
||||
|
||||
if (oldValue && !newValue) {
|
||||
InputValidator.ValidationResult result = isBtcInputValid(minAmount.get());
|
||||
minAmountValidationResult.set(result);
|
||||
@ -287,6 +286,12 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
}
|
||||
validateInput();
|
||||
});
|
||||
|
||||
minAmount.addListener((ov, oldValue, newValue) -> {
|
||||
setMinAmountToModel();
|
||||
validateInput();
|
||||
});
|
||||
|
||||
price.addListener((ov, oldValue, newValue) -> {
|
||||
@ -296,6 +301,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
}
|
||||
validateInput();
|
||||
});
|
||||
|
||||
volume.addListener((ov, oldValue, newValue) -> {
|
||||
@ -306,6 +312,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.calculateTotalToPay();
|
||||
model.calculateCollateral();
|
||||
}
|
||||
validateInput();
|
||||
});
|
||||
|
||||
// Binding with Bindings.createObjectBinding does not work because of bi-directional binding
|
||||
@ -314,6 +321,13 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.priceAsFiat.addListener((ov, oldValue, newValue) -> price.set(formatFiat(newValue)));
|
||||
model.volumeAsFiat.addListener((ov, oldValue, newValue) -> volume.set(formatFiat(newValue)));
|
||||
|
||||
model.requestPlaceOfferFailed.addListener((ov, oldValue, newValue) -> {
|
||||
isPlaceOfferButtonDisabled.set(!newValue);
|
||||
requestPlaceOfferFailed.set(newValue);
|
||||
});
|
||||
model.requestPlaceOfferSuccess.addListener((ov, oldValue, newValue) -> isPlaceOfferButtonVisible.set
|
||||
(!newValue));
|
||||
|
||||
// ObservableLists
|
||||
model.acceptedCountries.addListener((Observable o) -> acceptedCountries.set(BSFormatter
|
||||
.countryLocalesToString(model.acceptedCountries)));
|
||||
@ -340,14 +354,7 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
|
||||
isCloseButtonVisible.bind(model.requestPlaceOfferSuccess);
|
||||
requestPlaceOfferErrorMessage.bind(model.requestPlaceOfferErrorMessage);
|
||||
requestPlaceOfferFailed.bind(model.requestPlaceOfferFailed);
|
||||
showTransactionPublishedScreen.bind(model.requestPlaceOfferSuccess);
|
||||
|
||||
isPlaceOfferButtonDisabled.bind(Bindings.createBooleanBinding(() -> !model.requestPlaceOfferFailed.get(),
|
||||
model.requestPlaceOfferFailed));
|
||||
|
||||
isPlaceOfferButtonVisible.bind(Bindings.createBooleanBinding(() -> !model.requestPlaceOfferSuccess.get(),
|
||||
model.requestPlaceOfferSuccess));
|
||||
}
|
||||
|
||||
private void calculateVolume() {
|
||||
@ -390,6 +397,14 @@ class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||
model.volumeAsFiat.set(parseToFiatWith2Decimals(volume.get()));
|
||||
}
|
||||
|
||||
private void validateInput() {
|
||||
isPlaceOfferButtonDisabled.set(!(isBtcInputValid(amount.get()).isValid &&
|
||||
isBtcInputValid(minAmount.get()).isValid &&
|
||||
isBtcInputValid(price.get()).isValid &&
|
||||
isBtcInputValid(volume.get()).isValid &&
|
||||
model.isMinAmountLessOrEqualAmount())
|
||||
);
|
||||
}
|
||||
|
||||
private InputValidator.ValidationResult isBtcInputValid(String input) {
|
||||
|
||||
|
@ -552,11 +552,9 @@ public class OrderBookController extends CachedViewController {
|
||||
volume.setText(BSFormatter.formatPrice(a * p));
|
||||
}
|
||||
|
||||
|
||||
public void onCreateOfferViewRemoved() {
|
||||
createOfferButton.setDisable(false);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user