mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 08:55:22 -04:00
Rename initialized to initialize, add null checks in base UI classes
This commit is contained in:
parent
46863bb4c2
commit
52b04206e8
28 changed files with 90 additions and 76 deletions
|
@ -30,6 +30,7 @@ public class CachedViewCB<T extends PresentationModel> extends ViewCB<T> {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
|
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
|
||||||
|
if (root != null) {
|
||||||
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
|
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
|
||||||
// we got removed from the scene
|
// we got removed from the scene
|
||||||
// lets terminate
|
// lets terminate
|
||||||
|
@ -38,8 +39,10 @@ public class CachedViewCB<T extends PresentationModel> extends ViewCB<T> {
|
||||||
if (oldValue == null && newValue != null) activate();
|
if (oldValue == null && newValue != null) activate();
|
||||||
else if (oldValue != null && newValue == null) deactivate();
|
else if (oldValue != null && newValue == null) deactivate();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
presentationModel.initialized();
|
if (presentationModel != null)
|
||||||
|
presentationModel.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +52,7 @@ public class CachedViewCB<T extends PresentationModel> extends ViewCB<T> {
|
||||||
log.trace("Lifecycle: activate " + this.getClass().getSimpleName());
|
log.trace("Lifecycle: activate " + this.getClass().getSimpleName());
|
||||||
if (childController instanceof CachedViewCB) ((CachedViewCB) childController).activate();
|
if (childController instanceof CachedViewCB) ((CachedViewCB) childController).activate();
|
||||||
|
|
||||||
|
if (presentationModel != null)
|
||||||
presentationModel.activate();
|
presentationModel.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +63,7 @@ public class CachedViewCB<T extends PresentationModel> extends ViewCB<T> {
|
||||||
log.trace("Lifecycle: deactivate " + this.getClass().getSimpleName());
|
log.trace("Lifecycle: deactivate " + this.getClass().getSimpleName());
|
||||||
if (childController instanceof CachedViewCB) ((CachedViewCB) childController).deactivate();
|
if (childController instanceof CachedViewCB) ((CachedViewCB) childController).deactivate();
|
||||||
|
|
||||||
|
if (presentationModel != null)
|
||||||
presentationModel.deactivate();
|
presentationModel.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +75,7 @@ public class CachedViewCB<T extends PresentationModel> extends ViewCB<T> {
|
||||||
log.trace("Lifecycle: terminate " + this.getClass().getSimpleName());
|
log.trace("Lifecycle: terminate " + this.getClass().getSimpleName());
|
||||||
super.terminate();
|
super.terminate();
|
||||||
|
|
||||||
|
if (presentationModel != null)
|
||||||
presentationModel.terminate();
|
presentationModel.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,25 +8,31 @@ public class PresentationModel<T extends UIModel> {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Still open question if we enforce a model or not? For small UIs it might be too much overhead.
|
||||||
public PresentationModel() {
|
public PresentationModel() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
model.initialized();
|
if (model != null)
|
||||||
|
model.initialize();
|
||||||
|
|
||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void activate() {
|
public void activate() {
|
||||||
|
if (model != null)
|
||||||
model.activate();
|
model.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deactivate() {
|
public void deactivate() {
|
||||||
|
if (model != null)
|
||||||
model.deactivate();
|
model.deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void terminate() {
|
public void terminate() {
|
||||||
|
if (model != null)
|
||||||
model.terminate();
|
model.terminate();
|
||||||
|
|
||||||
deactivate();
|
deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.slf4j.LoggerFactory;
|
||||||
public class UIModel<T> {
|
public class UIModel<T> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(UIModel.class);
|
private static final Logger log = LoggerFactory.getLogger(UIModel.class);
|
||||||
|
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
activate();
|
activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,14 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
|
||||||
protected Initializable childController;
|
protected Initializable childController;
|
||||||
//TODO Initializable has to be changed to CodeBehind<? extends PresentationModel> when all UIs are updated
|
//TODO Initializable has to be changed to CodeBehind<? extends PresentationModel> when all UIs are updated
|
||||||
protected Initializable parentController;
|
protected Initializable parentController;
|
||||||
|
|
||||||
@FXML protected Parent root;
|
@FXML protected Parent root;
|
||||||
|
|
||||||
public ViewCB(T presentationModel) {
|
public ViewCB(T presentationModel) {
|
||||||
this.presentationModel = presentationModel;
|
this.presentationModel = presentationModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Still open question if we enforce a presentationModel or not? For small UIs it might be too much overhead.
|
||||||
public ViewCB() {
|
public ViewCB() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,16 +44,17 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL url, ResourceBundle rb) {
|
public void initialize(URL url, ResourceBundle rb) {
|
||||||
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
|
log.trace("Lifecycle: initialize " + this.getClass().getSimpleName());
|
||||||
|
if (root != null) {
|
||||||
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
|
root.sceneProperty().addListener((ov, oldValue, newValue) -> {
|
||||||
// we got removed from the scene
|
// we got removed from the scene
|
||||||
// lets terminate
|
// lets terminate
|
||||||
if (oldValue != null && newValue == null)
|
if (oldValue != null && newValue == null)
|
||||||
terminate();
|
terminate();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
presentationModel.initialized();
|
if (presentationModel != null)
|
||||||
presentationModel.activate();
|
presentationModel.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +66,7 @@ public class ViewCB<T extends PresentationModel> implements Initializable {
|
||||||
if (childController != null)
|
if (childController != null)
|
||||||
((ViewCB<? extends PresentationModel>) childController).terminate();
|
((ViewCB<? extends PresentationModel>) childController).terminate();
|
||||||
|
|
||||||
presentationModel.deactivate();
|
if (presentationModel != null)
|
||||||
presentationModel.terminate();
|
presentationModel.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,8 +84,8 @@ public class MainModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class MainPM extends PresentationModel<MainModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
backendInited.bind(model.backendInited);
|
backendInited.bind(model.backendInited);
|
||||||
networkSyncComplete.bind(model.networkSyncComplete);
|
networkSyncComplete.bind(model.networkSyncComplete);
|
||||||
|
|
|
@ -50,7 +50,6 @@ import javafx.scene.layout.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
public class MainViewCB extends ViewCB<MainPM> {
|
public class MainViewCB extends ViewCB<MainPM> {
|
||||||
private static final Logger log = LoggerFactory.getLogger(MainViewCB.class);
|
private static final Logger log = LoggerFactory.getLogger(MainViewCB.class);
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class AccountModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class AccountPM extends PresentationModel<AccountModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -42,8 +42,8 @@ public class ChangePasswordModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class ChangePasswordPM extends PresentationModel<ChangePasswordModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -89,8 +89,8 @@ public class FiatAccountModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -78,8 +78,8 @@ public class FiatAccountPm extends PresentationModel<FiatAccountModel> {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
// input
|
// input
|
||||||
title.bindBidirectional(model.title);
|
title.bindBidirectional(model.title);
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class PasswordModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -63,8 +63,8 @@ public class PasswordPM extends PresentationModel<PasswordModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -78,8 +78,8 @@ public class RegistrationModel extends UIModel {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
if (walletFacade != null && walletFacade.getWallet() != null) {
|
if (walletFacade != null && walletFacade.getWallet() != null) {
|
||||||
addressEntry = walletFacade.getRegistrationAddressEntry();
|
addressEntry = walletFacade.getRegistrationAddressEntry();
|
||||||
|
|
|
@ -64,8 +64,8 @@ public class RegistrationPM extends PresentationModel<RegistrationModel> {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
if (model.getAddressEntry() != null) {
|
if (model.getAddressEntry() != null) {
|
||||||
address.set(model.getAddressEntry().getAddress());
|
address.set(model.getAddressEntry().getAddress());
|
||||||
|
|
|
@ -79,8 +79,8 @@ public class RestrictionsModel extends UIModel {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
Settings persistedSettings = (Settings) persistence.read(settings);
|
Settings persistedSettings = (Settings) persistence.read(settings);
|
||||||
if (persistedSettings != null) {
|
if (persistedSettings != null) {
|
||||||
|
|
|
@ -55,8 +55,8 @@ public class RestrictionsPM extends PresentationModel<RestrictionsModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class SeedWordsModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class SeedWordsPM extends PresentationModel<SeedWordsModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
if (model.getMnemonicCode() != null)
|
if (model.getMnemonicCode() != null)
|
||||||
seedWords.set(BSFormatter.mnemonicCodeToString(model.getMnemonicCode()));
|
seedWords.set(BSFormatter.mnemonicCodeToString(model.getMnemonicCode()));
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class AccountSettingsModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class AccountSettingsPM extends PresentationModel<AccountSettingsModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class AccountSetupModel extends UIModel {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -44,8 +44,8 @@ public class AccountSetupPM extends PresentationModel<AccountSetupModel> {
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -126,8 +126,8 @@ public class CreateOfferModel extends UIModel {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
// static data
|
// static data
|
||||||
offerFeeAsCoin.set(FeePolicy.CREATE_OFFER_FEE);
|
offerFeeAsCoin.set(FeePolicy.CREATE_OFFER_FEE);
|
||||||
|
|
|
@ -115,8 +115,8 @@ public class CreateOfferPM extends PresentationModel<CreateOfferModel> {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialized() {
|
public void initialize() {
|
||||||
super.initialized();
|
super.initialize();
|
||||||
|
|
||||||
// static
|
// static
|
||||||
paymentLabel.set(BSResources.get("createOffer.fundsBox.paymentLabel", model.getOfferId()));
|
paymentLabel.set(BSResources.get("createOffer.fundsBox.paymentLabel", model.getOfferId()));
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class CreateOfferPMTest {
|
||||||
BSFormatter.setFiatCurrencyCode("USD");
|
BSFormatter.setFiatCurrencyCode("USD");
|
||||||
|
|
||||||
presenter = new CreateOfferPM(model, new FiatValidator(null), new BtcValidator());
|
presenter = new CreateOfferPM(model, new FiatValidator(null), new BtcValidator());
|
||||||
presenter.initialized();
|
presenter.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue