Search in sources :

Example 56 with CurrencyNode

use of jgnash.engine.CurrencyNode 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 57 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class AddRemoveCurrencyController method loadModel.

private void loadModel() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    // Defaults
    final Set<CurrencyNode> defaultNodes = DefaultCurrencies.generateCurrencies();
    // Active
    final Set<CurrencyNode> activeNodes = engine.getActiveCurrencies();
    // Available
    final List<CurrencyNode> availNodes = engine.getCurrencies();
    // remove any overlap between the available and the default
    availNodes.forEach(defaultNodes::remove);
    availableList.getItems().addAll(defaultNodes);
    final ArrayList<LockedCommodityNode<CurrencyNode>> list = new ArrayList<>();
    for (final CurrencyNode node : availNodes) {
        if (activeNodes.contains(node)) {
            list.add(new LockedCommodityNode<>(node, true));
        } else {
            list.add(new LockedCommodityNode<>(node, false));
        }
    }
    selectedList.getItems().addAll(list);
    FXCollections.sort(availableList.getItems());
    FXCollections.sort(selectedList.getItems());
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) ArrayList(java.util.ArrayList) LockedCommodityNode(jgnash.util.LockedCommodityNode) Engine(jgnash.engine.Engine)

Example 58 with CurrencyNode

use of jgnash.engine.CurrencyNode in project jgnash by ccavanaugh.

the class AddRemoveCurrencyController method handleAddAction.

@FXML
private void handleAddAction() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    for (final CurrencyNode currencyNode : availableList.getSelectionModel().getSelectedItems()) {
        engine.addCurrency(currencyNode);
        availableList.getItems().remove(currencyNode);
        selectedList.getItems().add(new LockedCommodityNode<>(currencyNode, false));
    }
    FXCollections.sort(selectedList.getItems());
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Aggregations

CurrencyNode (jgnash.engine.CurrencyNode)58 Account (jgnash.engine.Account)28 Engine (jgnash.engine.Engine)28 BigDecimal (java.math.BigDecimal)10 ArrayList (java.util.ArrayList)10 LocalDate (java.time.LocalDate)8 NumberFormat (java.text.NumberFormat)7 List (java.util.List)7 FXML (javafx.fxml.FXML)7 AccountGroup (jgnash.engine.AccountGroup)7 Transaction (jgnash.engine.Transaction)6 ResourceBundle (java.util.ResourceBundle)5 SecurityNode (jgnash.engine.SecurityNode)5 InjectFXML (jgnash.uifx.util.InjectFXML)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 JasperPrint (net.sf.jasperreports.engine.JasperPrint)4 HashMap (java.util.HashMap)3 Objects (java.util.Objects)3 ExecutionException (java.util.concurrent.ExecutionException)3