Search in sources :

Example 1 with NodeEntry

use of com.sparrowwallet.sparrow.wallet.NodeEntry in project sparrow by sparrowwallet.

the class AddressTreeTable method initialize.

public void initialize(NodeEntry rootEntry) {
    getStyleClass().add("address-treetable");
    setBitcoinUnit(rootEntry.getWallet());
    String address = rootEntry.getAddress().toString();
    updateAll(rootEntry);
    setShowRoot(false);
    TreeTableColumn<Entry, Entry> addressCol = new TreeTableColumn<>("Address / Outpoints");
    addressCol.setCellValueFactory((TreeTableColumn.CellDataFeatures<Entry, Entry> param) -> {
        return new ReadOnlyObjectWrapper<>(param.getValue().getValue());
    });
    addressCol.setCellFactory(p -> new EntryCell());
    addressCol.setSortable(false);
    getColumns().add(addressCol);
    if (address != null && !rootEntry.getWallet().isWhirlpoolChildWallet()) {
        addressCol.setMinWidth(TextUtils.computeTextWidth(AppServices.getMonospaceFont(), address, 0.0));
    }
    TreeTableColumn<Entry, String> labelCol = new TreeTableColumn<>("Label");
    labelCol.setCellValueFactory((TreeTableColumn.CellDataFeatures<Entry, String> param) -> {
        return param.getValue().getValue().labelProperty();
    });
    labelCol.setCellFactory(p -> new LabelCell());
    labelCol.setSortable(false);
    getColumns().add(labelCol);
    TreeTableColumn<Entry, Number> amountCol = new TreeTableColumn<>("Value");
    amountCol.setCellValueFactory((TreeTableColumn.CellDataFeatures<Entry, Number> param) -> {
        return new ReadOnlyObjectWrapper<>(param.getValue().getValue().getValue());
    });
    amountCol.setCellFactory(p -> new CoinCell());
    amountCol.setSortable(false);
    getColumns().add(amountCol);
    setEditable(true);
    setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
    addressCol.setSortType(TreeTableColumn.SortType.ASCENDING);
    getSortOrder().add(addressCol);
    Integer highestUsedIndex = rootEntry.getNode().getHighestUsedIndex();
    if (highestUsedIndex != null) {
        OptionalInt tableIndex = rootEntry.getChildren().stream().filter(childEntry -> ((NodeEntry) childEntry).getNode().getIndex() == highestUsedIndex + 1).mapToInt(childEntry -> rootEntry.getChildren().indexOf(childEntry)).findFirst();
        if (tableIndex.isPresent() && tableIndex.getAsInt() > 5) {
            scrollTo(tableIndex.getAsInt());
        }
    }
    if (!rootEntry.getWallet().isWhirlpoolChildWallet()) {
        setOnMouseClicked(mouseEvent -> {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                if (mouseEvent.getClickCount() == 2) {
                    TreeItem<Entry> treeItem = getSelectionModel().getSelectedItem();
                    if (treeItem != null && treeItem.getChildren().isEmpty()) {
                        Entry entry = getSelectionModel().getSelectedItem().getValue();
                        if (entry instanceof NodeEntry) {
                            NodeEntry nodeEntry = (NodeEntry) entry;
                            EventManager.get().post(new ReceiveActionEvent(nodeEntry));
                            Platform.runLater(() -> EventManager.get().post(new ReceiveToEvent(nodeEntry)));
                        }
                    }
                }
            }
        });
    }
    rootEntry.getChildren().addListener((ListChangeListener<Entry>) c -> {
        this.refresh();
    });
}
Also used : MouseButton(javafx.scene.input.MouseButton) javafx.scene.control(javafx.scene.control) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) OptionalInt(java.util.OptionalInt) Entry(com.sparrowwallet.sparrow.wallet.Entry) Platform(javafx.application.Platform) ReceiveActionEvent(com.sparrowwallet.sparrow.event.ReceiveActionEvent) List(java.util.List) AppServices(com.sparrowwallet.sparrow.AppServices) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) ReceiveToEvent(com.sparrowwallet.sparrow.event.ReceiveToEvent) EventManager(com.sparrowwallet.sparrow.EventManager) Optional(java.util.Optional) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode) OptionalInt(java.util.OptionalInt) ReceiveActionEvent(com.sparrowwallet.sparrow.event.ReceiveActionEvent) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) Entry(com.sparrowwallet.sparrow.wallet.Entry) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ReceiveToEvent(com.sparrowwallet.sparrow.event.ReceiveToEvent)

