use of bisq.desktop.components.InfoAutoTooltipLabel 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;
}
Aggregations