Refactor trade UIs to new pattern

This commit is contained in:
Manfred Karrer 2014-09-11 12:40:35 +02:00
parent 52b04206e8
commit 81129b8203
20 changed files with 340 additions and 57 deletions

View file

@ -3,7 +3,7 @@ package io.bitsquare.gui;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class UIModel<T> {
public class UIModel {
private static final Logger log = LoggerFactory.getLogger(UIModel.class);
public void initialize() {

View file

@ -23,7 +23,7 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
//TODO Initializable has to be changed to CodeBehind<? extends PresentationModel> when all UIs are updated
protected Initializable childController;
//TODO Initializable has to be changed to CodeBehind<? extends PresentationModel> when all UIs are updated
protected Initializable parentController;
protected Initializable parent;
@FXML protected Parent root;
@ -71,13 +71,13 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
}
/**
* @param parentController Controller who has created this.getClass().getSimpleName() instance (via
* navigateToView/FXMLLoader).
* @param parent Controller who has created this.getClass().getSimpleName() instance (via
* navigateToView/FXMLLoader).
*/
public void setParentController(Initializable parentController) {
public void setParent(Initializable parent) {
log.trace("Lifecycle: setParentController " + this.getClass().getSimpleName() + " / parent = " +
parentController);
this.parentController = parentController;
parent);
this.parent = parent;
}
/**

View file

@ -185,7 +185,7 @@ public class MainViewCB extends ViewCB<MainPM> {
childController = loader.getController();
if (childController instanceof ViewCB)
((ViewCB) childController).setParentController(this);
((ViewCB) childController).setParent(this);
presentationModel.setSelectedNavigationItem(navigationItem);
return childController;

View file

@ -110,7 +110,7 @@ public class AccountViewCB extends CachedViewCB<AccountPM> {
Pane view = loader.load();
tab.setContent(view);
Initializable childController = loader.getController();
((ViewCB) childController).setParentController(this);
((ViewCB) childController).setParent(this);
if (childController instanceof AccountSetupViewCB)
((AccountSetupViewCB) childController).setRemoveCallBack(() -> {

View file

@ -107,8 +107,8 @@ public class ChangePasswordViewCB extends CachedViewCB<ChangePasswordPM> impleme
private void onSaved() {
boolean result = presentationModel.requestSavePassword();
if (result) {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
else {
log.debug(presentationModel.getErrorMessage()); // TODO use validating TF
@ -122,8 +122,8 @@ public class ChangePasswordViewCB extends CachedViewCB<ChangePasswordPM> impleme
@FXML
private void onSkipped() {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
}

View file

@ -176,8 +176,8 @@ public class FiatAccountViewCB extends CachedViewCB<FiatAccountPm> implements Co
@FXML
private void onCompleted() {
if (parentController != null)
((MultiStepNavigation) parentController).nextStep(this);
if (parent != null)
((MultiStepNavigation) parent).nextStep(this);
}
@FXML

View file

@ -107,8 +107,8 @@ public class PasswordViewCB extends CachedViewCB<PasswordPM> implements ContextA
private void onSaved() {
boolean result = presentationModel.requestSavePassword();
if (result) {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
else {
// TODO use validating passwordTF
@ -118,8 +118,8 @@ public class PasswordViewCB extends CachedViewCB<PasswordPM> implements ContextA
@FXML
private void onSkipped() {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
@FXML

View file

@ -117,8 +117,8 @@ public class RegistrationViewCB extends CachedViewCB<RegistrationPM> implements
@Override
public void handle(ActionEvent actionEvent) {
try {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(RegistrationViewCB.this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(RegistrationViewCB.this);
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -160,8 +160,8 @@ public class RestrictionsViewCB extends CachedViewCB<RestrictionsPM> implements
@FXML
private void onCompleted() {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
@FXML

View file

@ -101,8 +101,8 @@ public class SeedWordsViewCB extends CachedViewCB<SeedWordsPM> implements Contex
@FXML
private void onCompleted() {
if (parentController instanceof MultiStepNavigation)
((MultiStepNavigation) parentController).nextStep(this);
if (parent instanceof MultiStepNavigation)
((MultiStepNavigation) parent).nextStep(this);
}
@FXML

View file

@ -160,7 +160,7 @@ public class AccountSettingsViewCB extends CachedViewCB<AccountSettingsPM> {
final Pane view = loader.load();
content.getChildren().setAll(view);
childController = loader.getController();
((ViewCB<? extends PresentationModel>) childController).setParentController(this);
((ViewCB<? extends PresentationModel>) childController).setParent(this);
((ContextAware) childController).useSettingsContext(true);
return childController;
} catch (IOException e) {

View file

@ -170,7 +170,7 @@ public class AccountSetupViewCB extends CachedViewCB<AccountSetupPM> implements
final Pane view = loader.load();
content.getChildren().setAll(view);
childController = loader.getController();
((ViewCB<? extends PresentationModel>) childController).setParentController(this);
((ViewCB<? extends PresentationModel>) childController).setParent(this);
((ContextAware) childController).useSettingsContext(false);
return childController;
} catch (IOException e) {

View file

@ -19,7 +19,15 @@ package io.bitsquare.gui.main.trade;
import io.bitsquare.trade.Direction;
import javax.inject.Inject;
public class BuyController extends TradeController {
@Inject
public BuyController(TradePM presentationModel) {
super(presentationModel);
}
@Override
protected void applyDirection() {
//tabPane.getSelectionModel().select(0);

View file

@ -19,7 +19,15 @@ package io.bitsquare.gui.main.trade;
import io.bitsquare.trade.Direction;
import javax.inject.Inject;
public class SellController extends TradeController {
@Inject
public SellController(TradePM presentationModel) {
super(presentationModel);
}
@Override
protected void applyDirection() {
orderBookController.applyDirection(Direction.SELL);

View file

@ -17,7 +17,7 @@
package io.bitsquare.gui.main.trade;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.components.InputTextField;
import io.bitsquare.gui.main.trade.createoffer.CreateOfferViewCB;
@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkArgument;
public class TradeController extends CachedViewController {
public class TradeController extends CachedViewCB<TradePM> {
private static final Logger log = LoggerFactory.getLogger(TradeController.class);
protected OrderBookController orderBookController;
@ -53,20 +53,25 @@ public class TradeController extends CachedViewController {
private Node createOfferView;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
protected TradeController(TradePM presentationModel) {
super(presentationModel);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Lifecycle
///////////////////////////////////////////////////////////////////////////////////////////
@SuppressWarnings("EmptyMethod")
@Override
public void initialize(URL url, ResourceBundle rb) {
super.initialize(url, rb);
loadViewAndGetChildController(NavigationItem.ORDER_BOOK);
}
@Override
public void deactivate() {
super.deactivate();
loadView(NavigationItem.ORDER_BOOK);
}
@Override
@ -99,13 +104,27 @@ public class TradeController extends CachedViewController {
});
}
@SuppressWarnings("EmptyMethod")
@Override
public void deactivate() {
super.deactivate();
}
@SuppressWarnings("EmptyMethod")
@Override
public void terminate() {
super.terminate();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Navigation
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public Initializable loadViewAndGetChildController(NavigationItem navigationItem) {
// @Override
public Initializable loadView(NavigationItem navigationItem) {
super.loadView(navigationItem);
TabPane tabPane = (TabPane) root;
if (navigationItem == NavigationItem.ORDER_BOOK) {
checkArgument(orderBookLoader == null);
@ -122,7 +141,7 @@ public class TradeController extends CachedViewController {
log.error(e.getMessage());
}
orderBookController = orderBookLoader.getController();
orderBookController.setParentController(this);
orderBookController.setParent(this);
return orderBookController;
}
else if (navigationItem == NavigationItem.CREATE_OFFER) {
@ -134,7 +153,7 @@ public class TradeController extends CachedViewController {
try {
createOfferView = loader.load();
createOfferCodeBehind = loader.getController();
createOfferCodeBehind.setParentController(this);
createOfferCodeBehind.setParent(this);
createOfferCodeBehind.setOnClose(() -> {
orderBookController.onCreateOfferViewRemoved();
return null;
@ -159,7 +178,8 @@ public class TradeController extends CachedViewController {
try {
final Parent view = loader.load();
takeOfferController = loader.getController();
takeOfferController.setParentController(this);
//TODO
//takeOfferController.setParentController(this);
final Tab tab = new Tab("Take offer");
tab.setContent(view);
tabPane.getTabs().add(tab);

View file

@ -0,0 +1,59 @@
/*
* 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.trade;
import io.bitsquare.gui.UIModel;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TradeModel extends UIModel {
private static final Logger log = LoggerFactory.getLogger(TradeModel.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public TradeModel() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View file

@ -0,0 +1,65 @@
/*
* 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.trade;
import io.bitsquare.gui.PresentationModel;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TradePM extends PresentationModel<TradeModel> {
private static final Logger log = LoggerFactory.getLogger(TradePM.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public TradePM(TradeModel model) {
super(model);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Interface implementation: Initializable
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View file

@ -19,7 +19,7 @@ package io.bitsquare.gui.main.trade.orderbook;
import io.bitsquare.bank.BankAccountType;
import io.bitsquare.btc.WalletFacade;
import io.bitsquare.gui.CachedViewController;
import io.bitsquare.gui.CachedViewCB;
import io.bitsquare.gui.NavigationController;
import io.bitsquare.gui.NavigationItem;
import io.bitsquare.gui.OverlayController;
@ -82,7 +82,7 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OrderBookController extends CachedViewController {
public class OrderBookController extends CachedViewCB<OrderBookPM> {
private static final Logger log = LoggerFactory.getLogger(OrderBookController.class);
private NavigationController navigationController;
@ -114,11 +114,14 @@ public class OrderBookController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private OrderBookController(NavigationController navigationController,
private OrderBookController(OrderBookPM presentationModel,
NavigationController navigationController,
OverlayController overlayController,
OrderBook orderBook, User user,
MessageFacade messageFacade,
WalletFacade walletFacade, Settings settings, Persistence persistence) {
super(presentationModel);
this.navigationController = navigationController;
this.overlayController = overlayController;
this.orderBook = orderBook;
@ -173,13 +176,13 @@ public class OrderBookController extends CachedViewController {
///////////////////////////////////////////////////////////////////////////////////////////
@Override
public void setParentController(ViewController parentController) {
super.setParentController(parentController);
public void setParent(Initializable parent) {
super.setParent(parent);
}
@Override
public Initializable loadViewAndGetChildController(NavigationItem navigationItem) {
return null;
public Initializable loadView(NavigationItem navigationItem) {
return super.loadView(navigationItem);
}
@ -242,12 +245,12 @@ public class OrderBookController extends CachedViewController {
//TODO Remove that when all UIs are converted to CodeBehind
Initializable nextController = null;
if (parentController != null) {
if (parentController instanceof ViewController)
nextController = ((ViewController) parentController).loadViewAndGetChildController(NavigationItem
if (parent != null) {
if (parent instanceof ViewController)
nextController = ((ViewController) parent).loadViewAndGetChildController(NavigationItem
.CREATE_OFFER);
else if (parentController instanceof ViewCB)
nextController = ((ViewCB) parentController).loadView(NavigationItem
else if (parent instanceof ViewCB)
nextController = ((ViewCB) parent).loadView(NavigationItem
.CREATE_OFFER);
}
@ -322,13 +325,13 @@ public class OrderBookController extends CachedViewController {
//TODO Remove that when all UIs are converted to CodeBehind
TakeOfferController takeOfferController = null;
if (parentController != null) {
if (parentController instanceof ViewController)
takeOfferController = (TakeOfferController) ((ViewController) parentController)
if (parent != null) {
if (parent instanceof ViewController)
takeOfferController = (TakeOfferController) ((ViewController) parent)
.loadViewAndGetChildController(NavigationItem
.TAKE_OFFER);
else if (parentController instanceof ViewCB)
takeOfferController = (TakeOfferController) ((ViewCB) parentController)
else if (parent instanceof ViewCB)
takeOfferController = (TakeOfferController) ((ViewCB) parent)
.loadView(NavigationItem
.TAKE_OFFER);
}

View file

@ -0,0 +1,60 @@
/*
* 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.trade.orderbook;
import io.bitsquare.gui.UIModel;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OrderBookModel extends UIModel {
private static final Logger log = LoggerFactory.getLogger(OrderBookModel.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public OrderBookModel() {
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
}

View file

@ -0,0 +1,60 @@
/*
* 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.trade.orderbook;
import io.bitsquare.gui.PresentationModel;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OrderBookPM extends PresentationModel<OrderBookModel> {
private static final Logger log = LoggerFactory.getLogger(OrderBookPM.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
public OrderBookPM(OrderBookModel model) {
super(model);
}
///////////////////////////////////////////////////////////////////////////////////////////
// Public methods
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Getters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Setters
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////////////////////////////////
}