Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SortAddresses: addresses are now sortable descending/ascending by bal… #88

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class AddressController implements Initializable, PropertyChangeListener
private Text addressDisplay;
@FXML
private CheckBox chkAddress;
@FXML
private CheckBox chkAmountSort;

@Override
public void initialize(URL url, ResourceBundle rb) {
Expand All @@ -84,6 +86,7 @@ public void initialize(URL url, ResourceBundle rb) {
addresses.addPropertyChangeListener(this);
setupAddressList();
addresses.setSelected(chkAddress.isSelected());
addresses.setSorted(chkAmountSort.isSelected());
// addButtonToTable();
}

Expand Down Expand Up @@ -248,6 +251,14 @@ private void copyToClipboard(String address) {
@FXML
private void onChecboxChange(MouseEvent event) {
addresses.setSelected(chkAddress.isSelected());
addresses.setSorted(chkAmountSort.isSelected());
loadAddresses();
}

@FXML
private void onSortChange(MouseEvent event) {
addresses.setSelected(chkAddress.isSelected());
addresses.setSorted(chkAmountSort.isSelected());
loadAddresses();
}
}
14 changes: 14 additions & 0 deletions fx/src/main/java/org/unigrid/janus/model/AddressListModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ of the License (see COPYING and COPYING.addendum).

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Comparator;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import lombok.Getter;
Expand All @@ -33,6 +35,8 @@ public class AddressListModel {
private static ObservableList<Address> addresses = FXCollections.observableArrayList();
@Getter @Setter
private Boolean selected;
@Getter @Setter
private Boolean sorted;

public AddressListModel() {
if (this.pcs != null) {
Expand All @@ -56,6 +60,7 @@ public ObservableList<Address> getAddresses() {
public void setAddresses(ListAddressBalances list) {
int oldCount = 0;
addresses.clear();

int newCount = 0;
for (Address g : list.getResult()) {
//System.out.println(String.format("address: %s", g.getAmount()));
Expand All @@ -70,6 +75,15 @@ public void setAddresses(ListAddressBalances list) {
}
}

if(sorted) {
addresses.sort(Comparator.comparingDouble(Address::getAmount)
.reversed());
//System.out.println(String.format("addresses: %s", addresses.size()));
} else {
addresses.sort(Comparator.comparingDouble(Address::getAmount));
//System.out.println(String.format("addresses: %s", addresses.size()));
}

this.pcs.firePropertyChange(this.ADDRESS_LIST, oldCount, newCount);
}
}
26 changes: 19 additions & 7 deletions fx/src/main/resources/org/unigrid/janus/view/address.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<?import org.unigrid.janus.view.component.PTableColumn?>
<?import org.unigrid.janus.view.component.WindowBarButton?>

<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="364.0" prefWidth="450.0" style="-fx-background-color: linear-gradient(from 75px 75px to 200px 150px, #00001c, #000024);" stylesheets="@main.css" xmlns="http://javafx.com/javafx/" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.janus.controller.AddressController">
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="364.0" prefWidth="450.0" style="-fx-background-color: linear-gradient(from 75px 75px to 200px 150px, #00001c, #000024);" stylesheets="@main.css" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.unigrid.janus.controller.AddressController">
<children>
<VBox maxWidth="1.7976931348623157E308" prefHeight="364.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
Expand Down Expand Up @@ -87,19 +87,31 @@
<Insets bottom="10.0" />
</VBox.margin>
</FlowPane>
<CheckBox fx:id="chkAddress" mnemonicParsing="false" onMouseClicked="#onChecboxChange" text="Hide zero balances" textFill="#2e7090">
<padding>
<Insets left="20.0" />
</padding>
</CheckBox>
<FlowPane>
<children>
<CheckBox fx:id="chkAddress" mnemonicParsing="false" onMouseClicked="#onChecboxChange" text="Hide zero balances" textFill="#2e7090">
<padding>
<Insets left="20.0" />
</padding>
</CheckBox>
<CheckBox fx:id="chkAmountSort" mnemonicParsing="false" onMouseClicked="#onSortChange" selected="true" text="Descending" textFill="#2e7090">
<padding>
<Insets left="20.0" />
</padding>
</CheckBox>
</children>
<VBox.margin>
<Insets bottom="5.0" />
</VBox.margin>
</FlowPane>
<StackPane VBox.vgrow="ALWAYS">
<children>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" StackPane.alignment="CENTER">
<children>
<TableView fx:id="tblAddresses" VBox.vgrow="ALWAYS">
<columns>
<PTableColumn fx:id="colAddress" editable="false" percentageWidth="0.48" prefWidth="130.0" sortType="DESCENDING" sortable="false" text="Address" />
<PTableColumn fx:id="colAddressBalance" editable="false" percentageWidth="0.39" prefWidth="85.0" sortable="false" text="Balance" />
<PTableColumn fx:id="colAddressBalance" editable="false" percentageWidth="0.39" prefWidth="85.0" sortType="DESCENDING" sortable="false" text="Balance" />
</columns>
<VBox.margin>
<Insets />
Expand Down