use of io.bitsquare.trade.statistics.TradeStatistics in project bitsquare by bitsquare.
the class TradesChartsView method createTable.
///////////////////////////////////////////////////////////////////////////////////////////
// Table
///////////////////////////////////////////////////////////////////////////////////////////
private void createTable() {
tableView = new TableView<>();
tableView.setMinHeight(140);
tableView.setPrefHeight(140);
VBox.setVgrow(tableView, Priority.ALWAYS);
// date
TableColumn<TradeStatistics, TradeStatistics> dateColumn = new TableColumn<TradeStatistics, TradeStatistics>("Date/Time") {
{
setMinWidth(190);
setMaxWidth(190);
}
};
dateColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
dateColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(formatter.formatDateTime(item.getTradeDate()));
else
setText("");
}
};
}
});
dateColumn.setComparator((o1, o2) -> o1.getTradeDate().compareTo(o2.getTradeDate()));
tableView.getColumns().add(dateColumn);
// market
marketColumn = new TableColumn<TradeStatistics, TradeStatistics>("Market") {
{
setMinWidth(130);
setMaxWidth(130);
}
};
marketColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
marketColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(formatter.getCurrencyPair(item.currency));
else
setText("");
}
};
}
});
marketColumn.setComparator((o1, o2) -> o1.getTradeDate().compareTo(o2.getTradeDate()));
tableView.getColumns().add(marketColumn);
// price
priceColumn = new TableColumn<>();
priceColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
priceColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(formatter.formatPrice(item.getTradePrice()));
else
setText("");
}
};
}
});
priceColumn.setComparator((o1, o2) -> o1.getTradePrice().compareTo(o2.getTradePrice()));
tableView.getColumns().add(priceColumn);
// amount
TableColumn<TradeStatistics, TradeStatistics> amountColumn = new TableColumn<>("Amount in BTC");
amountColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
amountColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(formatter.formatCoinWithCode(item.getTradeAmount()));
else
setText("");
}
};
}
});
amountColumn.setComparator((o1, o2) -> o1.getTradeAmount().compareTo(o2.getTradeAmount()));
tableView.getColumns().add(amountColumn);
// volume
volumeColumn = new TableColumn<>();
volumeColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
volumeColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(model.showAllTradeCurrenciesProperty.get() ? formatter.formatVolumeWithCode(item.getTradeVolume()) : formatter.formatVolume(item.getTradeVolume()));
else
setText("");
}
};
}
});
volumeColumn.setComparator((o1, o2) -> {
final Fiat tradeVolume1 = o1.getTradeVolume();
final Fiat tradeVolume2 = o2.getTradeVolume();
return tradeVolume1 != null && tradeVolume2 != null ? tradeVolume1.compareTo(tradeVolume2) : 0;
});
tableView.getColumns().add(volumeColumn);
// paymentMethod
TableColumn<TradeStatistics, TradeStatistics> paymentMethodColumn = new TableColumn<>("Payment method");
paymentMethodColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
paymentMethodColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(getPaymentMethodLabel(item));
else
setText("");
}
};
}
});
paymentMethodColumn.setComparator((o1, o2) -> getPaymentMethodLabel(o1).compareTo(getPaymentMethodLabel(o2)));
tableView.getColumns().add(paymentMethodColumn);
// direction
TableColumn<TradeStatistics, TradeStatistics> directionColumn = new TableColumn<>("Trade type");
directionColumn.setCellValueFactory((tradeStatistics) -> new ReadOnlyObjectWrapper<>(tradeStatistics.getValue()));
directionColumn.setCellFactory(new Callback<TableColumn<TradeStatistics, TradeStatistics>, TableCell<TradeStatistics, TradeStatistics>>() {
@Override
public TableCell<TradeStatistics, TradeStatistics> call(TableColumn<TradeStatistics, TradeStatistics> column) {
return new TableCell<TradeStatistics, TradeStatistics>() {
@Override
public void updateItem(final TradeStatistics item, boolean empty) {
super.updateItem(item, empty);
if (item != null)
setText(getDirectionLabel(item));
else
setText("");
}
};
}
});
directionColumn.setComparator((o1, o2) -> getDirectionLabel(o1).compareTo(getDirectionLabel(o2)));
tableView.getColumns().add(directionColumn);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Label placeholder = new Label("There is no data available");
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
dateColumn.setSortType(TableColumn.SortType.DESCENDING);
tableView.getSortOrder().add(dateColumn);
}
Aggregations