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
///////////////////////////////////////////////////////////////////////////////////////////
MAIN(0, "/io/bitsquare/gui/main/MainView.fxml"),
MAIN("/io/bitsquare/gui/main/MainView.fxml"),
///////////////////////////////////////////////////////////////////////////////////////////
// Main menu screens
///////////////////////////////////////////////////////////////////////////////////////////
HOME(1, "/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),
SELL(1, "/io/bitsquare/gui/main/trade/SellView.fxml", ImageUtil.NAV_SELL, ImageUtil.NAV_SELL_ACTIVE),
ORDERS(1, "/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),
MSG(1, "/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),
ACCOUNT(1, "/io/bitsquare/gui/main/account/AccountView.fxml", ImageUtil.ACCOUNT, ImageUtil.ACCOUNT_ACTIVE),
HOME("/io/bitsquare/gui/main/home/HomeView.fxml", ImageUtil.HOME, ImageUtil.HOME_ACTIVE),
BUY("/io/bitsquare/gui/main/trade/BuyView.fxml", ImageUtil.BUY, ImageUtil.BUY_ACTIVE),
SELL("/io/bitsquare/gui/main/trade/SellView.fxml", ImageUtil.SELL, ImageUtil.SELL_ACTIVE),
ORDERS("/io/bitsquare/gui/main/orders/OrdersView.fxml", ImageUtil.ORDERS, ImageUtil.ORDERS_ACTIVE),
FUNDS("/io/bitsquare/gui/main/funds/FundsView.fxml", ImageUtil.FUNDS, ImageUtil.FUNDS_ACTIVE),
MSG("/io/bitsquare/gui/main/msg/MsgView.fxml", ImageUtil.MSG, ImageUtil.MSG_ACTIVE),
SETTINGS("/io/bitsquare/gui/main/settings/SettingsView.fxml", ImageUtil.SETTINGS, ImageUtil.SETTINGS_ACTIVE),
ACCOUNT("/io/bitsquare/gui/main/account/AccountView.fxml", ImageUtil.ACCOUNT, ImageUtil.ACCOUNT_ACTIVE),
///////////////////////////////////////////////////////////////////////////////////////////
@ -47,23 +47,23 @@ public enum NavigationItem {
///////////////////////////////////////////////////////////////////////////////////////////
// buy/sell (trade)
ORDER_BOOK(2, "/io/bitsquare/gui/main/trade/orderbook/OrderBookView.fxml"),
CREATE_OFFER(2, "/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.fxml"),
TAKE_OFFER(2, "/io/bitsquare/gui/main/trade/takeoffer/TakeOfferView.fxml"),
ORDER_BOOK("/io/bitsquare/gui/main/trade/orderbook/OrderBookView.fxml"),
CREATE_OFFER("/io/bitsquare/gui/main/trade/createoffer/CreateOfferView.fxml"),
TAKE_OFFER("/io/bitsquare/gui/main/trade/takeoffer/TakeOfferView.fxml"),
// orders
OFFER(2, "/io/bitsquare/gui/main/orders/offer/OfferView.fxml"),
PENDING_TRADE(2, "/io/bitsquare/gui/main/orders/pending/PendingTradeView.fxml"),
CLOSED_TRADE(2, "/io/bitsquare/gui/main/orders/closed/ClosedTradeView.fxml"),
OFFER("/io/bitsquare/gui/main/orders/offer/OfferView.fxml"),
PENDING_TRADE("/io/bitsquare/gui/main/orders/pending/PendingTradeView.fxml"),
CLOSED_TRADE("/io/bitsquare/gui/main/orders/closed/ClosedTradeView.fxml"),
// funds
DEPOSIT(2, "/io/bitsquare/gui/main/funds/deposit/DepositView.fxml"),
WITHDRAWAL(2, "/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml"),
TRANSACTIONS(2, "/io/bitsquare/gui/main/funds/transactions/TransactionsView.fxml"),
DEPOSIT("/io/bitsquare/gui/main/funds/deposit/DepositView.fxml"),
WITHDRAWAL("/io/bitsquare/gui/main/funds/withdrawal/WithdrawalView.fxml"),
TRANSACTIONS("/io/bitsquare/gui/main/funds/transactions/TransactionsView.fxml"),
// account
ACCOUNT_SETUP(2, "/io/bitsquare/gui/main/account/setup/AccountSetupView.fxml"),
ACCOUNT_SETTINGS(2, "/io/bitsquare/gui/main/account/settings/AccountSettingsView.fxml"),
ACCOUNT_SETUP("/io/bitsquare/gui/main/account/setup/AccountSetupView.fxml"),
ACCOUNT_SETTINGS("/io/bitsquare/gui/main/account/settings/AccountSettingsView.fxml"),
///////////////////////////////////////////////////////////////////////////////////////////
@ -71,12 +71,12 @@ public enum NavigationItem {
///////////////////////////////////////////////////////////////////////////////////////////
// account content
SEED_WORDS(3, "/io/bitsquare/gui/main/account/content/seedwords/SeedWordsView.fxml"),
ADD_PASSWORD(3, "/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
CHANGE_PASSWORD(3, "/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
RESTRICTIONS(3, "/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.fxml"),
REGISTRATION(3, "/io/bitsquare/gui/main/account/content/registration/RegistrationView.fxml"),
FIAT_ACCOUNT(3, "/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.fxml"),
SEED_WORDS("/io/bitsquare/gui/main/account/content/seedwords/SeedWordsView.fxml"),
ADD_PASSWORD("/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
CHANGE_PASSWORD("/io/bitsquare/gui/main/account/content/password/PasswordView.fxml"),
RESTRICTIONS("/io/bitsquare/gui/main/account/content/restrictions/RestrictionsView.fxml"),
REGISTRATION("/io/bitsquare/gui/main/account/content/registration/RegistrationView.fxml"),
FIAT_ACCOUNT("/io/bitsquare/gui/main/account/content/fiat/FiatAccountView.fxml"),
///////////////////////////////////////////////////////////////////////////////////////////
@ -84,39 +84,30 @@ public enum NavigationItem {
///////////////////////////////////////////////////////////////////////////////////////////
// arbitrator
ARBITRATOR_PROFILE(2, "/io/bitsquare/gui/main/arbitrators/profile/ArbitratorProfileView.fxml"),
ARBITRATOR_BROWSER(-1, "/io/bitsquare/gui/main/arbitrators/browser/ArbitratorBrowserView.fxml"),
ARBITRATOR_REGISTRATION(-1, "/io/bitsquare/gui/main/arbitrators/registration/ArbitratorRegistrationView.fxml");
ARBITRATOR_PROFILE("/io/bitsquare/gui/main/arbitrators/profile/ArbitratorProfileView.fxml"),
ARBITRATOR_BROWSER("/io/bitsquare/gui/main/arbitrators/browser/ArbitratorBrowserView.fxml"),
ARBITRATOR_REGISTRATION("/io/bitsquare/gui/main/arbitrators/registration/ArbitratorRegistrationView.fxml");
private int level;
private final String fxmlUrl;
private String icon;
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 icon
* @param activeIcon
*/
NavigationItem(int level, String fxmlUrl, String icon, String activeIcon) {
this.level = level;
NavigationItem(String fxmlUrl, String icon, String activeIcon) {
this.fxmlUrl = fxmlUrl;
this.icon = icon;
this.activeIcon = activeIcon;
}
NavigationItem(int level, String fxmlUrl) {
this.level = level;
NavigationItem(String fxmlUrl) {
this.fxmlUrl = fxmlUrl;
}
public int getLevel() {
return level;
}
public String getFxmlUrl() {
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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class NavigationManager {
private static final Logger log = LoggerFactory.getLogger(NavigationManager.class);
private Persistence persistence;
///////////////////////////////////////////////////////////////////////////////////////////
// Interface
///////////////////////////////////////////////////////////////////////////////////////////
public interface NavigationListener {
public interface Listener {
void onNavigationRequested(NavigationItem... navigationItems);
}
private List<NavigationListener> listeners = new ArrayList<>();
private NavigationItem[] previousMainNavigationItems;
// New listeners can be added during iteration so we use CopyOnWriteArrayList to prevent invalid array
// modification
private List<Listener> listeners = new CopyOnWriteArrayList<>();
private Persistence persistence;
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
@ -58,18 +65,38 @@ public class NavigationManager {
///////////////////////////////////////////////////////////////////////////////////////////
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;
persistence.write(this, "navigationItems", navigationItems);
log.trace("navigationTo notify listeners " + Arrays.asList(navigationItems).toString() + " / " + listeners
.size());
listeners.stream().forEach((e) -> e.onNavigationRequested(navigationItems));
}
public void navigateToLastStoredItem() {
NavigationItem[] navigationItems = (NavigationItem[]) persistence.read(this, "navigationItems");
if (navigationItems == null || navigationItems.length == 0)
navigationItems = new NavigationItem[]{NavigationItem.HOME};
navigationItems = new NavigationItem[]{NavigationItem.MAIN, NavigationItem.HOME};
navigationTo(navigationItems);
}
@ -77,11 +104,11 @@ public class NavigationManager {
// Listeners
///////////////////////////////////////////////////////////////////////////////////////////
public void addListener(NavigationListener listener) {
public void addListener(Listener listener) {
listeners.add(listener);
}
public void removeListener(NavigationListener listener) {
public void removeListener(Listener listener) {
listeners.remove(listener);
}
@ -90,12 +117,21 @@ public class NavigationManager {
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
public NavigationItem[] getPreviousMainNavigationItems() {
return previousMainNavigationItems;
public NavigationItem[] getNavigationItemsForReturning() {
return navigationItemsForReturning;
}
public NavigationItem[] getCurrentNavigationItems() {
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.
* @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 " +
"= " + navigationItem);
return null;

View File

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

View File

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

View File

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

View File

@ -33,9 +33,9 @@ import java.util.ResourceBundle;
import javax.inject.Inject;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
@ -50,12 +50,13 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
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 NavigationManager navigationManager;
private NavigationManager.Listener listener;
@FXML VBox leftVBox;
@FXML AnchorPane content;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -75,18 +76,25 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
@Override
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();
seedWords = new MenuItem(this, content, "Wallet seed",
seedWords = new MenuItem(navigationManager, "Wallet seed",
NavigationItem.SEED_WORDS, toggleGroup);
password = new MenuItem(this, content, "Wallet password",
password = new MenuItem(navigationManager, "Wallet password",
NavigationItem.CHANGE_PASSWORD, toggleGroup);
restrictions = new MenuItem(this, content, "Trading restrictions",
restrictions = new MenuItem(navigationManager, "Trading restrictions",
NavigationItem.RESTRICTIONS, toggleGroup);
fiatAccount = new MenuItem(this, content, "Payments account(s)",
fiatAccount = new MenuItem(navigationManager, "Payments account(s)",
NavigationItem.FIAT_ACCOUNT, toggleGroup);
registration = new MenuItem(this, content, "Renew your account",
registration = new MenuItem(navigationManager, "Renew your account",
NavigationItem.REGISTRATION, toggleGroup);
registration.setDisable(true);
@ -94,27 +102,72 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
leftVBox.getChildren().addAll(seedWords, password,
restrictions, fiatAccount, registration);
super.initialize(url, rb);
}
@Override
public void activate() {
super.activate();
NavigationItem[] navigationItems = navigationManager.getCurrentNavigationItems();
for (int i = 0; i < navigationItems.length; i++) {
if (navigationItems[i].getLevel() == 3) {
subMenuNavigationItem = navigationItems[i];
break;
navigationManager.addListener(listener);
NavigationItem[] items = navigationManager.getCurrentNavigationItems();
if (items.length == 3 &&
items[2] == NavigationItem.ACCOUNT_SETTINGS) {
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)
subMenuNavigationItem = NavigationItem.SEED_WORDS;
@Override
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:
seedWords.setSelected(true);
break;
@ -131,60 +184,17 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
registration.setSelected(true);
break;
default:
log.error(subMenuNavigationItem.getFxmlUrl() + " is no subMenuNavigationItem");
log.error(navigationItem.getFxmlUrl() + " is invalid");
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 {
private static final Logger log = LoggerFactory.getLogger(MenuItem.class);
private ViewCB<? extends PresentationModel> childController;
private final AccountSettingsViewCB parentCB;
private final Parent content;
private final NavigationItem navigationItem;
MenuItem(AccountSettingsViewCB parentCB, Parent content, String title, NavigationItem navigationItem,
MenuItem(NavigationManager navigationManager, String title, NavigationItem navigationItem,
ToggleGroup toggleGroup) {
this.parentCB = parentCB;
this.content = content;
this.navigationItem = navigationItem;
setToggleGroup(toggleGroup);
setText(title);
@ -204,7 +214,8 @@ class MenuItem extends ToggleButton {
setGraphic(icon);
setOnAction((event) -> parentCB.loadView(navigationItem));
setOnAction((event) -> navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT,
NavigationItem.ACCOUNT_SETTINGS, navigationItem));
selectedProperty().addListener((ov, oldValue, 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.NavigationItem;
import io.bitsquare.gui.NavigationManager;
import io.bitsquare.gui.PresentationModel;
import io.bitsquare.gui.ViewCB;
import io.bitsquare.gui.main.account.MultiStepNavigation;
@ -36,14 +37,12 @@ import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import javax.inject.Inject;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.image.*;
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 WizardItem seedWords, password, fiatAccount, restrictions, registration;
private Callable<Void> requestCloseCallable;
private NavigationManager navigationManager;
private NavigationManager.Listener listener;
@FXML private VBox leftVBox;
@FXML private AnchorPane content;
@FXML VBox leftVBox;
@FXML AnchorPane content;
///////////////////////////////////////////////////////////////////////////////////////////
@ -67,8 +67,9 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private AccountSetupViewCB(AccountSetupPM presentationModel) {
private AccountSetupViewCB(AccountSetupPM presentationModel, NavigationManager navigationManager) {
super(presentationModel);
this.navigationManager = navigationManager;
}
@ -78,37 +79,49 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
@Override
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);
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);
restrictions = new WizardItem(this, content, "Setup your preferences",
restrictions = new WizardItem(navigationManager, "Setup your preferences",
"Define your preferences with whom you want to trade",
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",
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",
NavigationItem.REGISTRATION);
leftVBox.getChildren().addAll(seedWords, password, restrictions, fiatAccount, registration);
childController = seedWords.show();
super.initialize(url, rb);
}
@SuppressWarnings("EmptyMethod")
@Override
public void activate() {
super.activate();
navigationManager.addListener(listener);
// triggers navigationTo
childController = seedWords.show();
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
navigationManager.removeListener(listener);
}
@SuppressWarnings("EmptyMethod")
@ -143,13 +156,7 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
registration.onCompleted();
childController = null;
if (requestCloseCallable != null) {
try {
requestCloseCallable.call();
} catch (Exception e) {
e.printStackTrace();
}
}
navigationManager.navigationTo(navigationManager.getNavigationItemsForReturning());
}
}
@ -158,13 +165,8 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////
public void setRemoveCallBack(Callable<Void> requestCloseCallable) {
this.requestCloseCallable = requestCloseCallable;
}
@Override
public Initializable loadView(NavigationItem navigationItem) {
protected Initializable loadView(NavigationItem navigationItem) {
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
@ -189,14 +191,12 @@ class WizardItem extends HBox {
private final ImageView imageView;
private final Label titleLabel;
private final Label subTitleLabel;
private final AccountSetupViewCB parentCB;
private final Parent content;
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) {
this.parentCB = parentCB;
this.content = content;
this.navigationManager = navigationManager;
this.navigationItem = navigationItem;
setId("wizard-item-background-deactivated");
@ -233,7 +233,9 @@ class WizardItem extends HBox {
}
ViewCB<? extends PresentationModel> show() {
parentCB.loadView(navigationItem);
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETUP,
navigationItem);
setId("wizard-item-background-active");
imageView.setImage(ImageUtil.getIconImage(ImageUtil.ARROW_BLUE));
titleLabel.setId("wizard-title-active");

View File

@ -155,7 +155,7 @@ public class OfferController extends CachedViewController {
@Override
public TableCell<String, OfferListItem> call(TableColumn<String, OfferListItem> directionColumn) {
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();
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -19,16 +19,11 @@ package io.bitsquare.gui.main.trade.orderbook;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.NavigationListener;
import io.bitsquare.gui.NavigationManager;
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.Popups;
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.validation.OptionalBtcValidator;
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.Offer;
import com.google.bitcoin.core.Coin;
import java.net.URL;
import java.util.ArrayList;
@ -69,32 +62,30 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
private static final Logger log = LoggerFactory.getLogger(OrderBookViewCB.class);
//TODO nav?
private NavigationManager navigationManager;
private NavigationItem tradeNavigationItem;
private OverlayManager overlayManager;
private OptionalBtcValidator optionalBtcValidator;
private OptionalFiatValidator optionalFiatValidator;
private NavigationListener navigationListener;
private boolean detailsVisible;
private boolean advancedScreenInited;
private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY);
private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL);
private final Image buyIcon = ImageUtil.getIconImage(ImageUtil.BUY_ICON);
private final Image sellIcon = ImageUtil.getIconImage(ImageUtil.SELL_ICON);
private ImageView expand;
private ImageView collapse;
@FXML private CheckBox extendedCheckBox;
@FXML private Label amountBtcLabel, priceDescriptionLabel, priceFiatLabel, volumeDescriptionLabel,
@FXML CheckBox extendedCheckBox;
@FXML Label amountBtcLabel, priceDescriptionLabel, priceFiatLabel, volumeDescriptionLabel,
volumeFiatLabel, extendedButton1Label, extendedButton2Label, extendedCheckBoxLabel;
@FXML private InputTextField volumeTextField, amountTextField, priceTextField;
@FXML private TableView<OrderBookListItem> orderBookTable;
@FXML private Button createOfferButton, showAdvancedSettingsButton, extendedButton1, extendedButton2;
@FXML private TableColumn<OrderBookListItem, OrderBookListItem> priceColumn, amountColumn, volumeColumn,
@FXML InputTextField volumeTextField, amountTextField, priceTextField;
@FXML TableView<OrderBookListItem> orderBookTable;
@FXML Button createOfferButton, showAdvancedSettingsButton, extendedButton1, extendedButton2;
@FXML TableColumn<OrderBookListItem, OrderBookListItem> priceColumn, amountColumn, volumeColumn,
directionColumn, countryColumn, bankAccountTypeColumn;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@ -120,8 +111,6 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
@Override
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
// init table
setAmountColumnCellFactory();
setPriceColumnCellFactory();
@ -129,72 +118,41 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
setCountryColumnCellFactory();
setBankAccountTypeColumnCellFactory();
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.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
amountTextField.setValidator(optionalBtcValidator);
priceTextField.setValidator(optionalFiatValidator);
volumeTextField.setValidator(optionalFiatValidator);
setupBindings();
setupValidators();
setupComparators();
expand = ImageUtil.getIconImageView(ImageUtil.EXPAND);
collapse = ImageUtil.getIconImageView(ImageUtil.COLLAPSE);
showAdvancedSettingsButton.setGraphic(expand);
}
super.initialize(url, rb);
}
@Override
public void activate() {
super.activate();
// setOrderBookInfo has been called before
SortedList<OrderBookListItem> offerList = presentationModel.getOfferList();
orderBookTable.setItems(offerList);
// presentationModel.comparator.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) ?
TableColumn.SortType.ASCENDING : TableColumn.SortType.DESCENDING);
orderBookTable.sort();
/* if (orderBookTable.getItems() != null)
createOfferButton.setDefaultButton(orderBookTable.getItems().isEmpty());*/
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
// orderBookTable.getSelectionModel().clearSelection();
// orderBookTable.setItems(null);
}
@SuppressWarnings("EmptyMethod")
@ -219,10 +177,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
public void setOrderBookInfo(OrderBookInfo 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() {
if (presentationModel.isRegistered()) {
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 {
openSetupScreen();
@ -261,6 +222,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void openSetupScreen() {
overlayManager.blurContent();
List<Action> actions = new ArrayList<>();
@ -269,7 +231,9 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
public void handle(ActionEvent actionEvent) {
Dialog.Actions.OK.handle(actionEvent);
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.",
@ -279,30 +243,13 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
//TODO not updated yet
private void takeOffer(Offer offer) {
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;
if (!"".equals(amountTextField.getText())) {
requestedAmount = BSFormatter.parseToCoin(amountTextField.getText());
}
else {
requestedAmount = offer.getAmount();
}
presentationModel.getOrderBookInfo().setOffer(offer);
if (takeOfferController != null) {
takeOfferController.initWithData(offer, requestedAmount);
}
if (presentationModel.getOrderBookInfo().getDirection() == Direction.BUY)
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.BUY, NavigationItem.TAKE_OFFER);
else
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.SELL, NavigationItem.TAKE_OFFER);
}
else {
openSetupScreen();
@ -320,7 +267,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
actions);
if (response == Dialog.Actions.YES)
navigationManager.navigationTo(NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETTINGS,
navigationManager.navigationTo(NavigationItem.MAIN, NavigationItem.ACCOUNT, NavigationItem.ACCOUNT_SETTINGS,
NavigationItem.RESTRICTIONS);
else
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() {
amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper(offer.getValue()));
amountColumn.setCellFactory(
@ -479,7 +463,7 @@ public class OrderBookViewCB extends CachedViewCB<OrderBookPM> {
Offer offer = item.getOffer();
if (presentationModel.isMyOffer(offer)) {
icon = ImageUtil.getIconImage(ImageUtil.REMOVE);
icon = ImageUtil.getIconImage(ImageUtil.REMOVE_ICON);
title = "Remove";
button.setOnAction(event -> presentationModel.removeOffer(item
.getOffer()));

View File

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

View File

@ -34,10 +34,10 @@ public class ImageUtil {
public static final String HOME = "/images/nav/home.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 NAV_BUY_ACTIVE = "/images/nav/buy_active.png";
public static final String NAV_SELL = "/images/nav/sell.png";
public static final String NAV_SELL_ACTIVE = "/images/nav/sell_active.png";
public static final String BUY = "/images/nav/buy.png";
public static final String BUY_ACTIVE = "/images/nav/buy_active.png";
public static final String SELL = "/images/nav/sell.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_ACTIVE = "/images/nav/orders_active.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 BUY = "/images/buy.png";
public static final String SELL = "/images/sell.png";
public static final String REMOVE = "/images/removeOffer.png";
public static final String BUY_ICON = "/images/buy.png";
public static final String SELL_ICON = "/images/sell.png";
public static final String REMOVE_ICON = "/images/removeOffer.png";
public static final String EXPAND = "/images/expand.png";
public static final String COLLAPSE = "/images/collapse.png";

View File

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

View File

@ -299,7 +299,7 @@ public class MessageFacade implements MessageBroker {
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
+ ", values: " + futureGet.dataMap() + "]");*/
}