From 44a858becc5e47943c943ffeb1bed3d693e514d0 Mon Sep 17 00:00:00 2001 From: Christoph Atteneder Date: Mon, 29 Oct 2018 09:34:40 +0100 Subject: [PATCH] Clean up AccountsViews --- .../altcoinaccounts/AltCoinAccountsView.java | 113 ++++-------------- 1 file changed, 22 insertions(+), 91 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java index 2958585f34..c90fab6e93 100644 --- a/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java +++ b/desktop/src/main/java/bisq/desktop/main/account/content/altcoinaccounts/AltCoinAccountsView.java @@ -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 { - - private ListView paymentAccountsListView; +public class AltCoinAccountsView extends PaymentAccountsView { private final InputValidator inputValidator; private final AltCoinAddressValidator altCoinAddressValidator; @@ -82,9 +69,8 @@ public class AltCoinAccountsView extends ActivatableViewAndModel paymentAccountChangeListener; @Inject public AltCoinAccountsView(AltCoinAccountsViewModel model, @@ -103,32 +89,18 @@ public class AltCoinAccountsView extends ActivatableViewAndModel { - if (newValue != null) - onSelectAccount(newValue); - }; - Label placeholder = new AutoTooltipLabel(Res.get("shared.noAccountsSetupYet")); - placeholder.setWrapText(true); - paymentAccountsListView.setPlaceholder(placeholder); + protected ObservableList 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 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().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, 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, ListCell>() { - @Override - public ListCell call(ListView list) { - return new ListCell() { - 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 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