Search in sources :

Example 6 with TableView

use of javafx.scene.control.TableView in project bisq-desktop by bisq-network.

the class MyVotesView method createVoteColumns.

// /////////////////////////////////////////////////////////////////////////////////////////
// TableColumns
// /////////////////////////////////////////////////////////////////////////////////////////
private void createVoteColumns(TableView<VoteListItem> tableView) {
    TableColumn<VoteListItem, VoteListItem> dateColumn = new AutoTooltipTableColumn<VoteListItem, VoteListItem>(Res.get("shared.dateTime")) {

        {
            setMinWidth(190);
            setMaxWidth(190);
        }
    };
    dateColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    dateColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null)
                        setText(bsqFormatter.formatDateTime(new Date(item.getMyVote().getDate())));
                    else
                        setText("");
                }
            };
        }
    });
    dateColumn.setComparator(Comparator.comparing(o3 -> o3.getMyVote().getDate()));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getColumns().add(dateColumn);
    tableView.getSortOrder().add(dateColumn);
    TableColumn<VoteListItem, VoteListItem> proposalListColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.myVotes.proposalList"));
    proposalListColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    proposalListColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        ProposalList proposalList = item.getMyVote().getProposalList();
                        HyperlinkWithIcon field = new HyperlinkWithIcon(Res.get("dao.proposal.myVotes.showProposalList"), AwesomeIcon.INFO_SIGN);
                        field.setOnAction(event -> onShowProposalList(proposalList));
                        field.setTooltip(new Tooltip(Res.get("dao.proposal.myVotes.tooltip.showProposalList")));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    proposalListColumn.setSortable(false);
    tableView.getColumns().add(proposalListColumn);
    TableColumn<VoteListItem, VoteListItem> stakeColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.votes.stake"));
    stakeColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    stakeColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        textProperty().bind(item.getStakeAsStringProperty());
                    } else {
                        textProperty().unbind();
                        setText("");
                    }
                }
            };
        }
    });
    stakeColumn.setComparator(Comparator.comparing(VoteListItem::getStake));
    tableView.getColumns().add(stakeColumn);
    TableColumn<VoteListItem, VoteListItem> txColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.myVotes.tx"));
    txColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    txColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        String txId = item.getMyVote().getTxId();
                        HyperlinkWithIcon hyperlinkWithIcon = new HyperlinkWithIcon(txId, AwesomeIcon.EXTERNAL_LINK);
                        hyperlinkWithIcon.setOnAction(event -> {
                            if (txId != null)
                                GUIUtil.openWebPage(preferences.getBlockChainExplorer().txUrl + txId);
                        });
                        hyperlinkWithIcon.setTooltip(new Tooltip(Res.get("tooltip.openBlockchainForTx", txId)));
                        setGraphic(hyperlinkWithIcon);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    txColumn.setComparator(Comparator.comparing(o2 -> o2.getMyVote().getBlindVote().getTxId()));
    tableView.getColumns().add(txColumn);
    TableColumn<VoteListItem, VoteListItem> confidenceColumn = new TableColumn<>(Res.get("shared.confirmations"));
    confidenceColumn.setMinWidth(130);
    confidenceColumn.setMaxWidth(confidenceColumn.getMinWidth());
    confidenceColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    confidenceColumn.setCellFactory(new Callback<TableColumn<VoteListItem, VoteListItem>, TableCell<VoteListItem, VoteListItem>>() {

        @Override
        public TableCell<VoteListItem, VoteListItem> call(TableColumn<VoteListItem, VoteListItem> column) {
            return new TableCell<VoteListItem, VoteListItem>() {

                @Override
                public void updateItem(final VoteListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        setGraphic(item.getTxConfidenceIndicator());
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    confidenceColumn.setComparator(Comparator.comparing(VoteListItem::getConfirmations));
    tableView.getColumns().add(confidenceColumn);
}
Also used : TableGroupHeadline(bisq.desktop.components.TableGroupHeadline) GUIUtil(bisq.desktop.util.GUIUtil) BsqBlockChainChangeDispatcher(bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Date(java.util.Date) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) FXCollections(javafx.collections.FXCollections) Layout(bisq.desktop.util.Layout) BsqNodeProvider(bisq.core.dao.node.BsqNodeProvider) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ProposalListItem(bisq.desktop.main.dao.proposal.ProposalListItem) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) VoteService(bisq.core.dao.vote.VoteService) Tooltip(javafx.scene.control.Tooltip) BsqBlockChain(bisq.core.dao.blockchain.BsqBlockChain) GridPane(javafx.scene.layout.GridPane) SortedList(javafx.collections.transformation.SortedList) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) DaoPeriodService(bisq.core.dao.DaoPeriodService) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) VoteResult(bisq.core.dao.vote.VoteResult) Subscription(org.fxmisc.easybind.Subscription) Collectors(java.util.stream.Collectors) BsqFormatter(bisq.desktop.util.BsqFormatter) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) Priority(javafx.scene.layout.Priority) BaseProposalView(bisq.desktop.main.dao.proposal.BaseProposalView) List(java.util.List) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) ProposalList(bisq.core.dao.proposal.ProposalList) Preferences(bisq.core.user.Preferences) BooleanVoteResult(bisq.core.dao.vote.BooleanVoteResult) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) Comparator(java.util.Comparator) ProposalCollectionsService(bisq.core.dao.proposal.ProposalCollectionsService) Tooltip(javafx.scene.control.Tooltip) TableColumn(javafx.scene.control.TableColumn) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) Date(java.util.Date) TableCell(javafx.scene.control.TableCell) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) ProposalList(bisq.core.dao.proposal.ProposalList)

Example 7 with TableView

use of javafx.scene.control.TableView in project bisq-desktop by bisq-network.

the class OfferBookView method initialize.

@Override
public void initialize() {
    root.setPadding(new Insets(20, 25, 5, 25));
    addTitledGroupBg(root, gridRow, 2, Res.get("offerbook.availableOffers"));
    final Tuple3<HBox, AutoTooltipLabel, ComboBox> filterBoxTuple = addHBoxLabelComboBox(root, gridRow, Res.get("offerbook.filterByCurrency"), Layout.FIRST_ROW_DISTANCE);
    final HBox filterBox = filterBoxTuple.first;
    currencyComboBox = filterBoxTuple.third;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    // noinspection unchecked
    paymentMethodComboBox = new ComboBox<>();
    final Label paymentMethodLabel = new AutoTooltipLabel(Res.getWithCol("offerbook.filterByPaymentMethod"));
    paymentMethodLabel.setPadding(new Insets(0, 0, 0, 10));
    filterBox.getChildren().addAll(paymentMethodLabel, paymentMethodComboBox);
    paymentMethodComboBox.setPromptText(Res.get("shared.selectPaymentMethod"));
    paymentMethodComboBox.setVisibleRowCount(20);
    paymentMethodComboBox.setConverter(new StringConverter<PaymentMethod>() {

        @Override
        public String toString(PaymentMethod paymentMethod) {
            String id = paymentMethod.getId();
            if (id.equals(GUIUtil.SHOW_ALL_FLAG))
                return "▶ " + Res.get("list.currency.showAll");
            else if (paymentMethod.equals(PaymentMethod.BLOCK_CHAINS))
                return "✦ " + Res.get(id);
            else
                return "★ " + Res.get(id);
        }

        @Override
        public PaymentMethod fromString(String s) {
            return null;
        }
    });
    tableView = new TableView<>();
    GridPane.setRowIndex(tableView, ++gridRow);
    GridPane.setColumnIndex(tableView, 0);
    GridPane.setColumnSpan(tableView, 2);
    GridPane.setMargin(tableView, new Insets(10, -10, -10, -10));
    GridPane.setVgrow(tableView, Priority.ALWAYS);
    root.getChildren().add(tableView);
    marketColumn = getMarketColumn();
    priceColumn = getPriceColumn();
    tableView.getColumns().add(priceColumn);
    amountColumn = getAmountColumn();
    tableView.getColumns().add(amountColumn);
    volumeColumn = getVolumeColumn();
    tableView.getColumns().add(volumeColumn);
    TableColumn<OfferBookListItem, OfferBookListItem> paymentMethodColumn = getPaymentMethodColumn();
    tableView.getColumns().add(paymentMethodColumn);
    TableColumn<OfferBookListItem, OfferBookListItem> avatarColumn = getAvatarColumn();
    tableView.getColumns().add(avatarColumn);
    tableView.getColumns().add(getActionColumn());
    tableView.getSortOrder().add(priceColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    marketColumn.setComparator((o1, o2) -> {
        String str1 = formatter.getCurrencyPair(o1.getOffer().getCurrencyCode());
        String str2 = formatter.getCurrencyPair(o2.getOffer().getCurrencyCode());
        return str1 != null && str2 != null ? str1.compareTo(str2) : 0;
    });
    priceColumn.setComparator((o1, o2) -> {
        Price price1 = o1.getOffer().getPrice();
        Price price2 = o2.getOffer().getPrice();
        return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
    });
    amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getAmount()));
    volumeColumn.setComparator((o1, o2) -> {
        Volume offerVolume1 = o1.getOffer().getVolume();
        Volume offerVolume2 = o2.getOffer().getVolume();
        return offerVolume1 != null && offerVolume2 != null ? offerVolume1.compareTo(offerVolume2) : 0;
    });
    paymentMethodColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPaymentMethod()));
    avatarColumn.setComparator(Comparator.comparing(o -> o.getOffer().getOwnerNodeAddress().getFullAddress()));
    nrOfOffersLabel = new AutoTooltipLabel("");
    nrOfOffersLabel.setId("num-offers");
    GridPane.setHalignment(nrOfOffersLabel, HPos.LEFT);
    GridPane.setVgrow(nrOfOffersLabel, Priority.NEVER);
    GridPane.setValignment(nrOfOffersLabel, VPos.TOP);
    GridPane.setRowIndex(nrOfOffersLabel, ++gridRow);
    GridPane.setColumnIndex(nrOfOffersLabel, 0);
    GridPane.setMargin(nrOfOffersLabel, new Insets(10, 0, 0, -5));
    root.getChildren().add(nrOfOffersLabel);
    createOfferButton = addButton(root, gridRow, "");
    createOfferButton.setMinHeight(40);
    createOfferButton.setPadding(new Insets(0, 20, 0, 20));
    createOfferButton.setGraphicTextGap(10);
    GridPane.setMargin(createOfferButton, new Insets(15, 0, 0, 0));
    GridPane.setHalignment(createOfferButton, HPos.RIGHT);
    GridPane.setVgrow(createOfferButton, Priority.NEVER);
    GridPane.setValignment(createOfferButton, VPos.TOP);
    offerListListener = c -> nrOfOffersLabel.setText(Res.get("offerbook.nrOffers", model.getOfferList().size()));
    // Fixes incorrect ordering of Available offers:
    // https://github.com/bisq-network/exchange/issues/588
    priceFeedUpdateCounterListener = (observable, oldValue, newValue) -> tableView.sort();
}
Also used : Button(javafx.scene.control.Button) HPos(javafx.geometry.HPos) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) ArbitratorSelectionView(bisq.desktop.main.account.content.arbitratorselection.ArbitratorSelectionView) Coin(org.bitcoinj.core.Coin) Layout(bisq.desktop.util.Layout) FiatAccountsView(bisq.desktop.main.account.content.fiataccounts.FiatAccountsView) BSFormatter(bisq.desktop.util.BSFormatter) FormBuilder.getIcon(bisq.desktop.util.FormBuilder.getIcon) ComboBox(javafx.scene.control.ComboBox) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) TableView(javafx.scene.control.TableView) Navigation(bisq.desktop.Navigation) HBox(javafx.scene.layout.HBox) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder.addTitledGroupBg(bisq.desktop.util.FormBuilder.addTitledGroupBg) Canvas(javafx.scene.canvas.Canvas) Subscription(org.fxmisc.easybind.Subscription) PaymentMethod(bisq.core.payment.payload.PaymentMethod) Priority(javafx.scene.layout.Priority) PaymentAccount(bisq.core.payment.PaymentAccount) NodeAddress(bisq.network.p2p.NodeAddress) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AppOptionKeys(bisq.core.app.AppOptionKeys) AccountSettingsView(bisq.desktop.main.account.settings.AccountSettingsView) Optional(java.util.Optional) MaterialDesignIcon(de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon) NotNull(org.jetbrains.annotations.NotNull) GUIUtil(bisq.desktop.util.GUIUtil) Scene(javafx.scene.Scene) TradeCurrency(bisq.core.locale.TradeCurrency) FormBuilder.addHBoxLabelComboBox(bisq.desktop.util.FormBuilder.addHBoxLabelComboBox) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) FiatCurrency(bisq.core.locale.FiatCurrency) Volume(bisq.core.monetary.Volume) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) WithdrawalView(bisq.desktop.main.funds.withdrawal.WithdrawalView) OfferPayload(bisq.core.offer.OfferPayload) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) VPos(javafx.geometry.VPos) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) Callback(javafx.util.Callback) FundsView(bisq.desktop.main.funds.FundsView) Tooltip(javafx.scene.control.Tooltip) AccountView(bisq.desktop.main.account.AccountView) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) TableRow(javafx.scene.control.TableRow) DontShowAgainLookup(bisq.core.user.DontShowAgainLookup) OfferView(bisq.desktop.main.offer.OfferView) StringConverter(javafx.util.StringConverter) PeerInfoIcon(bisq.desktop.components.PeerInfoIcon) FormBuilder.addButton(bisq.desktop.util.FormBuilder.addButton) MainView(bisq.desktop.main.MainView) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) Price(bisq.core.monetary.Price) ObservableValue(javafx.beans.value.ObservableValue) Named(com.google.inject.name.Named) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) Comparator(java.util.Comparator) ContentDisplay(javafx.scene.control.ContentDisplay) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) FormBuilder.addHBoxLabelComboBox(bisq.desktop.util.FormBuilder.addHBoxLabelComboBox) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel) Label(javafx.scene.control.Label) Price(bisq.core.monetary.Price) Volume(bisq.core.monetary.Volume) PaymentMethod(bisq.core.payment.payload.PaymentMethod) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel)

