use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class OfferBookView method getActionColumn.
private TableColumn<OfferBookListItem, OfferBookListItem> getActionColumn() {
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(80);
setSortable(false);
}
};
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
final ImageView iconView = new ImageView();
final Button button = new AutoTooltipButton();
boolean isTradable, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit;
{
button.setGraphic(iconView);
button.setMinWidth(130);
button.setMaxWidth(130);
button.setGraphicTextGap(10);
}
@Override
public void updateItem(final OfferBookListItem newItem, boolean empty) {
super.updateItem(newItem, empty);
TableRow tableRow = getTableRow();
if (newItem != null && !empty) {
final Offer offer = newItem.getOffer();
boolean myOffer = model.isMyOffer(offer);
if (tableRow != null) {
isPaymentAccountValidForOffer = model.isAnyPaymentAccountValidForOffer(offer);
hasMatchingArbitrator = model.hasMatchingArbitrator(offer);
hasSameProtocolVersion = model.hasSameProtocolVersion(offer);
isIgnored = model.isIgnored(offer);
isOfferBanned = model.isOfferBanned(offer);
isCurrencyBanned = model.isCurrencyBanned(offer);
isPaymentMethodBanned = model.isPaymentMethodBanned(offer);
isNodeAddressBanned = model.isNodeAddressBanned(offer);
isInsufficientTradeLimit = model.isInsufficientTradeLimit(offer);
isTradable = isPaymentAccountValidForOffer && hasMatchingArbitrator && hasSameProtocolVersion && !isIgnored && !isOfferBanned && !isCurrencyBanned && !isPaymentMethodBanned && !isNodeAddressBanned && !isInsufficientTradeLimit;
tableRow.setOpacity(isTradable || myOffer ? 1 : 0.4);
if (isTradable) {
// set first row button as default
button.setDefaultButton(getIndex() == 0);
tableRow.setOnMousePressed(null);
} else {
button.setDefaultButton(false);
tableRow.setOnMousePressed(e -> {
// ugly hack to get the icon clickable when deactivated
if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas))
onShowInfo(offer, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit);
});
}
}
String title;
if (myOffer) {
iconView.setId("image-remove");
title = Res.get("shared.remove");
button.setId("cancel-button");
// does not take the font colors sometimes from the style
button.setStyle("-fx-text-fill: #444;");
button.setOnAction(e -> onRemoveOpenOffer(offer));
} else {
boolean isSellOffer = offer.getDirection() == OfferPayload.Direction.SELL;
iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
button.setId(isSellOffer ? "buy-button" : "sell-button");
// does not take the font colors sometimes from the style
button.setStyle("-fx-text-fill: white;");
title = Res.get("offerbook.takeOffer");
button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer))));
button.setOnAction(e -> onTakeOffer(offer));
}
if (!myOffer && !isTradable)
button.setOnAction(e -> onShowInfo(offer, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit));
button.setText(title);
setGraphic(button);
} else {
setGraphic(null);
if (button != null)
button.setOnAction(null);
if (tableRow != null) {
tableRow.setOpacity(1);
tableRow.setOnMousePressed(null);
}
}
}
};
}
});
return column;
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class OfferBookView method getPriceColumn.
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> getPriceColumn() {
AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(100);
}
};
column.getStyleClass().add("number-column");
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
private OfferBookListItem offerBookListItem;
private ChangeListener<Number> priceChangedListener;
ChangeListener<Scene> sceneChangeListener;
@Override
public void updateItem(final OfferBookListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (getTableView().getScene() != null && sceneChangeListener == null) {
sceneChangeListener = (observable, oldValue, newValue) -> {
if (newValue == null) {
if (priceChangedListener != null) {
model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
priceChangedListener = null;
}
offerBookListItem = null;
setGraphic(null);
getTableView().sceneProperty().removeListener(sceneChangeListener);
sceneChangeListener = null;
}
};
getTableView().sceneProperty().addListener(sceneChangeListener);
}
this.offerBookListItem = item;
if (priceChangedListener == null) {
priceChangedListener = (observable, oldValue, newValue) -> {
if (offerBookListItem != null && offerBookListItem.getOffer().getPrice() != null) {
setGraphic(getPriceLabel(model.getPrice(offerBookListItem), offerBookListItem));
}
};
model.priceFeedService.updateCounterProperty().addListener(priceChangedListener);
}
setGraphic(getPriceLabel(item.getOffer().getPrice() == null ? Res.get("shared.na") : model.getPrice(item), item));
} else {
if (priceChangedListener != null) {
model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
priceChangedListener = null;
}
if (sceneChangeListener != null) {
getTableView().sceneProperty().removeListener(sceneChangeListener);
sceneChangeListener = null;
}
this.offerBookListItem = null;
setGraphic(null);
}
}
@NotNull
private AutoTooltipLabel getPriceLabel(String priceString, OfferBookListItem item) {
final Offer offer = item.getOffer();
final MaterialDesignIcon icon = offer.isUseMarketBasedPrice() ? MaterialDesignIcon.CHART_LINE : MaterialDesignIcon.LOCK;
String info;
if (offer.isUseMarketBasedPrice()) {
if (offer.getMarketPriceMargin() == 0) {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAtMarketPrice");
} else {
info = Res.get("offerbook.info.buyAtMarketPrice");
}
} else if (offer.getMarketPriceMargin() > 0) {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellBelowMarketPrice", model.getAbsolutePriceMargin(offer));
} else {
info = Res.get("offerbook.info.buyAboveMarketPrice", model.getAbsolutePriceMargin(offer));
}
} else {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAboveMarketPrice", model.getAbsolutePriceMargin(offer));
} else {
info = Res.get("offerbook.info.buyBelowMarketPrice", model.getAbsolutePriceMargin(offer));
}
}
} else {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAtFixedPrice");
} else {
info = Res.get("offerbook.info.buyAtFixedPrice");
}
}
return new InfoAutoTooltipLabel(priceString, icon, ContentDisplay.RIGHT, info);
}
};
}
});
return column;
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class OfferBookViewModel method getPaymentMethod.
String getPaymentMethod(OfferBookListItem item) {
String result = "";
if (item != null) {
Offer offer = item.getOffer();
String method = Res.get(offer.getPaymentMethod().getId() + "_SHORT");
String methodCountryCode = offer.getCountryCode();
if (methodCountryCode != null)
result = method + " (" + methodCountryCode + ")";
else
result = method;
}
return result;
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class OfferBookViewModel method getPrice.
String getPrice(OfferBookListItem item) {
if ((item == null))
return "";
final Offer offer = item.getOffer();
final Price price = offer.getPrice();
if (price != null) {
return formatPrice(offer, true) + formatMarketPriceMargin(offer, true);
} else {
return Res.get("shared.na");
}
}
use of bisq.core.offer.Offer in project bisq-desktop by bisq-network.
the class OfferBookViewModel method getPaymentMethodToolTip.
String getPaymentMethodToolTip(OfferBookListItem item) {
String result = "";
if (item != null) {
Offer offer = item.getOffer();
result = Res.getWithCol("shared.paymentMethod") + " " + Res.get(offer.getPaymentMethod().getId());
result += "\n" + Res.getWithCol("shared.currency") + " " + CurrencyUtil.getNameAndCode(offer.getCurrencyCode());
String methodCountryCode = offer.getCountryCode();
if (methodCountryCode != null) {
String bankId = offer.getBankId();
if (bankId != null && !bankId.equals("null")) {
if (BankUtil.isBankIdRequired(methodCountryCode))
result += "\n" + Res.get("offerbook.offerersBankId", bankId);
else if (BankUtil.isBankNameRequired(methodCountryCode))
result += "\n" + Res.get("offerbook.offerersBankName", bankId);
}
}
if (methodCountryCode != null)
result += "\n" + Res.get("offerbook.offerersBankSeat", CountryUtil.getNameByCode(methodCountryCode));
List<String> acceptedCountryCodes = offer.getAcceptedCountryCodes();
List<String> acceptedBanks = offer.getAcceptedBankIds();
if (acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty()) {
if (CountryUtil.containsAllSepaEuroCountries(acceptedCountryCodes))
result += "\n" + Res.get("offerbook.offerersAcceptedBankSeatsEuro");
else
result += "\n" + Res.get("offerbook.offerersAcceptedBankSeats", CountryUtil.getNamesByCodesString(acceptedCountryCodes));
} else if (acceptedBanks != null && !acceptedBanks.isEmpty()) {
if (offer.getPaymentMethod().equals(PaymentMethod.SAME_BANK))
result += "\n" + Res.getWithCol("shared.bankName") + " " + acceptedBanks.get(0);
else if (offer.getPaymentMethod().equals(PaymentMethod.SPECIFIC_BANKS))
result += "\n" + Res.getWithCol("shared.acceptedBanks") + " " + Joiner.on(", ").join(acceptedBanks);
}
}
return result;
}
Aggregations