Merge pull request #4193 from jmacxx/add_paymentmethod_openoffers

Display "Payment Method" column in Open Offers view
This commit is contained in:
sqrrm 2020-06-04 12:32:06 +02:00 committed by GitHub
commit 1a62f6b8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 15 deletions

View File

@ -365,6 +365,14 @@ public class Offer implements NetworkPayload, PersistablePayload {
return "";
}
public String getPaymentMethodNameWithCountryCode() {
String method = this.getPaymentMethod().getShortName();
String methodCountryCode = this.getCountryCode();
if (methodCountryCode != null)
method = method + " (" + methodCountryCode + ")";
return method;
}
// domain properties
public Offer.State getState() {
return stateProperty.get();

View File

@ -313,6 +313,12 @@ public final class PaymentMethod implements PersistablePayload, Comparable<Payme
return Coin.valueOf(tradeLimits.getRoundedRiskBasedTradeLimit(maxTradeLimit, riskFactor));
}
public String getShortName() {
// in cases where translation is not found, Res.get() simply returns the key string
// so no need for special error-handling code.
return Res.get(this.id + "_SHORT");
}
@Override
public int compareTo(@NotNull PaymentMethod other) {
return id.compareTo(other.id);

View File

@ -31,14 +31,15 @@
<columns>
<TableColumn fx:id="offerIdColumn" minWidth="110" maxWidth="130"/>
<TableColumn fx:id="dateColumn" minWidth="180"/>
<TableColumn fx:id="marketColumn" minWidth="90"/>
<TableColumn fx:id="priceColumn" minWidth="150"/>
<TableColumn fx:id="amountColumn" minWidth="150"/>
<TableColumn fx:id="volumeColumn" minWidth="170"/>
<TableColumn fx:id="marketColumn" minWidth="75"/>
<TableColumn fx:id="priceColumn" minWidth="110"/>
<TableColumn fx:id="amountColumn" minWidth="100"/>
<TableColumn fx:id="volumeColumn" minWidth="150"/>
<TableColumn fx:id="paymentMethodColumn" minWidth="120" maxWidth="170"/>
<TableColumn fx:id="directionColumn" minWidth="80"/>
<TableColumn fx:id="deactivateItemColumn" minWidth="100" maxWidth="100" sortable="false"/>
<TableColumn fx:id="editItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="removeItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="deactivateItemColumn" minWidth="60" maxWidth="60" sortable="false"/>
<TableColumn fx:id="editItemColumn" minWidth="50" maxWidth="60" sortable="false"/>
<TableColumn fx:id="removeItemColumn" minWidth="50" maxWidth="60" sortable="false"/>
</columns>
</TableView>

View File

@ -69,7 +69,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
@FXML
TableColumn<OpenOfferListItem, OpenOfferListItem> priceColumn, amountColumn, volumeColumn,
marketColumn, directionColumn, dateColumn, offerIdColumn, deactivateItemColumn,
removeItemColumn, editItemColumn;
removeItemColumn, editItemColumn, paymentMethodColumn;
private final Navigation navigation;
private final OfferDetailsWindow offerDetailsWindow;
private SortedList<OpenOfferListItem> sortedList;
@ -84,6 +84,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
@Override
public void initialize() {
paymentMethodColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.paymentMethod")));
priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.BTCMinMax")));
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountMinMax")));
@ -101,6 +102,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
setPriceColumnCellFactory();
setAmountColumnCellFactory();
setVolumeColumnCellFactory();
setPaymentMethodColumnCellFactory();
setDateColumnCellFactory();
setDeactivateColumnCellFactory();
setEditColumnCellFactory();
@ -116,6 +118,7 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
priceColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPrice(), Comparator.nullsFirst(Comparator.naturalOrder())));
volumeColumn.setComparator(Comparator.comparing(o -> o.getOffer().getVolume(), Comparator.nullsFirst(Comparator.naturalOrder())));
dateColumn.setComparator(Comparator.comparing(o -> o.getOffer().getDate()));
paymentMethodColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPaymentMethod().getId()));
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
@ -330,6 +333,31 @@ public class OpenOffersView extends ActivatableViewAndModel<VBox, OpenOffersView
});
}
private void setPaymentMethodColumnCellFactory() {
paymentMethodColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
paymentMethodColumn.setCellFactory(
new Callback<>() {
@Override
public TableCell<OpenOfferListItem, OpenOfferListItem> call(
TableColumn<OpenOfferListItem, OpenOfferListItem> column) {
return new TableCell<>() {
@Override
public void updateItem(final OpenOfferListItem item, boolean empty) {
super.updateItem(item, empty);
getStyleClass().removeAll("offer-disabled");
if (item != null) {
if (model.isDeactivated(item)) getStyleClass().add("offer-disabled");
setGraphic(new AutoTooltipLabel(model.getPaymentMethod(item)));
} else {
setGraphic(null);
}
}
};
}
});
}
private void setDirectionColumnCellFactory() {
directionColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
directionColumn.setCellFactory(

View File

@ -42,6 +42,8 @@ import javax.inject.Named;
import javafx.collections.ObservableList;
import static com.google.common.base.Preconditions.checkNotNull;
class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel> implements ViewModel {
private final P2PService p2PService;
private final CoinFormatter btcFormatter;
@ -118,6 +120,17 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
return CurrencyUtil.getCurrencyPair(item.getOffer().getCurrencyCode());
}
String getPaymentMethod(OpenOfferListItem item) {
String result = "";
if (item != null) {
Offer offer = item.getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
result = offer.getPaymentMethodNameWithCountryCode();
}
return result;
}
String getDate(OpenOfferListItem item) {
return DisplayUtils.formatDateTime(item.getOffer().getDate());
}

View File

@ -276,13 +276,7 @@ public class PendingTradesViewModel extends ActivatableWithDataModel<PendingTrad
Offer offer = item.getTrade().getOffer();
checkNotNull(offer);
checkNotNull(offer.getPaymentMethod());
String method = Res.get(offer.getPaymentMethod().getId() + "_SHORT");
String methodCountryCode = offer.getCountryCode();
if (methodCountryCode != null)
result = method + " (" + methodCountryCode + ")";
else
result = method;
result = offer.getPaymentMethodNameWithCountryCode();
}
return result;
}