Search in sources :

Example 1 with ChoiceDialog

use of jgnash.uifx.control.ChoiceDialog in project jgnash by ccavanaugh.

the class DefaultCurrencyAction method showAndWait.

public static void showAndWait() {
    final Task<List<CurrencyNode>> task = new Task<>() {

        final ResourceBundle resources = ResourceUtils.getBundle();

        private List<CurrencyNode> currencyNodeList;

        @Override
        protected List<CurrencyNode> call() {
            final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
            Objects.requireNonNull(engine);
            currencyNodeList = engine.getCurrencies();
            return currencyNodeList;
        }

        @Override
        protected void succeeded() {
            super.succeeded();
            JavaFXUtils.runLater(() -> {
                final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
                Objects.requireNonNull(engine);
                final ChoiceDialog<CurrencyNode> dialog = new ChoiceDialog<>(engine.getDefaultCurrency(), currencyNodeList);
                dialog.setTitle(resources.getString("Title.SelDefCurr"));
                dialog.setContentText(resources.getString("Title.SelDefCurr"));
                final Optional<CurrencyNode> optional = dialog.showAndWait();
                optional.ifPresent(currencyNode -> {
                    engine.setDefaultCurrency(currencyNode);
                    JavaFXUtils.runLater(() -> StaticUIMethods.displayMessage(resources.getString("Message.CurrChange") + " " + engine.getDefaultCurrency().getSymbol()));
                });
            });
        }
    };
    new Thread(task).start();
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ChoiceDialog(jgnash.uifx.control.ChoiceDialog) Task(javafx.concurrent.Task) List(java.util.List) ResourceBundle(java.util.ResourceBundle) Engine(jgnash.engine.Engine)

Example 2 with ChoiceDialog

use of jgnash.uifx.control.ChoiceDialog in project jgnash by ccavanaugh.

the class DefaultLocaleAction method showAndWait.

public static void showAndWait() {
    final Task<Collection<LocaleObject>> task = new Task<>() {

        final ResourceBundle resources = ResourceUtils.getBundle();

        private Collection<LocaleObject> localeObjects;

        @Override
        protected Collection<LocaleObject> call() {
            localeObjects = new ArrayList<>(LocaleObject.getLocaleObjects());
            return localeObjects;
        }

        @Override
        protected void succeeded() {
            super.succeeded();
            JavaFXUtils.runLater(() -> {
                final ChoiceDialog<LocaleObject> dialog = new ChoiceDialog<>(new LocaleObject(Locale.getDefault()), localeObjects);
                dialog.setTitle(resources.getString("Title.SelDefLocale"));
                dialog.setContentText(resources.getString("Title.SelDefLocale"));
                final Optional<LocaleObject> optional = dialog.showAndWait();
                optional.ifPresent(localeObject -> {
                    ResourceUtils.setLocale(localeObject.getLocale());
                    JavaFXUtils.runLater(() -> StaticUIMethods.displayMessage(localeObject + "\n" + resources.getString("Message.RestartLocale")));
                });
            });
        }
    };
    new Thread(task).start();
}
Also used : ChoiceDialog(jgnash.uifx.control.ChoiceDialog) Task(javafx.concurrent.Task) Collection(java.util.Collection) ResourceBundle(java.util.ResourceBundle) LocaleObject(jgnash.util.LocaleObject)

Aggregations

ResourceBundle (java.util.ResourceBundle)2 Task (javafx.concurrent.Task)2 ChoiceDialog (jgnash.uifx.control.ChoiceDialog)2 Collection (java.util.Collection)1 List (java.util.List)1 CurrencyNode (jgnash.engine.CurrencyNode)1 Engine (jgnash.engine.Engine)1 LocaleObject (jgnash.util.LocaleObject)1