mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-06-26 07:40:35 -04:00
Fix text input handling for offer filter
This commit is contained in:
parent
71df030a11
commit
6db8157d2c
4 changed files with 90 additions and 13 deletions
|
@ -110,6 +110,11 @@ public class InputTextField extends TextField {
|
||||||
// Public methods
|
// Public methods
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void resetValidation() {
|
||||||
|
setEffect(null);
|
||||||
|
hideErrorMessageDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Setters
|
// Setters
|
||||||
|
|
|
@ -97,24 +97,17 @@ class OfferBookDataModel implements Activatable, DataModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activate() {
|
public void activate() {
|
||||||
addBindings();
|
|
||||||
addListeners();
|
|
||||||
|
|
||||||
// reset filter values
|
|
||||||
amountAsCoin.set(null);
|
amountAsCoin.set(null);
|
||||||
priceAsFiat.set(null);
|
priceAsFiat.set(null);
|
||||||
volumeAsFiat.set(null);
|
volumeAsFiat.set(null);
|
||||||
|
|
||||||
/*
|
addBindings();
|
||||||
//TODO temp for testing
|
addListeners();
|
||||||
amountAsCoin.set(Coin.COIN);
|
|
||||||
priceAsFiat.set(Fiat.valueOf("EUR", 300*10000));
|
|
||||||
// volumeAsFiat.set(Fiat.valueOf("EUR", 300));*/
|
|
||||||
|
|
||||||
setBankAccount(user.currentFiatAccountProperty().get());
|
setBankAccount(user.currentFiatAccountProperty().get());
|
||||||
applyFilter();
|
|
||||||
|
|
||||||
offerBook.startPolling();
|
offerBook.startPolling();
|
||||||
|
applyFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -82,6 +82,13 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
private final OptionalFiatValidator optionalFiatValidator;
|
private final OptionalFiatValidator optionalFiatValidator;
|
||||||
private OfferView.OfferActionHandler offerActionHandler;
|
private OfferView.OfferActionHandler offerActionHandler;
|
||||||
|
|
||||||
|
private ChangeListener<String> amountTextFieldListener;
|
||||||
|
private ChangeListener<String> priceTextFieldListener;
|
||||||
|
private ChangeListener<String> volumeTextFieldListener;
|
||||||
|
private ChangeListener<Boolean> amountTextFieldFocusedListener;
|
||||||
|
private ChangeListener<Boolean> priceTextFieldFocusedListener;
|
||||||
|
private ChangeListener<Boolean> volumeTextFieldFocusedListener;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Constructor, lifecycle
|
// Constructor, lifecycle
|
||||||
|
@ -126,10 +133,22 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
// for irc demo
|
// for irc demo
|
||||||
showAdvancedSettingsButton.setVisible(false);
|
showAdvancedSettingsButton.setVisible(false);
|
||||||
showAdvancedSettingsButton.setManaged(false);
|
showAdvancedSettingsButton.setManaged(false);
|
||||||
|
|
||||||
|
createListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doActivate() {
|
public void doActivate() {
|
||||||
|
// reset filter values
|
||||||
|
amountTextField.setText("");
|
||||||
|
priceTextField.setText("");
|
||||||
|
volumeTextField.setText("");
|
||||||
|
|
||||||
|
amountTextField.resetValidation();
|
||||||
|
priceTextField.resetValidation();
|
||||||
|
volumeTextField.resetValidation();
|
||||||
|
|
||||||
|
addListeners();
|
||||||
addBindings();
|
addBindings();
|
||||||
|
|
||||||
// setOfferBookInfo has been called before
|
// setOfferBookInfo has been called before
|
||||||
|
@ -141,12 +160,68 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||||
@Override
|
@Override
|
||||||
public void doDeactivate() {
|
public void doDeactivate() {
|
||||||
removeBindings();
|
removeBindings();
|
||||||
|
removeListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createListeners() {
|
||||||
|
amountTextFieldListener = (observable, oldValue, newValue) -> model.amount.set(newValue);
|
||||||
|
priceTextFieldListener = (observable, oldValue, newValue) -> model.price.set(newValue);
|
||||||
|
volumeTextFieldListener = (observable, oldValue, newValue) -> model.volume.set(newValue);
|
||||||
|
|
||||||
|
amountTextFieldFocusedListener = (ov, oldValue, newValue) -> {
|
||||||
|
if (newValue) {
|
||||||
|
amountTextField.textProperty().unbind();
|
||||||
|
amountTextField.textProperty().addListener(amountTextFieldListener);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
amountTextField.textProperty().removeListener(amountTextFieldListener);
|
||||||
|
amountTextField.textProperty().bind(model.amount);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
priceTextFieldFocusedListener = (ov, oldValue, newValue) -> {
|
||||||
|
if (newValue) {
|
||||||
|
priceTextField.textProperty().unbind();
|
||||||
|
priceTextField.textProperty().addListener(priceTextFieldListener);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
priceTextField.textProperty().removeListener(priceTextFieldListener);
|
||||||
|
priceTextField.textProperty().bind(model.price);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
volumeTextFieldFocusedListener = (ov, oldValue, newValue) -> {
|
||||||
|
if (newValue) {
|
||||||
|
volumeTextField.textProperty().unbind();
|
||||||
|
volumeTextField.textProperty().addListener(volumeTextFieldListener);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
volumeTextField.textProperty().removeListener(volumeTextFieldListener);
|
||||||
|
volumeTextField.textProperty().bind(model.volume);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addListeners() {
|
||||||
|
amountTextField.focusedProperty().addListener(amountTextFieldFocusedListener);
|
||||||
|
priceTextField.focusedProperty().addListener(priceTextFieldFocusedListener);
|
||||||
|
volumeTextField.focusedProperty().addListener(volumeTextFieldFocusedListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeListeners() {
|
||||||
|
amountTextField.focusedProperty().removeListener(amountTextFieldFocusedListener);
|
||||||
|
priceTextField.focusedProperty().removeListener(priceTextFieldFocusedListener);
|
||||||
|
volumeTextField.focusedProperty().removeListener(volumeTextFieldFocusedListener);
|
||||||
|
|
||||||
|
amountTextField.textProperty().removeListener(amountTextFieldListener);
|
||||||
|
priceTextField.textProperty().removeListener(priceTextFieldListener);
|
||||||
|
volumeTextField.textProperty().removeListener(volumeTextFieldListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addBindings() {
|
private void addBindings() {
|
||||||
amountTextField.textProperty().bindBidirectional(model.amount);
|
// those bindings are unbinded by focus change handlers
|
||||||
priceTextField.textProperty().bindBidirectional(model.price);
|
amountTextField.textProperty().bind(model.amount);
|
||||||
volumeTextField.textProperty().bindBidirectional(model.volume);
|
priceTextField.textProperty().bind(model.price);
|
||||||
|
volumeTextField.textProperty().bind(model.volume);
|
||||||
|
|
||||||
amountBtcLabel.textProperty().bind(model.btcCode);
|
amountBtcLabel.textProperty().bind(model.btcCode);
|
||||||
priceFiatLabel.textProperty().bind(model.fiatCode);
|
priceFiatLabel.textProperty().bind(model.fiatCode);
|
||||||
volumeFiatLabel.textProperty().bind(model.fiatCode);
|
volumeFiatLabel.textProperty().bind(model.fiatCode);
|
||||||
|
|
|
@ -82,6 +82,10 @@ class OfferBookViewModel extends ActivatableWithDataModel<OfferBookDataModel> im
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doActivate() {
|
protected void doActivate() {
|
||||||
|
amount.set("");
|
||||||
|
price.set("");
|
||||||
|
volume.set("");
|
||||||
|
|
||||||
addBindings();
|
addBindings();
|
||||||
addListeners();
|
addListeners();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue