Search in sources :

Example 1 with BsqFormatter

use of bisq.desktop.util.BsqFormatter in project bisq-desktop by bisq-network.

the class BaseProposalView method createProposalColumns.

// /////////////////////////////////////////////////////////////////////////////////////////
// TableColumns
// /////////////////////////////////////////////////////////////////////////////////////////
protected void createProposalColumns(TableView<ProposalListItem> tableView) {
    TableColumn<ProposalListItem, ProposalListItem> dateColumn = new AutoTooltipTableColumn<ProposalListItem, ProposalListItem>(Res.get("shared.dateTime")) {

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

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

                @Override
                public void updateItem(final ProposalListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null)
                        setText(bsqFormatter.formatDateTime(item.getProposal().getProposalPayload().getCreationDate()));
                    else
                        setText("");
                }
            };
        }
    });
    dateColumn.setComparator(Comparator.comparing(o3 -> o3.getProposal().getProposalPayload().getCreationDate()));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getColumns().add(dateColumn);
    tableView.getSortOrder().add(dateColumn);
    TableColumn<ProposalListItem, ProposalListItem> nameColumn = new AutoTooltipTableColumn<>(Res.get("shared.name"));
    nameColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    nameColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {

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

                @Override
                public void updateItem(final ProposalListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null)
                        setText(item.getProposal().getProposalPayload().getName());
                    else
                        setText("");
                }
            };
        }
    });
    nameColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getProposalPayload().getName()));
    tableView.getColumns().add(nameColumn);
    TableColumn<ProposalListItem, ProposalListItem> titleColumn = new AutoTooltipTableColumn<>(Res.get("dao.proposal.title"));
    titleColumn.setPrefWidth(100);
    titleColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    titleColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {

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

                @Override
                public void updateItem(final ProposalListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null)
                        setText(item.getProposal().getProposalPayload().getTitle());
                    else
                        setText("");
                }
            };
        }
    });
    titleColumn.setComparator(Comparator.comparing(o2 -> o2.getProposal().getProposalPayload().getTitle()));
    tableView.getColumns().add(titleColumn);
    TableColumn<ProposalListItem, ProposalListItem> uidColumn = new AutoTooltipTableColumn<>(Res.get("shared.id"));
    uidColumn.setCellValueFactory((item) -> new ReadOnlyObjectWrapper<>(item.getValue()));
    uidColumn.setCellFactory(new Callback<TableColumn<ProposalListItem, ProposalListItem>, TableCell<ProposalListItem, ProposalListItem>>() {

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

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final ProposalListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        final Proposal proposal = item.getProposal();
                        final ProposalPayload proposalPayload = proposal.getProposalPayload();
                        field = new HyperlinkWithIcon(proposalPayload.getShortId());
                        field.setOnAction(event -> {
                            new ProposalDetailsWindow(bsqFormatter, bsqWalletService, proposalPayload).show();
                        });
                        field.setTooltip(new Tooltip(Res.get("tooltip.openPopupForDetails")));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
    uidColumn.setComparator(Comparator.comparing(o -> o.getProposal().getProposalPayload().getUid()));
    tableView.getColumns().add(uidColumn);
}
Also used : TableGroupHeadline(bisq.desktop.components.TableGroupHeadline) ActivatableView(bisq.desktop.common.view.ActivatableView) BsqBlockChainChangeDispatcher(bisq.core.dao.blockchain.BsqBlockChainChangeDispatcher) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) FXCollections(javafx.collections.FXCollections) BsqNode(bisq.core.dao.node.BsqNode) Proposal(bisq.core.dao.proposal.Proposal) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) ScrollPane(javafx.scene.control.ScrollPane) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) 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) Node(javafx.scene.Node) 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) ProposalPayload(bisq.core.dao.proposal.ProposalPayload) List(java.util.List) EasyBind(org.fxmisc.easybind.EasyBind) ObservableList(javafx.collections.ObservableList) ChangeListener(javafx.beans.value.ChangeListener) 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) TableCell(javafx.scene.control.TableCell) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) ProposalPayload(bisq.core.dao.proposal.ProposalPayload) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Proposal(bisq.core.dao.proposal.Proposal)

Example 2 with BsqFormatter

use of bisq.desktop.util.BsqFormatter in project bisq-desktop by bisq-network.

the class BsqTxView method getCompensationRequestTxListItems.