Example 2 with NodeEntry

use of com.sparrowwallet.sparrow.wallet.NodeEntry in project sparrow by sparrowwallet.

the class AddressCell method updateItem.

@Override
protected void updateItem(UtxoEntry.AddressStatus addressStatus, boolean empty) {
    super.updateItem(addressStatus, empty);
    UtxoEntry utxoEntry = addressStatus == null ? null : addressStatus.getUtxoEntry();
    EntryCell.applyRowStyles(this, utxoEntry);
    if (empty) {
        setText(null);
        setGraphic(null);
    } else {
        if (utxoEntry != null) {
            Address address = addressStatus.getAddress();
            setText(address.toString());
            setContextMenu(new EntryCell.AddressContextMenu(address, utxoEntry.getOutputDescriptor(), new NodeEntry(utxoEntry.getWallet(), utxoEntry.getNode())));
            Tooltip tooltip = new Tooltip();
            tooltip.setShowDelay(Duration.millis(250));
            tooltip.setText(getTooltipText(utxoEntry, addressStatus.isDuplicate()));
            setTooltip(tooltip);
            if (addressStatus.isDuplicate()) {
                setGraphic(getDuplicateGlyph());
            } else {
                setGraphic(null);
            }
        }
    }
}
Also used : Address(com.sparrowwallet.drongo.address.Address) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) Tooltip(javafx.scene.control.Tooltip) UtxoEntry(com.sparrowwallet.sparrow.wallet.UtxoEntry)

Example 3 with NodeEntry

use of com.sparrowwallet.sparrow.wallet.NodeEntry in project sparrow by sparrowwallet.

the class AddressTreeTable method updateHistory.

public void updateHistory(List<WalletNode> updatedNodes) {
    // We only ever add child nodes - never remove in order to keep a full sequence
    NodeEntry rootEntry = (NodeEntry) getRoot().getValue();
    for (WalletNode updatedNode : updatedNodes) {
        Optional<Entry> optEntry = rootEntry.getChildren().stream().filter(childEntry -> ((NodeEntry) childEntry).getNode().equals(updatedNode)).findFirst();
        if (optEntry.isPresent()) {
            NodeEntry existingEntry = (NodeEntry) optEntry.get();
            existingEntry.refreshChildren();
        } else {
            NodeEntry nodeEntry = new NodeEntry(rootEntry.getWallet(), updatedNode);
            rootEntry.getChildren().add(nodeEntry);
        }
    }
    refresh();
}
Also used : MouseButton(javafx.scene.input.MouseButton) javafx.scene.control(javafx.scene.control) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) OptionalInt(java.util.OptionalInt) Entry(com.sparrowwallet.sparrow.wallet.Entry) Platform(javafx.application.Platform) ReceiveActionEvent(com.sparrowwallet.sparrow.event.ReceiveActionEvent) List(java.util.List) AppServices(com.sparrowwallet.sparrow.AppServices) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) ReceiveToEvent(com.sparrowwallet.sparrow.event.ReceiveToEvent) EventManager(com.sparrowwallet.sparrow.EventManager) Optional(java.util.Optional) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) Entry(com.sparrowwallet.sparrow.wallet.Entry) NodeEntry(com.sparrowwallet.sparrow.wallet.NodeEntry) WalletNode(com.sparrowwallet.drongo.wallet.WalletNode)

Aggregations

NodeEntry (com.sparrowwallet.sparrow.wallet.NodeEntry)3 WalletNode (com.sparrowwallet.drongo.wallet.WalletNode)2 AppServices (com.sparrowwallet.sparrow.AppServices)2 EventManager (com.sparrowwallet.sparrow.EventManager)2 ReceiveActionEvent (com.sparrowwallet.sparrow.event.ReceiveActionEvent)2 ReceiveToEvent (com.sparrowwallet.sparrow.event.ReceiveToEvent)2 Entry (com.sparrowwallet.sparrow.wallet.Entry)2 List (java.util.List)2 Optional (java.util.Optional)2 OptionalInt (java.util.OptionalInt)2 Platform (javafx.application.Platform)2 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)2 ListChangeListener (javafx.collections.ListChangeListener)2 javafx.scene.control (javafx.scene.control)2 MouseButton (javafx.scene.input.MouseButton)2 Address (com.sparrowwallet.drongo.address.Address)1 UtxoEntry (com.sparrowwallet.sparrow.wallet.UtxoEntry)1 Tooltip (javafx.scene.control.Tooltip)1