mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +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;
|
package bisq.desktop.main.account.content.altcoinaccounts;
|
||||||
|
|
||||||
import bisq.desktop.common.view.ActivatableViewAndModel;
|
|
||||||
import bisq.desktop.common.view.FxmlView;
|
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.TitledGroupBg;
|
||||||
import bisq.desktop.components.paymentmethods.CryptoCurrencyForm;
|
import bisq.desktop.components.paymentmethods.CryptoCurrencyForm;
|
||||||
import bisq.desktop.components.paymentmethods.PaymentMethodForm;
|
import bisq.desktop.components.paymentmethods.PaymentMethodForm;
|
||||||
|
import bisq.desktop.main.account.content.PaymentAccountsView;
|
||||||
import bisq.desktop.main.overlays.popups.Popup;
|
import bisq.desktop.main.overlays.popups.Popup;
|
||||||
import bisq.desktop.util.FormBuilder;
|
import bisq.desktop.util.FormBuilder;
|
||||||
import bisq.desktop.util.ImageUtil;
|
|
||||||
import bisq.desktop.util.Layout;
|
import bisq.desktop.util.Layout;
|
||||||
|
|
||||||
import bisq.core.dao.governance.asset.AssetService;
|
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.BSFormatter;
|
||||||
import bisq.core.util.validation.InputValidator;
|
import bisq.core.util.validation.InputValidator;
|
||||||
|
|
||||||
import bisq.common.UserThread;
|
|
||||||
import bisq.common.util.Tuple2;
|
import bisq.common.util.Tuple2;
|
||||||
import bisq.common.util.Tuple3;
|
import bisq.common.util.Tuple3;
|
||||||
|
|
||||||
|
@ -51,18 +47,11 @@ import javafx.stage.Stage;
|
||||||
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.ListCell;
|
|
||||||
import javafx.scene.control.ListView;
|
import javafx.scene.control.ListView;
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
import javafx.scene.layout.GridPane;
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import javafx.beans.value.ChangeListener;
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
import javafx.util.Callback;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static bisq.desktop.util.FormBuilder.add2ButtonsAfterGroup;
|
import static bisq.desktop.util.FormBuilder.add2ButtonsAfterGroup;
|
||||||
import static bisq.desktop.util.FormBuilder.add3ButtonsAfterGroup;
|
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;
|
import static bisq.desktop.util.FormBuilder.addTopLabelListView;
|
||||||
|
|
||||||
@FxmlView
|
@FxmlView
|
||||||
public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCoinAccountsViewModel> {
|
public class AltCoinAccountsView extends PaymentAccountsView<GridPane, AltCoinAccountsViewModel> {
|
||||||
|
|
||||||
private ListView<PaymentAccount> paymentAccountsListView;
|
|
||||||
|
|
||||||
private final InputValidator inputValidator;
|
private final InputValidator inputValidator;
|
||||||
private final AltCoinAddressValidator altCoinAddressValidator;
|
private final AltCoinAddressValidator altCoinAddressValidator;
|
||||||
|
@ -82,9 +69,8 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
|
|
||||||
private PaymentMethodForm paymentMethodForm;
|
private PaymentMethodForm paymentMethodForm;
|
||||||
private TitledGroupBg accountTitledGroupBg;
|
private TitledGroupBg accountTitledGroupBg;
|
||||||
private Button addAccountButton, saveNewAccountButton, exportButton, importButton;
|
private Button saveNewAccountButton;
|
||||||
private int gridRow = 0;
|
private int gridRow = 0;
|
||||||
private ChangeListener<PaymentAccount> paymentAccountChangeListener;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AltCoinAccountsView(AltCoinAccountsViewModel model,
|
public AltCoinAccountsView(AltCoinAccountsViewModel model,
|
||||||
|
@ -103,32 +89,18 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
protected ObservableList<PaymentAccount> getPaymentAccounts() {
|
||||||
buildForm();
|
return model.getPaymentAccounts();
|
||||||
paymentAccountChangeListener = (observable, oldValue, newValue) -> {
|
|
||||||
if (newValue != null)
|
|
||||||
onSelectAccount(newValue);
|
|
||||||
};
|
|
||||||
Label placeholder = new AutoTooltipLabel(Res.get("shared.noAccountsSetupYet"));
|
|
||||||
placeholder.setWrapText(true);
|
|
||||||
paymentAccountsListView.setPlaceholder(placeholder);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void activate() {
|
protected void importAccounts() {
|
||||||
paymentAccountsListView.setItems(model.getPaymentAccounts());
|
model.dataModel.importAccounts((Stage) root.getScene().getWindow());
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void deactivate() {
|
protected void exportAccounts() {
|
||||||
paymentAccountsListView.getSelectionModel().selectedItemProperty().removeListener(paymentAccountChangeListener);
|
model.dataModel.exportAccounts((Stage) root.getScene().getWindow());
|
||||||
addAccountButton.setOnAction(null);
|
|
||||||
exportButton.setOnAction(null);
|
|
||||||
importButton.setOnAction(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -188,8 +160,8 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!model.getPaymentAccounts().stream().filter(e -> e.getAccountName() != null &&
|
if (model.getPaymentAccounts().stream().noneMatch(e -> e.getAccountName() != null &&
|
||||||
e.getAccountName().equals(paymentAccount.getAccountName())).findAny().isPresent()) {
|
e.getAccountName().equals(paymentAccount.getAccountName()))) {
|
||||||
model.onSaveNewAccount(paymentAccount);
|
model.onSaveNewAccount(paymentAccount);
|
||||||
removeNewAccountForm();
|
removeNewAccountForm();
|
||||||
} else {
|
} else {
|
||||||
|
@ -202,62 +174,17 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
removeNewAccountForm();
|
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
|
// Base form
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
private void buildForm() {
|
protected void buildForm() {
|
||||||
addTitledGroupBg(root, gridRow, 2, Res.get("shared.manageAccounts"));
|
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);
|
Tuple3<Label, ListView<PaymentAccount>, VBox> tuple = addTopLabelListView(root, gridRow, Res.get("account.altcoin.yourAltcoinAccounts"), Layout.FIRST_ROW_DISTANCE);
|
||||||
paymentAccountsListView = tuple.second;
|
paymentAccountsListView = tuple.second;
|
||||||
paymentAccountsListView.setPrefHeight(2 * Layout.LIST_ROW_HEIGHT + 14);
|
paymentAccountsListView.setPrefHeight(2 * Layout.LIST_ROW_HEIGHT + 14);
|
||||||
paymentAccountsListView.setCellFactory(new Callback<ListView<PaymentAccount>, ListCell<PaymentAccount>>() {
|
setPaymentAccountsCellFactory();
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Tuple3<Button, Button, Button> tuple3 = add3ButtonsAfterGroup(root, ++gridRow, Res.get("shared.addNewAccount"),
|
Tuple3<Button, Button, Button> tuple3 = add3ButtonsAfterGroup(root, ++gridRow, Res.get("shared.addNewAccount"),
|
||||||
Res.get("shared.ExportAccounts"), Res.get("shared.importAccounts"));
|
Res.get("shared.ExportAccounts"), Res.get("shared.importAccounts"));
|
||||||
|
@ -267,7 +194,7 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new account form
|
// Add new account form
|
||||||
private void addNewAccount() {
|
protected void addNewAccount() {
|
||||||
paymentAccountsListView.getSelectionModel().clearSelection();
|
paymentAccountsListView.getSelectionModel().clearSelection();
|
||||||
removeAccountRows();
|
removeAccountRows();
|
||||||
addAccountButton.setDisable(true);
|
addAccountButton.setDisable(true);
|
||||||
|
@ -291,7 +218,7 @@ public class AltCoinAccountsView extends ActivatableViewAndModel<GridPane, AltCo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select account form
|
// Select account form
|
||||||
private void onSelectAccount(PaymentAccount paymentAccount) {
|
protected void onSelectAccount(PaymentAccount paymentAccount) {
|
||||||
removeAccountRows();
|
removeAccountRows();
|
||||||
addAccountButton.setDisable(false);
|
addAccountButton.setDisable(false);
|
||||||
accountTitledGroupBg = addTitledGroupBg(root, ++gridRow, 1, Res.get("shared.selectedAccount"), Layout.GROUP_DISTANCE);
|
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);
|
addAccountButton.setDisable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeSelectAccountForm() {
|
@Override
|
||||||
|
protected void removeSelectAccountForm() {
|
||||||
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
||||||
gridRow = 1;
|
gridRow = 1;
|
||||||
addAccountButton.setDisable(false);
|
addAccountButton.setDisable(false);
|
||||||
paymentAccountsListView.getSelectionModel().clearSelection();
|
paymentAccountsListView.getSelectionModel().clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean deleteAccountFromModel(PaymentAccount paymentAccount) {
|
||||||
|
return model.onDeleteAccount(paymentAccount);
|
||||||
|
}
|
||||||
|
|
||||||
private void removeAccountRows() {
|
private void removeAccountRows() {
|
||||||
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
FormBuilder.removeRowsFromGridPane(root, 2, gridRow);
|
||||||
gridRow = 1;
|
gridRow = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue