Remove old Controller classes

This commit is contained in:
Manfred Karrer 2014-09-26 11:42:12 +02:00
parent 33148a9a8a
commit 9ea6fb9b55
22 changed files with 268 additions and 514 deletions

View File

@ -1,88 +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;
import java.net.URL;
import java.util.ResourceBundle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* If caching is used for loader we use the CachedViewController for turning the controller into sleep mode if not
* active and awake it at reactivation.
*/
// for new PM pattern use CachedCodeBehind
@Deprecated
public abstract class CachedViewController extends ViewController {
private static final Logger log = LoggerFactory.getLogger(CachedViewController.class);
public CachedViewController() {
}
/**
* Get called form GUI framework when the UI is ready.
* In caching controllers the initialize is only used for static UI setup.
* The activate() method is called to start resources like.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
// we got removed from the scene
// lets terminate
log.trace("Lifecycle: sceneProperty changed: " + this.getClass().getSimpleName() + " / oldValue=" +
oldValue + " / newValue=" + newValue);
if (oldValue == null && newValue != null) activate();
else if (oldValue != null && newValue == null) deactivate();
});
}
/**
* In caching controllers the terminate calls the deactivate method.
*/
@Override
public void terminate() {
log.trace("Lifecycle: terminate " + this.getClass().getSimpleName());
super.terminate();
deactivate();
}
/**
* Used for deactivating resources (removing listeners, stopping timers or animations,...)
*/
public void deactivate() {
log.trace("Lifecycle: deactivate " + this.getClass().getSimpleName());
if (childController instanceof CachedViewController) ((CachedViewController) childController).deactivate();
}
/**
* Used to activate resources (adding listeners, starting timers or animations,...)
*/
public void activate() {
log.trace("Lifecycle: activate " + this.getClass().getSimpleName());
if (childController instanceof CachedViewController) ((CachedViewController) childController).activate();
}
}

View File

@ -1,96 +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;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Base class for all controllers.
*/
// for new PM pattern use CodeBehind
@Deprecated
public abstract class ViewController implements Initializable {
private static final Logger log = LoggerFactory.getLogger(ViewController.class);
protected Initializable childController;
protected Initializable parentController;
@FXML protected Parent root;
/**
* Get called form GUI framework when the UI is ready.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
// we got removed from the scene
// lets terminate
if (oldValue != null && newValue == null) terminate();
});
}
/**
* Called automatically when view gets removed. Used for house keeping (removing listeners,
* stopping timers or animations,...).
*/
public void terminate() {
log.trace("Lifecycle: terminate " + this.getClass().getSimpleName());
if (childController != null) {
if (childController instanceof ViewController)
((ViewController) childController).terminate();
else if (childController instanceof ViewCB)
((ViewCB) childController).terminate();
}
}
/**
* @param parentController Controller who has created this.getClass().getSimpleName() instance (via
* navigateToView/FXMLLoader).
*/
public void setParentController(Initializable parentController) {
log.trace("Lifecycle: setParentController " + this.getClass().getSimpleName() + " / parent = " +
parentController);
this.parentController = parentController;
}
/**
* @param item NavigationItem to be loaded.
* @return The ViewController of the loaded view.
*/
public Initializable loadViewAndGetChildController(Navigation.Item item) {
log.trace("Lifecycle: loadViewAndGetChildController " + this.getClass().getSimpleName() + " / navigationItem " +
"= " + item);
return null;
}
}

View File

@ -1,125 +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.components;
import io.bitsquare.gui.ViewController;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.util.ViewLoader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.*;
import javafx.scene.control.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* That class caches the already created views in a tab pane.
* So when switching back to an already opened tab it is faster as no fxml loading is needed anymore.
*/
public class CachingTabPane extends TabPane {
private static final Logger log = LoggerFactory.getLogger(CachingTabPane.class);
private final List<TabInfo> tabInfoList = new ArrayList<>();
private ViewController parentController;
private Persistence persistence;
private int selectedTabIndex;
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
public void initialize(ViewController parentController, Persistence persistence, String... tabContentFXMLUrls) {
if (tabContentFXMLUrls.length == 0) {
throw new IllegalArgumentException("No tabContentFXMLUrls defined");
}
this.parentController = parentController;
this.persistence = persistence;
for (String tabContentFXMLUrl : tabContentFXMLUrls) tabInfoList.add(new TabInfo(tabContentFXMLUrl));
getSelectionModel().selectedItemProperty().addListener((observableValue, oldTab, newTab) -> loadView());
// use parent to read selectedTabIndex
Object indexObject = persistence.read(parentController, "selectedTabIndex");
selectedTabIndex = (indexObject == null) ? 0 : (int) indexObject;
// if selectedTabIndex = 0 the the change listener will not fire so we load it manually
if (selectedTabIndex == 0) loadView();
getSelectionModel().select(selectedTabIndex);
}
public ViewController loadViewAndGetChildController(String fxmlView) {
for (int i = 0; i < tabInfoList.size(); i++) {
if (tabInfoList.get(i).url.equals(fxmlView)) {
// selection will cause loadView() call
getSelectionModel().select(i);
return currentController();
}
}
throw new IllegalArgumentException("fxmlView not defined in tabContentFXMLUrlMap.");
}
public void setSelectedTabIndex(int selectedTabIndex) {
getSelectionModel().select(selectedTabIndex);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
private void loadView() {
selectedTabIndex = getSelectionModel().getSelectedIndex();
TabInfo selectedTabInfo = tabInfoList.get(selectedTabIndex);
final ViewLoader loader = new ViewLoader(getClass().getResource(selectedTabInfo.url));
try {
Node view = loader.load();
selectedTabInfo.controller = loader.getController();
getSelectionModel().getSelectedItem().setContent(view);
} catch (IOException e) {
log.error(e.getMessage());
}
selectedTabInfo.controller.setParentController(parentController);
// use parent to write selectedTabIndex
persistence.write(parentController, "selectedTabIndex", selectedTabIndex);
}
private ViewController currentController() {
return tabInfoList.get(selectedTabIndex).controller;
}
}
class TabInfo {
ViewController controller;
final String url;
TabInfo(String url) {
this.url = url;
}
}

View File

@ -18,7 +18,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.browser.ArbitratorBrowserController"
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.browser.ArbitratorBrowserViewCB"
prefHeight="600" prefWidth="800" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
xmlns:fx="http://javafx.com/fxml">

View File

@ -18,9 +18,10 @@
package io.bitsquare.gui.main.arbitrators.browser;
import io.bitsquare.arbitrator.Arbitrator;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
import io.bitsquare.gui.ViewCB;
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileViewCB;
import io.bitsquare.locale.LanguageUtil;
import io.bitsquare.msg.MessageFacade;
import io.bitsquare.msg.listeners.ArbitratorListener;
@ -51,15 +52,15 @@ import org.slf4j.LoggerFactory;
/**
* Arbitration is not much developed yet
*/
public class ArbitratorBrowserController extends CachedViewController implements ArbitratorListener {
private static final Logger log = LoggerFactory.getLogger(ArbitratorBrowserController.class);
public class ArbitratorBrowserViewCB extends CachedViewCB implements ArbitratorListener {
private static final Logger log = LoggerFactory.getLogger(ArbitratorBrowserViewCB.class);
private final Settings settings;
private final Persistence persistence;
private final List<Arbitrator> allArbitrators = new ArrayList<>();
private Arbitrator currentArbitrator;
private ArbitratorProfileController arbitratorProfileController;
private ArbitratorProfileViewCB arbitratorProfileViewCB;
private int index = -1;
@FXML Button prevButton, nextButton, selectButton, closeButton;
@ -70,7 +71,7 @@ public class ArbitratorBrowserController extends CachedViewController implements
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public ArbitratorBrowserController(Settings settings, Persistence persistence, MessageFacade messageFacade) {
public ArbitratorBrowserViewCB(Settings settings, Persistence persistence, MessageFacade messageFacade) {
this.settings = settings;
this.persistence = persistence;
@ -88,23 +89,26 @@ public class ArbitratorBrowserController extends CachedViewController implements
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
loadViewAndGetChildController(Navigation.Item.ARBITRATOR_PROFILE);
loadView(Navigation.Item.ARBITRATOR_PROFILE);
checkButtonState();
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
public void activate() {
super.activate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void activate() {
super.activate();
public void terminate() {
super.terminate();
}
@ -112,28 +116,44 @@ public class ArbitratorBrowserController extends CachedViewController implements
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setParentController(Initializable parentController) {
super.setParentController(parentController);
}
@Override
public Initializable loadViewAndGetChildController(Navigation.Item item) {
/* public Initializable loadViewAndGetChildController(Navigation.Item item) {
final ViewLoader loader = new ViewLoader(getClass().getResource(item.getFxmlUrl()));
try {
final Node view = loader.load();
arbitratorProfileController = loader.getController();
arbitratorProfileController.setParentController(this);
arbitratorProfileViewCB = loader.getController();
arbitratorProfileViewCB.setParentController(this);
((Pane) root).getChildren().set(0, view);
return arbitratorProfileController;
return arbitratorProfileViewCB;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}*/
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected Initializable loadView(Navigation.Item navigationItem) {
super.loadView(navigationItem);
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
Node view = loader.load();
((Pane) root).getChildren().set(0, view);
Initializable childController = arbitratorProfileViewCB = loader.getController();
((ViewCB) childController).setParent(this);
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.printStackTrace();
}
return childController;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: ArbitratorListener
///////////////////////////////////////////////////////////////////////////////////////////
@ -150,7 +170,7 @@ public class ArbitratorBrowserController extends CachedViewController implements
if (!allArbitrators.isEmpty()) {
index = 0;
currentArbitrator = allArbitrators.get(index);
arbitratorProfileController.applyArbitrator(currentArbitrator);
arbitratorProfileViewCB.applyArbitrator(currentArbitrator);
checkButtonState();
}
}
@ -169,7 +189,7 @@ public class ArbitratorBrowserController extends CachedViewController implements
if (index > 0) {
index--;
currentArbitrator = allArbitrators.get(index);
arbitratorProfileController.applyArbitrator(currentArbitrator);
arbitratorProfileViewCB.applyArbitrator(currentArbitrator);
}
checkButtonState();
}
@ -179,7 +199,7 @@ public class ArbitratorBrowserController extends CachedViewController implements
if (index < allArbitrators.size() - 1) {
index++;
currentArbitrator = allArbitrators.get(index);
arbitratorProfileController.applyArbitrator(currentArbitrator);
arbitratorProfileViewCB.applyArbitrator(currentArbitrator);
}
checkButtonState();
}

View File

@ -19,7 +19,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<GridPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController"
<GridPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileViewCB"
hgap="5.0" vgap="5.0" AnchorPane.bottomAnchor="80.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
xmlns:fx="http://javafx.com/fxml">

View File

@ -18,8 +18,7 @@
package io.bitsquare.gui.main.arbitrators.profile;
import io.bitsquare.arbitrator.Arbitrator;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.persistence.Persistence;
import io.bitsquare.settings.Settings;
@ -31,11 +30,10 @@ import java.util.ResourceBundle;
import javax.inject.Inject;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
// Arbitration is not much developed yet
public class ArbitratorProfileController extends CachedViewController {
public class ArbitratorProfileViewCB extends CachedViewCB {
private final Settings settings;
@ -56,7 +54,7 @@ public class ArbitratorProfileController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public ArbitratorProfileController(Settings settings, Persistence persistence, BSFormatter formatter) {
public ArbitratorProfileViewCB(Settings settings, Persistence persistence, BSFormatter formatter) {
this.settings = settings;
this.persistence = persistence;
@ -70,39 +68,28 @@ public class ArbitratorProfileController extends CachedViewController {
// Lifecycle
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("EmptyMethod")
@Override
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
}
@Override
public void terminate() {
super.terminate();
}
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void activate() {
super.activate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("EmptyMethod")
@Override
public void setParentController(Initializable parentController) {
super.setParentController(parentController);
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public Initializable loadViewAndGetChildController(Navigation.Item item) {
return null;
public void terminate() {
super.terminate();
}

View File

@ -20,7 +20,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.registration.ArbitratorRegistrationController"
<AnchorPane fx:id="root" fx:controller="io.bitsquare.gui.main.arbitrators.registration.ArbitratorRegistrationViewCB"
prefHeight="600" prefWidth="800" AnchorPane.bottomAnchor="30.0" AnchorPane.leftAnchor="10.0"
AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"
xmlns:fx="http://javafx.com/fxml">

View File

@ -20,10 +20,9 @@ package io.bitsquare.gui.main.arbitrators.registration;
import io.bitsquare.arbitrator.Arbitrator;
import io.bitsquare.arbitrator.Reputation;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.components.confidence.ConfidenceProgressIndicator;
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileController;
import io.bitsquare.gui.main.arbitrators.profile.ArbitratorProfileViewCB;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.LanguageUtil;
@ -51,7 +50,6 @@ import javax.inject.Inject;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.input.*;
import javafx.stage.Stage;
@ -64,8 +62,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Arbitration is not much developed yet
public class ArbitratorRegistrationController extends CachedViewController {
private static final Logger log = LoggerFactory.getLogger(ArbitratorRegistrationController.class);
public class ArbitratorRegistrationViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(ArbitratorRegistrationViewCB.class);
private final Persistence persistence;
private final WalletFacade walletFacade;
@ -73,7 +71,7 @@ public class ArbitratorRegistrationController extends CachedViewController {
private final User user;
private BSFormatter formatter;
private Arbitrator arbitrator = new Arbitrator();
private ArbitratorProfileController arbitratorProfileController;
private ArbitratorProfileViewCB arbitratorProfileViewCB;
private boolean isEditMode;
private List<Locale> languageList = new ArrayList<>();
@ -104,8 +102,8 @@ public class ArbitratorRegistrationController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private ArbitratorRegistrationController(Persistence persistence, WalletFacade walletFacade,
MessageFacade messageFacade, User user, BSFormatter formatter) {
private ArbitratorRegistrationViewCB(Persistence persistence, WalletFacade walletFacade,
MessageFacade messageFacade, User user, BSFormatter formatter) {
this.persistence = persistence;
this.walletFacade = walletFacade;
this.messageFacade = messageFacade;
@ -197,37 +195,24 @@ public class ArbitratorRegistrationController extends CachedViewController {
});
}
@Override
public void terminate() {
super.terminate();
}
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void activate() {
super.activate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("EmptyMethod")
@Override
public void setParentController(Initializable parentController) {
super.setParentController(parentController);
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public Initializable loadViewAndGetChildController(Navigation.Item item) {
return null;
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public Methods
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,88 +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.main.funds;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.ViewController;
import io.bitsquare.gui.components.CachingTabPane;
import io.bitsquare.persistence.Persistence;
import java.net.URL;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javafx.fxml.Initializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FundsController extends CachedViewController {
private static final Logger log = LoggerFactory.getLogger(FundsController.class);
private final Persistence persistence;
private ViewController childController;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private FundsController(Persistence persistence) {
this.persistence = persistence;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Lifecycle
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
((CachingTabPane) root).initialize(
this, persistence, Navigation.Item.WITHDRAWAL.getFxmlUrl(),
Navigation.Item.TRANSACTIONS.getFxmlUrl());
}
@Override
public void deactivate() {
super.deactivate();
}
@Override
public void activate() {
super.activate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public Initializable loadViewAndGetChildController(Navigation.Item item) {
childController = ((CachingTabPane) root).loadViewAndGetChildController(item.getFxmlUrl());
return childController;
}
}

View File

@ -16,15 +16,14 @@
~ along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
-->
<?import io.bitsquare.gui.components.CachingTabPane?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<CachingTabPane fx:id="root" fx:controller="io.bitsquare.gui.main.funds.FundsController"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"
xmlns:fx="http://javafx.com/fxml">
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.main.funds.FundsViewCB"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"
xmlns:fx="http://javafx.com/fxml">
<Tab text="Withdrawal" closable="false"/>
<Tab text="Transactions" closable="false"/>
<Tab fx:id="withdrawalTab" text="Withdrawal" closable="false"/>
<Tab fx:id="transactionsTab" text="Transactions" closable="false"/>
</CachingTabPane>
</TabPane>

View File

@ -0,0 +1,148 @@
/*
* 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.main.funds;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.ViewCB;
import io.bitsquare.util.ViewLoader;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javax.inject.Inject;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.*;
import javafx.scene.control.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FundsViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(FundsViewCB.class);
private final Navigation navigation;
private Navigation.Listener navigationListener;
private ChangeListener<Tab> tabChangeListener;
@FXML Tab withdrawalTab, transactionsTab;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
FundsViewCB(Navigation navigation) {
super();
this.navigation = navigation;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Lifecycle
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void initialize(URL url, ResourceBundle rb) {
navigationListener = navigationItems -> {
if (navigationItems != null && navigationItems.length == 3
&& navigationItems[1] == Navigation.Item.FUNDS)
loadView(navigationItems[2]);
};
tabChangeListener = (ov, oldValue, newValue) -> {
if (newValue == withdrawalTab)
navigation.navigationTo(Navigation.Item.MAIN, Navigation.Item.FUNDS, Navigation.Item.WITHDRAWAL);
else if (newValue == transactionsTab)
navigation.navigationTo(Navigation.Item.MAIN, Navigation.Item.FUNDS, Navigation.Item.TRANSACTIONS);
};
super.initialize(url, rb);
}
@Override
public void activate() {
super.activate();
((TabPane) root).getSelectionModel().selectedItemProperty().addListener(tabChangeListener);
navigation.addListener(navigationListener);
if (((TabPane) root).getSelectionModel().getSelectedItem() == transactionsTab)
navigation.navigationTo(Navigation.Item.MAIN, Navigation.Item.FUNDS, Navigation.Item.TRANSACTIONS);
else
navigation.navigationTo(Navigation.Item.MAIN, Navigation.Item.FUNDS, Navigation.Item.WITHDRAWAL);
}
@Override
public void deactivate() {
super.deactivate();
((TabPane) root).getSelectionModel().selectedItemProperty().removeListener(tabChangeListener);
navigation.removeListener(navigationListener);
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@Override
protected Initializable loadView(Navigation.Item navigationItem) {
super.loadView(navigationItem);
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()));
try {
Node view = loader.load();
Tab tab = null;
switch (navigationItem) {
case WITHDRAWAL:
tab = withdrawalTab;
break;
case TRANSACTIONS:
tab = transactionsTab;
break;
}
tab.setContent(view);
((TabPane) root).getSelectionModel().select(tab);
Initializable childController = loader.getController();
((ViewCB) childController).setParent(this);
} catch (IOException e) {
log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl());
e.printStackTrace();
}
return childController;
}
}

View File

@ -21,7 +21,7 @@
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox fx:id="root" fx:controller="io.bitsquare.gui.main.funds.transactions.TransactionsController"
<VBox fx:id="root" fx:controller="io.bitsquare.gui.main.funds.transactions.TransactionsViewCB"
spacing="10" xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>

View File

@ -18,7 +18,7 @@
package io.bitsquare.gui.main.funds.transactions;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.util.BSFormatter;
import com.google.bitcoin.core.Transaction;
@ -41,8 +41,8 @@ import javafx.util.Callback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TransactionsController extends CachedViewController {
private static final Logger log = LoggerFactory.getLogger(TransactionsController.class);
public class TransactionsViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(TransactionsViewCB.class);
private final WalletFacade walletFacade;
private BSFormatter formatter;
@ -58,7 +58,7 @@ public class TransactionsController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private TransactionsController(WalletFacade walletFacade, BSFormatter formatter) {
private TransactionsViewCB(WalletFacade walletFacade, BSFormatter formatter) {
this.walletFacade = walletFacade;
this.formatter = formatter;
}
@ -98,6 +98,12 @@ public class TransactionsController extends CachedViewController {
tableView.setItems(transactionsListItems);
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers

View File

@ -21,7 +21,7 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.scene.layout.*?>
<VBox fx:id="root" fx:controller="io.bitsquare.gui.main.funds.withdrawal.WithdrawalController"
<VBox fx:id="root" fx:controller="io.bitsquare.gui.main.funds.withdrawal.WithdrawalViewCB"
spacing="10" xmlns:fx="http://javafx.com/fxml">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0"/>

View File

@ -21,7 +21,7 @@ import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.Restrictions;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.components.Popups;
import io.bitsquare.gui.util.BSFormatter;
@ -59,8 +59,8 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class WithdrawalController extends CachedViewController {
private static final Logger log = LoggerFactory.getLogger(WithdrawalController.class);
public class WithdrawalViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(WithdrawalViewCB.class);
private final WalletFacade walletFacade;
@ -79,7 +79,7 @@ public class WithdrawalController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private WithdrawalController(WalletFacade walletFacade, BSFormatter formatter) {
private WithdrawalViewCB(WalletFacade walletFacade, BSFormatter formatter) {
this.walletFacade = walletFacade;
this.formatter = formatter;
}
@ -90,14 +90,14 @@ public class WithdrawalController extends CachedViewController {
@Override
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
setLabelColumnCellFactory();
setBalanceColumnCellFactory();
setCopyColumnCellFactory();
setConfidenceColumnCellFactory();
super.initialize(url, rb);
}
@Override
@ -137,6 +137,12 @@ public class WithdrawalController extends CachedViewController {
tableView.setItems(addressList);
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// UI handlers

View File

@ -20,7 +20,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.main.home.HomeController"
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.main.home.HomeViewCB"
AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0"
xmlns:fx="http://javafx.com/fxml">

View File

@ -20,7 +20,7 @@ package io.bitsquare.gui.main.home;
import io.bitsquare.BitSquare;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.main.arbitrators.registration.ArbitratorRegistrationController;
import io.bitsquare.gui.main.arbitrators.registration.ArbitratorRegistrationViewCB;
import io.bitsquare.util.ViewLoader;
import java.io.IOException;
@ -40,10 +40,10 @@ import org.slf4j.LoggerFactory;
// home is just hosting the arbiters buttons yet, but that's just for dev, not clear yet what will be in home,
// probably overview, event history, news, charts,... -> low prio
public class HomeController extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(HomeController.class);
public class HomeViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(HomeViewCB.class);
private ArbitratorRegistrationController arbitratorRegistrationController;
private ArbitratorRegistrationViewCB arbitratorRegistrationViewCB;
///////////////////////////////////////////////////////////////////////////////////////////
// Lifecycle
@ -84,8 +84,7 @@ public class HomeController extends CachedViewCB {
final ViewLoader loader = new ViewLoader(getClass().getResource(navigationItem.getFxmlUrl()), false);
try {
final Parent view = loader.load();
arbitratorRegistrationController = loader.getController();
arbitratorRegistrationController.setParentController(this);
arbitratorRegistrationViewCB = loader.getController();
final Stage rootStage = BitSquare.getPrimaryStage();
final Stage stage = new Stage();
@ -102,7 +101,7 @@ public class HomeController extends CachedViewCB {
stage.setScene(scene);
stage.show();
return arbitratorRegistrationController;
return arbitratorRegistrationViewCB;
} catch (IOException e) {
e.printStackTrace();
}
@ -122,7 +121,7 @@ public class HomeController extends CachedViewCB {
@FXML
public void onArbitratorEdit() {
loadView(Navigation.Item.ARBITRATOR_REGISTRATION);
arbitratorRegistrationController.setEditMode(true);
arbitratorRegistrationViewCB.setEditMode(true);
}

View File

@ -20,7 +20,7 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.main.msg.MsgController"
<TabPane fx:id="root" fx:controller="io.bitsquare.gui.main.msg.MsgViewCB"
AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0"
AnchorPane.rightAnchor="0" AnchorPane.topAnchor="0"
xmlns:fx="http://javafx.com/fxml">

View File

@ -34,8 +34,8 @@ import org.slf4j.LoggerFactory;
// will be probably only used for arbitration communication, will be renamed and the icon changed
public class MsgController extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(MsgController.class);
public class MsgViewCB extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(MsgViewCB.class);
///////////////////////////////////////////////////////////////////////////////////////////
@ -43,7 +43,7 @@ public class MsgController extends CachedViewCB {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private MsgController() {
private MsgViewCB() {
}
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -45,10 +45,11 @@ public class OrdersViewCB extends CachedViewCB {
private final Navigation navigation;
private final TradeManager tradeManager;
private Navigation.Listener navigationListener;
private ChangeListener<Tab> tabChangeListener;
@FXML Tab offersTab, pendingTradesTab, closedTradesTab;
private ChangeListener<Tab> tabChangeListener;
///////////////////////////////////////////////////////////////////////////////////////////

View File

@ -17,7 +17,7 @@
package io.bitsquare.gui.main.orders.pending.uimock;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.components.processbar.ProcessStepBar;
import io.bitsquare.gui.components.processbar.ProcessStepItem;
@ -32,7 +32,7 @@ import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PendingTradesControllerUIMock extends CachedViewController {
public class PendingTradesControllerUIMock extends CachedViewCB {
private static final Logger log = LoggerFactory.getLogger(PendingTradesControllerUIMock.class);
public ProcessStepBar processBar;