Search in sources :

Example 1 with AccountItem

use of com.owlplug.auth.ui.AccountItem in project OwlPlug by DropSnorz.

the class MainController method initialize.

/**
 * FXML initialize method.
 */
@FXML
public void initialize() {
    viewRegistry.preload();
    this.tabPaneHeader.getSelectionModel().selectedIndexProperty().addListener((options, oldValue, newValue) -> {
        tabPaneContent.getSelectionModel().select(newValue.intValue());
        leftDrawer.close();
        // store tab.
        if (newValue.intValue() == 2) {
            storeController.requestLayout();
        }
    });
    accountComboBox.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
        if (newValue instanceof AccountMenuItem) {
            accountController.show();
            // Delay comboBox selector change
            Platform.runLater(() -> accountComboBox.setValue(oldValue));
        }
        if (newValue instanceof UserAccount) {
            UserAccount userAccount = (UserAccount) newValue;
            this.getPreferences().putLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, userAccount.getId());
        }
        accountComboBox.hide();
    });
    accountComboBox.setButtonCell(new AccountCellFactory(imageCache, Pos.CENTER_RIGHT).call(null));
    accountComboBox.setCellFactory(new AccountCellFactory(authenticationService, imageCache, true));
    JFXComboBoxListViewSkin<AccountItem> accountCBSkin = new JFXComboBoxListViewSkin<AccountItem>(accountComboBox);
    accountCBSkin.setHideOnClick(false);
    accountComboBox.setSkin(accountCBSkin);
    refreshAccounts();
    downloadUpdateButton.setOnAction(e -> {
        PlatformUtils.openDefaultBrowser(this.getApplicationDefaults().getUpdateDownloadUrl());
    });
    updatePane.setVisible(false);
    Task<Boolean> retrieveUpdateStatusTask = new Task<Boolean>() {

        @Override
        protected Boolean call() throws Exception {
            return updateService.isUpToDate();
        }
    };
    retrieveUpdateStatusTask.setOnSucceeded(e -> {
        if (!retrieveUpdateStatusTask.getValue()) {
            updatePane.setVisible(true);
        }
    });
    new Thread(retrieveUpdateStatusTask).start();
}
Also used : Task(javafx.concurrent.Task) AccountMenuItem(com.owlplug.auth.ui.AccountMenuItem) JFXComboBoxListViewSkin(com.jfoenix.skins.JFXComboBoxListViewSkin) AccountItem(com.owlplug.auth.ui.AccountItem) UserAccount(com.owlplug.auth.model.UserAccount) AccountCellFactory(com.owlplug.auth.ui.AccountCellFactory) FXML(javafx.fxml.FXML)

Aggregations

JFXComboBoxListViewSkin (com.jfoenix.skins.JFXComboBoxListViewSkin)1 UserAccount (com.owlplug.auth.model.UserAccount)1 AccountCellFactory (com.owlplug.auth.ui.AccountCellFactory)1 AccountItem (com.owlplug.auth.ui.AccountItem)1 AccountMenuItem (com.owlplug.auth.ui.AccountMenuItem)1 Task (javafx.concurrent.Task)1 FXML (javafx.fxml.FXML)1