Search in sources :

Example 1 with BudgetResultsModel

use of jgnash.engine.budget.BudgetResultsModel in project jgnash by ccavanaugh.

the class BudgetPanel method showBudgetPane.

private void showBudgetPane() {
    logger.entering(BudgetPanel.class.getName(), "showBudgetPane");
    // unregister the listener so we don't leak by listening to stale models
    if (tableModel != null) {
        tableModel.removeMessageListener(this);
    }
    activeBudget = budgetCombo.getSelectedBudget();
    if (activeBudget != null) {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        Objects.requireNonNull(engine);
        final CurrencyNode baseCurrency = engine.getDefaultCurrency();
        resultsModel = new BudgetResultsModel(activeBudget, budgetYear, baseCurrency, false);
        tableModel = new ExpandingBudgetTableModel(resultsModel);
        // register the listener
        tableModel.addMessageListener(this);
        activeBudget.setWorkingYear(budgetYear);
        preferences.put(LAST_BUDGET, activeBudget.getUuid());
        List<BudgetPeriodPanel> newPanels = buildPeriodPanels();
        JPanel budgetPanel = getBudgetPanel(newPanels);
        AccountRowHeaderPanel accountPanel = new AccountRowHeaderPanel(activeBudget, tableModel);
        BudgetColumnHeader header = new BudgetColumnHeader(newPanels);
        panels = newPanels;
        for (BudgetPeriodPanel periodPanel : panels) {
            periodPanel.setRowHeight(accountPanel.getRowHeight());
        }
        scrollPane.setViewportView(budgetPanel);
        scrollPane.setRowHeaderView(accountPanel);
        scrollPane.setColumnHeaderView(header);
        scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, accountPanel.getTableHeader());
        if (summaryRowVisibleCheckBox.isSelected()) {
            addSummaryRows();
        }
        if (activeBudget.getBudgetPeriod() != Period.YEARLY && summaryColVisibleCheckBox.isSelected()) {
            // summary is redundant for a yearly view
            addSummaryColumn();
            if (summaryRowVisibleCheckBox.isSelected()) {
                addSummaryCorner();
            }
        }
        rowHeaderResizeHandler.attachListeners();
        showCurrentPeriod();
        overviewPanel.updateSparkLines();
    }
    logger.exiting(BudgetPanel.class.getName(), "showBudgetPane");
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) JPanel(javax.swing.JPanel) Engine(jgnash.engine.Engine) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel)

Example 2 with BudgetResultsModel

use of jgnash.engine.budget.BudgetResultsModel in project jgnash by ccavanaugh.

the class BudgetTableController method handleBudgetChange.

/**
 * Model must be rebuilt if the year or a budget property is changed.
 * <p>
 * This method is synchronized to limit more than one update attempt at a time.
 */
private synchronized void handleBudgetChange() {
    lock.writeLock().lock();
    try {
        final Engine engine = EngineFactory.getEngine(EngineFactory.DEFAULT);
        if (budget.get() != null && engine != null) {
            // unregister listener from the old model because the model will be replaced
            if (budgetResultsModel != null) {
                // unregister from the old model
                budgetResultsModel.removeMessageListener(this);
            }
            // Build the new results model
            budgetResultsModel = new BudgetResultsModel(budget.get(), yearSpinner.getValue(), engine.getDefaultCurrency(), runningTotalsButton.isSelected());
            // model has changed, calculate the minimum column width for the summary columns
            minSummaryColumnWidth.set(calculateMinSummaryWidthColumnWidth());
            // model has changed, calculate the minimum column width the data model needs
            minColumnWidth = calculateMinPeriodColumnWidth();
            // register the listener with the new model
            // register with the new model
            budgetResultsModel.addMessageListener(this);
            // update the number of periods the budget model has
            periodCount.set(budgetResultsModel.getDescriptorList().size());
            // load the model
            loadModel();
        } else {
            JavaFXUtils.runLater(() -> {
                accountTreeView.setRoot(null);
                expandedAccountList.clear();
                accountGroupList.clear();
            });
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : Engine(jgnash.engine.Engine) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel)

Example 3 with BudgetResultsModel

use of jgnash.engine.budget.BudgetResultsModel in project jgnash by ccavanaugh.

the class BudgetResultsExportTest method testExportBudgetResultsModel.

@Test
void testExportBudgetResultsModel() throws Exception {
    final String file = Files.createTempFile("budget-", DataStoreType.XML.getDataStore().getFileExt()).toString();
    EngineFactory.deleteDatabase(file);
    Engine e = EngineFactory.bootLocalEngine(file, EngineFactory.DEFAULT, EngineFactory.EMPTY_PASSWORD, DataStoreType.XML);
    e.setCreateBackups(false);
    CurrencyNode node = e.getDefaultCurrency();
    Account account1 = new Account(AccountType.EXPENSE, node);
    account1.setName("Expense 1");
    e.addAccount(e.getRootAccount(), account1);
    Account account2 = new Account(AccountType.EXPENSE, node);
    account2.setName("Expense 2");
    e.addAccount(e.getRootAccount(), account2);
    Budget budget = new Budget();
    budget.setName("My Budget");
    budget.setDescription("Test");
    budget.setBudgetPeriod(Period.MONTHLY);
    assertTrue(e.addBudget(budget));
    BudgetResultsModel model = new BudgetResultsModel(budget, 2012, node, false);
    final Path exportFile = Files.createTempFile("testworkbook", ".xls");
    final String errors = BudgetResultsExport.exportBudgetResultsModel(exportFile, model);
    assertNull(errors);
    assertTrue(Files.exists(exportFile));
    Files.delete(exportFile);
    EngineFactory.closeEngine(EngineFactory.DEFAULT);
    Files.deleteIfExists(Paths.get(file));
}
Also used : CurrencyNode(jgnash.engine.CurrencyNode) Path(java.nio.file.Path) Account(jgnash.engine.Account) Budget(jgnash.engine.budget.Budget) Engine(jgnash.engine.Engine) BudgetResultsModel(jgnash.engine.budget.BudgetResultsModel) Test(org.junit.jupiter.api.Test)

Aggregations

Engine (jgnash.engine.Engine)3 BudgetResultsModel (jgnash.engine.budget.BudgetResultsModel)3 CurrencyNode (jgnash.engine.CurrencyNode)2 Path (java.nio.file.Path)1 JPanel (javax.swing.JPanel)1 Account (jgnash.engine.Account)1 Budget (jgnash.engine.budget.Budget)1 Test (org.junit.jupiter.api.Test)1