mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 13:16:44 +00:00
refactor cointreetable column sorting, add default sorting if table was empty
This commit is contained in:
parent
97f21394a7
commit
05a1fd8e8d
3 changed files with 15 additions and 14 deletions
|
@ -18,6 +18,7 @@ import javafx.geometry.Pos;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import javafx.scene.control.Hyperlink;
|
import javafx.scene.control.Hyperlink;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TreeTableColumn;
|
||||||
import javafx.scene.control.TreeTableView;
|
import javafx.scene.control.TreeTableView;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
|
@ -133,4 +134,12 @@ public class CoinTreeTable extends TreeTableView<Entry> {
|
||||||
stackPane.setAlignment(Pos.CENTER);
|
stackPane.setAlignment(Pos.CENTER);
|
||||||
return stackPane;
|
return stackPane;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSortColumn(int columnIndex, TreeTableColumn.SortType sortType) {
|
||||||
|
if(columnIndex >= 0 && columnIndex < getColumns().size() && getSortOrder().isEmpty() && !getRoot().getChildren().isEmpty()) {
|
||||||
|
TreeTableColumn<Entry, ?> column = getColumns().get(columnIndex);
|
||||||
|
column.setSortType(sortType == null ? TreeTableColumn.SortType.DESCENDING : sortType);
|
||||||
|
getSortOrder().add(column);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,7 @@ public class TransactionsTreeTable extends CoinTreeTable {
|
||||||
setPlaceholder(getDefaultPlaceholder(rootEntry.getWallet()));
|
setPlaceholder(getDefaultPlaceholder(rootEntry.getWallet()));
|
||||||
setEditable(true);
|
setEditable(true);
|
||||||
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
||||||
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
setSortColumn(0, TreeTableColumn.SortType.DESCENDING);
|
||||||
getSortOrder().add(dateCol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAll(WalletTransactionsEntry rootEntry) {
|
public void updateAll(WalletTransactionsEntry rootEntry) {
|
||||||
|
@ -61,16 +60,13 @@ public class TransactionsTreeTable extends CoinTreeTable {
|
||||||
setRoot(rootItem);
|
setRoot(rootItem);
|
||||||
rootItem.setExpanded(true);
|
rootItem.setExpanded(true);
|
||||||
|
|
||||||
if(getColumns().size() > 0 && getSortOrder().isEmpty()) {
|
setSortColumn(0, TreeTableColumn.SortType.DESCENDING);
|
||||||
TreeTableColumn<Entry, ?> dateCol = getColumns().get(0);
|
|
||||||
getSortOrder().add(dateCol);
|
|
||||||
dateCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHistory() {
|
public void updateHistory() {
|
||||||
//Transaction entries should have already been updated using WalletTransactionsEntry.updateHistory, so only a resort required
|
//Transaction entries should have already been updated using WalletTransactionsEntry.updateHistory, so only a resort required
|
||||||
sort();
|
sort();
|
||||||
|
setSortColumn(0, TreeTableColumn.SortType.DESCENDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateLabel(Entry entry) {
|
public void updateLabel(Entry entry) {
|
||||||
|
|
|
@ -83,8 +83,7 @@ public class UtxosTreeTable extends CoinTreeTable {
|
||||||
setPlaceholder(getDefaultPlaceholder(rootEntry.getWallet()));
|
setPlaceholder(getDefaultPlaceholder(rootEntry.getWallet()));
|
||||||
setEditable(true);
|
setEditable(true);
|
||||||
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
|
||||||
amountCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
setSortColumn(getColumns().size() - 1, TreeTableColumn.SortType.DESCENDING);
|
||||||
getSortOrder().add(amountCol);
|
|
||||||
|
|
||||||
getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
}
|
}
|
||||||
|
@ -96,17 +95,14 @@ public class UtxosTreeTable extends CoinTreeTable {
|
||||||
setRoot(rootItem);
|
setRoot(rootItem);
|
||||||
rootItem.setExpanded(true);
|
rootItem.setExpanded(true);
|
||||||
|
|
||||||
if(getColumns().size() > 0 && getSortOrder().isEmpty()) {
|
setSortColumn(getColumns().size() - 1, TreeTableColumn.SortType.DESCENDING);
|
||||||
TreeTableColumn<Entry, ?> amountCol = getColumns().get(getColumns().size() - 1);
|
|
||||||
getSortOrder().add(amountCol);
|
|
||||||
amountCol.setSortType(TreeTableColumn.SortType.DESCENDING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHistory() {
|
public void updateHistory() {
|
||||||
//Utxo entries should have already been updated, so only a resort required
|
//Utxo entries should have already been updated, so only a resort required
|
||||||
if(!getRoot().getChildren().isEmpty()) {
|
if(!getRoot().getChildren().isEmpty()) {
|
||||||
sort();
|
sort();
|
||||||
|
setSortColumn(getColumns().size() - 1, TreeTableColumn.SortType.DESCENDING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue