Support sub menu navigation

This commit is contained in:
Manfred Karrer 2014-09-10 01:02:41 +02:00
parent 1db44639bf
commit fcb2e6c5f9
7 changed files with 80 additions and 112 deletions

View file

@ -58,7 +58,7 @@ public class NavigationController {
previousMainNavigationItems = currentNavigationItems; previousMainNavigationItems = currentNavigationItems;
currentNavigationItems = navigationItems; currentNavigationItems = navigationItems;
listeners.stream().forEach((e) -> e.onNavigationRequested(currentNavigationItems)); listeners.stream().forEach((e) -> e.onNavigationRequested(navigationItems));
} }

View file

@ -46,6 +46,7 @@ import org.slf4j.LoggerFactory;
* TODO Replace it with custom views as they are graphically more flexible and the Dialogs are a bit limited from the * TODO Replace it with custom views as they are graphically more flexible and the Dialogs are a bit limited from the
* API * API
*/ */
@Deprecated
public class Popups { public class Popups {
private static final Logger log = LoggerFactory.getLogger(Popups.class); private static final Logger log = LoggerFactory.getLogger(Popups.class);
@ -55,7 +56,7 @@ public class Popups {
} }
private static OverlayController overlayController; private static OverlayController overlayController;
// Information // Information
public static void openInfo(String message) { public static void openInfo(String message) {
openInfo(message, null, null); openInfo(message, null, null);

View file

@ -87,17 +87,6 @@ public class MainModel extends UIModel {
super.initialized(); super.initialized();
} }
@Override
public void activate() {
super.activate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@Override @Override
public void terminate() { public void terminate() {

View file

@ -92,17 +92,6 @@ public class MainPM extends PresentationModel<MainModel> {
bankAccountsComboBoxPrompt.set(model.getBankAccounts().isEmpty() ? "No accounts" : ""); bankAccountsComboBoxPrompt.set(model.getBankAccounts().isEmpty() ? "No accounts" : "");
} }
@Override
public void activate() {
super.activate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@Override @Override
public void terminate() { public void terminate() {

View file

@ -51,9 +51,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class MainViewCB extends CachedCodeBehind<MainPM> { public class MainViewCB extends CodeBehind<MainPM> {
private static final Logger log = LoggerFactory.getLogger(MainViewCB.class); private static final Logger log = LoggerFactory.getLogger(MainViewCB.class);
private NavigationController navigationController;
private OverlayController overlayController;
private final ToggleGroup navButtonsGroup = new ToggleGroup(); private final ToggleGroup navButtonsGroup = new ToggleGroup();
private NavigationItem mainNavigationItem; private NavigationItem mainNavigationItem;
@ -68,8 +71,6 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, fundsButton, settingsButton, private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, fundsButton, settingsButton,
accountButton; accountButton;
private Pane ordersButtonButtonPane; private Pane ordersButtonButtonPane;
private NavigationController navigationController;
private OverlayController overlayController;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -80,6 +81,7 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
private MainViewCB(MainPM presentationModel, NavigationController navigationController, private MainViewCB(MainPM presentationModel, NavigationController navigationController,
OverlayController overlayController) { OverlayController overlayController) {
super(presentationModel); super(presentationModel);
this.navigationController = navigationController; this.navigationController = navigationController;
this.overlayController = overlayController; this.overlayController = overlayController;
@ -87,20 +89,22 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
Popups.setOverlayController(overlayController); Popups.setOverlayController(overlayController);
navigationController.addListener(navigationItems -> { navigationController.addListener(navigationItems -> {
if (navigationItems != null && navigationItems.length > 0) { if (navigationItems != null) {
NavigationItem navigationItem = navigationItems[0]; for (int i = 0; i < navigationItems.length; i++) {
if (navigationItem.getLevel() == 1) { if (navigationItems[i].getLevel() == 1) {
mainNavigationItem = navigationItem; mainNavigationItem = navigationItems[i];
loadView(mainNavigationItem); break;
selectMainMenuButton(mainNavigationItem); }
} }
} }
else {
if (mainNavigationItem == null)
mainNavigationItem = NavigationItem.HOME; mainNavigationItem = NavigationItem.HOME;
loadView(mainNavigationItem);
selectMainMenuButton(mainNavigationItem); loadView(mainNavigationItem);
} selectMainMenuButton(mainNavigationItem);
}); });
overlayController.addListener(new OverlayController.OverlayListener() { overlayController.addListener(new OverlayController.OverlayListener() {
@Override @Override
public void onBlurContentRequested() { public void onBlurContentRequested() {
@ -128,17 +132,6 @@ public class MainViewCB extends CachedCodeBehind<MainPM> {
startup(); startup();
} }
@Override
public void activate() {
super.activate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@Override @Override
public void terminate() { public void terminate() {

View file

@ -34,6 +34,7 @@ import java.util.ResourceBundle;
import javax.inject.Inject; import javax.inject.Inject;
import javafx.fxml.Initializable;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.*; import javafx.scene.*;
import javafx.scene.control.*; import javafx.scene.control.*;
@ -54,6 +55,8 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
public VBox leftVBox; public VBox leftVBox;
public AnchorPane content; public AnchorPane content;
private MenuItem seedWords, password, restrictions, fiatAccount, registration;
private NavigationController navigationController;
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Constructor // Constructor
@ -63,14 +66,7 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
private AccountSettingsViewCB(AccountSettingsPM presentationModel, NavigationController navigationController) { private AccountSettingsViewCB(AccountSettingsPM presentationModel, NavigationController navigationController) {
super(presentationModel); super(presentationModel);
navigationController.addListener(navigationItem -> { this.navigationController = navigationController;
if (navigationItem.length > 1) {
NavigationItem subMenuNavigationItem1 = navigationItem[1];
if (subMenuNavigationItem1.getLevel() == 2) {
AccountSettingsViewCB.this.subMenuNavigationItem = subMenuNavigationItem1;
}
}
});
} }
@ -83,15 +79,15 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
super.initialize(url, rb); super.initialize(url, rb);
ToggleGroup toggleGroup = new ToggleGroup(); ToggleGroup toggleGroup = new ToggleGroup();
MenuItem seedWords = new MenuItem(this, content, "Wallet seed", seedWords = new MenuItem(this, content, "Wallet seed",
NavigationItem.SEED_WORDS, toggleGroup); NavigationItem.SEED_WORDS, toggleGroup);
MenuItem password = new MenuItem(this, content, "Wallet password", password = new MenuItem(this, content, "Wallet password",
NavigationItem.CHANGE_PASSWORD, toggleGroup); NavigationItem.CHANGE_PASSWORD, toggleGroup);
MenuItem restrictions = new MenuItem(this, content, "Trading restrictions", restrictions = new MenuItem(this, content, "Trading restrictions",
NavigationItem.RESTRICTIONS, toggleGroup); NavigationItem.RESTRICTIONS, toggleGroup);
MenuItem fiatAccount = new MenuItem(this, content, "Payments account(s)", fiatAccount = new MenuItem(this, content, "Payments account(s)",
NavigationItem.FIAT_ACCOUNT, toggleGroup); NavigationItem.FIAT_ACCOUNT, toggleGroup);
MenuItem registration = new MenuItem(this, content, "Renew your account", registration = new MenuItem(this, content, "Renew your account",
NavigationItem.REGISTRATION, toggleGroup); NavigationItem.REGISTRATION, toggleGroup);
registration.setDisable(true); registration.setDisable(true);
@ -99,6 +95,21 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
leftVBox.getChildren().addAll(seedWords, password, leftVBox.getChildren().addAll(seedWords, password,
restrictions, fiatAccount, registration); restrictions, fiatAccount, registration);
}
@Override
public void activate() {
super.activate();
NavigationItem[] navigationItems = navigationController.getCurrentNavigationItems();
for (int i = 0; i < navigationItems.length; i++) {
if (navigationItems[i].getLevel() == 3) {
subMenuNavigationItem = navigationItems[i];
break;
}
}
if (subMenuNavigationItem == null) if (subMenuNavigationItem == null)
subMenuNavigationItem = NavigationItem.SEED_WORDS; subMenuNavigationItem = NavigationItem.SEED_WORDS;
@ -126,12 +137,6 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
} }
} }
@SuppressWarnings("EmptyMethod")
@Override
public void activate() {
super.activate();
}
@SuppressWarnings("EmptyMethod") @SuppressWarnings("EmptyMethod")
@Override @Override
public void deactivate() { public void deactivate() {
@ -145,24 +150,26 @@ public class AccountSettingsViewCB extends CachedCodeBehind<AccountSettingsPM> {
} }
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers
///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Public Methods // Public Methods
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@Override
/////////////////////////////////////////////////////////////////////////////////////////// public Initializable loadView(NavigationItem navigationItem) {
// UI handlers final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()));
/////////////////////////////////////////////////////////////////////////////////////////// try {
final Pane view = loader.load();
content.getChildren().setAll(view);
/////////////////////////////////////////////////////////////////////////////////////////// childController = loader.getController();
// Private methods ((CodeBehind<? extends PresentationModel>) childController).setParentController(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 {
@ -198,7 +205,7 @@ class MenuItem extends ToggleButton {
setGraphic(icon); setGraphic(icon);
setOnAction((event) -> show()); setOnAction((event) -> parentCB.loadView(navigationItem));
selectedProperty().addListener((ov, oldValue, newValue) -> { selectedProperty().addListener((ov, oldValue, newValue) -> {
if (newValue) { if (newValue) {
@ -222,19 +229,5 @@ class MenuItem extends ToggleButton {
} }
}); });
} }
void show() {
final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
((AnchorPane) content).getChildren().setAll(view);
childController = loader.getController();
childController.setParentController(parentCB);
((ContextAware) childController).useSettingsContext(true);
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.getStackTrace();
}
}
} }

View file

@ -41,6 +41,7 @@ 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.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.*; import javafx.scene.*;
import javafx.scene.control.*; import javafx.scene.control.*;
@ -161,6 +162,23 @@ public class AccountSetupViewCB extends CachedCodeBehind<AccountSetupPM> {
this.requestCloseCallable = requestCloseCallable; this.requestCloseCallable = requestCloseCallable;
} }
@Override
public Initializable loadView(NavigationItem navigationItem) {
final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
content.getChildren().setAll(view);
childController = loader.getController();
((CodeBehind<? extends PresentationModel>) childController).setParentController(this);
((ContextAware) childController).useSettingsContext(false);
return childController;
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.getStackTrace();
}
return null;
}
} }
class WizardItem extends HBox { class WizardItem extends HBox {
@ -215,7 +233,7 @@ class WizardItem extends HBox {
} }
CodeBehind<? extends PresentationModel> show() { CodeBehind<? extends PresentationModel> show() {
loadView(navigationItem); parentCB.loadView(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");
@ -229,20 +247,5 @@ class WizardItem extends HBox {
titleLabel.setId("wizard-title-completed"); titleLabel.setId("wizard-title-completed");
subTitleLabel.setId("wizard-sub-title-completed"); subTitleLabel.setId("wizard-sub-title-completed");
} }
private void loadView(NavigationItem navigationItem) {
final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
final Pane view = loader.load();
((AnchorPane) content).getChildren().setAll(view);
childController = loader.getController();
childController.setParentController(parentCB);
((ContextAware) childController).useSettingsContext(false);
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.getStackTrace();
}
}
} }