Extract StringConverter for paymentAccountComboBox to GUIUtils. Handle multicurrency accounts.

This commit is contained in:
Manfred Karrer 2018-02-13 15:32:22 -05:00
parent e6001b17da
commit 6a3206543d
No known key found for this signature in database
GPG Key ID: 401250966A6B2C46
3 changed files with 23 additions and 30 deletions

View File

@ -160,20 +160,7 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
balanceTextField.setFormatter(model.getBtcFormatter());
paymentAccountsComboBox.setConverter(new StringConverter<PaymentAccount>() {
@Override
public String toString(PaymentAccount paymentAccount) {
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
String code = singleTradeCurrency != null ? singleTradeCurrency.getCode() : "";
return paymentAccount.getAccountName() + " (" + code + ", " +
Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
}
@Override
public PaymentAccount fromString(String s) {
return null;
}
});
paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter());
}
@Override

View File

@ -22,7 +22,6 @@ import de.jensd.fx.fontawesome.AwesomeIcon;
import io.bisq.common.UserThread;
import io.bisq.common.app.DevEnv;
import io.bisq.common.locale.Res;
import io.bisq.common.locale.TradeCurrency;
import io.bisq.common.util.Tuple2;
import io.bisq.common.util.Tuple3;
import io.bisq.common.util.Utilities;
@ -62,7 +61,6 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.text.Font;
import javafx.stage.Window;
import javafx.util.StringConverter;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
import org.bitcoinj.core.Coin;
@ -672,20 +670,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
//noinspection unchecked
paymentAccountsComboBox = tuple.second;
paymentAccountsComboBox.setPromptText(Res.get("shared.selectTradingAccount"));
paymentAccountsComboBox.setConverter(new StringConverter<PaymentAccount>() {
@Override
public String toString(PaymentAccount paymentAccount) {
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
String code = singleTradeCurrency != null ? singleTradeCurrency.getCode() : "";
return paymentAccount.getAccountName() + " (" + code + ", " +
Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
}
@Override
public PaymentAccount fromString(String s) {
return null;
}
});
paymentAccountsComboBox.setConverter(GUIUtil.getPaymentAccountsComboBoxStringConverter());
paymentAccountsComboBox.setVisible(false);
paymentAccountsComboBox.setManaged(false);
paymentAccountsComboBox.setOnAction(e -> {

View File

@ -484,4 +484,25 @@ public class GUIUtil {
.show();
}));
}
public static StringConverter<PaymentAccount> getPaymentAccountsComboBoxStringConverter() {
return new StringConverter<PaymentAccount>() {
@Override
public String toString(PaymentAccount paymentAccount) {
if (paymentAccount.hasMultipleCurrencies()) {
return paymentAccount.getAccountName() + " (" + Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
} else {
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
String prefix = singleTradeCurrency != null ? singleTradeCurrency.getCode() + ", " : "";
return paymentAccount.getAccountName() + " (" + prefix +
Res.get(paymentAccount.getPaymentMethod().getId()) + ")";
}
}
@Override
public PaymentAccount fromString(String s) {
return null;
}
};
}
}