Example usage for javafx.concurrent Task setOnSucceeded

List of usage examples for javafx.concurrent Task setOnSucceeded

Introduction

In this page you can find the example usage for javafx.concurrent Task setOnSucceeded.

Prototype

public final void setOnSucceeded(EventHandler<WorkerStateEvent> value) 

Source Link

Document

The onSucceeded event handler is called whenever the Task state transitions to the SUCCEEDED state.

Usage

From source file:benedict.zhang.addon.soundmanager.controller.SoundManagerController.java

public void doSearchAction(ActionEvent e) {
    soundList.clear();//from   w  w  w.ja v  a2s.  c om
    this.btnSearch.setDisable(true);
    Task<List> queryTask = new SoundQueryTask(this.soundName.getText(), this.actor.getText());
    queryTask.setOnSucceeded((WorkerStateEvent event) -> {
        List<Sound> resultList = queryTask.getValue();
        for (int i = 0; i < resultList.size(); i++) {
            resultList.get(i).setNo(new Integer(i + 1));
        }
        this.btnSearch.setDisable(false);
        soundList.setAll(resultList);
    });
    queryTask.run();
}

From source file:ninja.eivind.hotsreplayuploader.ClientTest.java

@Test
public void testJavaFXIsAvailable() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(2);
    Task<Void> javaFxTask = new Task<Void>() {
        @Override/*from w  w w.j  a  v  a 2  s  . c  om*/
        protected Void call() throws Exception {
            latch.countDown();
            return null;
        }
    };
    javaFxTask.setOnSucceeded((result) -> latch.countDown());
    new Thread(javaFxTask).run();

    if (!latch.await(1, TimeUnit.SECONDS)) {
        fail("JavaFX is not available.");
    }
}

From source file:com.QuarkLabs.BTCeClientJavaFX.OrdersBookController.java

@FXML
void initialize() {

    assert asksTable != null : "fx:id=\"asksTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";
    assert asksTablePriceColumn != null : "fx:id=\"asksTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";
    assert asksTableVolumeColumn != null : "fx:id=\"asksTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";
    assert bidsTable != null : "fx:id=\"bidsTable\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";
    assert bidsTablePriceColumn != null : "fx:id=\"bidsTablePriceColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";
    assert bidsTableVolumeColumn != null : "fx:id=\"bidsTableVolumeColumn\" was not injected: check your FXML file 'ordersbooklayout.fxml'.";

    asksTable.setItems(asks);//from  w w  w . j a va  2  s .c  o  m
    bidsTable.setItems(bids);

    asksTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price"));
    asksTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume"));

    asksTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    bidsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    bidsTablePriceColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("price"));
    bidsTableVolumeColumn.setCellValueFactory(new PropertyValueFactory<OrdersBookEntry, Double>("volume"));

    Task<JSONObject> loadOrdersBook = new Task<JSONObject>() {
        @Override
        protected JSONObject call() throws Exception {
            return App.getOrdersBook(pair);
        }
    };
    loadOrdersBook.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue();
            JSONArray asksArray = jsonObject.optJSONArray("asks");
            JSONArray bidsArray = jsonObject.optJSONArray("bids");
            for (int i = 0; i < asksArray.length(); i++) {
                JSONArray item = asksArray.optJSONArray(i);
                OrdersBookEntry ordersBookEntry = new OrdersBookEntry();
                ordersBookEntry.setPrice(item.optDouble(0));
                ordersBookEntry.setVolume(item.optDouble(1));
                asks.add(ordersBookEntry);
            }
            for (int i = 0; i < bidsArray.length(); i++) {
                JSONArray item = bidsArray.optJSONArray(i);
                OrdersBookEntry ordersBookEntry = new OrdersBookEntry();
                ordersBookEntry.setPrice(item.optDouble(0));
                ordersBookEntry.setVolume(item.optDouble(1));
                bids.add(ordersBookEntry);
            }
        }
    });
    Thread thread = new Thread(loadOrdersBook);
    thread.start();

}

From source file:ninja.eivind.hotsreplayuploader.window.HomeController.java

private void checkNewVersion() {
    final Task<Optional<GitHubRelease>> task = new Task<Optional<GitHubRelease>>() {
        @Override/*from  ww w  .  j  a  v a 2 s.c  o  m*/
        protected Optional<GitHubRelease> call() throws Exception {
            return releaseManager.getNewerVersionIfAny();
        }
    };
    task.setOnSucceeded(event -> task.getValue().ifPresent(this::displayUpdateMessage));
    new Thread(task).start();
}

From source file:com.QuarkLabs.BTCeClientJavaFX.PublicTradesController.java

@FXML
void initialize() {
    assert publicTradesTable != null : "fx:id=\"publicTradesTable\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableAmountColumn != null : "fx:id=\"publicTradesTableAmountColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableDateColumn != null : "fx:id=\"publicTradesTableDateColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableItemColumn != null : "fx:id=\"publicTradesTableItemColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTablePriceColumn != null : "fx:id=\"publicTradesTablePriceColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTablePriceCurrencyColumn != null : "fx:id=\"publicTradesTablePriceCurrencyColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableTIDColumn != null : "fx:id=\"publicTradesTableTIDColumn\" was not injected: check your FXML file 'markettrades.fxml'.";
    assert publicTradesTableTradeTypeColumn != null : "fx:id=\"publicTradesTableTradeTypeColumn\" was not injected: check your FXML file 'markettrades.fxml'.";

    publicTradesTable.setItems(publicTrades);
    publicTradesTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    publicTradesTableAmountColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("amount"));
    publicTradesTableDateColumn.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<PublicTrade, String>, ObservableValue<String>>() {
                @Override/*from   w  w w  .j a v a2  s . c o  m*/
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<PublicTrade, String> publicTradeStringCellDataFeatures) {
                    PublicTrade publicTrade = publicTradeStringCellDataFeatures.getValue();
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(publicTrade.getDate() * 1000);
                    DateFormat dateFormat = DateFormat.getDateTimeInstance();
                    return new SimpleStringProperty(dateFormat.format(calendar.getTime()));
                }
            });
    publicTradesTableItemColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("item"));
    publicTradesTablePriceColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Double>("price"));
    publicTradesTablePriceCurrencyColumn
            .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("priceCurrency"));
    publicTradesTableTIDColumn.setCellValueFactory(new PropertyValueFactory<PublicTrade, Long>("tid"));
    publicTradesTableTradeTypeColumn
            .setCellValueFactory(new PropertyValueFactory<PublicTrade, String>("tradeType"));

    Task<JSONArray> loadPublicTrades = new Task<JSONArray>() {
        @Override
        protected JSONArray call() throws Exception {
            return App.getPublicTrades(pair);
        }
    };
    loadPublicTrades.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONArray jsonArray = (JSONArray) workerStateEvent.getSource().getValue();
            publicTrades.clear();
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject item = jsonArray.getJSONObject(i);
                PublicTrade publicTrade = new PublicTrade();
                publicTrade.setDate(item.getLong("date"));
                publicTrade.setAmount(item.getDouble("amount"));
                publicTrade.setItem(item.getString("item"));
                publicTrade.setPrice(item.getDouble("price"));
                publicTrade.setPriceCurrency(item.getString("price_currency"));
                publicTrade.setTid(item.getLong("tid"));
                publicTrade.setTradeType(item.getString("trade_type"));
                publicTrades.add(publicTrade);
            }
        }
    });
    Thread thread = new Thread(loadPublicTrades);
    thread.start();
}

From source file:poe.trade.assist.Main.java

public void manualTaskRun(Search search) {
    String url = search.getUrl();
    if (isNotBlank(url)) {
        Task<Search> task = new Task<Search>() {
            @Override/*ww  w.j av  a  2  s  .c om*/
            protected Search call() throws Exception {
                String html = AutoSearchService.doDownload(search.getUrl(), search.getSort());
                search.setHtml(html);
                search.parseHtml();
                return search;
            }
        };
        resultPane.progressIndicator.visibleProperty().unbind();
        resultPane.progressIndicator.visibleProperty().bind(task.runningProperty());
        task.setOnSucceeded(e -> {
            resultPane.setSearch(task.getValue());
            //            refreshResultColumn();
        });
        task.setOnFailed(e -> {
            Dialogs.showError(task.getException());
            //            refreshResultColumn();
        });
        new Thread(task).start();
    } else {
        resultPane.setSearch(search);
    }
}

From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java

/**
 * Gets funds data from server, displays error message at the Log field in case of any Exception
 *//*from ww  w . ja v a 2 s .  c  om*/
@FXML
private void updateFunds() {
    Task<JSONObject> task = new Task<JSONObject>() {

        @Override
        protected JSONObject call() throws Exception {
            try {
                return app.getAccountInfo();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return new JSONObject();
        }
    };
    task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue();
            //TODO make a check for errors
            if (jsonObject.optInt("success", 0) == 1) {
                parseFundsObject(jsonObject.optJSONObject("return").optJSONObject("funds"));
            } else {
                logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n");
            }
        }
    });
    task.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n");
        }
    });
    Thread thread = new Thread(task);
    thread.start();

}

From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java

/**
 * Gets Active Orders data from server, displays error message at the Log field in case of any Exception
 *//*from  www  . j ava  2s  .  c  o  m*/
@FXML
private void showActiveOrders() {

    Task<JSONObject> task = new Task<JSONObject>() {
        @Override
        protected JSONObject call() throws Exception {
            try {
                return app.getActiveOrders();
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            return new JSONObject();
        }
    };
    task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue();
            if (jsonObject.optInt("success") == 1) {
                JSONObject data = jsonObject.getJSONObject("return");
                for (Iterator iterator = data.keys(); iterator.hasNext();) {
                    String key = (String) iterator.next();
                    ActiveOrder activeOrder = new ActiveOrder();
                    activeOrder.setId(Long.parseLong(key));
                    activeOrder.setAmount(data.optJSONObject(key).optDouble("amount"));
                    activeOrder.setRate(data.optJSONObject(key).optDouble("rate"));
                    activeOrder.setStatus(data.optJSONObject(key).optInt("status"));
                    activeOrder.setTimestamp(data.optJSONObject(key).optLong("timestamp_created"));
                    activeOrder.setPair(data.optJSONObject(key).optString("pair"));
                    activeOrder.setType(data.optJSONObject(key).optString("type"));
                    activeOrders.add(activeOrder);
                }
                activeOrdersTable.setItems(activeOrders);
            } else {
                logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n");
            }

        }
    });
    task.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n");
        }
    });
    Thread thread = new Thread(task);
    thread.start();
}

From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java

/**
 * Reads data from Trading section, sends trade request to server
 * Displays error message at the Log field in case of any Exception
 *
 * @param event Source fired an event (either "Buy" or "Sell" button)
 *///from www. j a v a2s  .  c om
@FXML
private void makeTradeRequest(final ActionEvent event) {

    Task<JSONObject> task = new Task<JSONObject>() {
        @Override
        protected JSONObject call() throws Exception {
            String type;
            String idOfSource = ((Button) event.getSource()).getId();
            if (buyButton.getId().equals(idOfSource)) {
                type = "buy";
            } else {
                type = "sell";
            }
            String pair = tradeCurrencyType.getValue().toLowerCase() + "_"
                    + tradePriceCurrencyType.getValue().toLowerCase();

            String rate = tradePriceValue.getText();
            String amount = tradeAmountValue.getText();
            return app.trade(pair, type, rate, amount);
        }
    };
    task.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue();
            if (jsonObject.optInt("success") == 1) {
                parseFundsObject(jsonObject.optJSONObject("return").optJSONObject("funds"));
                logField.appendText("Order ID = " + jsonObject.optJSONObject("return").optString("order_id")
                        + " was registered successfully" + "\r\n");
            } else {
                logField.appendText(ERROR_TITLE + jsonObject.optString("error", SOMETHING_WENT_WRONG) + "\r\n");
            }

        }
    });

    task.setOnFailed(new EventHandler<WorkerStateEvent>() {
        @Override
        public void handle(WorkerStateEvent workerStateEvent) {
            logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n");
        }
    });
    Thread thread = new Thread(task);
    thread.start();
}

From source file:com.QuarkLabs.BTCeClientJavaFX.MainController.java