Example 8 with TableView

use of javafx.scene.control.TableView in project bisq-desktop by bisq-network.

the class OfferBookChartView method getOfferTable.

private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) {
    TableView<OfferListItem> tableView = new TableView<>();
    tableView.setMinHeight(initialOfferTableViewHeight);
    tableView.setPrefHeight(121);
    tableView.setMinWidth(480);
    tableView.getStyleClass().add("offer-table");
    // price
    TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
    priceColumn.textProperty().bind(priceColumnLabel);
    priceColumn.setMinWidth(115);
    priceColumn.setMaxWidth(115);
    priceColumn.setSortable(false);
    priceColumn.getStyleClass().add("number-column");
    priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                final ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        final Offer offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offer;
                            model.priceFeedService.updateCounterProperty().addListener(listener);
                            setText(Res.get("shared.na"));
                        } else {
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // volume
    TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
    volumeColumn.setMinWidth(115);
    volumeColumn.setSortable(false);
    volumeColumn.textProperty().bind(volumeColumnLabel);
    volumeColumn.getStyleClass().add("number-column");
    volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                private Offer offer;

                final ChangeListener<Number> listener = new ChangeListener<Number>() {

                    @Override
                    public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                        if (offer != null && offer.getPrice() != null) {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        }
                    }
                };

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        this.offer = offerListItem.offer;
                        if (offer.getPrice() == null) {
                            this.offer = offerListItem.offer;
                            model.priceFeedService.updateCounterProperty().addListener(listener);
                            setText(Res.get("shared.na"));
                        } else {
                            setText("");
                            setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
                        }
                    } else {
                        if (listener != null)
                            model.priceFeedService.updateCounterProperty().removeListener(listener);
                        this.offer = null;
                        setText("");
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // amount
    TableColumn<OfferListItem, OfferListItem> amountColumn = new AutoTooltipTableColumn<>(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode()));
    amountColumn.setMinWidth(115);
    amountColumn.setSortable(false);
    amountColumn.getStyleClass().add("number-column");
    amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {

        @Override
        public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
            return new TableCell<OfferListItem, OfferListItem>() {

                @Override
                public void updateItem(final OfferListItem offerListItem, boolean empty) {
                    super.updateItem(offerListItem, empty);
                    if (offerListItem != null && !empty) {
                        setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatCoin(offerListItem.offer.getAmount(), 4), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    tableView.getColumns().add(volumeColumn);
    tableView.getColumns().add(amountColumn);
    tableView.getColumns().add(priceColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    Label titleLabel = new AutoTooltipLabel();
    titleLabel.getStyleClass().add("table-title");
    UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
    boolean isSellOffer = direction == OfferPayload.Direction.SELL;
    Button button = new AutoTooltipButton();
    ImageView iconView = new ImageView();
    iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
    button.setGraphic(iconView);
    button.setGraphicTextGap(10);
    button.setText(isSellOffer ? Res.get("market.offerBook.buy") : Res.get("market.offerBook.sell"));
    button.setMinHeight(40);
    button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
    button.setOnAction(e -> {
        if (isSellOffer) {
            model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
            // noinspection unchecked
            navigation.navigateTo(MainView.class, BuyOfferView.class);
        } else {
            model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
            // noinspection unchecked
            navigation.navigateTo(MainView.class, SellOfferView.class);
        }
    });
    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.setFillWidth(true);
    vBox.setMinHeight(190);
    vBox.setVgrow(tableView, Priority.ALWAYS);
    vBox.getChildren().addAll(titleLabel, tableView, button);
    button.prefWidthProperty().bind(vBox.widthProperty());
    return new Tuple4<>(tableView, vBox, button, titleLabel);
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) TableCell(javafx.scene.control.TableCell) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) TableView(javafx.scene.control.TableView) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) TableColumn(javafx.scene.control.TableColumn) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Tuple4(bisq.common.util.Tuple4) Offer(bisq.core.offer.Offer) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) VBox(javafx.scene.layout.VBox)

Example 9 with TableView

use of javafx.scene.control.TableView in project org.csstudio.display.builder by kasemir.

the class RulesDialog method createRulesTable.

/**
 * @return Node for UI elements that edit the rules
 */
private Node createRulesTable() {
    // Create table with editable rule 'name' column
    final TableColumn<RuleItem, String> name_col = new TableColumn<>(Messages.RulesDialog_ColName);
    name_col.setCellValueFactory(new PropertyValueFactory<RuleItem, String>("name"));
    name_col.setCellFactory(list -> new TextFieldTableCell<RuleItem, String>(new DefaultStringConverter()) {

        private final ChangeListener<? super Boolean> focusedListener = (ob, o, n) -> {
            if (!n)
                cancelEdit();
        };

        @Override
        public void cancelEdit() {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.cancelEdit();
        }

        @Override
        public void commitEdit(final String newValue) {
            ((TextField) getGraphic()).focusedProperty().removeListener(focusedListener);
            super.commitEdit(newValue);
            Platform.runLater(() -> btn_add_pv.requestFocus());
        }

        @Override
        public void startEdit() {
            super.startEdit();
            ((TextField) getGraphic()).focusedProperty().addListener(focusedListener);
        }
    });
    name_col.setOnEditCommit(event -> {
        final int row = event.getTablePosition().getRow();
        rule_items.get(row).name.set(event.getNewValue());
        fixupRules(row);
    });
    rules_table = new TableView<>(rule_items);
    rules_table.getColumns().add(name_col);
    rules_table.setEditable(true);
    rules_table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    rules_table.setTooltip(new Tooltip(Messages.RulesDialog_RulesTT));
    rules_table.setPlaceholder(new Label(Messages.RulesDialog_NoRules));
    // Buttons
    btn_add_rule = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    btn_add_rule.setMaxWidth(Double.MAX_VALUE);
    btn_add_rule.setAlignment(Pos.CENTER_LEFT);
    btn_add_rule.setOnAction(event -> {
        final RuleItem newItem = new RuleItem(attached_widget, selected_rule_item == null ? ((propinfo_ls.size() == 0) ? "" : propinfo_ls.get(0).getPropID()) : selected_rule_item.prop_id.get());
        rule_items.add(newItem);
        rules_table.getSelectionModel().select(newItem);
        final int newRow = rules_table.getSelectionModel().getSelectedIndex();
        ModelThreadPool.getTimer().schedule(() -> {
            Platform.runLater(() -> rules_table.edit(newRow, name_col));
        }, 123, TimeUnit.MILLISECONDS);
    });
    btn_remove_rule = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    btn_remove_rule.setMaxWidth(Double.MAX_VALUE);
    btn_remove_rule.setAlignment(Pos.CENTER_LEFT);
    btn_remove_rule.setDisable(true);
    btn_remove_rule.setOnAction(event -> {
        final int sel = rules_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            rule_items.remove(sel);
            fixupRules(sel);
        }
    });
    btn_move_rule_up = new Button(Messages.MoveUp, JFXUtil.getIcon("up.png"));
    btn_move_rule_up.setMaxWidth(Double.MAX_VALUE);
    btn_move_rule_up.setAlignment(Pos.CENTER_LEFT);
    btn_move_rule_up.setDisable(true);
    btn_move_rule_up.setOnAction(event -> TableHelper.move_item_up(rules_table, rule_items));
    btn_move_rule_down = new Button(Messages.MoveDown, JFXUtil.getIcon("down.png"));
    btn_move_rule_down.setMaxWidth(Double.MAX_VALUE);
    btn_move_rule_down.setAlignment(Pos.CENTER_LEFT);
    btn_move_rule_down.setDisable(true);
    btn_move_rule_down.setOnAction(event -> TableHelper.move_item_down(rules_table, rule_items));
    btn_dup_rule = new Button(Messages.Duplicate, JFXUtil.getIcon("file-duplicate.png"));
    btn_dup_rule.setMaxWidth(Double.MAX_VALUE);
    btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
    btn_dup_rule.setDisable(true);
    btn_dup_rule.setOnAction(event -> {
        if (selected_rule_item != null) {
            final RuleItem newItem = RuleItem.forInfo(attached_widget, selected_rule_item.getRuleInfo(), undo);
            if (!newItem.nameProperty().get().endsWith(" (duplicate)"))
                newItem.nameProperty().set(newItem.nameProperty().get() + " (duplicate)");
            rule_items.add(newItem);
            rules_table.getSelectionModel().select(newItem);
            final int newRow = rules_table.getSelectionModel().getSelectedIndex();
            ModelThreadPool.getTimer().schedule(() -> {
                Platform.runLater(() -> rules_table.edit(newRow, name_col));
            }, 123, TimeUnit.MILLISECONDS);
        }
    });
    btn_show_script = new Button(Messages.RulesDialog_ShowScript, JFXUtil.getIcon("file.png"));
    btn_show_script.setMaxWidth(Double.MAX_VALUE);
    btn_show_script.setMinWidth(120);
    btn_dup_rule.setAlignment(Pos.CENTER_LEFT);
    btn_show_script.setDisable(true);
    btn_show_script.setOnAction(event -> {
        final int sel = rules_table.getSelectionModel().getSelectedIndex();
        if (sel >= 0) {
            final String content = rule_items.get(sel).getRuleInfo().getTextPy(attached_widget);
            final SyntaxHighlightedMultiLineInputDialog dialog = new SyntaxHighlightedMultiLineInputDialog(btn_show_script, content, Language.Python, false);
            DialogHelper.positionDialog(dialog, btn_show_script, -200, -300);
            dialog.setTextHeight(600);
            dialog.show();
        }
    });
    final VBox buttons = new VBox(10, btn_add_rule, btn_remove_rule, btn_move_rule_up, btn_move_rule_down, new Pane(), btn_dup_rule, btn_show_script);
    final HBox content = new HBox(10, rules_table, buttons);
    HBox.setHgrow(rules_table, Priority.ALWAYS);
    HBox.setHgrow(buttons, Priority.NEVER);
    return content;
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) UndoableActionManager(org.csstudio.display.builder.util.undo.UndoableActionManager) ScriptPV(org.csstudio.display.builder.model.properties.ScriptPV) LineNumberTableCellFactory(org.csstudio.javafx.LineNumberTableCellFactory) VBox(javafx.scene.layout.VBox) AutoCompletedTableCell(org.csstudio.display.builder.representation.javafx.PVTableItem.AutoCompletedTableCell) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo) TableHelper(org.csstudio.javafx.TableHelper) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) TableView(javafx.scene.control.TableView) ModelThreadPool(org.csstudio.display.builder.model.util.ModelThreadPool) Pane(javafx.scene.layout.Pane) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PVTableItem(org.csstudio.display.builder.representation.javafx.PVTableItem) SplitPane(javafx.scene.control.SplitPane) TextField(javafx.scene.control.TextField) Language(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog.Language) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Collectors(java.util.stream.Collectors) CommonWidgetProperties(org.csstudio.display.builder.model.properties.CommonWidgetProperties) Platform(javafx.application.Platform) Priority(javafx.scene.layout.Priority) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) Region(javafx.scene.layout.Region) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AutocompleteMenu(org.csstudio.display.builder.representation.javafx.AutocompleteMenu) JFXUtil(org.csstudio.display.builder.representation.javafx.JFXUtil) ObservableList(javafx.collections.ObservableList) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) StringProperty(javafx.beans.property.StringProperty) ExpressionInfo(org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) ExprInfoValue(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoValue) Plugin.logger(org.csstudio.display.builder.editor.Plugin.logger) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ButtonType(javafx.scene.control.ButtonType) JFXBaseRepresentation(org.csstudio.display.builder.representation.javafx.widgets.JFXBaseRepresentation) FXCollections(javafx.collections.FXCollections) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) Messages(org.csstudio.display.builder.representation.javafx.Messages) TableCell(javafx.scene.control.TableCell) Insets(javafx.geometry.Insets) Tooltip(javafx.scene.control.Tooltip) Dialog(javafx.scene.control.Dialog) Label(javafx.scene.control.Label) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Preferences(java.util.prefs.Preferences) TimeUnit(java.util.concurrent.TimeUnit) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ScriptsDialog(org.csstudio.display.builder.representation.javafx.ScriptsDialog) DialogHelper(org.csstudio.javafx.DialogHelper) Widget(org.csstudio.display.builder.model.Widget) ChangeListener(javafx.beans.value.ChangeListener) PropInfo(org.csstudio.display.builder.model.rules.RuleInfo.PropInfo) HBox(javafx.scene.layout.HBox) Tooltip(javafx.scene.control.Tooltip) Label(javafx.scene.control.Label) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) TableColumn(javafx.scene.control.TableColumn) Pane(javafx.scene.layout.Pane) SplitPane(javafx.scene.control.SplitPane) DefaultStringConverter(javafx.util.converter.DefaultStringConverter) Button(javafx.scene.control.Button) SyntaxHighlightedMultiLineInputDialog(org.csstudio.javafx.SyntaxHighlightedMultiLineInputDialog) TextField(javafx.scene.control.TextField) VBox(javafx.scene.layout.VBox)

