Search in sources :

Example 36 with TableColumn

use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.

the class RecurringViewController method initialize.

@FXML
private void initialize() {
    tableView.setTableMenuButtonVisible(true);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    // hide the horizontal scrollbar and prevent ghosting
    tableView.getStylesheets().addAll(StyleClass.HIDE_HORIZONTAL_CSS);
    final TableColumn<Reminder, String> descriptionColumn = new TableColumn<>(resources.getString("Column.Description"));
    descriptionColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
    tableView.getColumns().add(descriptionColumn);
    final TableColumn<Reminder, String> accountColumn = new TableColumn<>(resources.getString("Column.Account"));
    accountColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getDescription()));
    accountColumn.setCellValueFactory(param -> {
        if (param.getValue().getAccount() != null) {
            return new SimpleObjectProperty<>(param.getValue().getAccount().toString());
        }
        return null;
    });
    tableView.getColumns().add(accountColumn);
    final TableColumn<Reminder, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setCellValueFactory(param -> {
        if (param.getValue().getTransaction() != null) {
            return new SimpleObjectProperty<>(param.getValue().getTransaction().getAmount(param.getValue().getAccount()));
        }
        return null;
    });
    amountColumn.setCellFactory(new Callback<TableColumn<Reminder, BigDecimal>, TableCell<Reminder, BigDecimal>>() {

        @Override
        public TableCell<Reminder, BigDecimal> call(TableColumn<Reminder, BigDecimal> param) {
            return new TableCell<Reminder, BigDecimal>() {

                {
                    setStyle("-fx-alignment: center-right;");
                }

                @Override
                protected void updateItem(final BigDecimal amount, final boolean empty) {
                    super.updateItem(amount, empty);
                    if (!empty && getTableRow() != null && getTableRow().getItem() != null) {
                        final Reminder reminder = (Reminder) getTableRow().getItem();
                        if (reminder.getTransaction() != null) {
                            setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(amount));
                            if (amount != null && amount.signum() < 0) {
                                setId(StyleClass.NORMAL_NEGATIVE_CELL_ID);
                            } else {
                                setId(StyleClass.NORMAL_CELL_ID);
                            }
                        } else {
                            setText(CommodityFormat.getFullNumberFormat(reminder.getAccount().getCurrencyNode()).format(BigDecimal.ZERO));
                        }
                    }
                }
            };
        }
    });
    tableView.getColumns().add(amountColumn);
    final TableColumn<Reminder, String> frequencyColumn = new TableColumn<>(resources.getString("Column.Freq"));
    frequencyColumn.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getReminderType().toString()));
    tableView.getColumns().add(frequencyColumn);
    final TableColumn<Reminder, Boolean> enabledColumn = new TableColumn<>(resources.getString("Column.Enabled"));
    enabledColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue().isEnabled()));
    enabledColumn.setCellFactory(CheckBoxTableCell.forTableColumn(enabledColumn));
    tableView.getColumns().add(enabledColumn);
    final TableColumn<Reminder, LocalDate> lastPosted = new TableColumn<>(resources.getString("Column.LastPosted"));
    lastPosted.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getLastDate()));
    lastPosted.setCellFactory(cell -> new ShortDateTableCell<>());
    tableView.getColumns().add(lastPosted);
    final TableColumn<Reminder, LocalDate> due = new TableColumn<>(resources.getString("Column.Due"));
    due.setCellValueFactory(param -> new SimpleObjectProperty<>(param.getValue().getIterator().next()));
    due.setCellFactory(cell -> new ShortDateTableCell<>());
    tableView.getColumns().add(due);
    sortedReminderList.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(sortedReminderList);
    selectedReminder.bind(tableView.getSelectionModel().selectedItemProperty());
    // bind enabled state of the buttons to the selected reminder property
    deleteButton.disableProperty().bind(Bindings.isNull(selectedReminder));
    modifyButton.disableProperty().bind(Bindings.isNull(selectedReminder));
    MessageBus.getInstance().registerListener(this, MessageChannel.SYSTEM, MessageChannel.REMINDER);
    JavaFXUtils.runLater(this::loadTable);
    startTimer();
    // Update the period when the snooze value changes
    Options.reminderSnoozePeriodProperty().addListener((observable, oldValue, newValue) -> {
        stopTimer();
        startTimer();
    });
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) PendingReminder(jgnash.engine.recurring.PendingReminder) Reminder(jgnash.engine.recurring.Reminder) TableColumn(javafx.scene.control.TableColumn) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) TableCell(javafx.scene.control.TableCell) ShortDateTableCell(jgnash.uifx.control.ShortDateTableCell) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXML(javafx.fxml.FXML)

Example 37 with TableColumn

use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.

