Search in sources :

Example 1 with Subscription

use of org.fxmisc.easybind.Subscription in project bitsquare by bitsquare.

the class MainViewModel method onDisputesChangeListener.

private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
    if (removedList != null) {
        removedList.stream().forEach(dispute -> {
            String id = dispute.getId();
            if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
                disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
                disputeIsClosedSubscriptionsMap.remove(id);
            }
        });
    }
    addedList.stream().forEach(dispute -> {
        String id = dispute.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
            UserThread.execute(() -> {
                int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
                if (openDisputes > 0)
                    numOpenDisputesAsString.set(String.valueOf(openDisputes));
                if (openDisputes > 9)
                    numOpenDisputesAsString.set("★");
                showOpenDisputesNotification.set(openDisputes > 0);
            });
        });
        disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
    });
}
Also used : Subscription(org.fxmisc.easybind.Subscription)

Example 2 with Subscription

use of org.fxmisc.easybind.Subscription in project bitsquare by bitsquare.

the class NotificationCenter method onAllServicesAndViewsInitialized.

public void onAllServicesAndViewsInitialized() {
    tradeManager.getTrades().addListener((ListChangeListener<Trade>) change -> {
        change.next();
        if (change.wasRemoved()) {
            change.getRemoved().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    disputeStateSubscriptionsMap.get(tradeId).unsubscribe();
                    disputeStateSubscriptionsMap.remove(tradeId);
                }
                if (tradeStateSubscriptionsMap.containsKey(tradeId)) {
                    tradeStateSubscriptionsMap.get(tradeId).unsubscribe();
                    tradeStateSubscriptionsMap.remove(tradeId);
                }
            });
        }
        if (change.wasAdded()) {
            change.getAddedSubList().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in disputeStateSubscriptionsMap.");
                } else {
                    Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
                    disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
                }
                if (tradeStateSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in tradeStateSubscriptionsMap.");
                } else {
                    Subscription tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), tradeState -> onTradeStateChanged(trade, tradeState));
                    tradeStateSubscriptionsMap.put(tradeId, tradeStateSubscription);
                }
            });
        }
    });
    tradeManager.getTrades().stream().forEach(trade -> {
        String tradeId = trade.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
        disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
        Subscription tradeStateSubscription = EasyBind.subscribe(trade.stateProperty(), tradeState -> onTradeStateChanged(trade, tradeState));
        tradeStateSubscriptionsMap.put(tradeId, tradeStateSubscription);
    });
}
Also used : MainView(io.bitsquare.gui.main.MainView) Logger(org.slf4j.Logger) Inject(com.google.inject.Inject) UserThread(io.bitsquare.common.UserThread) LoggerFactory(org.slf4j.LoggerFactory) DisputeManager(io.bitsquare.arbitration.DisputeManager) Trade(io.bitsquare.trade.Trade) HashMap(java.util.HashMap) Subscription(org.fxmisc.easybind.Subscription) ArrayList(java.util.ArrayList) DisputesView(io.bitsquare.gui.main.disputes.DisputesView) Consumer(java.util.function.Consumer) TradeManager(io.bitsquare.trade.TradeManager) Preferences(io.bitsquare.user.Preferences) PortfolioView(io.bitsquare.gui.main.portfolio.PortfolioView) List(java.util.List) ListChangeListener(javafx.collections.ListChangeListener) EasyBind(org.fxmisc.easybind.EasyBind) Navigation(io.bitsquare.gui.Navigation) TraderDisputeView(io.bitsquare.gui.main.disputes.trader.TraderDisputeView) Map(java.util.Map) PendingTradesView(io.bitsquare.gui.main.portfolio.pendingtrades.PendingTradesView) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) Trade(io.bitsquare.trade.Trade) Subscription(org.fxmisc.easybind.Subscription)

Example 3 with Subscription

use of org.fxmisc.easybind.Subscription in project bisq-desktop by bisq-network.

the class MainViewModel method onDisputesChangeListener.

private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
    if (removedList != null) {
        removedList.stream().forEach(dispute -> {
            String id = dispute.getId();
            if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
                disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
                disputeIsClosedSubscriptionsMap.remove(id);
            }
        });
    }
    addedList.stream().forEach(dispute -> {
        String id = dispute.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
            // We get event before list gets updated, so we execute on next frame
            UserThread.execute(() -> {
                int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
                if (openDisputes > 0)
                    numOpenDisputesAsString.set(String.valueOf(openDisputes));
                if (openDisputes > 9)
                    numOpenDisputesAsString.set("★");
                showOpenDisputesNotification.set(openDisputes > 0);
            });
        });
        disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
    });
}
Also used : Subscription(org.fxmisc.easybind.Subscription)

Example 4 with Subscription

use of org.fxmisc.easybind.Subscription in project bisq-desktop by bisq-network.

the class NotificationCenter method onAllServicesAndViewsInitialized.

