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