the class AboutDialogController method getSystemPropertiesTab.

private Tab getSystemPropertiesTab() {
    final ObservableList<SystemProperty> propertiesList = FXCollections.observableArrayList();
    final Properties properties = System.getProperties();
    propertiesList.addAll(properties.stringPropertyNames().stream().map(prop -> new SystemProperty(prop, properties.getProperty(prop))).collect(Collectors.toList()));
    FXCollections.sort(propertiesList);
    final TableColumn<SystemProperty, String> keyCol = new TableColumn<>(resources.getString("Column.PropName"));
    keyCol.setCellValueFactory(param -> param.getValue().keyProperty());
    final TableColumn<SystemProperty, String> valueCol = new TableColumn<>(resources.getString("Column.PropVal"));
    valueCol.setCellValueFactory(param -> param.getValue().valueProperty());
    final TableView<SystemProperty> tableView = new TableView<>(propertiesList);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    final ObservableList<TableColumn<SystemProperty, ?>> tableViewColumns = tableView.getColumns();
    tableViewColumns.add(keyCol);
    tableViewColumns.add(valueCol);
    tableView.getStylesheets().addAll(MainView.DEFAULT_CSS);
    final ContextMenu menu = new ContextMenu();
    final MenuItem copyMenuItem = new MenuItem(resources.getString("Menu.Copy.Name"));
    copyMenuItem.setOnAction(event -> dumpPropertiesToClipboard(tableView));
    menu.getItems().add(copyMenuItem);
    tableView.setContextMenu(menu);
    return new Tab(ResourceUtils.getString("Tab.SysInfo"), tableView);
}
Also used : Tab(javafx.scene.control.Tab) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Properties(java.util.Properties) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 38 with TableColumn

use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.

the class BudgetGoalsDialogController method initialize.

@FXML
private void initialize() {
    buttonBar.buttonOrderProperty().bind(Options.buttonOrderProperty());
    endRowSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1));
    startRowSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 1));
    periodComboBox.getItems().addAll(Period.values());
    patternComboBox.getItems().addAll(Pattern.values());
    patternComboBox.setValue(Pattern.EveryRow);
    fillAllDecimalTextField.emptyWhenZeroProperty().set(false);
    fillPatternAmountDecimalTextField.emptyWhenZeroProperty().set(false);
    fillAllDecimalTextField.setDecimal(BigDecimal.ZERO);
    fillPatternAmountDecimalTextField.setDecimal(BigDecimal.ZERO);
    goalTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    goalTable.setEditable(true);
    final TableColumn<BudgetPeriodDescriptor, String> periodColumn = new TableColumn<>(resources.getString("Column.Period"));
    periodColumn.setEditable(false);
    periodColumn.setCellValueFactory(param -> {
        if (param != null) {
            return new SimpleStringProperty(param.getValue().getPeriodDescription());
        }
        return new SimpleStringProperty("");
    });
    periodColumn.setSortable(false);
    goalTable.getColumns().add(periodColumn);
    final TableColumn<BudgetPeriodDescriptor, BigDecimal> amountColumn = new TableColumn<>(resources.getString("Column.Amount"));
    amountColumn.setEditable(true);
    amountColumn.setSortable(false);
    amountColumn.setCellValueFactory(param -> {
        if (param != null) {
            final BudgetPeriodDescriptor descriptor = param.getValue();
            final BigDecimal goal = budgetGoal.get().getGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod());
            return new SimpleObjectProperty<>(goal.setScale(accountProperty().get().getCurrencyNode().getScale(), MathConstants.roundingMode));
        }
        return new SimpleObjectProperty<>(BigDecimal.ZERO);
    });
    amountColumn.setCellFactory(cell -> new BigDecimalTableCell<>(numberFormat));
    /// fTextFieldTableCell.forTableColumn()
    amountColumn.setOnEditCommit(event -> {
        final BudgetPeriodDescriptor descriptor = event.getTableView().getItems().get(event.getTablePosition().getRow());
        budgetGoalProperty().get().setGoal(descriptor.getStartPeriod(), descriptor.getEndPeriod(), event.getNewValue());
    });
    goalTable.getColumns().add(amountColumn);
    periodComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            budgetGoalProperty().get().setBudgetPeriod(newValue);
            final List<BudgetPeriodDescriptor> descriptors = getDescriptors();
            goalTable.getItems().setAll(descriptors);
            descriptorSize.set(descriptors.size());
        }
    });
    budgetGoalProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            periodComboBox.setValue(newValue.getBudgetPeriod());
        }
    });
    // the spinner factory max values do not like being bound; Set value instead
    descriptorSize.addListener((observable, oldValue, newValue) -> {
        ((SpinnerValueFactory.IntegerSpinnerValueFactory) endRowSpinner.getValueFactory()).setMax(newValue.intValue());
        ((SpinnerValueFactory.IntegerSpinnerValueFactory) startRowSpinner.getValueFactory()).setMax(newValue.intValue());
        endRowSpinner.getValueFactory().setValue(newValue.intValue());
    });
    // account has changed; update currency related properties
    accountProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final CurrencyNode currencyNode = newValue.getCurrencyNode();
            currencyLabel.setText(currencyNode.getSymbol());
            fillAllDecimalTextField.scaleProperty().set(currencyNode.getScale());
            fillAllDecimalTextField.minScaleProperty().set(currencyNode.getScale());
            fillPatternAmountDecimalTextField.scaleProperty().set(currencyNode.getScale());
            fillPatternAmountDecimalTextField.minScaleProperty().set(currencyNode.getScale());
            final NumberFormat decimalFormat = NumberFormat.getInstance();
            if (decimalFormat instanceof DecimalFormat) {
                decimalFormat.setMinimumFractionDigits(currencyNode.getScale());
                decimalFormat.setMaximumFractionDigits(currencyNode.getScale());
            }
            numberFormat.set(decimalFormat);
        }
    });
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) DecimalFormat(java.text.DecimalFormat) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) TableColumn(javafx.scene.control.TableColumn) BigDecimal(java.math.BigDecimal) SpinnerValueFactory(javafx.scene.control.SpinnerValueFactory) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) BudgetPeriodDescriptor(jgnash.engine.budget.BudgetPeriodDescriptor) NumberFormat(java.text.NumberFormat) FXML(javafx.fxml.FXML)

