mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Clean up AccountsViews
This commit is contained in:
parent
e266232b17
commit
44a858becc
1 changed files with 22 additions and 91 deletions
|
@ -17,16 +17,13 @@
|
|||
|
||||
package bisq.desktop.main.account.content.altcoinaccounts;
|
||||
|
||||
import bisq.desktop.common.view.ActivatableViewAndModel;
|
||||
import bisq.desktop.common.view.FxmlView;
|
||||
import bisq.desktop.components.AutoTooltipButton;
|
||||
import bisq.desktop.components.AutoTooltipLabel;
|
||||
import bisq.desktop.components.TitledGroupBg;
|
||||
import bisq.desktop.components.paymentmethods.CryptoCurrencyForm;
|
||||
import bisq.desktop.components.paymentmethods.PaymentMethodForm;
|
||||
import bisq.desktop.main.account.content.PaymentAccountsView;
|
||||
import bisq.desktop.main.overlays.popups.Popup;
|
||||
import bisq.desktop.util.FormBuilder;
|
||||
import bisq.desktop.util.ImageUtil;
|
||||
import bisq.desktop.util.Layout;
|
||||
|
||||
import bisq.core.dao.governance.asset.AssetService;
|
||||
|
@ -41,7 +38,6 @@ import bisq.core.payment.validation.AltCoinAddressValidator;
|
|||
import bisq.core.util.BSFormatter;
|
||||
import bisq.core.util.validation.InputValidator;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.util.Tuple2;
|
||||
import bisq.common.util.Tuple3;
|
||||
|
||||
|
@ -51,18 +47,11 @@ import javafx.stage.Stage;
|
|||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.ListView;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
|
||||
import javafx.util.Callback;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import static bisq.desktop.util.FormBuilder.add2ButtonsAfterGroup;
|
||||
import static bisq.desktop.util.FormBuilder.add3ButtonsAfterGroup;
|
||||
|
@ -70,9 +59,7 @@ import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
|
|||
import static bisq.desktop.util.FormBuilder.addTopLabelListView;
|
||||
|
||||
@FxmlView
|
||||
public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCoinAccountsViewModel> {
|
||||
|
||||
private ListView<PaymentAccount> paymentAccountsListView;
|
||||
public class AltCoinAccountsView extends PaymentAccountsView<GridPane, AltCoinAccountsViewModel> {
|
||||
|
||||
private final InputValidator inputValidator;
|
||||
private final AltCoinAddressValidator altCoinAddressValidator;
|
||||
|
@ -82,9 +69,8 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
|
||||
private PaymentMethodForm paymentMethodForm;
|
||||
private TitledGroupBg accountTitledGroupBg;
|
||||
private Button addAccountButton, saveNewAccountButton, exportButton, importButton;
|
||||
private Button saveNewAccountButton;
|
||||
private int gridRow = 0;
|
||||
private ChangeListener<PaymentAccount> paymentAccountChangeListener;
|
||||
|
||||
@Inject
|
||||
public AltCoinAccountsView(AltCoinAccountsViewModel model,
|
||||
|
@ -103,32 +89,18 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
buildForm();
|
||||
paymentAccountChangeListener = (observable, oldValue, newValue) -> {
|
||||
if (newValue != null)
|
||||
onSelectAccount(newValue);
|
||||
};
|
||||
Label placeholder = new AutoTooltipLabel(Res.get("shared.noAccountsSetupYet"));
|
||||
placeholder.setWrapText(true);
|
||||
paymentAccountsListView.setPlaceholder(placeholder);
|
||||
protected ObservableList<PaymentAccount> getPaymentAccounts() {
|
||||
return model.getPaymentAccounts();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate() {
|
||||
paymentAccountsListView.setItems(model.getPaymentAccounts());
|
||||
paymentAccountsListView.getSelectionModel().selectedItemProperty().addListener(paymentAccountChangeListener);
|
||||
addAccountButton.setOnAction(event -> addNewAccount());
|
||||
exportButton.setOnAction(event -> model.dataModel.exportAccounts((Stage) root.getScene().getWindow()));
|
||||
importButton.setOnAction(event -> model.dataModel.importAccounts((Stage) root.getScene().getWindow()));
|
||||
protected void importAccounts() {
|
||||
model.dataModel.importAccounts((Stage) root.getScene().getWindow());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
paymentAccountsListView.getSelectionModel().selectedItemProperty().removeListener(paymentAccountChangeListener);
|
||||
addAccountButton.setOnAction(null);
|
||||
exportButton.setOnAction(null);
|
||||
importButton.setOnAction(null);
|
||||
protected void exportAccounts() {
|
||||
model.dataModel.exportAccounts((Stage) root.getScene().getWindow());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -188,8 +160,8 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
break;
|
||||
}
|
||||
|
||||
if (!model.getPaymentAccounts().stream().filter(e -> e.getAccountName() != null &&
|
||||
e.getAccountName().equals(paymentAccount.getAccountName())).findAny().isPresent()) {
|
||||
if (model.getPaymentAccounts().stream().noneMatch(e -> e.getAccountName() != null &&
|
||||
e.getAccountName().equals(paymentAccount.getAccountName()))) {
|
||||
model.onSaveNewAccount(paymentAccount);
|
||||
removeNewAccountForm();
|
||||
} else {
|
||||
|
@ -202,62 +174,17 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
removeNewAccountForm();
|
||||
}
|
||||
|
||||
private void onDeleteAccount(PaymentAccount paymentAccount) {
|
||||
new Popup<>().warning(Res.get("shared.askConfirmDeleteAccount"))
|
||||
.actionButtonText(Res.get("shared.yes"))
|
||||
.onAction(() -> {
|
||||
boolean isPaymentAccountUsed = model.onDeleteAccount(paymentAccount);
|
||||
if (!isPaymentAccountUsed)
|
||||
removeSelectAccountForm();
|
||||
else
|
||||
UserThread.runAfter(() -> new Popup<>().warning(
|
||||
Res.get("shared.cannotDeleteAccount"))
|
||||
.show(), 100, TimeUnit.MILLISECONDS);
|
||||
})
|
||||
.closeButtonText(Res.get("shared.cancel"))
|
||||
.show();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Base form
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void buildForm() {
|
||||
protected void buildForm() {
|
||||
addTitledGroupBg(root, gridRow, 2, Res.get("shared.manageAccounts"));
|
||||
|
||||
Tuple3<Label, ListView<PaymentAccount>, VBox> tuple = addTopLabelListView(root, gridRow, Res.get("account.altcoin.yourAltcoinAccounts"), Layout.FIRST_ROW_DISTANCE);
|
||||
paymentAccountsListView = tuple.second;
|
||||
paymentAccountsListView.setPrefHeight(2 * Layout.LIST_ROW_HEIGHT + 14);
|
||||
paymentAccountsListView.setCellFactory(new Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>>() {
|
||||
@Override
|
||||
public ListCell<PaymentAccount> call(ListView<PaymentAccount> list) {
|
||||
return new ListCell<PaymentAccount>() {
|
||||
final Label label = new AutoTooltipLabel();
|
||||
final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);
|
||||
final Button removeButton = new AutoTooltipButton("", icon);
|
||||
final AnchorPane pane = new AnchorPane(label, removeButton);
|
||||
|
||||
{
|
||||
label.setLayoutY(5);
|
||||
removeButton.setId("icon-button");
|
||||
AnchorPane.setRightAnchor(removeButton, 0d);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateItem(final PaymentAccount item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty) {
|
||||
label.setText(item.getAccountName());
|
||||
removeButton.setOnAction(e -> onDeleteAccount(item));
|
||||
setGraphic(pane);
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
setPaymentAccountsCellFactory();
|
||||
|
||||
Tuple3<Button, Button, Button> tuple3 = add3ButtonsAfterGroup(root, ++gridRow, Res.get("shared.addNewAccount"),
|
||||
Res.get("shared.ExportAccounts"), Res.get("shared.importAccounts"));
|
||||
|
@ -267,7 +194,7 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
}
|
||||
|
||||
// Add new account form
|
||||
private void addNewAccount() {
|
||||
protected void addNewAccount() {
|
||||
paymentAccountsListView.getSelectionModel().clearSelection();
|
||||
removeAccountRows();
|
||||
addAccountButton.setDisable(true);
|
||||
|
@ -291,7 +218,7 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
}
|
||||
|
||||
// Select account form
|
||||
private void onSelectAccount(PaymentAccount paymentAccount) {
|
||||
protected void onSelectAccount(PaymentAccount paymentAccount) {
|
||||
removeAccountRows();
|
||||
addAccountButton.setDisable(false);
|
||||
accountTitledGroupBg = addTitledGroupBg(root, ++gridRow, 1, Res.get("shared.selectedAccount"), Layout.GROUP_DISTANCE);
|
||||
|
@ -329,17 +256,21 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
|||
addAccountButton.setDisable(false);
|
||||
}
|
||||
|
||||
private void removeSelectAccountForm() {
|
||||
@Override
|
||||
protected void removeSelectAccountForm() {
|
||||
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
||||
gridRow = 1;
|
||||
addAccountButton.setDisable(false);
|
||||
paymentAccountsListView.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean deleteAccountFromModel(PaymentAccount paymentAccount) {
|
||||
return model.onDeleteAccount(paymentAccount);
|
||||
}
|
||||
|
||||
private void removeAccountRows() {
|
||||
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
||||
gridRow = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue