Search in sources :

Example 1 with ExchangeRateHistoryNode

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

the class EditExchangeRatesController method handleDeleteAction.

@FXML
private void handleDeleteAction() {
    final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
    Objects.requireNonNull(engine);
    // Create a defensive list of the selected history nodes
    final List<ExchangeRateHistoryNode> historyNodes = new ArrayList<>(exchangeRateTable.getSelectionModel().getSelectedItems());
    for (final ExchangeRateHistoryNode historyNode : historyNodes) {
        engine.removeExchangeRateHistory(selectedExchangeRate.get(), historyNode);
    }
}
Also used : ArrayList(java.util.ArrayList) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) Engine(jgnash.engine.Engine) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 2 with ExchangeRateHistoryNode

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

the class CurrencyExchangeDialog method updateForm.

private void updateForm() {
    int row = table.getSelectedRow();
    if (row >= 0) {
        ExchangeRateHistoryNode node = getSelectedExchangeRate().getHistory().get(row);
        rateField.setDecimal(node.getRate());
        dateField.setDate(node.getLocalDate());
    }
}
Also used : ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode)

Example 3 with ExchangeRateHistoryNode

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

the class EditExchangeRatesController method initialize.

@FXML
void initialize() {
    exchangeRateField.scaleProperty().set(MathConstants.EXCHANGE_RATE_ACCURACY);
    exchangeRateTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    exchangeRateTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    final TableColumn<ExchangeRateHistoryNode, LocalDate> dateColumn = new TableColumn<>(resources.getString("Column.Date"));
    dateColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLocalDate()));
    dateColumn.setCellFactory(cell -> new ShortDateTableCell<>());
    exchangeRateTable.getColumns().add(dateColumn);
    final NumberFormat decimalFormat = NumberFormat.getInstance();
    if (decimalFormat instanceof DecimalFormat) {
        decimalFormat.setMinimumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
        decimalFormat.setMaximumFractionDigits(MathConstants.EXCHANGE_RATE_ACCURACY);
    }
    final TableColumn<ExchangeRateHistoryNode, BigDecimal> rateColumn = new TableColumn<>(resources.getString("Column.ExchangeRate"));
    rateColumn.setCellValueFactory(param -> {
        if (param == null || selectedExchangeRate.get() == null) {
            return null;
        }
        if (selectedExchangeRate.get().getRateId().startsWith(baseCurrencyComboBox.getValue().getSymbol())) {
            return new SimpleObjectProperty<>(param.getValue().getRate());
        }
        return new SimpleObjectProperty<>(BigDecimal.ONE.divide(param.getValue().getRate(), MathConstants.mathContext));
    });
    rateColumn.setCellFactory(cell -> new BigDecimalTableCell<>(decimalFormat));
    exchangeRateTable.getColumns().add(rateColumn);
    baseCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    targetCurrencyComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> handleExchangeRateSelectionChange());
    selectedHistoryNode.bind(exchangeRateTable.getSelectionModel().selectedItemProperty());
    deleteButton.disableProperty().bind(selectedHistoryNode.isNull());
    clearButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty());
    addButton.disableProperty().bind(exchangeRateField.textProperty().isEmpty().or(Bindings.equal(baseCurrencyComboBox.getSelectionModel().selectedItemProperty(), targetCurrencyComboBox.getSelectionModel().selectedItemProperty())));
    selectedExchangeRate.addListener((observable, oldValue, newValue) -> Platform.runLater(EditExchangeRatesController.this::loadExchangeRateHistory));
    selectedHistoryNode.addListener((observable, oldValue, newValue) -> Platform.runLater(EditExchangeRatesController.this::updateForm));
    MessageBus.getInstance().registerListener(this, MessageChannel.COMMODITY);
    // Install a listener to unregister from the message bus when the window closes
    parent.addListener((observable, oldValue, scene) -> {
        if (scene != null) {
            scene.windowProperty().addListener((observable1, oldValue1, window) -> window.addEventHandler(WindowEvent.WINDOW_HIDING, event -> {
                handleStopAction();
                Logger.getLogger(EditExchangeRatesController.class.getName()).info("Unregistered from the message bus");
                MessageBus.getInstance().unregisterListener(EditExchangeRatesController.this, MessageChannel.COMMODITY);
            }));
        }
    });
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) Engine(jgnash.engine.Engine) CurrencyUpdateFactory(jgnash.net.currency.CurrencyUpdateFactory) EngineFactory(jgnash.engine.EngineFactory) ResourceUtils(jgnash.util.ResourceUtils) FXCollections(javafx.collections.FXCollections) MathConstants(jgnash.engine.MathConstants) BigDecimalTableCell(jgnash.uifx.control.BigDecimalTableCell) MessageBus(jgnash.engine.message.MessageBus) Bindings(javafx.beans.binding.Bindings) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) ExchangeRate(jgnash.engine.ExchangeRate) BigDecimal(java.math.BigDecimal) Task(javafx.concurrent.Task) MessageProperty(jgnash.engine.message.MessageProperty) ProgressBar(javafx.scene.control.ProgressBar) ResourceBundle(java.util.ResourceBundle) MessageChannel(jgnash.engine.message.MessageChannel) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) CurrencyNode(jgnash.engine.CurrencyNode) MessageListener(jgnash.engine.message.MessageListener) ObjectProperty(javafx.beans.property.ObjectProperty) InjectFXML(jgnash.uifx.util.InjectFXML) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) FXMLUtils(jgnash.uifx.util.FXMLUtils) DecimalFormat(java.text.DecimalFormat) Logger(java.util.logging.Logger) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) CurrencyComboBox(jgnash.uifx.control.CurrencyComboBox) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) LocalDate(java.time.LocalDate) Optional(java.util.Optional) DecimalTextField(jgnash.uifx.control.DecimalTextField) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) DatePickerEx(jgnash.uifx.control.DatePickerEx) Message(jgnash.engine.message.Message) DecimalFormat(java.text.DecimalFormat) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) NumberFormat(java.text.NumberFormat) InjectFXML(jgnash.uifx.util.InjectFXML) FXML(javafx.fxml.FXML)

Example 4 with ExchangeRateHistoryNode

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

the class CurrencyExchangeDialog method removeExchangeRates.

private void removeExchangeRates() {
    ExchangeRate rate = getSelectedExchangeRate();
    if (rate != null) {
        int[] rows = table.getSelectedRows();
        List<ExchangeRateHistoryNode> history = rate.getHistory();
        /* Capture a list of references */
        ExchangeRateHistoryNode[] temp = new ExchangeRateHistoryNode[rows.length];
        for (int i = 0; i < rows.length; i++) {
            temp[i] = history.get(rows[i]);
        }
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        if (engine != null) {
            for (int i = rows.length - 1; i >= 0; i--) {
                engine.removeExchangeRateHistory(rate, temp[i]);
            }
        }
    }
}
Also used : ExchangeRate(jgnash.engine.ExchangeRate) ExchangeRateHistoryNode(jgnash.engine.ExchangeRateHistoryNode) Engine(jgnash.engine.Engine)

Aggregations

ExchangeRateHistoryNode (jgnash.engine.ExchangeRateHistoryNode)4 Engine (jgnash.engine.Engine)3 ArrayList (java.util.ArrayList)2 FXML (javafx.fxml.FXML)2 ExchangeRate (jgnash.engine.ExchangeRate)2 BigDecimal (java.math.BigDecimal)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 LocalDate (java.time.LocalDate)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 ExecutionException (java.util.concurrent.ExecutionException)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Platform (javafx.application.Platform)1 Bindings (javafx.beans.binding.Bindings)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1