Search in sources :

Example 1 with CreateOfferView

use of bisq.desktop.main.offer.createoffer.CreateOfferView in project bisq-desktop by bisq-network.

the class OfferView method loadView.

private void loadView(Class<? extends View> viewClass) {
    TabPane tabPane = root;
    View view;
    boolean isBuy = direction == OfferPayload.Direction.BUY;
    if (viewClass == OfferBookView.class && offerBookView == null) {
        view = viewLoader.load(viewClass);
        // Offerbook must not be cached by ViewLoader as we use 2 instances for sell and buy screens.
        offerBookTab = new Tab(isBuy ? Res.get("shared.buyBitcoin") : Res.get("shared.sellBitcoin"));
        offerBookTab.setClosable(false);
        offerBookTab.setContent(view.getRoot());
        tabPane.getTabs().add(offerBookTab);
        offerBookView = (OfferBookView) view;
        offerBookView.onTabSelected(true);
        OfferActionHandler offerActionHandler = new OfferActionHandler() {

            @Override
            public void onCreateOffer(TradeCurrency tradeCurrency) {
                if (!createOfferViewOpen) {
                    OfferView.this.createOfferViewOpen = true;
                    OfferView.this.tradeCurrency = tradeCurrency;
                    // noinspection unchecked
                    OfferView.this.navigation.navigateTo(MainView.class, OfferView.this.getClass(), CreateOfferView.class);
                } else {
                    log.error("You have already a \"Create offer\" tab open.");
                }
            }

            @Override
            public void onTakeOffer(Offer offer) {
                if (!takeOfferViewOpen) {
                    OfferView.this.takeOfferViewOpen = true;
                    OfferView.this.offer = offer;
                    // noinspection unchecked
                    OfferView.this.navigation.navigateTo(MainView.class, OfferView.this.getClass(), TakeOfferView.class);
                } else {
                    log.error("You have already a \"Take offer\" tab open.");
                }
            }
        };
        offerBookView.setOfferActionHandler(offerActionHandler);
        offerBookView.setDirection(direction);
    } else if (viewClass == CreateOfferView.class && createOfferView == null) {
        view = viewLoader.load(viewClass);
        // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
        // in different graphs
        createOfferView = (CreateOfferView) view;
        createOfferView.initWithData(direction, tradeCurrency);
        createOfferPane = createOfferView.getRoot();
        createOfferTab = new Tab(getCreateOfferTabName());
        // close handler from close on create offer action
        createOfferView.setCloseHandler(() -> tabPane.getTabs().remove(createOfferTab));
        createOfferTab.setContent(createOfferPane);
        tabPane.getTabs().add(createOfferTab);
        tabPane.getSelectionModel().select(createOfferTab);
    } else if (viewClass == TakeOfferView.class && takeOfferView == null && offer != null) {
        view = viewLoader.load(viewClass);
        // CreateOffer and TakeOffer must not be cached by ViewLoader as we cannot use a view multiple times
        // in different graphs
        takeOfferView = (TakeOfferView) view;
        takeOfferView.initWithData(offer);
        takeOfferPane = ((TakeOfferView) view).getRoot();
        takeOfferTab = new Tab(getTakeOfferTabName());
        // close handler from close on take offer action
        takeOfferView.setCloseHandler(() -> tabPane.getTabs().remove(takeOfferTab));
        takeOfferTab.setContent(takeOfferPane);
        tabPane.getTabs().add(takeOfferTab);
        tabPane.getSelectionModel().select(takeOfferTab);
    }
}
Also used : TabPane(javafx.scene.control.TabPane) TradeCurrency(bisq.core.locale.TradeCurrency) CreateOfferView(bisq.desktop.main.offer.createoffer.CreateOfferView) Tab(javafx.scene.control.Tab) Offer(bisq.core.offer.Offer) OfferBookView(bisq.desktop.main.offer.offerbook.OfferBookView) ActivatableView(bisq.desktop.common.view.ActivatableView) TakeOfferView(bisq.desktop.main.offer.takeoffer.TakeOfferView) OfferBookView(bisq.desktop.main.offer.offerbook.OfferBookView) View(bisq.desktop.common.view.View) MainView(bisq.desktop.main.MainView) CreateOfferView(bisq.desktop.main.offer.createoffer.CreateOfferView)

Aggregations

TradeCurrency (bisq.core.locale.TradeCurrency)1 Offer (bisq.core.offer.Offer)1 ActivatableView (bisq.desktop.common.view.ActivatableView)1 View (bisq.desktop.common.view.View)1 MainView (bisq.desktop.main.MainView)1 CreateOfferView (bisq.desktop.main.offer.createoffer.CreateOfferView)1 OfferBookView (bisq.desktop.main.offer.offerbook.OfferBookView)1 TakeOfferView (bisq.desktop.main.offer.takeoffer.TakeOfferView)1 Tab (javafx.scene.control.Tab)1 TabPane (javafx.scene.control.TabPane)1