Example 10 with TableView

use of javafx.scene.control.TableView in project org.csstudio.display.builder by kasemir.

the class WidgetInfoDialog method createProperties.

private Tab createProperties(final Widget widget) {
    // Use text field to allow copying the name (for use in scripts)
    // and value, but not the localized description and category
    // which are just for information
    final TableColumn<WidgetProperty<?>, String> cat = new TableColumn<>(Messages.WidgetInfoDialog_Category);
    cat.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getCategory().getDescription()));
    final TableColumn<WidgetProperty<?>, String> descr = new TableColumn<>(Messages.WidgetInfoDialog_Property);
    descr.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getDescription()));
    final TableColumn<WidgetProperty<?>, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getName()));
    final TableColumn<WidgetProperty<?>, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> new ReadOnlyStringWrapper(Objects.toString(param.getValue().getValue())));
    final TableView<WidgetProperty<?>> table = new TableView<>(FXCollections.observableArrayList(widget.getProperties()));
    table.getColumns().add(cat);
    table.getColumns().add(descr);
    table.getColumns().add(name);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabProperties, table);
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Aggregations

TableView (javafx.scene.control.TableView)70 TableColumn (javafx.scene.control.TableColumn)60 Map (java.util.Map)40 List (java.util.List)39 ArrayList (java.util.ArrayList)38 Button (javafx.scene.control.Button)38 Label (javafx.scene.control.Label)38 FXCollections (javafx.collections.FXCollections)37 Insets (javafx.geometry.Insets)36 Collectors (java.util.stream.Collectors)33 Scene (javafx.scene.Scene)33 Tab (javafx.scene.control.Tab)33 BorderPane (javafx.scene.layout.BorderPane)32 Optional (java.util.Optional)31 ObservableValue (javafx.beans.value.ObservableValue)30 VBox (javafx.scene.layout.VBox)29 Collections (java.util.Collections)28 MenuItem (javafx.scene.control.MenuItem)28 HashMap (java.util.HashMap)27 Set (java.util.Set)27