mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Refactor of FilterWindow - eliminate duplicates (#3616)
* Extract setupFieldFromList method in FilterWindow * Extract readAsPaymentAccountFiltersList method in FilterWindow * Extract setupFieldFromPaymentAccountFiltersList method in FilterWindow * Reformat sendButton handler in FilterWindow
This commit is contained in:
commit
95257b10f9
@ -148,70 +148,29 @@ public class FilterWindow extends Overlay<FilterWindow> {
|
|||||||
|
|
||||||
final Filter filter = filterManager.getDevelopersFilter();
|
final Filter filter = filterManager.getDevelopersFilter();
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
offerIdsInputTextField.setText(filter.getBannedOfferIds().stream().collect(Collectors.joining(", ")));
|
setupFieldFromList(offerIdsInputTextField, filter.getBannedOfferIds());
|
||||||
nodesInputTextField.setText(filter.getBannedNodeAddress().stream().collect(Collectors.joining(", ")));
|
setupFieldFromList(nodesInputTextField, filter.getBannedNodeAddress());
|
||||||
if (filter.getBannedPaymentAccounts() != null) {
|
setupFieldFromPaymentAccountFiltersList(paymentAccountFilterInputTextField, filter.getBannedPaymentAccounts());
|
||||||
StringBuilder sb = new StringBuilder();
|
setupFieldFromList(bannedCurrenciesInputTextField, filter.getBannedCurrencies());
|
||||||
filter.getBannedPaymentAccounts().stream().forEach(e -> {
|
setupFieldFromList(bannedPaymentMethodsInputTextField, filter.getBannedPaymentMethods());
|
||||||
if (e != null && e.getPaymentMethodId() != null) {
|
setupFieldFromList(arbitratorsInputTextField, filter.getArbitrators());
|
||||||
sb.append(e.getPaymentMethodId())
|
setupFieldFromList(mediatorsInputTextField, filter.getMediators());
|
||||||
.append("|")
|
setupFieldFromList(refundAgentsInputTextField, filter.getRefundAgents());
|
||||||
.append(e.getGetMethodName())
|
setupFieldFromList(seedNodesInputTextField, filter.getSeedNodes());
|
||||||
.append("|")
|
setupFieldFromList(priceRelayNodesInputTextField, filter.getPriceRelayNodes());
|
||||||
.append(e.getValue())
|
setupFieldFromList(btcNodesInputTextField, filter.getBtcNodes());
|
||||||
.append(", ");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
paymentAccountFilterInputTextField.setText(sb.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.getBannedCurrencies() != null)
|
|
||||||
bannedCurrenciesInputTextField.setText(filter.getBannedCurrencies().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getBannedPaymentMethods() != null)
|
|
||||||
bannedPaymentMethodsInputTextField.setText(filter.getBannedPaymentMethods().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getArbitrators() != null)
|
|
||||||
arbitratorsInputTextField.setText(filter.getArbitrators().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getMediators() != null)
|
|
||||||
mediatorsInputTextField.setText(filter.getMediators().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getRefundAgents() != null)
|
|
||||||
refundAgentsInputTextField.setText(filter.getRefundAgents().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getSeedNodes() != null)
|
|
||||||
seedNodesInputTextField.setText(filter.getSeedNodes().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getPriceRelayNodes() != null)
|
|
||||||
priceRelayNodesInputTextField.setText(filter.getPriceRelayNodes().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
if (filter.getBtcNodes() != null)
|
|
||||||
btcNodesInputTextField.setText(filter.getBtcNodes().stream().collect(Collectors.joining(", ")));
|
|
||||||
|
|
||||||
preventPublicBtcNetworkCheckBox.setSelected(filter.isPreventPublicBtcNetwork());
|
preventPublicBtcNetworkCheckBox.setSelected(filter.isPreventPublicBtcNetwork());
|
||||||
|
|
||||||
disableDaoCheckBox.setSelected(filter.isDisableDao());
|
disableDaoCheckBox.setSelected(filter.isDisableDao());
|
||||||
disableDaoBelowVersionInputTextField.setText(filter.getDisableDaoBelowVersion());
|
disableDaoBelowVersionInputTextField.setText(filter.getDisableDaoBelowVersion());
|
||||||
disableTradeBelowVersionInputTextField.setText(filter.getDisableTradeBelowVersion());
|
disableTradeBelowVersionInputTextField.setText(filter.getDisableTradeBelowVersion());
|
||||||
}
|
}
|
||||||
Button sendButton = new AutoTooltipButton(Res.get("filterWindow.add"));
|
Button sendButton = new AutoTooltipButton(Res.get("filterWindow.add"));
|
||||||
sendButton.setOnAction(e -> {
|
sendButton.setOnAction(e -> {
|
||||||
List<PaymentAccountFilter> paymentAccountFilters = readAsList(paymentAccountFilterInputTextField)
|
if (sendFilterMessageHandler.handle(
|
||||||
.stream().map(item -> {
|
new Filter(
|
||||||
String[] list = item.split("\\|");
|
|
||||||
if (list.length == 3)
|
|
||||||
return new PaymentAccountFilter(list[0], list[1], list[2]);
|
|
||||||
else
|
|
||||||
return new PaymentAccountFilter("", "", "");
|
|
||||||
})
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
|
|
||||||
if (sendFilterMessageHandler.handle(new Filter(
|
|
||||||
readAsList(offerIdsInputTextField),
|
readAsList(offerIdsInputTextField),
|
||||||
readAsList(nodesInputTextField),
|
readAsList(nodesInputTextField),
|
||||||
paymentAccountFilters,
|
readAsPaymentAccountFiltersList(paymentAccountFilterInputTextField),
|
||||||
readAsList(bannedCurrenciesInputTextField),
|
readAsList(bannedCurrenciesInputTextField),
|
||||||
readAsList(bannedPaymentMethodsInputTextField),
|
readAsList(bannedPaymentMethodsInputTextField),
|
||||||
readAsList(arbitratorsInputTextField),
|
readAsList(arbitratorsInputTextField),
|
||||||
@ -223,8 +182,10 @@ public class FilterWindow extends Overlay<FilterWindow> {
|
|||||||
disableDaoBelowVersionInputTextField.getText(),
|
disableDaoBelowVersionInputTextField.getText(),
|
||||||
disableTradeBelowVersionInputTextField.getText(),
|
disableTradeBelowVersionInputTextField.getText(),
|
||||||
readAsList(mediatorsInputTextField),
|
readAsList(mediatorsInputTextField),
|
||||||
readAsList(refundAgentsInputTextField)),
|
readAsList(refundAgentsInputTextField)
|
||||||
keyInputTextField.getText()))
|
),
|
||||||
|
keyInputTextField.getText())
|
||||||
|
)
|
||||||
hide();
|
hide();
|
||||||
else
|
else
|
||||||
new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
|
new Popup<>().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
|
||||||
@ -254,6 +215,29 @@ public class FilterWindow extends Overlay<FilterWindow> {
|
|||||||
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
|
GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupFieldFromList(InputTextField field, List<String> values) {
|
||||||
|
if (values != null)
|
||||||
|
field.setText(values.stream().collect(Collectors.joining(", ")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupFieldFromPaymentAccountFiltersList(InputTextField field, List<PaymentAccountFilter> values) {
|
||||||
|
if (values != null) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
values.stream().forEach(e -> {
|
||||||
|
if (e != null && e.getPaymentMethodId() != null) {
|
||||||
|
sb
|
||||||
|
.append(e.getPaymentMethodId())
|
||||||
|
.append("|")
|
||||||
|
.append(e.getGetMethodName())
|
||||||
|
.append("|")
|
||||||
|
.append(e.getValue())
|
||||||
|
.append(", ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
field.setText(sb.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> readAsList(InputTextField field) {
|
private List<String> readAsList(InputTextField field) {
|
||||||
if (field.getText().isEmpty()) {
|
if (field.getText().isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@ -261,4 +245,16 @@ public class FilterWindow extends Overlay<FilterWindow> {
|
|||||||
return Arrays.asList(StringUtils.deleteWhitespace(field.getText()).split(","));
|
return Arrays.asList(StringUtils.deleteWhitespace(field.getText()).split(","));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<PaymentAccountFilter> readAsPaymentAccountFiltersList(InputTextField field) {
|
||||||
|
return readAsList(field)
|
||||||
|
.stream().map(item -> {
|
||||||
|
String[] list = item.split("\\|");
|
||||||
|
if (list.length == 3)
|
||||||
|
return new PaymentAccountFilter(list[0], list[1], list[2]);
|
||||||
|
else
|
||||||
|
return new PaymentAccountFilter("", "", "");
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user