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();
}
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());
}
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());
}
Aggregations