// We add manually a modified copy of the compensation request tx if it has become an issuance tx
// It is a bit weird to have one tx displayed 2 times but I think it is better to show both aspects
// separately. First the compensation request tx with the fee then after voting the issuance.
private List<BsqTxListItem> getCompensationRequestTxListItems(List<BsqTxListItem> items) {
    List<BsqTxListItem> issuanceTxList = new ArrayList<>();
    items.stream().filter(item -> item.getTxType() == TxType.COMPENSATION_REQUEST).peek(item -> {
        final Tx tx = readableBsqBlockChain.getTx(item.getTxId()).get();
        // We have mandatory BSQ change at output 0
        long changeValue = tx.getOutputs().get(0).getValue();
        long inputValue = tx.getInputs().stream().filter(input -> input.getConnectedTxOutput() != null).mapToLong(input -> input.getConnectedTxOutput().getValue()).sum();
        // We want to show fee as negative number
        long fee = changeValue - inputValue;
        item.setAmount(Coin.valueOf(fee));
    }).filter(item -> {
        final Optional<Tx> optionalTx = readableBsqBlockChain.getTx(item.getTxId());
        if (optionalTx.isPresent()) {
            final List<TxOutput> outputs = optionalTx.get().getOutputs();
            if (!outputs.isEmpty()) {
                return outputs.get(0).getTxOutputType() == TxOutputType.BSQ_OUTPUT;
            }
        }
        return false;
    }).forEach(item -> {
        final Tx tx = readableBsqBlockChain.getTx(item.getTxId()).get();
        final int blockHeight = tx.getBlockHeight();
        final int issuanceBlockHeight = daoPeriodService.getAbsoluteStartBlockOfPhase(blockHeight, DaoPeriodService.Phase.ISSUANCE);
        // We use the time of the block height of the start of the issuance period
        final long blockTimeInSec = readableBsqBlockChain.getBlockTime(issuanceBlockHeight);
        final BsqTxListItem issuanceItem = new BsqTxListItem(item.getTransaction(), bsqWalletService, btcWalletService, Optional.of(TxType.ISSUANCE), item.isBurnedBsqTx(), new Date(blockTimeInSec * 1000), bsqFormatter);
        // On output 1 we have the issuance candidate
        long issuanceValue = tx.getOutputs().get(1).getValue();
        issuanceItem.setAmount(Coin.valueOf(issuanceValue));
        issuanceTxList.add(issuanceItem);
    });
    return issuanceTxList;
}
Also used : Transaction(org.bitcoinj.core.Transaction) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) ReadableBsqBlockChain(bisq.core.dao.blockchain.ReadableBsqBlockChain) VBox(javafx.scene.layout.VBox) BsqBalanceListener(bisq.core.btc.wallet.BsqBalanceListener) BsqNode(bisq.core.dao.node.BsqNode) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) SortedList(javafx.collections.transformation.SortedList) HBox(javafx.scene.layout.HBox) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder(bisq.desktop.util.FormBuilder) TxOutput(bisq.core.dao.blockchain.vo.TxOutput) Collectors(java.util.stream.Collectors) BsqWalletService(bisq.core.btc.wallet.BsqWalletService) BsqBalanceUtil(bisq.desktop.main.dao.wallet.BsqBalanceUtil) List(java.util.List) Preferences(bisq.core.user.Preferences) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) GUIUtil(bisq.desktop.util.GUIUtil) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) ActivatableView(bisq.desktop.common.view.ActivatableView) FXCollections(javafx.collections.FXCollections) DoubleProperty(javafx.beans.property.DoubleProperty) BsqNodeProvider(bisq.core.dao.node.BsqNodeProvider) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) ProgressBar(javafx.scene.control.ProgressBar) Insets(javafx.geometry.Insets) AddressWithIconAndDirection(bisq.desktop.components.AddressWithIconAndDirection) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) DaoPeriodService(bisq.core.dao.DaoPeriodService) Tx(bisq.core.dao.blockchain.vo.Tx) AwesomeDude(de.jensd.fx.fontawesome.AwesomeDude) BisqEnvironment(bisq.core.app.BisqEnvironment) TxType(bisq.core.dao.blockchain.vo.TxType) BsqFormatter(bisq.desktop.util.BsqFormatter) TxOutputType(bisq.core.dao.blockchain.vo.TxOutputType) ChangeListener(javafx.beans.value.ChangeListener) Tx(bisq.core.dao.blockchain.vo.Tx) Optional(java.util.Optional) ArrayList(java.util.ArrayList) SortedList(javafx.collections.transformation.SortedList) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

BsqWalletService (bisq.core.btc.wallet.BsqWalletService)2 DaoPeriodService (bisq.core.dao.DaoPeriodService)2 BsqNode (bisq.core.dao.node.BsqNode)2 Res (bisq.core.locale.Res)2 ActivatableView (bisq.desktop.common.view.ActivatableView)2 FxmlView (bisq.desktop.common.view.FxmlView)2 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)2 AutoTooltipTableColumn (bisq.desktop.components.AutoTooltipTableColumn)2 HyperlinkWithIcon (bisq.desktop.components.HyperlinkWithIcon)2 BsqFormatter (bisq.desktop.util.BsqFormatter)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)2 ChangeListener (javafx.beans.value.ChangeListener)2 FXCollections (javafx.collections.FXCollections)2 ListChangeListener (javafx.collections.ListChangeListener)2 ObservableList (javafx.collections.ObservableList)2 SortedList (javafx.collections.transformation.SortedList)2 Insets (javafx.geometry.Insets)2