mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-22 16:39:23 -04:00
Refactor ViewLoader construction in src/main
This commit is contained in:
parent
75775e7e42
commit
77044d5cfe
@ -103,8 +103,7 @@ public class BitsquareUI extends Application {
|
||||
|
||||
ViewLoader.setInjector(injector);
|
||||
|
||||
ViewLoader loader =
|
||||
new ViewLoader(getClass().getResource(Navigation.Item.MAIN.getFxmlUrl()), false);
|
||||
ViewLoader loader = new ViewLoader(Navigation.Item.MAIN, false);
|
||||
try {
|
||||
Parent view = loader.load();
|
||||
|
||||
|
@ -146,7 +146,7 @@ public class MainViewCB extends ViewCB<MainPM> {
|
||||
@Override
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
super.loadView((navigationItem));
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
final Node view = loader.load();
|
||||
contentContainer.getChildren().setAll(view);
|
||||
|
@ -136,7 +136,7 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
super.loadView(navigationItem);
|
||||
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
Node view = loader.load();
|
||||
Tab tab = null;
|
||||
|
@ -97,7 +97,7 @@ public class ArbitratorSettingsViewCB extends CachedViewCB {
|
||||
@Override
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
// don't use caching here, cause exc. -> need to investigate and is rarely called so no caching is better
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
|
||||
final ViewLoader loader = new ViewLoader(navigationItem, false);
|
||||
try {
|
||||
final Parent view = loader.load();
|
||||
arbitratorRegistrationViewCB = loader.getController();
|
||||
|
@ -140,7 +140,7 @@ public class ArbitratorBrowserViewCB extends CachedViewCB implements ArbitratorL
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
super.loadView(navigationItem);
|
||||
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
Node view = loader.load();
|
||||
((Pane) root).getChildren().set(0, view);
|
||||
|
@ -189,7 +189,7 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
|
||||
@Override
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
// TODO caching causes exception
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
|
||||
final ViewLoader loader = new ViewLoader(navigationItem, false);
|
||||
try {
|
||||
final Node view = loader.load();
|
||||
//TODO Resolve type problem...
|
||||
|
@ -148,7 +148,7 @@ public class AccountSettingsViewCB extends CachedViewCB {
|
||||
|
||||
@Override
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
final Pane view = loader.load();
|
||||
content.getChildren().setAll(view);
|
||||
|
@ -188,7 +188,7 @@ public class AccountSetupViewCB extends ViewCB implements MultiStepNavigation {
|
||||
|
||||
@Override
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
final Pane view = loader.load();
|
||||
content.getChildren().setAll(view);
|
||||
|
@ -120,7 +120,7 @@ public class FundsViewCB extends CachedViewCB {
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
super.loadView(navigationItem);
|
||||
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
Node view = loader.load();
|
||||
Tab tab = null;
|
||||
|
@ -126,7 +126,7 @@ public class PortfolioViewCB extends CachedViewCB {
|
||||
protected Initializable loadView(Navigation.Item navigationItem) {
|
||||
super.loadView(navigationItem);
|
||||
|
||||
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
|
||||
final ViewLoader loader = new ViewLoader(navigationItem);
|
||||
try {
|
||||
Parent view = loader.load();
|
||||
Tab tab = null;
|
||||
|
@ -168,8 +168,7 @@ public class TradeViewCB extends CachedViewCB implements TradeNavigator {
|
||||
TabPane tabPane = (TabPane) root;
|
||||
if (navigationItem == Navigation.Item.OFFER_BOOK && offerBookViewCB == null) {
|
||||
// Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
|
||||
ViewLoader offerBookLoader =
|
||||
new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
|
||||
ViewLoader offerBookLoader = new ViewLoader(navigationItem, false);
|
||||
try {
|
||||
final Parent view = offerBookLoader.load();
|
||||
final Tab tab = new Tab(direction == Direction.BUY ? "Buy Bitcoin" : "Sell Bitcoin");
|
||||
@ -190,7 +189,7 @@ public class TradeViewCB extends CachedViewCB implements TradeNavigator {
|
||||
else if (navigationItem == Navigation.Item.CREATE_OFFER && createOfferViewCB == null) {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
|
||||
final ViewLoader loader = new ViewLoader(navigationItem, false);
|
||||
try {
|
||||
createOfferView = loader.load();
|
||||
createOfferViewCB = loader.getController();
|
||||
@ -210,7 +209,7 @@ public class TradeViewCB extends CachedViewCB implements TradeNavigator {
|
||||
offer != null) {
|
||||
// CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
|
||||
// in different graphs
|
||||
ViewLoader loader = new ViewLoader(getClass().getResource(Navigation.Item.TAKE_OFFER.getFxmlUrl()), false);
|
||||
ViewLoader loader = new ViewLoader(Navigation.Item.TAKE_OFFER, false);
|
||||
try {
|
||||
takeOfferView = loader.load();
|
||||
takeOfferViewCB = loader.getController();
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
package io.bitsquare.util;
|
||||
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
@ -51,14 +52,8 @@ public class ViewLoader {
|
||||
// TODO maybe add more sophisticated caching strategy with removal of rarely accessed items
|
||||
private static final Map<URL, Item> cachedGUIItems = new HashMap<>();
|
||||
|
||||
public ViewLoader(URL url) {
|
||||
this(url, true);
|
||||
}
|
||||
|
||||
// TODO check relationship with CachedViewCB -> derive caching strategy, but there are some special cases where
|
||||
// we need an override, as caching is done manually in the client class
|
||||
public ViewLoader(URL url, boolean useCaching) {
|
||||
this.url = url;
|
||||
public ViewLoader(Navigation.Item navItem, boolean useCaching) {
|
||||
this.url = ViewLoader.class.getResource(navItem.getFxmlUrl());
|
||||
|
||||
isCached = useCaching && cachedGUIItems.containsKey(url);
|
||||
if (!isCached) {
|
||||
@ -69,6 +64,10 @@ public class ViewLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public ViewLoader(Navigation.Item navItem) {
|
||||
this(navItem, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T load() throws java.io.IOException {
|
||||
if (isCached) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user