use of com.owlplug.auth.ui.AccountMenuItem in project OwlPlug by DropSnorz.
the class MainController method refreshAccounts.
/**
* Refresh Account comboBox.
*/
public void refreshAccounts() {
ArrayList<UserAccount> accounts = new ArrayList<UserAccount>();
for (UserAccount account : authenticationService.getAccounts()) {
accounts.add(account);
}
accountComboBox.hide();
accountComboBox.getItems().clear();
accountComboBox.getItems().setAll(accounts);
accountComboBox.getItems().add(new AccountMenuItem(" + New Account"));
long selectedAccountId = this.getPreferences().getLong(ApplicationDefaults.SELECTED_ACCOUNT_KEY, -1);
if (selectedAccountId != -1) {
Optional<UserAccount> selectedAccount = authenticationService.getUserAccountById(selectedAccountId);
if (selectedAccount.isPresent()) {
// Bug workaround. The only way to pre-select the account is to find its
// index in the list
// If not, the selected cell is not rendered correctly
accountComboBox.getItems().stream().filter(account -> account.getId().equals(selectedAccount.get().getId())).findAny().ifPresent(accountComboBox.getSelectionModel()::select);
} else {
accountComboBox.setValue(null);
}
} else {
accountComboBox.setValue(null);
}
}
use of com.owlplug.auth.ui.AccountMenuItem 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();
}
Aggregations