@FXML
void initialize() {
    assert clearLogButton != null : "fx:id=\"clearLogButton\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert fundsTable != null : "fx:id=\"fundsTable\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert logField != null : "fx:id=\"logField\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert buyButton != null : "fx:id=\"buyButton\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert sellButton != null : "fx:id=\"sellButton\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert showActiveOrdersButton != null : "fx:id=\"showActiveOrdersButton\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTableLastColumn != null : "fx:id=\"tickerTableLastColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTablePairColumn != null : "fx:id=\"tickerTablePairColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTable != null : "fx:id=\"tickersTable\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTableBuyColumn != null : "fx:id=\"tickersTableBuyColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTableFeeColumn != null : "fx:id=\"tickersTableFeeColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tickersTableSellColumn != null : "fx:id=\"tickersTableSellColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tradeAmountValue != null : "fx:id=\"tradeAmountValue\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tradePriceCurrencyType != null : "fx:id=\"tradeCurrencyPriceValue\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tradeCurrencyType != null : "fx:id=\"tradeCurrencyType\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert tradePriceValue != null : "fx:id=\"tradePriceValue\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert updateFundsButton != null : "fx:id=\"updateFundsButton\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert fundsTableCurrencyColumn != null : "fx:id=\"fundsTableCurrencyColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert fundsTableValueColumn != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersTable != null : "fx:id=\"fundsTableValueColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersAmountColumn != null : "fx:id=\"activeOrdersAmountColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersPairColumn != null : "fx:id=\"activeOrdersPairColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersRateColumn != null : "fx:id=\"activeOrdersRateColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersTimeColumn != null : "fx:id=\"activeOrdersTimeColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersTypeColumn != null : "fx:id=\"activeOrdersTypeColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";
    assert activeOrdersCancelColumn != null : "fx:id=\"activeOrdersCancelColumn\" was not injected: check your FXML file 'mainlayout.fxml'.";

    //Holder for all main API methods of exchange
    app = new App();

    //Loading configs
    loadExchangeConfig();//from   ww w  . j  a  va2 s .  c o m

    //Populate choiceboxes at the trading section
    tradeCurrencyType.setItems(FXCollections.observableArrayList(currencies));
    tradeCurrencyType.setValue(currencies.get(0));
    tradePriceCurrencyType.setItems(FXCollections.observableArrayList(currencies));
    tradePriceCurrencyType.setValue(currencies.get(0));

    //Active Orders table
    activeOrdersAmountColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("amount"));
    activeOrdersPairColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("pair"));
    activeOrdersRateColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, Double>("rate"));
    activeOrdersTimeColumn.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<ActiveOrder, String>, ObservableValue<String>>() {
                @Override
                public ObservableValue<String> call(
                        TableColumn.CellDataFeatures<ActiveOrder, String> activeOrderStringCellDataFeatures) {
                    ActiveOrder activeOrder = activeOrderStringCellDataFeatures.getValue();
                    DateFormat dateFormat = DateFormat.getDateTimeInstance();
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTimeInMillis(activeOrder.getTimestamp() * 1000);
                    return new SimpleStringProperty(dateFormat.format(calendar.getTime()));
                }
            });
    activeOrdersTypeColumn.setCellValueFactory(new PropertyValueFactory<ActiveOrder, String>("type"));
    activeOrdersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    activeOrdersCancelColumn
            .setCellFactory(new Callback<TableColumn<ActiveOrder, Boolean>, TableCell<ActiveOrder, Boolean>>() {
                @Override
                public TableCell<ActiveOrder, Boolean> call(
                        TableColumn<ActiveOrder, Boolean> activeOrderBooleanTableColumn) {
                    return new ButtonCell<>(activeOrdersTable);
                }
            });
    activeOrdersCancelColumn.setCellValueFactory(
            new Callback<TableColumn.CellDataFeatures<ActiveOrder, Boolean>, ObservableValue<Boolean>>() {
                @Override
                public ObservableValue<Boolean> call(
                        TableColumn.CellDataFeatures<ActiveOrder, Boolean> activeOrderBooleanCellDataFeatures) {
                    return new SimpleBooleanProperty(true);
                }
            });

    //Tickers Table
    MenuItem showOrdersBook = new MenuItem("Show Orders Book");
    MenuItem showPublicTrades = new MenuItem("Show Public Trades");

    ContextMenu contextMenu = new ContextMenu(showOrdersBook, showPublicTrades);

    tickersTable.setItems(tickers);
    tickersTable.setContextMenu(contextMenu);
    tickersTableBuyColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("buy"));
    tickersTableFeeColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("fee"));
    tickersTableSellColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("sell"));
    tickersTableLastColumn.setCellValueFactory(new PropertyValueFactory<Ticker, Double>("last"));
    tickersTablePairColumn.setCellValueFactory(new PropertyValueFactory<Ticker, String>("pair"));
    tickersTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tickersTable.setRowFactory(new Callback<TableView<Ticker>, TableRow<Ticker>>() {
        @Override
        public TableRow<Ticker> call(TableView<Ticker> tickerTableView) {
            return new TableRow<Ticker>() {
                @Override
                protected void updateItem(Ticker ticker, boolean b) {
                    super.updateItem(ticker, b);
                    if (!b) {
                        if (tickersData.containsKey(ticker.getPair())) {
                            if (ticker.getLast() < tickersData.get(ticker.getPair()).getLast()) {
                                setStyle("-fx-control-inner-background: rgba(186, 0, 0, 0.5);");
                            } else if (ticker.getLast() == tickersData.get(ticker.getPair()).getLast()) {
                                setStyle("-fx-control-inner-background: rgba(215, 193, 44, 0.5);");
                            } else {
                                setStyle("-fx-control-inner-background: rgba(0, 147, 0, 0.5);");
                            }
                        }
                    }
                }
            };
        }
    });

    //Menu item to show Orders Book
    showOrdersBook.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem();
            Parent root;
            try {
                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_ORDERS_BOOK_LAYOUT),
                        resources);
                root = (Parent) fxmlLoader.load();
                OrdersBookController ordersBookController = fxmlLoader.getController();
                ordersBookController.injectPair(selectedTicker.getPair());
                Stage stage = new Stage();
                stage.setTitle("Orders Book for " + selectedTicker.getPair().replace("_", "/").toUpperCase());
                stage.setScene(new Scene(root));
                stage.setResizable(false);
                stage.show();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    //Menu item to show Public Trades
    showPublicTrades.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            Ticker selectedTicker = tickersTable.getSelectionModel().getSelectedItem();
            Parent root;
            try {
                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(PATH_TO_TRADES_LAYOUT),
                        resources);
                root = (Parent) fxmlLoader.load();
                PublicTradesController publicTradesController = fxmlLoader.getController();
                publicTradesController.injectPair(selectedTicker.getPair());
                Stage stage = new Stage();
                stage.setTitle("Public Trades for " + selectedTicker.getPair().replace("_", "/").toUpperCase());
                stage.setScene(new Scene(root));
                stage.setResizable(false);
                stage.show();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    //Funds Table
    fundsTableCurrencyColumn.setCellValueFactory(new PropertyValueFactory<Fund, String>("currency"));
    fundsTableValueColumn.setCellValueFactory(new PropertyValueFactory<Fund, Double>("value"));
    fundsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    fundsTable.setItems(fundsData);

    //Task to load tickers data from server
    final javafx.concurrent.Service loadTickersService = new javafx.concurrent.Service() {
        @Override
        protected Task createTask() {
            Task<JSONObject> loadTickers = new Task<JSONObject>() {
                @Override
                protected JSONObject call() throws Exception {
                    String[] pairsArray = new String[pairs.size()];
                    pairsArray = pairs.toArray(pairsArray);
                    return App.getPairInfo(pairsArray);
                }
            };

            loadTickers.setOnFailed(new EventHandler<WorkerStateEvent>() {
                @Override
                public void handle(WorkerStateEvent workerStateEvent) {
                    logField.appendText(workerStateEvent.getSource().getException().getMessage() + "\r\n");
                }
            });

            loadTickers.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
                @Override
                public void handle(WorkerStateEvent workerStateEvent) {
                    JSONObject jsonObject = (JSONObject) workerStateEvent.getSource().getValue();

                    //ugly hack to store old values
                    //dump old values to tickersData
                    //TODO think about better solution
                    if (tickers.size() != 0) {
                        for (Ticker x : tickers) {
                            tickersData.put(x.getPair(), x);
                        }
                    }
                    tickers.clear();
                    for (Iterator iterator = jsonObject.keys(); iterator.hasNext();) {
                        String key = (String) iterator.next();
                        JSONObject data = jsonObject.getJSONObject(key);
                        Ticker ticker = new Ticker();
                        ticker.setPair(key);
                        ticker.setUpdated(data.optLong("updated"));
                        ticker.setAvg(data.optDouble("avg"));
                        ticker.setBuy(data.optDouble("buy"));
                        ticker.setSell(data.optDouble("sell"));
                        ticker.setHigh(data.optDouble("high"));
                        ticker.setLast(data.optDouble("last"));
                        ticker.setLow(data.optDouble("low"));
                        ticker.setVol(data.optDouble("vol"));
                        ticker.setVolCur(data.optDouble("vol_cur"));
                        tickers.add(ticker);
                    }

                }
            });
            return loadTickers;
        }
    };

    //Update tickers every 15 seconds
    //TODO better solution is required
    Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            loadTickersService.restart();
        }
    }), new KeyFrame(Duration.seconds(15)));
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.playFromStart();

}