Refactor navigation handling

This commit is contained in:
Manfred Karrer 2014-09-15 23:08:03 +02:00
parent 4384125985
commit 33e8a8f921
21 changed files with 375 additions and 349 deletions

View file

@ -25,21 +25,21 @@ public enum NavigationItem {
// Application // Application
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
MAIN(0, "/io/bitsquare/gui/main/MainView.fxml"), MAIN("/io/bitsquare/gui/main/MainView.fxml"),
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Main menu screens // Main menu screens
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
HOME(1, "/io/bitsquare/gui/main/home/HomeView.fxml", ImageUtil.HOME, ImageUtil.HOME_ACTIVE), HOME("/io/bitsquare/gui/main/home/HomeView.fxml", ImageUtil.HOME, ImageUtil.HOME_ACTIVE),
BUY(1, "/io/bitsquare/gui/main/trade/BuyView.fxml", ImageUtil.NAV_BUY, ImageUtil.NAV_BUY_ACTIVE), BUY("/io/bitsquare/gui/main/trade/BuyView.fxml", ImageUtil.BUY, ImageUtil.BUY_ACTIVE),
SELL(1, "/io/bitsquare/gui/main/trade/SellView.fxml", ImageUtil.NAV_SELL, ImageUtil.NAV_SELL_ACTIVE), SELL("/io/bitsquare/gui/main/trade/SellView.fxml", ImageUtil.SELL, ImageUtil.SELL_ACTIVE),
ORDERS(1, "/io/bitsquare/gui/main/orders/OrdersView.fxml", ImageUtil.ORDERS, ImageUtil.ORDERS_ACTIVE), ORDERS("/io/bitsquare/gui/main/orders/OrdersView.fxml", ImageUtil.ORDERS, ImageUtil.ORDERS_ACTIVE),
FUNDS(1, "/io/bitsquare/gui/main/funds/FundsView.fxml", ImageUtil.FUNDS, ImageUtil.FUNDS_ACTIVE), FUNDS("/io/bitsquare/gui/main/funds/FundsView.fxml", ImageUtil.FUNDS, ImageUtil.FUNDS_ACTIVE),
MSG(1, "/io/bitsquare/gui/main/msg/MsgView.fxml", ImageUtil.MSG, ImageUtil.MSG_ACTIVE), MSG("/io/bitsquare/gui/main/msg/MsgView.fxml", ImageUtil.MSG, ImageUtil.MSG_ACTIVE),
SETTINGS(1, "/io/bitsquare/gui/main/settings/SettingsView.fxml", ImageUtil.SETTINGS, ImageUtil.SETTINGS_ACTIVE), SETTINGS("/io/bitsquare/gui/main/settings/SettingsView.fxml", ImageUtil.SETTINGS, ImageUtil.SETTINGS_ACTIVE),
ACCOUNT(1, "/io/bitsquare/gui/main/account/AccountView.fxml", ImageUtil.ACCOUNT, ImageUtil.ACCOUNT_ACTIVE), ACCOUNT("/io/bitsquare/gui/main/account/AccountView.fxml", ImageUtil.ACCOUNT, ImageUtil.ACCOUNT_ACTIVE),
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -47,23 +47,23 @@ public enum NavigationItem {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// buy/sell (trade) // buy/sell (trade)
ORDER_BOOK(2, "/io/bitsquare/gui/main/trade/orderbook/OrderBookView.fxml"), ORDER_BOOK("/io/bitsquare/gui/main/trade/orderbook/OrderBookView.fxml"),
CREATE_OFFER(2, "/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.fxml"), CREATE_OFFER("/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.fxml"),
TAKE_OFFER(2, "/io/bitsquare/gui/main/trade/takeoffer/TakeOfferView.fxml"), TAKE_OFFER("/io/bitsquare/gui/main/trade/takeoffer/TakeOfferView.fxml"),
// orders // orders
OFFER(2, "/io/bitsquare/gui/main/orders/offer/OfferView.fxml"), OFFER("/io/bitsquare/gui/main/orders/offer/OfferView.fxml"),
PENDING_TRADE(2, "/io/bitsquare/gui/main/orders/pending/PendingTradeView.fxml"), PENDING_TRADE("/io/bitsquare/gui/main/orders/pending/PendingTradeView.fxml"),
CLOSED_TRADE(2, "/io/bitsquare/gui/main/orders/closed/ClosedTradeView.fxml"), CLOSED_TRADE("/io/bitsquare/gui/main/orders/closed/ClosedTradeView.fxml"),
// funds // funds
DEPOSIT(2, "/io/bitsquare/gui/main/funds/deposit/DepositView.fxml"), DEPOSIT("/io/bitsquare/gui/main/funds/deposit/DepositView.fxml"),
WITHDRAWAL(2, "/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml"), WITHDRAWAL("/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml"),
TRANSACTIONS(2, "/io/bitsquare/gui/main/funds/transactions/TransactionsView.fxml"), TRANSACTIONS("/io/bitsquare/gui/main/funds/transactions/TransactionsView.fxml"),
// account // account
ACCOUNT_SETUP(2, "/io/bitsquare/gui/main/account/setup/AccountSetupView.fxml"), ACCOUNT_SETUP("/io/bitsquare/gui/main/account/setup/AccountSetupView.fxml"),
ACCOUNT_SETTINGS(2, "/io/bitsquare/gui/main/account/settings/AccountSettingsView.fxml"), ACCOUNT_SETTINGS("/io/bitsquare/gui/main/account/settings/AccountSettingsView.fxml"),
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -71,12 +71,12 @@ public enum NavigationItem {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// account content // account content
SEED_WORDS(3, "/io/bitsquare/gui/main/account/content/seedwords/SeedWordsView.fxml"), SEED_WORDS("/io/bitsquare/gui/main/account/content/seedwords/SeedWordsView.fxml"),
ADD_PASSWORD(3, "/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"), ADD_PASSWORD("/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
CHANGE_PASSWORD(3, "/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"), CHANGE_PASSWORD("/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
RESTRICTIONS(3, "/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.fxml"), RESTRICTIONS("/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.fxml"),
REGISTRATION(3, "/io/bitsquare/gui/main/account/content/registration/RegistrationView.fxml"), REGISTRATION("/io/bitsquare/gui/main/account/content/registration/RegistrationView.fxml"),
FIAT_ACCOUNT(3, "/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.fxml"), FIAT_ACCOUNT("/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.fxml"),
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -84,39 +84,30 @@ public enum NavigationItem {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// arbitrator // arbitrator
ARBITRATOR_PROFILE(2, "/io/bitsquare/gui/main/arbitrators/profile/ArbitratorProfileView.fxml"), ARBITRATOR_PROFILE("/io/bitsquare/gui/main/arbitrators/profile/ArbitratorProfileView.fxml"),
ARBITRATOR_BROWSER(-1, "/io/bitsquare/gui/main/arbitrators/browser/ArbitratorBrowserView.fxml"), ARBITRATOR_BROWSER("/io/bitsquare/gui/main/arbitrators/browser/ArbitratorBrowserView.fxml"),
ARBITRATOR_REGISTRATION(-1, "/io/bitsquare/gui/main/arbitrators/registration/ArbitratorRegistrationView.fxml"); ARBITRATOR_REGISTRATION("/io/bitsquare/gui/main/arbitrators/registration/ArbitratorRegistrationView.fxml");
private int level;
private final String fxmlUrl; private final String fxmlUrl;
private String icon; private String icon;
private String activeIcon; private String activeIcon;
/** /**
* @param level The navigation hierarchy depth. 0 is main app level, 1 is main menu items, 2 is sub-menus,
* 3 content in sub-menus, -1 is popup window
* @param fxmlUrl * @param fxmlUrl
* @param icon * @param icon
* @param activeIcon * @param activeIcon
*/ */
NavigationItem(int level, String fxmlUrl, String icon, String activeIcon) { NavigationItem(String fxmlUrl, String icon, String activeIcon) {
this.level = level;
this.fxmlUrl = fxmlUrl; this.fxmlUrl = fxmlUrl;
this.icon = icon; this.icon = icon;
this.activeIcon = activeIcon; this.activeIcon = activeIcon;
} }
NavigationItem(int level, String fxmlUrl) { NavigationItem(String fxmlUrl) {
this.level = level;
this.fxmlUrl = fxmlUrl; this.fxmlUrl = fxmlUrl;
} }
public int getLevel() {
return level;
}
public String getFxmlUrl() { public String getFxmlUrl() {
return fxmlUrl; return fxmlUrl;
} }

View file

@ -1,22 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.gui;
public interface NavigationListener {
public void navigate(NavigationItem navigationItem);
}

View file

@ -22,27 +22,34 @@ import io.bitsquare.persistence.Persistence;
import com.google.inject.Inject; import com.google.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class NavigationManager { public class NavigationManager {
private static final Logger log = LoggerFactory.getLogger(NavigationManager.class); private static final Logger log = LoggerFactory.getLogger(NavigationManager.class);
private Persistence persistence;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Interface // Interface
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public interface NavigationListener { public interface Listener {
void onNavigationRequested(NavigationItem... navigationItems); void onNavigationRequested(NavigationItem... navigationItems);
} }
private List<NavigationListener> listeners = new ArrayList<>(); // New listeners can be added during iteration so we use CopyOnWriteArrayList to prevent invalid array
private NavigationItem[] previousMainNavigationItems; // modification
private List<Listener> listeners = new CopyOnWriteArrayList<>();
private Persistence persistence;
private NavigationItem[] currentNavigationItems; private NavigationItem[] currentNavigationItems;
// Used for returning to the last important view
// After setup is done we want to return to the last opened view (e.g. sell/buy)
private NavigationItem[] navigationItemsForReturning;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
@ -58,18 +65,38 @@ public class NavigationManager {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void navigationTo(NavigationItem... navigationItems) { public void navigationTo(NavigationItem... navigationItems) {
previousMainNavigationItems = currentNavigationItems; log.trace("navigationTo " + Arrays.asList(navigationItems).toString());
List<NavigationItem> temp = new ArrayList<>();
for (int i = 0; i < navigationItems.length; i++) {
NavigationItem item = navigationItems[i];
temp.add(item);
if (currentNavigationItems == null ||
(currentNavigationItems != null &&
currentNavigationItems.length > i &&
item != currentNavigationItems[i] &&
i != navigationItems.length - 1)) {
List<NavigationItem> temp2 = new ArrayList<>(temp);
for (int n = i + 1; n < navigationItems.length; n++) {
NavigationItem[] newTemp = new NavigationItem[i + 1];
currentNavigationItems = temp2.toArray(newTemp);
navigationTo(currentNavigationItems);
item = navigationItems[n];
temp2.add(item);
}
}
}
currentNavigationItems = navigationItems; currentNavigationItems = navigationItems;
persistence.write(this, "navigationItems", navigationItems); persistence.write(this, "navigationItems", navigationItems);
log.trace("navigationTo notify listeners " + Arrays.asList(navigationItems).toString() + " / " + listeners
.size());
listeners.stream().forEach((e) -> e.onNavigationRequested(navigationItems)); listeners.stream().forEach((e) -> e.onNavigationRequested(navigationItems));
} }
public void navigateToLastStoredItem() { public void navigateToLastStoredItem() {
NavigationItem[] navigationItems = (NavigationItem[]) persistence.read(this, "navigationItems"); NavigationItem[] navigationItems = (NavigationItem[]) persistence.read(this, "navigationItems");
if (navigationItems == null || navigationItems.length == 0) if (navigationItems == null || navigationItems.length == 0)
navigationItems = new NavigationItem[]{NavigationItem.HOME}; navigationItems = new NavigationItem[]{NavigationItem.MAIN, NavigationItem.HOME};
navigationTo(navigationItems); navigationTo(navigationItems);
} }
@ -77,11 +104,11 @@ public class NavigationManager {
// Listeners // Listeners
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void addListener(NavigationListener listener) { public void addListener(Listener listener) {
listeners.add(listener); listeners.add(listener);
} }
public void removeListener(NavigationListener listener) { public void removeListener(Listener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
@ -90,12 +117,21 @@ public class NavigationManager {
// Getters // Getters
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public NavigationItem[] getPreviousMainNavigationItems() { public NavigationItem[] getNavigationItemsForReturning() {
return previousMainNavigationItems; return navigationItemsForReturning;
} }
public NavigationItem[] getCurrentNavigationItems() { public NavigationItem[] getCurrentNavigationItems() {
return currentNavigationItems; return currentNavigationItems;
} }
///////////////////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
public void setNavigationItemsForReturning(NavigationItem[] navigationItemsForReturning) {
this.navigationItemsForReturning = navigationItemsForReturning;
}
} }

View file

@ -83,7 +83,7 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
* @param navigationItem NavigationItem to be loaded. * @param navigationItem NavigationItem to be loaded.
* @return The ViewController of the loaded view. * @return The ViewController of the loaded view.
*/ */
public Initializable loadView(NavigationItem navigationItem) { protected Initializable loadView(NavigationItem navigationItem) {
log.trace("Lifecycle: loadViewAndGetChildController " + this.getClass().getSimpleName() + " / navigationItem " + log.trace("Lifecycle: loadViewAndGetChildController " + this.getClass().getSimpleName() + " / navigationItem " +
"= " + navigationItem); "= " + navigationItem);
return null; return null;

View file

@ -57,7 +57,6 @@ public class MainViewCB extends ViewCB<MainPM> {
private final OverlayManager overlayManager; private final OverlayManager overlayManager;
private final ToggleGroup navButtonsGroup = new ToggleGroup(); private final ToggleGroup navButtonsGroup = new ToggleGroup();
private NavigationItem mainNavigationItem;
private BorderPane baseApplicationContainer; private BorderPane baseApplicationContainer;
private VBox baseOverlayContainer; private VBox baseOverlayContainer;
@ -97,20 +96,12 @@ public class MainViewCB extends ViewCB<MainPM> {
Popups.setOverlayManager(overlayManager); Popups.setOverlayManager(overlayManager);
navigationManager.addListener(navigationItems -> { navigationManager.addListener(navigationItems -> {
if (navigationItems != null) { if (navigationItems != null && navigationItems.length == 2) {
for (NavigationItem navigationItem : navigationItems) { if (navigationItems[0] == NavigationItem.MAIN) {
if (navigationItem.getLevel() == 1) { loadView(navigationItems[1]);
mainNavigationItem = navigationItem; selectMainMenuButton(navigationItems[1]);
break;
}
} }
} }
if (mainNavigationItem == null)
mainNavigationItem = NavigationItem.HOME;
loadView(mainNavigationItem);
selectMainMenuButton(mainNavigationItem);
}); });
overlayManager.addListener(new OverlayManager.OverlayListener() { overlayManager.addListener(new OverlayManager.OverlayListener() {
@ -140,9 +131,8 @@ public class MainViewCB extends ViewCB<MainPM> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override @Override
public Initializable loadView(NavigationItem navigationItem) { protected Initializable loadView(NavigationItem navigationItem) {
super.loadView((navigationItem)); super.loadView((navigationItem));
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl())); final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try { try {
final Node view = loader.load(); final Node view = loader.load();
@ -203,7 +193,9 @@ public class MainViewCB extends ViewCB<MainPM> {
alertButton.setId("nav-alert-button"); alertButton.setId("nav-alert-button");
alertButton.relocate(36, 19); alertButton.relocate(36, 19);
alertButton.setOnAction((e) -> alertButton.setOnAction((e) ->
navigationManager.navigationTo(NavigationItem.ORDERS, NavigationItem.PENDING_TRADE)); navigationManager.navigationTo(NavigationItem.MAIN,
NavigationItem.ORDERS,
NavigationItem.PENDING_TRADE));
Tooltip.install(alertButton, new Tooltip("Your offer has been accepted")); Tooltip.install(alertButton, new Tooltip("Your offer has been accepted"));
ordersButtonButtonPane.getChildren().add(alertButton); ordersButtonButtonPane.getChildren().add(alertButton);
@ -399,8 +391,7 @@ public class MainViewCB extends ViewCB<MainPM> {
} }
}); });
toggleButton.setOnAction(e -> navigationManager.navigationTo(navigationItem)); toggleButton.setOnAction(e -> navigationManager.navigationTo(NavigationItem.MAIN, navigationItem));
// toggleButton.setOnAction(e -> loadView(navigationItem));
parent.getChildren().add(toggleButton); parent.getChildren().add(toggleButton);
return toggleButton; return toggleButton;

View file

@ -21,7 +21,6 @@ import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.NavigationManager; import io.bitsquare.gui.NavigationManager;
import io.bitsquare.gui.ViewCB; import io.bitsquare.gui.ViewCB;
import io.bitsquare.gui.main.account.setup.AccountSetupViewCB;
import io.bitsquare.util.ViewLoader; import io.bitsquare.util.ViewLoader;
import java.io.IOException; import java.io.IOException;
@ -45,6 +44,7 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
public Tab tab; public Tab tab;
private NavigationManager navigationManager; private NavigationManager navigationManager;
private NavigationManager.Listener listener;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -54,6 +54,7 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
@Inject @Inject
private AccountViewCB(AccountPM presentationModel, NavigationManager navigationManager) { private AccountViewCB(AccountPM presentationModel, NavigationManager navigationManager) {
super(presentationModel); super(presentationModel);
this.navigationManager = navigationManager; this.navigationManager = navigationManager;
} }
@ -65,6 +66,13 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
listener = navigationItems -> {
if (navigationItems != null &&
navigationItems.length == 3 &&
navigationItems[1] == NavigationItem.ACCOUNT)
loadView(navigationItems[2]);
};
super.initialize(url, rb); super.initialize(url, rb);
} }
@ -72,22 +80,24 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
public void activate() { public void activate() {
super.activate(); super.activate();
if (childController == null) { navigationManager.addListener(listener);
if (presentationModel.getNeedRegistration()) {
childController = loadView(NavigationItem.ACCOUNT_SETUP); if (navigationManager.getCurrentNavigationItems().length == 2 &&
tab.setText("Account setup"); navigationManager.getCurrentNavigationItems()[1] == NavigationItem.ACCOUNT) {
} if (presentationModel.getNeedRegistration())
else { navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
childController = loadView(NavigationItem.ACCOUNT_SETTINGS); NavigationItem.ACCOUNT_SETUP);
tab.setText("Account settings"); else
} navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETTINGS);
} }
} }
@SuppressWarnings("EmptyMethod")
@Override @Override
public void deactivate() { public void deactivate() {
super.deactivate(); super.deactivate();
navigationManager.removeListener(listener);
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -102,22 +112,17 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override @Override
public Initializable loadView(NavigationItem navigationItem) { protected Initializable loadView(NavigationItem navigationItem) {
super.loadView(navigationItem); super.loadView(navigationItem);
tab.setText((navigationItem == NavigationItem.ACCOUNT_SETUP) ? "Account setup" : "Account settings");
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl())); final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try { try {
Pane view = loader.load(); AnchorPane view = loader.load();
tab.setContent(view); tab.setContent(view);
Initializable childController = loader.getController(); Initializable childController = loader.getController();
((ViewCB) childController).setParent(this); ((ViewCB) childController).setParent(this);
if (childController instanceof AccountSetupViewCB)
((AccountSetupViewCB) childController).setRemoveCallBack(() -> {
removeSetup();
return null;
});
} catch (IOException e) { } catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + NavigationItem.ACCOUNT_SETUP.getFxmlUrl()); log.error("Loading view failed. FxmlUrl = " + NavigationItem.ACCOUNT_SETUP.getFxmlUrl());
e.getStackTrace(); e.getStackTrace();
@ -130,11 +135,6 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
// Private // Private
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void removeSetup() {
childController = null;
navigationManager.navigationTo(navigationManager.getPreviousMainNavigationItems());
}
} }

View file

@ -185,7 +185,7 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override @Override
public Initializable loadView(NavigationItem navigationItem) { protected Initializable loadView(NavigationItem navigationItem) {
// TODO caching causes exception // TODO caching causes exception
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false); final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
try { try {
@ -236,7 +236,7 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
public ListCell<Locale> call(ListView<Locale> list) { public ListCell<Locale> call(ListView<Locale> list) {
return new ListCell<Locale>() { return new ListCell<Locale>() {
final Label label = new Label(); final Label label = new Label();
final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE); final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE_ICON);
final Button removeButton = new Button("", icon); final Button removeButton = new Button("", icon);
final AnchorPane pane = new AnchorPane(label, removeButton); final AnchorPane pane = new AnchorPane(label, removeButton);
@ -294,7 +294,7 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
public ListCell<Country> call(ListView<Country> list) { public ListCell<Country> call(ListView<Country> list) {
return new ListCell<Country>() { return new ListCell<Country>() {
final Label label = new Label(); final Label label = new Label();
final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE); final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE_ICON);
final Button removeButton = new Button("", icon); final Button removeButton = new Button("", icon);
final AnchorPane pane = new AnchorPane(label, removeButton); final AnchorPane pane = new AnchorPane(label, removeButton);
@ -338,7 +338,7 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
public ListCell<Arbitrator> call(ListView<Arbitrator> list) { public ListCell<Arbitrator> call(ListView<Arbitrator> list) {
return new ListCell<Arbitrator>() { return new ListCell<Arbitrator>() {
final Label label = new Label(); final Label label = new Label();
final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE); final ImageView icon = ImageUtil.getIconImageView(ImageUtil.REMOVE_ICON);
final Button removeButton = new Button("", icon); final Button removeButton = new Button("", icon);
final AnchorPane pane = new AnchorPane(label, removeButton); final AnchorPane pane = new AnchorPane(label, removeButton);

View file

@ -33,9 +33,9 @@ import java.util.ResourceBundle;
import javax.inject.Inject; import javax.inject.Inject;
import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.scene.paint.*; import javafx.scene.paint.*;
@ -50,12 +50,13 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
private static final Logger log = LoggerFactory.getLogger(AccountSettingsViewCB.class); private static final Logger log = LoggerFactory.getLogger(AccountSettingsViewCB.class);
public NavigationItem subMenuNavigationItem;
public VBox leftVBox;
public AnchorPane content;
private MenuItem seedWords, password, restrictions, fiatAccount, registration; private MenuItem seedWords, password, restrictions, fiatAccount, registration;
private NavigationManager navigationManager; private NavigationManager navigationManager;
private NavigationManager.Listener listener;
@FXML VBox leftVBox;
@FXML AnchorPane content;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
@ -75,18 +76,25 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb); listener = navigationItems -> {
if (navigationItems != null &&
navigationItems.length == 4 &&
navigationItems[2] == NavigationItem.ACCOUNT_SETTINGS) {
loadView(navigationItems[3]);
selectMainMenuButton(navigationItems[3]);
}
};
ToggleGroup toggleGroup = new ToggleGroup(); ToggleGroup toggleGroup = new ToggleGroup();
seedWords = new MenuItem(this, content, "Wallet seed", seedWords = new MenuItem(navigationManager, "Wallet seed",
NavigationItem.SEED_WORDS, toggleGroup); NavigationItem.SEED_WORDS, toggleGroup);
password = new MenuItem(this, content, "Wallet password", password = new MenuItem(navigationManager, "Wallet password",
NavigationItem.CHANGE_PASSWORD, toggleGroup); NavigationItem.CHANGE_PASSWORD, toggleGroup);
restrictions = new MenuItem(this, content, "Trading restrictions", restrictions = new MenuItem(navigationManager, "Trading restrictions",
NavigationItem.RESTRICTIONS, toggleGroup); NavigationItem.RESTRICTIONS, toggleGroup);
fiatAccount = new MenuItem(this, content, "Payments account(s)", fiatAccount = new MenuItem(navigationManager, "Payments account(s)",
NavigationItem.FIAT_ACCOUNT, toggleGroup); NavigationItem.FIAT_ACCOUNT, toggleGroup);
registration = new MenuItem(this, content, "Renew your account", registration = new MenuItem(navigationManager, "Renew your account",
NavigationItem.REGISTRATION, toggleGroup); NavigationItem.REGISTRATION, toggleGroup);
registration.setDisable(true); registration.setDisable(true);
@ -94,27 +102,72 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
leftVBox.getChildren().addAll(seedWords, password, leftVBox.getChildren().addAll(seedWords, password,
restrictions, fiatAccount, registration); restrictions, fiatAccount, registration);
super.initialize(url, rb);
} }
@Override @Override
public void activate() { public void activate() {
super.activate(); super.activate();
NavigationItem[] navigationItems = navigationManager.getCurrentNavigationItems(); navigationManager.addListener(listener);
for (int i = 0; i < navigationItems.length; i++) { NavigationItem[] items = navigationManager.getCurrentNavigationItems();
if (navigationItems[i].getLevel() == 3) { if (items.length == 3 &&
subMenuNavigationItem = navigationItems[i]; items[2] == NavigationItem.ACCOUNT_SETTINGS) {
break; navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETTINGS, NavigationItem.SEED_WORDS);
}
else {
if (items != null &&
items.length == 4 &&
items[2] == NavigationItem.ACCOUNT_SETTINGS) {
loadView(items[3]);
selectMainMenuButton(items[3]);
} }
} }
}
if (subMenuNavigationItem == null) @Override
subMenuNavigationItem = NavigationItem.SEED_WORDS; public void deactivate() {
super.deactivate();
loadView(subMenuNavigationItem); navigationManager.removeListener(listener);
}
switch (subMenuNavigationItem) { @SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected Initializable loadView(NavigationItem navigationItem) {
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
content.getChildren().setAll(view);
childController = loader.getController();
((ViewCB<? extends PresentationModel>) childController).setParent(this);
((ContextAware) childController).useSettingsContext(true);
return childController;
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.getStackTrace();
}
return null;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////////////////////////////////
private void selectMainMenuButton(NavigationItem navigationItem) {
switch (navigationItem) {
case SEED_WORDS: case SEED_WORDS:
seedWords.setSelected(true); seedWords.setSelected(true);
break; break;
@ -131,60 +184,17 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
registration.setSelected(true); registration.setSelected(true);
break; break;
default: default:
log.error(subMenuNavigationItem.getFxmlUrl() + " is no subMenuNavigationItem"); log.error(navigationItem.getFxmlUrl() + " is invalid");
break; break;
} }
} }
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public Initializable loadView(NavigationItem navigationItem) {
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
content.getChildren().setAll(view);
childController = loader.getController();
((ViewCB<? extends PresentationModel>) childController).setParent(this);
((ContextAware) childController).useSettingsContext(true);
return childController;
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.getStackTrace();
}
return null;
}
} }
class MenuItem extends ToggleButton { class MenuItem extends ToggleButton {
private static final Logger log = LoggerFactory.getLogger(MenuItem.class); private static final Logger log = LoggerFactory.getLogger(MenuItem.class);
private ViewCB<? extends PresentationModel> childController; MenuItem(NavigationManager navigationManager, String title, NavigationItem navigationItem,
private final AccountSettingsViewCB parentCB;
private final Parent content;
private final NavigationItem navigationItem;
MenuItem(AccountSettingsViewCB parentCB, Parent content, String title, NavigationItem navigationItem,
ToggleGroup toggleGroup) { ToggleGroup toggleGroup) {
this.parentCB = parentCB;
this.content = content;
this.navigationItem = navigationItem;
setToggleGroup(toggleGroup); setToggleGroup(toggleGroup);
setText(title); setText(title);
@ -204,7 +214,8 @@ class MenuItem extends ToggleButton {
setGraphic(icon); setGraphic(icon);
setOnAction((event) -> parentCB.loadView(navigationItem)); setOnAction((event) -> navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETTINGS, navigationItem));
selectedProperty().addListener((ov, oldValue, newValue) -> { selectedProperty().addListener((ov, oldValue, newValue) -> {
if (newValue) { if (newValue) {

View file

@ -19,6 +19,7 @@ package io.bitsquare.gui.main.account.setup;
import io.bitsquare.gui.CachedViewCB; import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.NavigationManager;
import io.bitsquare.gui.PresentationModel; import io.bitsquare.gui.PresentationModel;
import io.bitsquare.gui.ViewCB; import io.bitsquare.gui.ViewCB;
import io.bitsquare.gui.main.account.MultiStepNavigation; import io.bitsquare.gui.main.account.MultiStepNavigation;
@ -36,14 +37,12 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import javax.inject.Inject; import javax.inject.Inject;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.*;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.image.*; import javafx.scene.image.*;
import javafx.scene.layout.*; import javafx.scene.layout.*;
@ -56,10 +55,11 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
private static final Logger log = LoggerFactory.getLogger(AccountSetupViewCB.class); private static final Logger log = LoggerFactory.getLogger(AccountSetupViewCB.class);
private WizardItem seedWords, password, fiatAccount, restrictions, registration; private WizardItem seedWords, password, fiatAccount, restrictions, registration;
private Callable<Void> requestCloseCallable; private NavigationManager navigationManager;
private NavigationManager.Listener listener;
@FXML private VBox leftVBox; @FXML VBox leftVBox;
@FXML private AnchorPane content; @FXML AnchorPane content;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -67,8 +67,9 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Inject @Inject
private AccountSetupViewCB(AccountSetupPM presentationModel) { private AccountSetupViewCB(AccountSetupPM presentationModel, NavigationManager navigationManager) {
super(presentationModel); super(presentationModel);
this.navigationManager = navigationManager;
} }
@ -78,37 +79,49 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb); listener = navigationItems -> {
if (navigationItems != null &&
navigationItems.length == 4 &&
navigationItems[2] == NavigationItem.ACCOUNT_SETUP) {
loadView(navigationItems[3]);
}
};
seedWords = new WizardItem(this, content, "Backup wallet seed", "Write down the seed word for your wallet", seedWords = new WizardItem(navigationManager, "Backup wallet seed", "Write down the seed word for your wallet",
NavigationItem.SEED_WORDS); NavigationItem.SEED_WORDS);
password = new WizardItem(this, content, "Setup password", "Protect your wallet with a password", password = new WizardItem(navigationManager, "Setup password", "Protect your wallet with a password",
NavigationItem.ADD_PASSWORD); NavigationItem.ADD_PASSWORD);
restrictions = new WizardItem(this, content, "Setup your preferences", restrictions = new WizardItem(navigationManager, "Setup your preferences",
"Define your preferences with whom you want to trade", "Define your preferences with whom you want to trade",
NavigationItem.RESTRICTIONS); NavigationItem.RESTRICTIONS);
fiatAccount = new WizardItem(this, content, " Setup Payments account(s)", fiatAccount = new WizardItem(navigationManager, " Setup Payments account(s)",
"You need to add a payments account to your trading account", "You need to add a payments account to your trading account",
NavigationItem.FIAT_ACCOUNT); NavigationItem.FIAT_ACCOUNT);
registration = new WizardItem(this, content, "Register your account", registration = new WizardItem(navigationManager, "Register your account",
"Pay in the registration fee of 0.0002 BTC and store your account in the BTC block chain", "Pay in the registration fee of 0.0002 BTC and store your account in the BTC block chain",
NavigationItem.REGISTRATION); NavigationItem.REGISTRATION);
leftVBox.getChildren().addAll(seedWords, password, restrictions, fiatAccount, registration); leftVBox.getChildren().addAll(seedWords, password, restrictions, fiatAccount, registration);
childController = seedWords.show(); super.initialize(url, rb);
} }
@SuppressWarnings("EmptyMethod")
@Override @Override
public void activate() { public void activate() {
super.activate(); super.activate();
navigationManager.addListener(listener);
// triggers navigationTo
childController = seedWords.show();
} }
@SuppressWarnings("EmptyMethod")
@Override @Override
public void deactivate() { public void deactivate() {
super.deactivate(); super.deactivate();
navigationManager.removeListener(listener);
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -143,13 +156,7 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
registration.onCompleted(); registration.onCompleted();
childController = null; childController = null;
if (requestCloseCallable != null) { navigationManager.navigationTo(navigationManager.getNavigationItemsForReturning());
try {
requestCloseCallable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
} }
} }
@ -158,13 +165,8 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
// Public Methods // Public Methods
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void setRemoveCallBack(Callable<Void> requestCloseCallable) {
this.requestCloseCallable = requestCloseCallable;
}
@Override @Override
public Initializable loadView(NavigationItem navigationItem) { protected Initializable loadView(NavigationItem navigationItem) {
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl())); final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try { try {
final Pane view = loader.load(); final Pane view = loader.load();
@ -189,14 +191,12 @@ class WizardItem extends HBox {
private final ImageView imageView; private final ImageView imageView;
private final Label titleLabel; private final Label titleLabel;
private final Label subTitleLabel; private final Label subTitleLabel;
private final AccountSetupViewCB parentCB;
private final Parent content;
private final NavigationItem navigationItem; private final NavigationItem navigationItem;
private final NavigationManager navigationManager;
WizardItem(AccountSetupViewCB parentCB, Parent content, String title, String subTitle, WizardItem(NavigationManager navigationManager, String title, String subTitle,
NavigationItem navigationItem) { NavigationItem navigationItem) {
this.parentCB = parentCB; this.navigationManager = navigationManager;
this.content = content;
this.navigationItem = navigationItem; this.navigationItem = navigationItem;
setId("wizard-item-background-deactivated"); setId("wizard-item-background-deactivated");
@ -233,7 +233,9 @@ class WizardItem extends HBox {
} }
ViewCB<? extends PresentationModel> show() { ViewCB<? extends PresentationModel> show() {
parentCB.loadView(navigationItem); navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETUP,
navigationItem);
setId("wizard-item-background-active"); setId("wizard-item-background-active");
imageView.setImage(ImageUtil.getIconImage(ImageUtil.ARROW_BLUE)); imageView.setImage(ImageUtil.getIconImage(ImageUtil.ARROW_BLUE));
titleLabel.setId("wizard-title-active"); titleLabel.setId("wizard-title-active");

View file

@ -155,7 +155,7 @@ public class OfferController extends CachedViewController {
@Override @Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn) { public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn) {
return new TableCell<String, OfferListItem>() { return new TableCell<String, OfferListItem>() {
final ImageView iconView = ImageUtil.getIconImageView(ImageUtil.REMOVE); final ImageView iconView = ImageUtil.getIconImageView(ImageUtil.REMOVE_ICON);
final Button button = new Button(); final Button button = new Button();
{ {

View file

@ -78,8 +78,8 @@ public class PendingTradeController extends CachedViewController {
private Trade currentTrade; private Trade currentTrade;
private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY); private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY_ICON);
private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL); private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL_ICON);
private ConfidenceDisplay confidenceDisplay; private ConfidenceDisplay confidenceDisplay;
@FXML private TableView openTradesTable; @FXML private TableView openTradesTable;

View file

@ -17,13 +17,15 @@
package io.bitsquare.gui.main.trade; package io.bitsquare.gui.main.trade;
import io.bitsquare.gui.NavigationManager;
import javax.inject.Inject; import javax.inject.Inject;
public class BuyViewCB extends TradeViewCB { public class BuyViewCB extends TradeViewCB {
@Inject @Inject
public BuyViewCB() { public BuyViewCB(NavigationManager navigationManager) {
super(); super(navigationManager);
} }
} }

View file

@ -18,6 +18,7 @@
package io.bitsquare.gui.main.trade; package io.bitsquare.gui.main.trade;
import io.bitsquare.trade.Direction; import io.bitsquare.trade.Direction;
import io.bitsquare.trade.Offer;
import com.google.bitcoin.core.Coin; import com.google.bitcoin.core.Coin;
import com.google.bitcoin.utils.Fiat; import com.google.bitcoin.utils.Fiat;
@ -36,6 +37,9 @@ public class OrderBookInfo {
private Fiat volume; private Fiat volume;
private Offer offer;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -64,6 +68,9 @@ public class OrderBookInfo {
this.direction.set(direction); this.direction.set(direction);
} }
public Offer getOffer() {
return offer;
}
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Getters // Getters
@ -88,4 +95,8 @@ public class OrderBookInfo {
public ObjectProperty<Direction> directionProperty() { public ObjectProperty<Direction> directionProperty() {
return direction; return direction;
} }
public void setOffer(Offer offer) {
this.offer = offer;
}
} }

View file

@ -17,13 +17,15 @@
package io.bitsquare.gui.main.trade; package io.bitsquare.gui.main.trade;
import io.bitsquare.gui.NavigationManager;
import javax.inject.Inject; import javax.inject.Inject;
public class SellViewCB extends TradeViewCB { public class SellViewCB extends TradeViewCB {
@Inject @Inject
public SellViewCB() { public SellViewCB(NavigationManager navigationManager) {
super(); super(navigationManager);
} }
} }

View file

@ -19,6 +19,7 @@ package io.bitsquare.gui.main.trade;
import io.bitsquare.gui.CachedViewCB; import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.NavigationManager;
import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.InputTextField;
import io.bitsquare.gui.main.trade.createoffer.CreateOfferViewCB; import io.bitsquare.gui.main.trade.createoffer.CreateOfferViewCB;
import io.bitsquare.gui.main.trade.orderbook.OrderBookViewCB; import io.bitsquare.gui.main.trade.orderbook.OrderBookViewCB;
@ -42,8 +43,6 @@ import javafx.scene.control.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkArgument;
public class TradeViewCB extends CachedViewCB { public class TradeViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(TradeViewCB.class); private static final Logger log = LoggerFactory.getLogger(TradeViewCB.class);
@ -52,14 +51,19 @@ public class TradeViewCB extends CachedViewCB {
private CreateOfferViewCB createOfferViewCB; private CreateOfferViewCB createOfferViewCB;
private TakeOfferController takeOfferController; private TakeOfferController takeOfferController;
private Node createOfferView; private Node createOfferView;
private NavigationManager navigationManager;
private NavigationManager.Listener listener;
private NavigationItem tradeNavigationItem;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
protected TradeViewCB() { protected TradeViewCB(NavigationManager navigationManager) {
super(); super();
this.navigationManager = navigationManager;
} }
@ -67,15 +71,19 @@ public class TradeViewCB extends CachedViewCB {
// Lifecycle // Lifecycle
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("EmptyMethod")
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb); listener = navigationItems -> {
if (navigationItems != null && navigationItems.length == 3 && navigationItems[1] == tradeNavigationItem) {
loadView(navigationItems[2]);
}
};
Direction direction = (this instanceof BuyViewCB) ? Direction.BUY : Direction.SELL; Direction direction = (this instanceof BuyViewCB) ? Direction.BUY : Direction.SELL;
orderBookInfo.setDirection(direction); orderBookInfo.setDirection(direction);
tradeNavigationItem = (direction == Direction.BUY) ? NavigationItem.BUY : NavigationItem.SELL;
loadView(NavigationItem.ORDER_BOOK); super.initialize(url, rb);
} }
@Override @Override
@ -83,8 +91,9 @@ public class TradeViewCB extends CachedViewCB {
super.activate(); super.activate();
// We need to remove open validation error popups // We need to remove open validation error popups
// TODO Find a way to do that in the InputTextField directly, but a tab change does not trigger any event there // TODO Find a way to do that in the InputTextField directly, but a tab change does not trigger any event
// Platform.runLater needed as focusout evetn is called after selectedIndexProperty changed // there
// Platform.runLater needed as focus-out event is called after selectedIndexProperty changed
TabPane tabPane = (TabPane) root; TabPane tabPane = (TabPane) root;
tabPane.getSelectionModel().selectedIndexProperty() tabPane.getSelectionModel().selectedIndexProperty()
.addListener((observableValue, oldValue, newValue) -> .addListener((observableValue, oldValue, newValue) ->
@ -94,9 +103,13 @@ public class TradeViewCB extends CachedViewCB {
tabPane.getTabs().addListener((ListChangeListener<Tab>) change -> { tabPane.getTabs().addListener((ListChangeListener<Tab>) change -> {
change.next(); change.next();
List<? extends Tab> removedTabs = change.getRemoved(); List<? extends Tab> removedTabs = change.getRemoved();
if (removedTabs.size() == 1 && removedTabs.get(0).getContent().equals(createOfferView)) if (removedTabs.size() == 1 && removedTabs.get(0).getContent().equals(createOfferView)) {
onCreateOfferViewRemoved(); onCreateOfferViewRemoved();
}
}); });
navigationManager.addListener(listener);
navigationManager.navigationTo(NavigationItem.MAIN, tradeNavigationItem, NavigationItem.ORDER_BOOK);
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -117,12 +130,11 @@ public class TradeViewCB extends CachedViewCB {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// @Override // @Override
public Initializable loadView(NavigationItem navigationItem) {
super.loadView(navigationItem);
protected Initializable loadView(NavigationItem navigationItem) {
super.loadView(navigationItem);
TabPane tabPane = (TabPane) root; TabPane tabPane = (TabPane) root;
if (navigationItem == NavigationItem.ORDER_BOOK) { if (navigationItem == NavigationItem.ORDER_BOOK && orderBookViewCB == null) {
checkArgument(orderBookViewCB == null);
// Orderbook must not be cached by GuiceFXMLLoader as we use 2 instances for sell and buy screens. // Orderbook must not be cached by GuiceFXMLLoader as we use 2 instances for sell and buy screens.
ViewLoader orderBookLoader = ViewLoader orderBookLoader =
new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false); new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
@ -135,16 +147,14 @@ public class TradeViewCB extends CachedViewCB {
orderBookViewCB = orderBookLoader.getController(); orderBookViewCB = orderBookLoader.getController();
orderBookViewCB.setParent(this); orderBookViewCB.setParent(this);
orderBookViewCB.setOrderBookInfo(orderBookInfo); orderBookViewCB.setOrderBookInfo(orderBookInfo);
orderBookViewCB.setNavigationListener(n -> loadView(n)); // orderBookViewCB.setNavigationListener(n -> loadView(n));
return orderBookViewCB; return orderBookViewCB;
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
} }
} }
else if (navigationItem == NavigationItem.CREATE_OFFER) { else if (navigationItem == NavigationItem.CREATE_OFFER && createOfferViewCB == null) {
checkArgument(createOfferViewCB == null);
// CreateOffer and TakeOffer must not be cached by GuiceFXMLLoader as we cannot use a view multiple times // CreateOffer and TakeOffer must not be cached by GuiceFXMLLoader as we cannot use a view multiple times
// in different graphs // in different graphs
ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false); ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
@ -163,9 +173,7 @@ public class TradeViewCB extends CachedViewCB {
log.error(e.getMessage()); log.error(e.getMessage());
} }
} }
else if (navigationItem == NavigationItem.TAKE_OFFER) { else if (navigationItem == NavigationItem.TAKE_OFFER && takeOfferController == null) {
checkArgument(takeOfferController == null);
// CreateOffer and TakeOffer must not be cached by GuiceFXMLLoader as we cannot use a view multiple times // CreateOffer and TakeOffer must not be cached by GuiceFXMLLoader as we cannot use a view multiple times
// in different graphs // in different graphs
ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false); ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
@ -173,10 +181,12 @@ public class TradeViewCB extends CachedViewCB {
final Parent view = loader.load(); final Parent view = loader.load();
takeOfferController = loader.getController(); takeOfferController = loader.getController();
takeOfferController.setParentController(this); takeOfferController.setParentController(this);
takeOfferController.initWithData(orderBookInfo);
final Tab tab = new Tab("Take offer"); final Tab tab = new Tab("Take offer");
tab.setContent(view); tab.setContent(view);
tabPane.getTabs().add(tab); tabPane.getTabs().add(tab);
tabPane.getSelectionModel().select(tab); tabPane.getSelectionModel().select(tab);
return takeOfferController; return takeOfferController;
} catch (IOException e) { } catch (IOException e) {
log.error(e.getMessage()); log.error(e.getMessage());
@ -207,6 +217,9 @@ public class TradeViewCB extends CachedViewCB {
if (createOfferViewCB != null) if (createOfferViewCB != null)
createOfferViewCB = null; createOfferViewCB = null;
orderBookViewCB.enableCreateOfferButton(); orderBookViewCB.enableCreateOfferButton();
// update the navigation state
navigationManager.navigationTo(NavigationItem.MAIN, tradeNavigationItem, NavigationItem.ORDER_BOOK);
} }
} }

View file

@ -237,7 +237,8 @@ public class CreateOfferViewCB extends CachedViewCB<CreateOfferPM> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void openAccountSettings() { private void openAccountSettings() {
navigationManager.navigationTo(NavigationItem.ACCOUNT, navigationManager.navigationTo(NavigationItem.MAIN,
NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETTINGS, NavigationItem.ACCOUNT_SETTINGS,
NavigationItem.RESTRICTIONS); NavigationItem.RESTRICTIONS);
} }

View file

@ -19,16 +19,11 @@ package io.bitsquare.gui.main.trade.orderbook;
import io.bitsquare.gui.CachedViewCB; import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.NavigationListener;
import io.bitsquare.gui.NavigationManager; import io.bitsquare.gui.NavigationManager;
import io.bitsquare.gui.OverlayManager; import io.bitsquare.gui.OverlayManager;
import io.bitsquare.gui.ViewCB;
import io.bitsquare.gui.ViewController;
import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.components.InputTextField;
import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.main.trade.OrderBookInfo; import io.bitsquare.gui.main.trade.OrderBookInfo;
import io.bitsquare.gui.main.trade.takeoffer.TakeOfferController;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.ImageUtil;
import io.bitsquare.gui.util.validation.OptionalBtcValidator; import io.bitsquare.gui.util.validation.OptionalBtcValidator;
import io.bitsquare.gui.util.validation.OptionalFiatValidator; import io.bitsquare.gui.util.validation.OptionalFiatValidator;
@ -37,8 +32,6 @@ import io.bitsquare.locale.Country;
import io.bitsquare.trade.Direction; import io.bitsquare.trade.Direction;
import io.bitsquare.trade.Offer; import io.bitsquare.trade.Offer;
import com.google.bitcoin.core.Coin;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -69,32 +62,30 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public class OrderBookViewCB extends CachedViewCB<OrderBookPM> { public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
private static final Logger log = LoggerFactory.getLogger(OrderBookViewCB.class); private static final Logger log = LoggerFactory.getLogger(OrderBookViewCB.class);
//TODO nav?
private NavigationManager navigationManager; private NavigationManager navigationManager;
private NavigationItem tradeNavigationItem;
private OverlayManager overlayManager; private OverlayManager overlayManager;
private OptionalBtcValidator optionalBtcValidator; private OptionalBtcValidator optionalBtcValidator;
private OptionalFiatValidator optionalFiatValidator; private OptionalFiatValidator optionalFiatValidator;
private NavigationListener navigationListener;
private boolean detailsVisible; private boolean detailsVisible;
private boolean advancedScreenInited; private boolean advancedScreenInited;
private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY); private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY_ICON);
private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL); private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL_ICON);
private ImageView expand; private ImageView expand;
private ImageView collapse; private ImageView collapse;
@FXML private CheckBox extendedCheckBox; @FXML CheckBox extendedCheckBox;
@FXML private Label amountBtcLabel, priceDescriptionLabel, priceFiatLabel, volumeDescriptionLabel, @FXML Label amountBtcLabel, priceDescriptionLabel, priceFiatLabel, volumeDescriptionLabel,
volumeFiatLabel, extendedButton1Label, extendedButton2Label, extendedCheckBoxLabel; volumeFiatLabel, extendedButton1Label, extendedButton2Label, extendedCheckBoxLabel;
@FXML private InputTextField volumeTextField, amountTextField, priceTextField; @FXML InputTextField volumeTextField, amountTextField, priceTextField;
@FXML private TableView<OrderBookListItem> orderBookTable; @FXML TableView<OrderBookListItem> orderBookTable;
@FXML private Button createOfferButton, showAdvancedSettingsButton, extendedButton1, extendedButton2; @FXML Button createOfferButton, showAdvancedSettingsButton, extendedButton1, extendedButton2;
@FXML private TableColumn<OrderBookListItem, OrderBookListItem> priceColumn, amountColumn, volumeColumn, @FXML TableColumn<OrderBookListItem, OrderBookListItem> priceColumn, amountColumn, volumeColumn,
directionColumn, countryColumn, bankAccountTypeColumn; directionColumn, countryColumn, bankAccountTypeColumn;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -120,8 +111,6 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
@Override @Override
public void initialize(URL url, ResourceBundle rb) { public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
// init table // init table
setAmountColumnCellFactory(); setAmountColumnCellFactory();
setPriceColumnCellFactory(); setPriceColumnCellFactory();
@ -129,72 +118,41 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
setCountryColumnCellFactory(); setCountryColumnCellFactory();
setBankAccountTypeColumnCellFactory(); setBankAccountTypeColumnCellFactory();
setDirectionColumnCellFactory(); setDirectionColumnCellFactory();
//setRowFactory();
amountTextField.textProperty().bindBidirectional(presentationModel.amount);
priceTextField.textProperty().bindBidirectional(presentationModel.price);
volumeTextField.textProperty().bindBidirectional(presentationModel.volume);
amountBtcLabel.textProperty().bind(presentationModel.btcCode);
priceFiatLabel.textProperty().bind(presentationModel.fiatCode);
volumeFiatLabel.textProperty().bind(presentationModel.fiatCode);
priceDescriptionLabel.textProperty().bind(presentationModel.fiatCode);
volumeDescriptionLabel.textProperty().bind(presentationModel.fiatCode);//Price per Bitcoin in EUR
priceDescriptionLabel.textProperty().bind(createStringBinding(() ->
BSResources.get("Filter by price in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
volumeDescriptionLabel.textProperty().bind(createStringBinding(() ->
BSResources.get("Filter by amount in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
volumeTextField.promptTextProperty().bind(createStringBinding(() ->
BSResources.get("Amount in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
orderBookTable.getSortOrder().add(priceColumn); orderBookTable.getSortOrder().add(priceColumn);
orderBookTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); orderBookTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
amountTextField.setValidator(optionalBtcValidator); setupBindings();
priceTextField.setValidator(optionalFiatValidator); setupValidators();
volumeTextField.setValidator(optionalFiatValidator); setupComparators();
expand = ImageUtil.getIconImageView(ImageUtil.EXPAND); expand = ImageUtil.getIconImageView(ImageUtil.EXPAND);
collapse = ImageUtil.getIconImageView(ImageUtil.COLLAPSE); collapse = ImageUtil.getIconImageView(ImageUtil.COLLAPSE);
showAdvancedSettingsButton.setGraphic(expand); showAdvancedSettingsButton.setGraphic(expand);
}
super.initialize(url, rb);
}
@Override @Override
public void activate() { public void activate() {
super.activate(); super.activate();
// setOrderBookInfo has been called before
SortedList<OrderBookListItem> offerList = presentationModel.getOfferList(); SortedList<OrderBookListItem> offerList = presentationModel.getOfferList();
orderBookTable.setItems(offerList); orderBookTable.setItems(offerList);
// presentationModel.comparator.bind(orderBookTable.comparatorProperty());
offerList.comparatorProperty().bind(orderBookTable.comparatorProperty()); offerList.comparatorProperty().bind(orderBookTable.comparatorProperty());
priceColumn.setComparator((o1, o2) -> o1.getOffer().getPrice().compareTo(o2.getOffer().getPrice()));
amountColumn.setComparator((o1, o2) -> o1.getOffer().getAmount().compareTo(o2.getOffer().getAmount()));
volumeColumn.setComparator((o1, o2) ->
o1.getOffer().getOfferVolume().compareTo(o2.getOffer().getOfferVolume()));
countryColumn.setComparator((o1, o2) -> o1.getOffer().getBankAccountCountry().getName().compareTo(o2.getOffer()
.getBankAccountCountry().getName()));
bankAccountTypeColumn.setComparator((o1, o2) -> o1.getOffer().getBankAccountType().compareTo(o2.getOffer()
.getBankAccountType()));
priceColumn.setSortType((presentationModel.getOrderBookInfo().getDirection() == Direction.BUY) ? priceColumn.setSortType((presentationModel.getOrderBookInfo().getDirection() == Direction.BUY) ?
TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING); TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
orderBookTable.sort(); orderBookTable.sort();
/* if (orderBookTable.getItems() != null)
createOfferButton.setDefaultButton(orderBookTable.getItems().isEmpty());*/
} }
@SuppressWarnings("EmptyMethod")
@Override @Override
public void deactivate() { public void deactivate() {
super.deactivate(); super.deactivate();
// orderBookTable.getSelectionModel().clearSelection();
// orderBookTable.setItems(null);
} }
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@ -219,10 +177,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
public void setOrderBookInfo(OrderBookInfo orderBookInfo) { public void setOrderBookInfo(OrderBookInfo orderBookInfo) {
presentationModel.setOrderBookInfo(orderBookInfo); presentationModel.setOrderBookInfo(orderBookInfo);
} tradeNavigationItem = (orderBookInfo.getDirection() == Direction.BUY) ? NavigationItem.BUY : NavigationItem
.SELL;
public void setNavigationListener(NavigationListener navigationListener) {
this.navigationListener = navigationListener;
} }
@ -234,7 +191,11 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
void createOffer() { void createOffer() {
if (presentationModel.isRegistered()) { if (presentationModel.isRegistered()) {
createOfferButton.setDisable(true); createOfferButton.setDisable(true);
navigationListener.navigate(NavigationItem.CREATE_OFFER); if (presentationModel.getOrderBookInfo().getDirection() == Direction.BUY)
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.BUY, NavigationItem.CREATE_OFFER);
else
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.SELL, NavigationItem.CREATE_OFFER);
} }
else { else {
openSetupScreen(); openSetupScreen();
@ -261,6 +222,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
// Private methods // Private methods
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void openSetupScreen() { private void openSetupScreen() {
overlayManager.blurContent(); overlayManager.blurContent();
List<Action> actions = new ArrayList<>(); List<Action> actions = new ArrayList<>();
@ -269,7 +231,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
Dialog.Actions.OK.handle(actionEvent); Dialog.Actions.OK.handle(actionEvent);
overlayManager.removeBlurContent(); overlayManager.removeBlurContent();
navigationManager.navigationTo(NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETUP); navigationManager.setNavigationItemsForReturning(navigationManager.getCurrentNavigationItems());
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETUP);
} }
}); });
Popups.openInfo("You need to setup your trading account before you can trade.", Popups.openInfo("You need to setup your trading account before you can trade.",
@ -279,30 +243,13 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
//TODO not updated yet //TODO not updated yet
private void takeOffer(Offer offer) { private void takeOffer(Offer offer) {
if (presentationModel.isRegistered()) { if (presentationModel.isRegistered()) {
//TODO Remove that when all UIs are converted to CodeBehind
TakeOfferController takeOfferController = null;
if (parent != null) {
if (parent instanceof ViewController)
takeOfferController = (TakeOfferController) ((ViewController) parent)
.loadViewAndGetChildController(NavigationItem
.TAKE_OFFER);
else if (parent instanceof ViewCB)
takeOfferController = (TakeOfferController) ((ViewCB) parent)
.loadView(NavigationItem
.TAKE_OFFER);
}
Coin requestedAmount; presentationModel.getOrderBookInfo().setOffer(offer);
if (!"".equals(amountTextField.getText())) {
requestedAmount = BSFormatter.parseToCoin(amountTextField.getText());
}
else {
requestedAmount = offer.getAmount();
}
if (takeOfferController != null) { if (presentationModel.getOrderBookInfo().getDirection() == Direction.BUY)
takeOfferController.initWithData(offer, requestedAmount); navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.BUY, NavigationItem.TAKE_OFFER);
} else
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.SELL, NavigationItem.TAKE_OFFER);
} }
else { else {
openSetupScreen(); openSetupScreen();
@ -320,7 +267,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
actions); actions);
if (response == Dialog.Actions.YES) if (response == Dialog.Actions.YES)
navigationManager.navigationTo(NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETTINGS, navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETTINGS,
NavigationItem.RESTRICTIONS); NavigationItem.RESTRICTIONS);
else else
orderBookTable.getSelectionModel().clearSelection(); orderBookTable.getSelectionModel().clearSelection();
@ -364,9 +311,46 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Table // Setup
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
private void setupBindings() {
amountTextField.textProperty().bindBidirectional(presentationModel.amount);
priceTextField.textProperty().bindBidirectional(presentationModel.price);
volumeTextField.textProperty().bindBidirectional(presentationModel.volume);
amountBtcLabel.textProperty().bind(presentationModel.btcCode);
priceFiatLabel.textProperty().bind(presentationModel.fiatCode);
volumeFiatLabel.textProperty().bind(presentationModel.fiatCode);
priceDescriptionLabel.textProperty().bind(presentationModel.fiatCode);
volumeDescriptionLabel.textProperty().bind(presentationModel.fiatCode);//Price per Bitcoin in EUR
priceDescriptionLabel.textProperty().bind(createStringBinding(() ->
BSResources.get("Filter by price in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
volumeDescriptionLabel.textProperty().bind(createStringBinding(() ->
BSResources.get("Filter by amount in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
volumeTextField.promptTextProperty().bind(createStringBinding(() ->
BSResources.get("Amount in {0}", presentationModel.fiatCode.get()),
presentationModel.fiatCode));
}
private void setupValidators() {
amountTextField.setValidator(optionalBtcValidator);
priceTextField.setValidator(optionalFiatValidator);
volumeTextField.setValidator(optionalFiatValidator);
}
private void setupComparators() {
priceColumn.setComparator((o1, o2) -> o1.getOffer().getPrice().compareTo(o2.getOffer().getPrice()));
amountColumn.setComparator((o1, o2) -> o1.getOffer().getAmount().compareTo(o2.getOffer().getAmount()));
volumeColumn.setComparator((o1, o2) ->
o1.getOffer().getOfferVolume().compareTo(o2.getOffer().getOfferVolume()));
countryColumn.setComparator((o1, o2) -> o1.getOffer().getBankAccountCountry().getName().compareTo(o2.getOffer()
.getBankAccountCountry().getName()));
bankAccountTypeColumn.setComparator((o1, o2) -> o1.getOffer().getBankAccountType().compareTo(o2.getOffer()
.getBankAccountType()));
}
private void setAmountColumnCellFactory() { private void setAmountColumnCellFactory() {
amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue())); amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
amountColumn.setCellFactory( amountColumn.setCellFactory(
@ -479,7 +463,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
Offer offer = item.getOffer(); Offer offer = item.getOffer();
if (presentationModel.isMyOffer(offer)) { if (presentationModel.isMyOffer(offer)) {
icon = ImageUtil.getIconImage(ImageUtil.REMOVE); icon = ImageUtil.getIconImage(ImageUtil.REMOVE_ICON);
title = "Remove"; title = "Remove";
button.setOnAction(event -> presentationModel.removeOffer(item button.setOnAction(event -> presentationModel.removeOffer(item
.getOffer())); .getOffer()));

View file

@ -23,6 +23,7 @@ import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController; import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.components.ValidatedTextField; import io.bitsquare.gui.components.ValidatedTextField;
import io.bitsquare.gui.main.trade.OrderBookInfo;
import io.bitsquare.gui.main.trade.TradeViewCB; import io.bitsquare.gui.main.trade.TradeViewCB;
import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.BitSquareValidator; import io.bitsquare.gui.util.BitSquareValidator;
@ -108,9 +109,12 @@ public class TakeOfferController extends CachedViewController {
// Public methods // Public methods
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void initWithData(Offer offer, Coin requestedAmount) { public void initWithData(OrderBookInfo orderBookInfo) {
this.offer = offer; this.offer = orderBookInfo.getOffer();
this.requestedAmount = requestedAmount.compareTo(Coin.ZERO) == 0 ? offer.getAmount() : requestedAmount; if (orderBookInfo.getAmount() != null && !orderBookInfo.getAmount().isZero())
requestedAmount = orderBookInfo.getAmount();
else
requestedAmount = offer.getAmount();
if (amountTextField != null) { if (amountTextField != null) {
applyData(); applyData();

View file

@ -34,10 +34,10 @@ public class ImageUtil {
public static final String HOME = "/images/nav/home.png"; public static final String HOME = "/images/nav/home.png";
public static final String HOME_ACTIVE = "/images/nav/home_active.png"; public static final String HOME_ACTIVE = "/images/nav/home_active.png";
public static final String NAV_BUY = "/images/nav/buy.png"; public static final String BUY = "/images/nav/buy.png";
public static final String NAV_BUY_ACTIVE = "/images/nav/buy_active.png"; public static final String BUY_ACTIVE = "/images/nav/buy_active.png";
public static final String NAV_SELL = "/images/nav/sell.png"; public static final String SELL = "/images/nav/sell.png";
public static final String NAV_SELL_ACTIVE = "/images/nav/sell_active.png"; public static final String SELL_ACTIVE = "/images/nav/sell_active.png";
public static final String ORDERS = "/images/nav/orders.png"; public static final String ORDERS = "/images/nav/orders.png";
public static final String ORDERS_ACTIVE = "/images/nav/orders_active.png"; public static final String ORDERS_ACTIVE = "/images/nav/orders_active.png";
public static final String FUNDS = "/images/nav/funds.png"; public static final String FUNDS = "/images/nav/funds.png";
@ -51,9 +51,9 @@ public class ImageUtil {
public static final String MSG_ALERT = "/images/nav/alertRound.png"; public static final String MSG_ALERT = "/images/nav/alertRound.png";
public static final String BUY = "/images/buy.png"; public static final String BUY_ICON = "/images/buy.png";
public static final String SELL = "/images/sell.png"; public static final String SELL_ICON = "/images/sell.png";
public static final String REMOVE = "/images/removeOffer.png"; public static final String REMOVE_ICON = "/images/removeOffer.png";
public static final String EXPAND = "/images/expand.png"; public static final String EXPAND = "/images/expand.png";
public static final String COLLAPSE = "/images/collapse.png"; public static final String COLLAPSE = "/images/collapse.png";

View file

@ -48,7 +48,7 @@ public class BSResources {
try { try {
return BSResources.getResourceBundle().getString(key); return BSResources.getResourceBundle().getString(key);
} catch (MissingResourceException e) { } catch (MissingResourceException e) {
log.error("MissingResourceException for key: " + key); log.warn("MissingResourceException for key: " + key);
return key; return key;
} }
} }

View file

@ -299,7 +299,7 @@ public class MessageFacade implements MessageBroker {
listener.onOffersReceived(offers))); listener.onOffersReceived(offers)));
} }
log.trace("Get offers from DHT was successful"); //log.trace("Get offers from DHT was successful");
/* log.trace("Get offers from DHT was successful. Stored data: [key: " + locationKey /* log.trace("Get offers from DHT was successful. Stored data: [key: " + locationKey
+ ", values: " + futureGet.dataMap() + "]");*/ + ", values: " + futureGet.dataMap() + "]");*/
} }