public void onAllServicesAndViewsInitialized() {
    tradeManager.getTradableList().addListener((ListChangeListener<Trade>) change -> {
        change.next();
        if (change.wasRemoved()) {
            change.getRemoved().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    disputeStateSubscriptionsMap.get(tradeId).unsubscribe();
                    disputeStateSubscriptionsMap.remove(tradeId);
                }
                if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
                    tradePhaseSubscriptionsMap.get(tradeId).unsubscribe();
                    tradePhaseSubscriptionsMap.remove(tradeId);
                }
            });
        }
        if (change.wasAdded()) {
            change.getAddedSubList().stream().forEach(trade -> {
                String tradeId = trade.getId();
                if (disputeStateSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in disputeStateSubscriptionsMap.");
                } else {
                    Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
                    disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
                }
                if (tradePhaseSubscriptionsMap.containsKey(tradeId)) {
                    log.debug("We have already an entry in tradePhaseSubscriptionsMap.");
                } else {
                    Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
                    tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
                }
            });
        }
    });
    tradeManager.getTradableList().stream().forEach(trade -> {
        String tradeId = trade.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(trade.disputeStateProperty(), disputeState -> onDisputeStateChanged(trade, disputeState));
        disputeStateSubscriptionsMap.put(tradeId, disputeStateSubscription);
        Subscription tradePhaseSubscription = EasyBind.subscribe(trade.statePhaseProperty(), phase -> onTradePhaseChanged(trade, phase));
        tradePhaseSubscriptionsMap.put(tradeId, tradePhaseSubscription);
    });
}
Also used : Inject(com.google.inject.Inject) PendingTradesView(bisq.desktop.main.portfolio.pendingtrades.PendingTradesView) HashMap(java.util.HashMap) DisputeManager(bisq.core.arbitration.DisputeManager) ArrayList(java.util.ArrayList) DisputesView(bisq.desktop.main.disputes.DisputesView) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) SellerTrade(bisq.core.trade.SellerTrade) Map(java.util.Map) Nullable(javax.annotation.Nullable) Navigation(bisq.desktop.Navigation) MakerTrade(bisq.core.trade.MakerTrade) Trade(bisq.core.trade.Trade) DontShowAgainLookup(bisq.core.user.DontShowAgainLookup) Log(bisq.common.app.Log) Subscription(org.fxmisc.easybind.Subscription) Consumer(java.util.function.Consumer) MainView(bisq.desktop.main.MainView) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) BuyerTrade(bisq.core.trade.BuyerTrade) EasyBind(org.fxmisc.easybind.EasyBind) TraderDisputeView(bisq.desktop.main.disputes.trader.TraderDisputeView) TradeManager(bisq.core.trade.TradeManager) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) PortfolioView(bisq.desktop.main.portfolio.PortfolioView) SellerTrade(bisq.core.trade.SellerTrade) MakerTrade(bisq.core.trade.MakerTrade) Trade(bisq.core.trade.Trade) BuyerTrade(bisq.core.trade.BuyerTrade) Subscription(org.fxmisc.easybind.Subscription)

Example 5 with Subscription

use of org.fxmisc.easybind.Subscription in project bisq-api by mrosseel.

the class MainViewModelHeadless method onDisputesChangeListener.

private void onDisputesChangeListener(List<? extends Dispute> addedList, @Nullable List<? extends Dispute> removedList) {
    if (removedList != null) {
        removedList.stream().forEach(dispute -> {
            String id = dispute.getId();
            if (disputeIsClosedSubscriptionsMap.containsKey(id)) {
                disputeIsClosedSubscriptionsMap.get(id).unsubscribe();
                disputeIsClosedSubscriptionsMap.remove(id);
            }
        });
    }
    addedList.stream().forEach(dispute -> {
        String id = dispute.getId();
        Subscription disputeStateSubscription = EasyBind.subscribe(dispute.isClosedProperty(), isClosed -> {
            // We get event before list gets updated, so we execute on next frame
            UserThread.execute(() -> {
                int openDisputes = disputeManager.getDisputesAsObservableList().stream().filter(e -> !e.isClosed()).collect(Collectors.toList()).size();
                if (openDisputes > 0)
                    numOpenDisputesAsString.set(String.valueOf(openDisputes));
                if (openDisputes > 9)
                    numOpenDisputesAsString.set("★");
                showOpenDisputesNotification.set(openDisputes > 0);
            });
        });
        disputeIsClosedSubscriptionsMap.put(id, disputeStateSubscription);
    });
}
Also used : Subscription(org.fxmisc.easybind.Subscription)

Aggregations

Subscription (org.fxmisc.easybind.Subscription)5 Inject (com.google.inject.Inject)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 ListChangeListener (javafx.collections.ListChangeListener)2 Nullable (javax.annotation.Nullable)2 EasyBind (org.fxmisc.easybind.EasyBind)2 UserThread (bisq.common.UserThread)1 Log (bisq.common.app.Log)1 DisputeManager (bisq.core.arbitration.DisputeManager)1 Res (bisq.core.locale.Res)1 BuyerTrade (bisq.core.trade.BuyerTrade)1 MakerTrade (bisq.core.trade.MakerTrade)1 SellerTrade (bisq.core.trade.SellerTrade)1 Trade (bisq.core.trade.Trade)1 TradeManager (bisq.core.trade.TradeManager)1 DontShowAgainLookup (bisq.core.user.DontShowAgainLookup)1