search across all wallet accounts, reveal child items if selected

This commit is contained in:
Craig Raw 2022-01-31 19:14:50 +02:00
parent 6d2167428f
commit 1eb595823b
9 changed files with 85 additions and 53 deletions

2
drongo

@ -1 +1 @@
Subproject commit 61317f15ac795ef1a40c120d1e8aae2b2735c6ec
Subproject commit 9618c73c50e59035cd373d932970f446032cd9e5

View file

@ -1359,9 +1359,14 @@ public class AppController implements Initializable {
}
public void searchWallet(ActionEvent event) {
WalletForm selectedWalletForm = getSelectedWalletForm();
if(selectedWalletForm != null) {
SearchWalletDialog searchWalletDialog = new SearchWalletDialog(selectedWalletForm);
Tab selectedTab = tabs.getSelectionModel().getSelectedItem();
if(selectedTab != null) {
TabData tabData = (TabData) selectedTab.getUserData();
if(tabData instanceof WalletTabData) {
TabPane subTabs = (TabPane) selectedTab.getContent();
List<WalletForm> walletForms = subTabs.getTabs().stream().map(subTab -> ((WalletTabData)subTab.getUserData()).getWalletForm()).collect(Collectors.toList());
if(!walletForms.isEmpty()) {
SearchWalletDialog searchWalletDialog = new SearchWalletDialog(walletForms);
Optional<Entry> optEntry = searchWalletDialog.showAndWait();
if(optEntry.isPresent()) {
Entry entry = optEntry.get();
@ -1370,6 +1375,8 @@ public class AppController implements Initializable {
}
}
}
}
}
public void refreshWallet(ActionEvent event) {
WalletForm selectedWalletForm = getSelectedWalletForm();

View file

@ -23,12 +23,16 @@ import java.util.List;
public class SearchWalletDialog extends Dialog<Entry> {
private static final Logger log = LoggerFactory.getLogger(SearchWalletDialog.class);
private final WalletForm walletForm;
private final List<WalletForm> walletForms;
private final TextField search;
private final CoinTreeTable results;
public SearchWalletDialog(WalletForm walletForm) {
this.walletForm = walletForm;
public SearchWalletDialog(List<WalletForm> walletForms) {
this.walletForms = walletForms;
if(walletForms.isEmpty()) {
throw new IllegalArgumentException("No wallets selected to search");
}
final DialogPane dialogPane = getDialogPane();
dialogPane.getStylesheets().add(AppServices.class.getResource("general.css").toExternalForm());
@ -65,11 +69,19 @@ public class SearchWalletDialog extends Dialog<Entry> {
results = new CoinTreeTable();
results.setShowRoot(false);
results.setPrefWidth(850);
results.setBitcoinUnit(walletForm.getWallet());
results.setPrefWidth(walletForms.size() > 1 ? 950 : 850);
results.setBitcoinUnit(walletForms.iterator().next().getWallet());
results.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
results.setPlaceholder(new Label("No results"));
if(walletForms.size() > 1) {
TreeTableColumn<Entry, String> walletColumn = new TreeTableColumn<>("Wallet");
walletColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Entry, String> param) -> {
return new ReadOnlyObjectWrapper<>(param.getValue().getValue().getWallet().getDisplayName());
});
results.getColumns().add(walletColumn);
}
TreeTableColumn<Entry, String> typeColumn = new TreeTableColumn<>("Type");
typeColumn.setCellValueFactory((TreeTableColumn.CellDataFeatures<Entry, String> param) -> {
return new ReadOnlyObjectWrapper<>(param.getValue().getValue().getEntryType());
@ -81,10 +93,8 @@ public class SearchWalletDialog extends Dialog<Entry> {
return new ReadOnlyObjectWrapper<>(param.getValue().getValue());
});
entryCol.setCellFactory(p -> new SearchEntryCell());
String address = walletForm.getNodeEntry(KeyPurpose.RECEIVE).getAddress().toString();
if(address != null) {
String address = walletForms.iterator().next().getNodeEntry(KeyPurpose.RECEIVE).getAddress().toString();
entryCol.setMinWidth(TextUtils.computeTextWidth(AppServices.getMonospaceFont(), address, 0.0));
}
results.getColumns().add(entryCol);
TreeTableColumn<Entry, String> labelCol = new TreeTableColumn<>("Label");
@ -138,6 +148,7 @@ public class SearchWalletDialog extends Dialog<Entry> {
//ignore
}
for(WalletForm walletForm : walletForms) {
WalletTransactionsEntry walletTransactionsEntry = walletForm.getWalletTransactionsEntry();
for(Entry entry : walletTransactionsEntry.getChildren()) {
if(entry instanceof TransactionEntry transactionEntry) {
@ -173,8 +184,9 @@ public class SearchWalletDialog extends Dialog<Entry> {
}
}
}
}
SearchWalletEntry rootEntry = new SearchWalletEntry(walletForm.getWallet(), matchingEntries);
SearchWalletEntry rootEntry = new SearchWalletEntry(walletForms.iterator().next().getWallet(), matchingEntries);
RecursiveTreeItem<Entry> rootItem = new RecursiveTreeItem<>(rootEntry, Entry::getChildren);
results.setRoot(rootItem);
}

View file

@ -105,7 +105,7 @@ public class AddressesController extends WalletFormController implements Initial
if(event.getWallet().equals(getWalletForm().getWallet()) && event.getEntry().getWalletFunction() == Function.ADDRESSES) {
List<AddressTreeTable> addressTreeTables = List.of(receiveTable, changeTable);
for(AddressTreeTable addressTreeTable : addressTreeTables) {
selectEntry(addressTreeTable, event.getEntry());
selectEntry(addressTreeTable, addressTreeTable.getRoot(), event.getEntry());
}
}
}

View file

@ -71,7 +71,7 @@ public class HashIndexEntry extends Entry implements Comparable<HashIndexEntry>
@Override
public String getEntryType() {
return "Hash Index";
return type == Type.INPUT ? "Input" : "Output";
}
@Override

View file

@ -33,4 +33,9 @@ public class TransactionHashIndexEntry extends HashIndexEntry {
public boolean isSpent() {
return false;
}
@Override
public Function getWalletFunction() {
return Function.TRANSACTIONS;
}
}

View file

@ -281,7 +281,7 @@ public class TransactionsController extends WalletFormController implements Init
@Subscribe
public void selectEntry(SelectEntryEvent event) {
if(event.getWallet().equals(getWalletForm().getWallet()) && event.getEntry().getWalletFunction() == Function.TRANSACTIONS) {
selectEntry(transactionsTable, event.getEntry());
selectEntry(transactionsTable, transactionsTable.getRoot(), event.getEntry());
}
}
}

View file

@ -609,7 +609,7 @@ public class UtxosController extends WalletFormController implements Initializab
public void selectEntry(SelectEntryEvent event) {
if(event.getWallet().equals(getWalletForm().getWallet()) && event.getEntry().getWalletFunction() == Function.UTXOS) {
utxosTable.getSelectionModel().clearSelection();
selectEntry(utxosTable, event.getEntry());
selectEntry(utxosTable, utxosTable.getRoot(), event.getEntry());
}
}
}

View file

@ -68,16 +68,24 @@ public abstract class WalletFormController extends BaseController {
}
}
protected void selectEntry(TreeTableView<Entry> treeTableView, Entry entry) {
for(TreeItem<Entry> treeEntry : treeTableView.getRoot().getChildren()) {
protected boolean selectEntry(TreeTableView<Entry> treeTableView, TreeItem<Entry> parentEntry, Entry entry) {
for(TreeItem<Entry> treeEntry : parentEntry.getChildren()) {
if(treeEntry.getValue().equals(entry)) {
treeTableView.getSelectionModel().select(treeEntry);
Platform.runLater(() -> {
treeTableView.requestFocus();
treeTableView.getSelectionModel().select(treeEntry);
treeTableView.scrollTo(treeTableView.getSelectionModel().getSelectedIndex());
});
break;
return true;
}
boolean selectedChild = selectEntry(treeTableView, treeEntry, entry);
if(selectedChild) {
treeEntry.setExpanded(true);
return true;
}
}
return false;
}
}