mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 15:26:03 -04:00
Add list view for payment accounts
This commit is contained in:
parent
cdba55f23e
commit
fa0d670901
@ -17,7 +17,7 @@
|
||||
|
||||
package io.bitsquare.gui.components.paymentmethods;
|
||||
|
||||
import io.bitsquare.common.util.Tuple2;
|
||||
import io.bitsquare.common.util.Tuple3;
|
||||
import io.bitsquare.gui.components.InputTextField;
|
||||
import io.bitsquare.gui.util.Layout;
|
||||
import io.bitsquare.gui.util.validation.BICValidator;
|
||||
@ -99,8 +99,10 @@ public class SepaForm extends PaymentMethodForm {
|
||||
|
||||
});
|
||||
|
||||
Tuple2<Label, ComboBox> tuple2 = addLabelComboBox(gridPane, ++gridRow, "Country of your Bank:");
|
||||
ComboBox<Country> countryComboBox = tuple2.second;
|
||||
Tuple3<Label, ComboBox, TextField> tuple3 = addLabelComboBoxLabel(gridPane, ++gridRow, "Country of your Bank:", "");
|
||||
ComboBox<Country> countryComboBox = tuple3.second;
|
||||
currencyTextField = tuple3.third;
|
||||
currencyTextField.setMinWidth(300);
|
||||
countryComboBox.setPromptText("Select country of your Bank");
|
||||
countryComboBox.setConverter(new StringConverter<Country>() {
|
||||
@Override
|
||||
@ -118,14 +120,12 @@ public class SepaForm extends PaymentMethodForm {
|
||||
sepaAccount.setCountry(selectedItem);
|
||||
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(selectedItem.code);
|
||||
sepaAccount.setSingleTradeCurrency(currency);
|
||||
currencyTextField.setText(currency.getCodeAndName());
|
||||
currencyTextField.setText("Currency: " + currency.getCodeAndName());
|
||||
updateCountriesSelection(true, euroCountryCheckBoxes);
|
||||
updateCountriesSelection(true, nonEuroCountryCheckBoxes);
|
||||
updateFromInputs();
|
||||
});
|
||||
|
||||
currencyTextField = addLabelTextField(gridPane, ++gridRow, "Currency:").second;
|
||||
|
||||
addEuroCountriesGrid(true);
|
||||
addNonEuroCountriesGrid(true);
|
||||
addAllowedPeriod();
|
||||
@ -138,7 +138,7 @@ public class SepaForm extends PaymentMethodForm {
|
||||
sepaAccount.setCountry(country);
|
||||
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(country.code);
|
||||
sepaAccount.setSingleTradeCurrency(currency);
|
||||
currencyTextField.setText(currency.getCodeAndName());
|
||||
currencyTextField.setText("Currency: " + currency.getCodeAndName());
|
||||
}
|
||||
|
||||
updateFromInputs();
|
||||
@ -176,6 +176,7 @@ public class SepaForm extends PaymentMethodForm {
|
||||
checkBoxList.add(checkBox);
|
||||
checkBox.setMouseTransparent(!isEditable);
|
||||
checkBox.setMinWidth(45);
|
||||
checkBox.setMaxWidth(45);
|
||||
checkBox.setTooltip(new Tooltip(country.name));
|
||||
checkBox.setOnAction(event -> {
|
||||
if (checkBox.isSelected())
|
||||
@ -256,8 +257,19 @@ public class SepaForm extends PaymentMethodForm {
|
||||
bicField.setMouseTransparent(false);
|
||||
addLabelTextField(gridPane, ++gridRow, "Location of Bank:", sepaAccount.getCountry().name);
|
||||
addLabelTextField(gridPane, ++gridRow, "Currency:", sepaAccount.getSingleTradeCurrency().getCodeAndName());
|
||||
String countries;
|
||||
Tooltip tooltip = null;
|
||||
if (CountryUtil.containsAllSepaEuroCountries(sepaAccount.getAcceptedCountryCodes())) {
|
||||
countries = "All Euro countries";
|
||||
} else {
|
||||
countries = CountryUtil.getCodesString(sepaAccount.getAcceptedCountryCodes());
|
||||
tooltip = new Tooltip(CountryUtil.getNamesByCodesString(sepaAccount.getAcceptedCountryCodes()));
|
||||
}
|
||||
TextField acceptedCountries = addLabelTextField(gridPane, ++gridRow, "Accepted countries:", countries).second;
|
||||
if (tooltip != null) {
|
||||
acceptedCountries.setMouseTransparent(false);
|
||||
acceptedCountries.setTooltip(tooltip);
|
||||
}
|
||||
addAllowedPeriod();
|
||||
addEuroCountriesGrid(false);
|
||||
addNonEuroCountriesGrid(false);
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ public class AccountView extends ActivatableView<TabPane, AccountViewModel> {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
navigationListener = viewPath -> {
|
||||
if (viewPath.size() == 3 && viewPath.indexOf(AccountView.class) == 1) {
|
||||
if (arbitratorRegistrationTab == null && viewPath.get(2).equals(ArbitratorRegistrationView.class))
|
||||
|
@ -25,7 +25,7 @@
|
||||
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-10.0"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" halignment="RIGHT" minWidth="140.0"/>
|
||||
<ColumnConstraints hgrow="SOMETIMES" halignment="RIGHT" minWidth="160.0" maxWidth="160"/>
|
||||
<ColumnConstraints hgrow="ALWAYS" minWidth="300.0"/>
|
||||
</columnConstraints>
|
||||
</GridPane>
|
||||
|
@ -20,22 +20,23 @@ package io.bitsquare.gui.main.account.content.paymentsaccount;
|
||||
import io.bitsquare.common.util.Tuple2;
|
||||
import io.bitsquare.gui.common.view.ActivatableViewAndModel;
|
||||
import io.bitsquare.gui.common.view.FxmlView;
|
||||
import io.bitsquare.gui.common.view.Wizard;
|
||||
import io.bitsquare.gui.components.TitledGroupBg;
|
||||
import io.bitsquare.gui.components.paymentmethods.*;
|
||||
import io.bitsquare.gui.popups.Popup;
|
||||
import io.bitsquare.gui.util.FormBuilder;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
import io.bitsquare.gui.util.Layout;
|
||||
import io.bitsquare.gui.util.validation.*;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.payment.*;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.geometry.VPos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.util.Callback;
|
||||
import javafx.util.StringConverter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -43,13 +44,11 @@ import javax.inject.Inject;
|
||||
import static io.bitsquare.gui.util.FormBuilder.*;
|
||||
|
||||
@FxmlView
|
||||
public class PaymentAccountView extends ActivatableViewAndModel<GridPane, PaymentAccountViewModel> implements Wizard.Step {
|
||||
public class PaymentAccountView extends ActivatableViewAndModel<GridPane, PaymentAccountViewModel> {
|
||||
|
||||
private ComboBox<PaymentAccount> paymentAccountsComboBox;
|
||||
private ListView<PaymentAccount> paymentAccountsListView;
|
||||
private ComboBox<PaymentMethod> paymentMethodsComboBox;
|
||||
|
||||
private Wizard wizard;
|
||||
|
||||
private final IBANValidator ibanValidator;
|
||||
private final BICValidator bicValidator;
|
||||
private final InputValidator inputValidator;
|
||||
@ -64,7 +63,7 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
private Button addAccountButton;
|
||||
private Button saveNewAccountButton;
|
||||
private int gridRow = 0;
|
||||
private ListChangeListener<PaymentAccount> paymentAccountListChangeListener;
|
||||
private ChangeListener<PaymentAccount> paymentAccountChangeListener;
|
||||
|
||||
@Inject
|
||||
public PaymentAccountView(PaymentAccountViewModel model,
|
||||
@ -91,37 +90,24 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
@Override
|
||||
public void initialize() {
|
||||
buildForm();
|
||||
paymentAccountListChangeListener = c -> paymentAccountsComboBox.setDisable(model.getPaymentAccounts().size() == 0);
|
||||
paymentAccountChangeListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue != null)
|
||||
onSelectAccount(newValue);
|
||||
};
|
||||
Label placeholder = new Label("There are no payment accounts set up yet");
|
||||
placeholder.setWrapText(true);
|
||||
paymentAccountsListView.setPlaceholder(placeholder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
paymentAccountsComboBox.setItems(model.getPaymentAccounts());
|
||||
EventHandler<ActionEvent> paymentAccountsComboBoxHandler = e -> {
|
||||
if (paymentAccountsComboBox.getSelectionModel().getSelectedItem() != null)
|
||||
onSelectAccount(paymentAccountsComboBox.getSelectionModel().getSelectedItem());
|
||||
};
|
||||
paymentAccountsComboBox.setOnAction(paymentAccountsComboBoxHandler);
|
||||
paymentAccountsComboBox.setVisibleRowCount(20);
|
||||
|
||||
model.getPaymentAccounts().addListener(paymentAccountListChangeListener);
|
||||
paymentAccountsComboBox.setDisable(model.getPaymentAccounts().size() == 0);
|
||||
paymentAccountsListView.setItems(model.getPaymentAccounts());
|
||||
paymentAccountsListView.getSelectionModel().selectedItemProperty().addListener(paymentAccountChangeListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
model.getPaymentAccounts().removeListener(paymentAccountListChangeListener);
|
||||
paymentAccountsComboBox.setOnAction(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWizard(Wizard wizard) {
|
||||
this.wizard = wizard;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideWizardNavigation() {
|
||||
|
||||
paymentAccountsListView.getSelectionModel().selectedItemProperty().removeListener(paymentAccountChangeListener);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -137,7 +123,6 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
}).findAny().isPresent()) {
|
||||
model.onSaveNewAccount(paymentAccount);
|
||||
removeNewAccountForm();
|
||||
paymentAccountsComboBox.getSelectionModel().clearSelection();
|
||||
} else {
|
||||
new Popup().error("That account name is already used in a saved account. \nPlease use another name.").show();
|
||||
}
|
||||
@ -145,7 +130,6 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
|
||||
private void onCancelNewAccount() {
|
||||
removeNewAccountForm();
|
||||
paymentAccountsComboBox.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
private void onDeleteAccount(PaymentAccount paymentAccount) {
|
||||
@ -153,7 +137,6 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
.onAction(() -> {
|
||||
model.onDeleteAccount(paymentAccount);
|
||||
removeSelectAccountForm();
|
||||
paymentAccountsComboBox.getSelectionModel().clearSelection();
|
||||
})
|
||||
.show();
|
||||
}
|
||||
@ -166,17 +149,37 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
private void buildForm() {
|
||||
addTitledGroupBg(root, gridRow, 2, "Manage payment accounts");
|
||||
|
||||
paymentAccountsComboBox = addLabelComboBox(root, gridRow, "Select account:", Layout.FIRST_ROW_DISTANCE).second;
|
||||
paymentAccountsComboBox.setPromptText("Select account");
|
||||
paymentAccountsComboBox.setConverter(new StringConverter<PaymentAccount>() {
|
||||
Tuple2<Label, ListView> tuple = addLabelListView(root, gridRow, "Your payment accounts:", Layout.FIRST_ROW_DISTANCE);
|
||||
GridPane.setValignment(tuple.first, VPos.TOP);
|
||||
paymentAccountsListView = tuple.second;
|
||||
paymentAccountsListView.setPrefHeight(2 * Layout.LIST_ROW_HEIGHT + 14);
|
||||
paymentAccountsListView.setCellFactory(new Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>>() {
|
||||
@Override
|
||||
public String toString(PaymentAccount paymentAccount) {
|
||||
return paymentAccount.getAccountName();
|
||||
}
|
||||
public ListCell<PaymentAccount> call(ListView<PaymentAccount> list) {
|
||||
return new ListCell<PaymentAccount>() {
|
||||
final Label label = new Label();
|
||||
final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);
|
||||
final Button removeButton = new Button("", icon);
|
||||
final AnchorPane pane = new AnchorPane(label, removeButton);
|
||||
|
||||
@Override
|
||||
public PaymentAccount fromString(String s) {
|
||||
return null;
|
||||
{
|
||||
label.setLayoutY(5);
|
||||
removeButton.setId("icon-button");
|
||||
AnchorPane.setRightAnchor(removeButton, 0d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateItem(final PaymentAccount item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty) {
|
||||
label.setText(item.getAccountName());
|
||||
removeButton.setOnAction(e -> onDeleteAccount(item));
|
||||
setGraphic(pane);
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
@ -186,7 +189,7 @@ public class PaymentAccountView extends ActivatableViewAndModel<GridPane, Paymen
|
||||
|
||||
// Add new account form
|
||||
private void addNewAccount() {
|
||||
paymentAccountsComboBox.getSelectionModel().clearSelection();
|
||||
paymentAccountsListView.getSelectionModel().clearSelection();
|
||||
removeAccountRows();
|
||||
addAccountButton.setDisable(true);
|
||||
accountTitledGroupBg = addTitledGroupBg(root, ++gridRow, 1, "Create new account", Layout.GROUP_DISTANCE);
|
||||
|
@ -48,7 +48,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
||||
private final ViewLoader viewLoader;
|
||||
private final Navigation navigation;
|
||||
|
||||
// private MenuItem registration;
|
||||
private MenuItem password, seedWords, backup, paymentAccount, arbitratorSelection;
|
||||
private Navigation.Listener listener;
|
||||
|
||||
@ -80,13 +79,18 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
||||
password = new MenuItem(navigation, toggleGroup, "Wallet password", PasswordView.class, AwesomeIcon.UNLOCK_ALT);
|
||||
seedWords = new MenuItem(navigation, toggleGroup, "Wallet seed", SeedWordsView.class, AwesomeIcon.KEY);
|
||||
backup = new MenuItem(navigation, toggleGroup, "Backup", BackupView.class, AwesomeIcon.CLOUD_DOWNLOAD);
|
||||
// registration = new MenuItem(navigation, toggleGroup, "Renew your account", RegistrationView.class, AwesomeIcon.BRIEFCASE);
|
||||
|
||||
leftVBox.getChildren().addAll(paymentAccount, arbitratorSelection, password, seedWords, backup);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
paymentAccount.activate();
|
||||
arbitratorSelection.activate();
|
||||
password.activate();
|
||||
seedWords.activate();
|
||||
backup.activate();
|
||||
|
||||
navigation.addListener(listener);
|
||||
ViewPath viewPath = navigation.getCurrentPath();
|
||||
if (viewPath.size() == 3 && viewPath.indexOf(AccountSettingsView.class) == 2 ||
|
||||
@ -96,11 +100,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
||||
selecteedViewClass = viewPath.get(3);
|
||||
loadView(selecteedViewClass);
|
||||
}
|
||||
paymentAccount.activate();
|
||||
arbitratorSelection.activate();
|
||||
password.activate();
|
||||
seedWords.activate();
|
||||
backup.activate();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -115,12 +114,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
||||
}
|
||||
|
||||
private void loadView(Class<? extends View> viewClass) {
|
||||
/* if (viewClass.equals(PaymentAccountView.class)) {
|
||||
PaymentAccountView view = new PaymentAccountView();
|
||||
content.getChildren().setAll(view.getRoot());
|
||||
paymentAccount.setSelected(true);
|
||||
}
|
||||
else {*/
|
||||
View view = viewLoader.load(viewClass);
|
||||
content.getChildren().setAll(view.getRoot());
|
||||
|
||||
@ -129,8 +122,6 @@ public class AccountSettingsView extends ActivatableViewAndModel {
|
||||
else if (view instanceof BackupView) backup.setSelected(true);
|
||||
else if (view instanceof PaymentAccountView) paymentAccount.setSelected(true);
|
||||
else if (view instanceof ArbitratorSelectionView) arbitratorSelection.setSelected(true);
|
||||
// else if (view instanceof RegistrationView) registration.setSelected(true);
|
||||
//}
|
||||
}
|
||||
|
||||
public Class<? extends View> getSelectedViewClass() {
|
||||
|
@ -452,7 +452,6 @@ public class FormBuilder {
|
||||
|
||||
GridPane.setRowIndex(hBox, rowIndex);
|
||||
GridPane.setColumnIndex(hBox, 1);
|
||||
// GridPane.setMargin(hBox, new Insets(15, 0, 0, 0));
|
||||
gridPane.getChildren().add(hBox);
|
||||
|
||||
return new Tuple3<>(label, comboBox1, comboBox2);
|
||||
@ -489,12 +488,48 @@ public class FormBuilder {
|
||||
|
||||
GridPane.setRowIndex(hBox, rowIndex);
|
||||
GridPane.setColumnIndex(hBox, 1);
|
||||
GridPane.setMargin(hBox, new Insets(15, 0, 0, 0));
|
||||
GridPane.setMargin(hBox, new Insets(top, 0, 0, 0));
|
||||
gridPane.getChildren().add(hBox);
|
||||
|
||||
return new Tuple3<>(label, comboBox, button);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Label + ComboBox + Label
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public static Tuple3<Label, ComboBox, TextField> addLabelComboBoxLabel(GridPane gridPane,
|
||||
int rowIndex,
|
||||
String title,
|
||||
String textFieldText) {
|
||||
return addLabelComboBoxLabel(gridPane, rowIndex, title, textFieldText, 0);
|
||||
}
|
||||
|
||||
public static Tuple3<Label, ComboBox, TextField> addLabelComboBoxLabel(GridPane gridPane,
|
||||
int rowIndex,
|
||||
String title,
|
||||
String textFieldText,
|
||||
double top) {
|
||||
Label label = addLabel(gridPane, rowIndex, title, top);
|
||||
|
||||
HBox hBox = new HBox();
|
||||
hBox.setSpacing(10);
|
||||
|
||||
ComboBox comboBox = new ComboBox();
|
||||
TextField textField = new TextField(textFieldText);
|
||||
textField.setEditable(false);
|
||||
textField.setMouseTransparent(true);
|
||||
textField.setFocusTraversable(false);
|
||||
|
||||
hBox.getChildren().addAll(comboBox, textField);
|
||||
GridPane.setRowIndex(hBox, rowIndex);
|
||||
GridPane.setColumnIndex(hBox, 1);
|
||||
GridPane.setMargin(hBox, new Insets(top, 0, 0, 0));
|
||||
gridPane.getChildren().add(hBox);
|
||||
|
||||
return new Tuple3<>(label, comboBox, textField);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Label + TxIdTextField
|
||||
|
Loading…
x
Reference in New Issue
Block a user