diff --git a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java index d3aa540a92..7ac38077f2 100644 --- a/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java +++ b/gui/src/main/java/io/bitsquare/gui/components/paymentmethods/SepaForm.java @@ -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 tuple2 = addLabelComboBox(gridPane, ++gridRow, "Country of your Bank:"); - ComboBox countryComboBox = tuple2.second; + Tuple3 tuple3 = addLabelComboBoxLabel(gridPane, ++gridRow, "Country of your Bank:", ""); + ComboBox countryComboBox = tuple3.second; + currencyTextField = tuple3.third; + currencyTextField.setMinWidth(300); countryComboBox.setPromptText("Select country of your Bank"); countryComboBox.setConverter(new StringConverter() { @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); } } diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/AccountView.java b/gui/src/main/java/io/bitsquare/gui/main/account/AccountView.java index cd34cf0b27..227e80e74f 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/AccountView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/account/AccountView.java @@ -64,7 +64,6 @@ public class AccountView extends ActivatableView { @Override public void initialize() { - navigationListener = viewPath -> { if (viewPath.size() == 3 && viewPath.indexOf(AccountView.class) == 1) { if (arbitratorRegistrationTab == null && viewPath.get(2).equals(ArbitratorRegistrationView.class)) diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.fxml b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.fxml index 63f11d6f05..7141349379 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.fxml +++ b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.fxml @@ -25,7 +25,7 @@ AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="-10.0" xmlns:fx="http://javafx.com/fxml"> - + diff --git a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java index 699189f424..4bc7777efb 100644 --- a/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java +++ b/gui/src/main/java/io/bitsquare/gui/main/account/content/paymentsaccount/PaymentAccountView.java @@ -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 implements Wizard.Step { +public class PaymentAccountView extends ActivatableViewAndModel { - private ComboBox paymentAccountsComboBox; + private ListView paymentAccountsListView; private ComboBox 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 paymentAccountListChangeListener; + private ChangeListener paymentAccountChangeListener; @Inject public PaymentAccountView(PaymentAccountViewModel model, @@ -91,37 +90,24 @@ public class PaymentAccountView extends ActivatableViewAndModel 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 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 { model.onDeleteAccount(paymentAccount); removeSelectAccountForm(); - paymentAccountsComboBox.getSelectionModel().clearSelection(); }) .show(); } @@ -166,17 +149,37 @@ public class PaymentAccountView extends ActivatableViewAndModel() { + Tuple2 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, ListCell>() { @Override - public String toString(PaymentAccount paymentAccount) { - return paymentAccount.getAccountName(); - } + public ListCell call(ListView list) { + return new ListCell() { + 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 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 getSelectedViewClass() { diff --git a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java index 9a806bea5c..5559d2b69e 100644 --- a/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java +++ b/gui/src/main/java/io/bitsquare/gui/util/FormBuilder.java @@ -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 addLabelComboBoxLabel(GridPane gridPane, + int rowIndex, + String title, + String textFieldText) { + return addLabelComboBoxLabel(gridPane, rowIndex, title, textFieldText, 0); + } + + public static Tuple3 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