Example 39 with TableColumn

use of javafx.scene.control.TableColumn in project jgnash by ccavanaugh.

the class TableViewManager method getCalculatedColumnWidth.

/**
     * Determines the preferred width of the column including contents.
     *
     * @param column {@code TableColumn} to measure content
     * @return preferred width
     */
private double getCalculatedColumnWidth(final TableColumnBase<S, ?> column) {
    double maxWidth = 0;
    /* Collect all the unique cell items and remove null*/
    final Set<Object> cellItems = new HashSet<>();
    for (int i = 0; i < tableView.getItems().size(); i++) {
        cellItems.add(column.getCellData(i));
    }
    cellItems.remove(null);
    if (cellItems.size() > 0) {
        // don't try if there is no data or the stream function will throw an error
        final OptionalDouble max = cellItems.parallelStream().filter(Objects::nonNull).mapToDouble(o -> {
            final Format format = columnFormatFactory.get().call(column);
            return JavaFXUtils.getDisplayedTextWidth(format != null ? format.format(o) : o.toString(), column.getStyle());
        }).max();
        maxWidth = max.isPresent() ? max.getAsDouble() : 0;
    }
    //noinspection SuspiciousMethodCalls
    maxWidth = Math.max(maxWidth, Math.max(column.getMinWidth(), minimumColumnWidthFactory.get().call(tableView.getColumns().indexOf(column))));
    // header text width
    maxWidth = Math.max(maxWidth, JavaFXUtils.getDisplayedTextWidth(column.getText(), column.getStyle()) * BOLD_MULTIPLIER);
    return Math.ceil(maxWidth + COLUMN_PADDING);
}
Also used : Format(java.text.Format) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OptionalDouble(java.util.OptionalDouble) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) EncodeDecode(jgnash.util.EncodeDecode) HashSet(java.util.HashSet) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) ObjectProperty(javafx.beans.property.ObjectProperty) NotNull(jgnash.util.NotNull) Set(java.util.Set) Logger(java.util.logging.Logger) Preferences(java.util.prefs.Preferences) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) TableColumnBase(javafx.scene.control.TableColumnBase) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) Format(java.text.Format) Objects(java.util.Objects) OptionalDouble(java.util.OptionalDouble) HashSet(java.util.HashSet)

Example 40 with TableColumn

use of javafx.scene.control.TableColumn 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)

Aggregations

TableColumn (javafx.scene.control.TableColumn)40 TableView (javafx.scene.control.TableView)13 BigDecimal (java.math.BigDecimal)11 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)10 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 LocalDate (java.time.LocalDate)8 Map (java.util.Map)8 Scene (javafx.scene.Scene)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BorderPane (javafx.scene.layout.BorderPane)7 List (java.util.List)6 FXML (javafx.fxml.FXML)5 TableCell (javafx.scene.control.TableCell)5 ObjectProperty (javafx.beans.property.ObjectProperty)4 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)4 ObservableValue (javafx.beans.value.ObservableValue)4 ObservableList (javafx.collections.ObservableList)4 Button (javafx.scene.control.Button)4 SelectionMode (javafx.scene.control.SelectionMode)4