Remove cyclic dependencies inside gui package

This commit is contained in:
Manfred Karrer 2014-09-09 10:12:09 +02:00
parent cd606d4b96
commit a51aafbdbd
4 changed files with 32 additions and 16 deletions

View File

@ -73,9 +73,6 @@ public class CreateOfferModel extends UIModel {
private final User user;
private final String offerId;
@Nullable private Direction direction = null;
public AddressEntry addressEntry;
public final StringProperty requestPlaceOfferErrorMessage = new SimpleStringProperty();
public final StringProperty transactionId = new SimpleStringProperty();
@ -104,6 +101,9 @@ public class CreateOfferModel extends UIModel {
public final ObservableList<Locale> acceptedLanguages = FXCollections.observableArrayList();
public final ObservableList<Arbitrator> acceptedArbitrators = FXCollections.observableArrayList();
@Nullable private Direction direction = null;
private AddressEntry addressEntry;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -118,8 +118,6 @@ public class CreateOfferModel extends UIModel {
this.user = user;
offerId = UUID.randomUUID().toString();
// Node: Don't do setup in constructor to make object creation faster
}
@ -138,13 +136,13 @@ public class CreateOfferModel extends UIModel {
if (walletFacade != null && walletFacade.getWallet() != null) {
addressEntry = walletFacade.getAddressInfoByTradeID(offerId);
walletFacade.addBalanceListener(new BalanceListener(addressEntry.getAddress()) {
walletFacade.addBalanceListener(new BalanceListener(getAddressEntry().getAddress()) {
@Override
public void onBalanceChanged(@NotNull Coin balance) {
updateBalance(balance);
}
});
updateBalance(walletFacade.getBalanceForAddress(addressEntry.getAddress()));
updateBalance(walletFacade.getBalanceForAddress(getAddressEntry().getAddress()));
}
}
@ -297,4 +295,8 @@ public class CreateOfferModel extends UIModel {
private void updateBalance(@NotNull Coin balance) {
isWalletFunded.set(totalToPayAsCoin.get() != null && balance.compareTo(totalToPayAsCoin.get()) >= 0);
}
public AddressEntry getAddressEntry() {
return addressEntry;
}
}

View File

@ -87,7 +87,7 @@ public class CreateOfferPM extends PresentationModel<CreateOfferModel> {
public final BooleanProperty showTransactionPublishedScreen = new SimpleBooleanProperty();
public final ObjectProperty<InputValidator.ValidationResult> amountValidationResult = new SimpleObjectProperty<>();
public final ObjectProperty<InputValidator.ValidationResult> minAmountValidationResult = new
public final ObjectProperty<InputValidator.ValidationResult> minAmountValidationResult = new
SimpleObjectProperty<>();
public final ObjectProperty<InputValidator.ValidationResult> priceValidationResult = new SimpleObjectProperty<>();
public final ObjectProperty<InputValidator.ValidationResult> volumeValidationResult = new SimpleObjectProperty<>();
@ -105,8 +105,6 @@ public class CreateOfferPM extends PresentationModel<CreateOfferModel> {
@Inject
CreateOfferPM(CreateOfferModel model) {
super(model);
// Note: Don't do setup in constructor to make object creation faster
}
@ -121,9 +119,9 @@ public class CreateOfferPM extends PresentationModel<CreateOfferModel> {
// static
paymentLabel.set(BSResources.get("createOffer.fundsBox.paymentLabel", model.getOfferId()));
if (model.addressEntry != null) {
addressAsString.set(model.addressEntry.getAddress().toString());
address.set(model.addressEntry.getAddress());
if (model.getAddressEntry() != null) {
addressAsString.set(model.getAddressEntry().getAddress().toString());
address.set(model.getAddressEntry().getAddress());
}
setupBindings();

View File

@ -135,6 +135,11 @@ public class TradeController extends CachedViewController {
createOfferView = loader.load();
createOfferCodeBehind = loader.getController();
createOfferCodeBehind.setParentController(this);
createOfferCodeBehind.setOnClose(() -> {
orderBookController.onCreateOfferViewRemoved();
return null;
});
final Tab tab = new Tab("Create offer");
tab.setContent(createOfferView);
tabPane.getTabs().add(tab);

View File

@ -28,7 +28,6 @@ import io.bitsquare.gui.components.btc.BalanceTextField;
import io.bitsquare.gui.help.Help;
import io.bitsquare.gui.help.HelpId;
import io.bitsquare.gui.pm.trade.CreateOfferPM;
import io.bitsquare.gui.trade.TradeController;
import io.bitsquare.gui.util.ImageUtil;
import io.bitsquare.locale.BSResources;
import io.bitsquare.trade.orderbook.OrderBookFilter;
@ -38,6 +37,7 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.concurrent.Callable;
import javax.inject.Inject;
@ -97,6 +97,7 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
acceptedLanguagesTextField;
@FXML private AddressTextField addressTextField;
@FXML private BalanceTextField balanceTextField;
private Callable<Void> onCloseCallBack;
///////////////////////////////////////////////////////////////////////////////////////////
@ -137,8 +138,15 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
public void terminate() {
super.terminate();
// Used to reset disable state of createOfferButton in OrderBookController
if (parentController != null) ((TradeController) parentController).onCreateOfferViewRemoved();
// Inform parent that we gor removed.
// Needed to reset disable state of createOfferButton in OrderBookController
if (onCloseCallBack != null)
try {
onCloseCallBack.call();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
}
@ -513,5 +521,8 @@ public class CreateOfferCB extends CachedCodeBehind<CreateOfferPM> {
return new Point2D(x, y);
}
public void setOnClose(Callable<Void> onCloseCallBack) {
this.onCloseCallBack = onCloseCallBack;
}
}