Skip to content

Commit

Permalink
Merge pull request #1610 from ManfredKarrer/refact-generics
Browse files Browse the repository at this point in the history
Refact generics
  • Loading branch information
ManfredKarrer authored Jul 26, 2018
2 parents 5c4f06c + d841a93 commit 1755388
Show file tree
Hide file tree
Showing 53 changed files with 607 additions and 927 deletions.
11 changes: 6 additions & 5 deletions src/main/java/bisq/desktop/Navigation.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -78,20 +79,20 @@ public void readPersisted() {
//noinspection unchecked
return ((Class<? extends View>) Class.forName(className));
} catch (ClassNotFoundException e) {
log.warn("Could not find the Viewpath class {}; exception: {}", className, e);
log.warn("Could not find the viewPath class {}; exception: {}", className, e);
}
return null;
})
.filter(e -> e != null)
.filter(Objects::nonNull)
.collect(Collectors.toList());

if (!viewClasses.isEmpty())
previousPath = new ViewPath(viewClasses);
}
}

@SuppressWarnings("unchecked")
public void navigateTo(Class<? extends View>... viewClasses) {
@SafeVarargs
public final void navigateTo(Class<? extends View>... viewClasses) {
navigateTo(ViewPath.to(viewClasses));
}

Expand Down Expand Up @@ -123,7 +124,7 @@ public void navigateTo(ViewPath newPath) {
currentPath = newPath;
previousPath = currentPath;
queueUpForSave();
listeners.stream().forEach((e) -> e.onNavigationRequested(currentPath));
listeners.forEach((e) -> e.onNavigationRequested(currentPath));
}

private void queueUpForSave() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/bisq/desktop/components/MenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public MenuItem(Navigation navigation,
}

public void activate() {
//noinspection unchecked
setOnAction((event) -> navigation.navigateTo(getNavPathClasses()));
selectedProperty().addListener(selectedPropertyChangeListener);
disableProperty().addListener(disablePropertyChangeListener);
Expand All @@ -105,6 +104,7 @@ public void activate() {
private Class<? extends View>[] getNavPathClasses() {
List<Class<? extends View>> list = new ArrayList<>(baseNavPath);
list.add(viewClass);
//noinspection unchecked
Class<? extends View>[] array = new Class[list.size()];
list.toArray(array);
return array;
Expand Down
355 changes: 147 additions & 208 deletions src/main/java/bisq/desktop/components/paymentmethods/BankForm.java

Large diffs are not rendered by default.

351 changes: 146 additions & 205 deletions src/main/java/bisq/desktop/components/paymentmethods/CashDepositForm.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.Layout;

import bisq.core.locale.CurrencyUtil;
Expand Down Expand Up @@ -51,7 +52,6 @@
import org.slf4j.LoggerFactory;

import static bisq.desktop.util.FormBuilder.addLabelInputTextField;
import static bisq.desktop.util.FormBuilder.addLabelSearchComboBox;
import static bisq.desktop.util.FormBuilder.addLabelTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextFieldWithCopyIcon;

Expand Down Expand Up @@ -159,8 +159,7 @@ public void updateAllInputsValid() {

@Override
protected void addTradeCurrencyComboBox() {
//noinspection unchecked
currencyComboBox = addLabelSearchComboBox(gridPane, ++gridRow, Res.get("payment.altcoin"),
currencyComboBox = FormBuilder.<TradeCurrency>addLabelSearchComboBox(gridPane, ++gridRow, Res.get("payment.altcoin"),
Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
currencyComboBox.setPromptText(Res.get("payment.select.altcoin"));
currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedCryptoCurrencies()));
Expand All @@ -176,10 +175,7 @@ public TradeCurrency fromString(String s) {
Optional<TradeCurrency> tradeCurrencyOptional = currencyComboBox.getItems().stream().
filter(tradeCurrency -> tradeCurrency.getNameAndCode().equals(s)).
findAny();
if (tradeCurrencyOptional.isPresent())
return tradeCurrencyOptional.get();
else
return null;
return tradeCurrencyOptional.orElse(null);
}
});
currencyComboBox.setOnAction(e -> {
Expand Down
143 changes: 43 additions & 100 deletions src/main/java/bisq/desktop/components/paymentmethods/F2FForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import bisq.desktop.components.InputTextField;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.GUIUtil;
import bisq.desktop.util.Layout;
import bisq.desktop.util.validation.F2FValidator;

import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.Region;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.Offer;
Expand All @@ -39,26 +39,24 @@
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;

import bisq.common.util.Tuple3;
import bisq.common.util.Tuple2;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;

import javafx.collections.FXCollections;

import javafx.util.StringConverter;

import static bisq.desktop.util.FormBuilder.*;
import static bisq.desktop.util.FormBuilder.addLabelInputTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextArea;
import static bisq.desktop.util.FormBuilder.addLabelTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextFieldWithCopyIcon;

public class F2FForm extends PaymentMethodForm {
private final F2FAccount f2fAccount;
private final F2FValidator f2fValidator;
private TextArea extraTextArea;
private InputTextField cityInputTextField;
private Country selectedCountry;

public static int addFormForBuyer(GridPane gridPane, int gridRow,
PaymentAccountPayload paymentAccountPayload, Offer offer) {
Expand Down Expand Up @@ -91,96 +89,9 @@ public F2FForm(PaymentAccount paymentAccount,
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;

Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));

//noinspection unchecked,unchecked,unchecked
ComboBox<Region> regionComboBox = tuple3.second;
regionComboBox.setPromptText(Res.get("payment.select.region"));
regionComboBox.setConverter(new StringConverter<Region>() {
@Override
public String toString(Region region) {
return region.name;
}

@Override
public Region fromString(String s) {
return null;
}
});
regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));

//noinspection unchecked,unchecked,unchecked
ComboBox<Country> countryComboBox = tuple3.third;
countryComboBox.setVisibleRowCount(15);
countryComboBox.setDisable(true);
countryComboBox.setPromptText(Res.get("payment.select.country"));
countryComboBox.setConverter(new StringConverter<Country>() {
@Override
public String toString(Country country) {
return country.name + " (" + country.code + ")";
}

@Override
public Country fromString(String s) {
return null;
}
});
countryComboBox.setOnAction(e -> {
Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
getCountryBasedPaymentAccount().setCountry(selectedItem);
String countryCode = selectedItem.code;
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
paymentAccount.setSingleTradeCurrency(currency);
currencyComboBox.setDisable(false);
currencyComboBox.getSelectionModel().select(currency);

updateFromInputs();
}
});

regionComboBox.setOnAction(e -> {
Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
countryComboBox.setDisable(false);
countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
}
});

//noinspection unchecked
currencyComboBox = addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
currencyComboBox.setPromptText(Res.get("list.currency.select"));
currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
currencyComboBox.setOnAction(e -> {
TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
if (!defaultCurrency.equals(selectedItem)) {
new Popup<>().warning(Res.get("payment.foreign.currency"))
.actionButtonText(Res.get("shared.yes"))
.onAction(() -> {
paymentAccount.setSingleTradeCurrency(selectedItem);
autoFillNameTextField();
})
.closeButtonText(Res.get("payment.restore.default"))
.onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency))
.show();
} else {
paymentAccount.setSingleTradeCurrency(selectedItem);
autoFillNameTextField();
}
});
currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
@Override
public String toString(TradeCurrency currency) {
return currency.getNameAndCode();
}

@Override
public TradeCurrency fromString(String string) {
return null;
}
});
currencyComboBox.setDisable(true);
Tuple2<ComboBox<TradeCurrency>, Integer> tuple = GUIUtil.addRegionCountryTradeCurrencyComboBoxes(gridPane, gridRow, this::onCountrySelected, this::onTradeCurrencySelected);
currencyComboBox = tuple.first;
gridRow = tuple.second;

InputTextField contactInputTextField = addLabelInputTextField(gridPane, ++gridRow,
Res.getWithCol("payment.f2f.contact")).second;
Expand All @@ -200,7 +111,7 @@ public TradeCurrency fromString(String string) {
updateFromInputs();
});

extraTextArea = addLabelTextArea(gridPane, ++gridRow,
TextArea extraTextArea = addLabelTextArea(gridPane, ++gridRow,
Res.getWithCol("payment.f2f.optionalExtra"), "").second;
extraTextArea.setPromptText(Res.get("payment.f2f.extra.prompt"));
extraTextArea.setPrefHeight(60);
Expand All @@ -214,6 +125,38 @@ public TradeCurrency fromString(String string) {
addAccountNameTextFieldWithAutoFillCheckBox();
}

private void onCountrySelected(Country country) {
selectedCountry = country;
if (selectedCountry != null) {
getCountryBasedPaymentAccount().setCountry(selectedCountry);
String countryCode = selectedCountry.code;
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
paymentAccount.setSingleTradeCurrency(currency);
currencyComboBox.setDisable(false);
currencyComboBox.getSelectionModel().select(currency);

updateFromInputs();
}
}

private void onTradeCurrencySelected(TradeCurrency tradeCurrency) {
FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(selectedCountry.code);
if (!defaultCurrency.equals(tradeCurrency)) {
new Popup<>().warning(Res.get("payment.foreign.currency"))
.actionButtonText(Res.get("shared.yes"))
.onAction(() -> {
paymentAccount.setSingleTradeCurrency(tradeCurrency);
autoFillNameTextField();
})
.closeButtonText(Res.get("payment.restore.default"))
.onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency))
.show();
} else {
paymentAccount.setSingleTradeCurrency(tradeCurrency);
autoFillNameTextField();
}
}

@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
Expand Down
Loading

0 comments on commit 1755388

Please sign in to comment.