/* * This file is part of the aidGer project. * * Copyright (C) 2010-2013 The aidGer Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.aidger.view.tabs; import static de.aidger.utils.Translation._; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.JPanel; import de.aidger.controller.ActionNotFoundException; import de.aidger.controller.ActionRegistry; import de.aidger.controller.actions.FinancialControllingGenerateAction; import de.aidger.model.controlling.FinancialControllingCreator; import de.aidger.model.models.FinancialCategory; import de.aidger.utils.controlling.ControllingHelper; import de.aidger.view.UI; import de.aidger.view.controlling.ControllingFinancialCategory; /** * This class is used to display the controlling report. * * @author aidGer Team */ @SuppressWarnings("serial") public class FinancialControllingViewerTab extends ReportTab { /** * The year, month to be used with the controlling report. */ private int year; /** * Initializes a new controlling viewer tab. */ public FinancialControllingViewerTab() { initComponents(); // Fill up the combo boxes for the first time. createYearItems(); /* * Assign the actions to the buttons. */ try { generateButton.setAction(ActionRegistry.getInstance().get( FinancialControllingGenerateAction.class.getName())); } catch (ActionNotFoundException e) { UI.displayError(e.getMessage()); } } /** * Generate a financial category controlling report */ public void generateReport() { clearPanel(); FinancialControllingCreator controllingCreator = new FinancialControllingCreator(); List<FinancialCategory> financialCategories = controllingCreator .getCategories(year); // Generate a table for every financial category for (FinancialCategory financialCategory : financialCategories) { addPanel(new ControllingFinancialCategory(financialCategory)); } } /** * Clears all data from the content panel */ private void clearPanel() { tablePanel.removeAll(); tablePanel.setVisible(false); tablePanel.setVisible(true); } /** * Adds a panel to the content panel */ private void addPanel(JPanel panel) { tablePanel.add(panel); tablePanel.setVisible(false); tablePanel.setVisible(true); } /** * Creates the year items for the year combo box. */ private void createYearItems() { List<Integer> years = new ControllingHelper().getFinancialYears(); yearComboBox.setModel(new DefaultComboBoxModel(years.toArray())); if (yearComboBox.getItemCount() > 0) { year = (Integer) yearComboBox.getSelectedItem(); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jToolBar1 = new javax.swing.JToolBar(); jSeparator3 = new javax.swing.JToolBar.Separator(); generateButton = new javax.swing.JButton(); jSeparator1 = new javax.swing.JToolBar.Separator(); contentPanel = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); tablePanel = new javax.swing.JPanel(); filtersPanel = new javax.swing.JPanel(); yearLabel = new javax.swing.JLabel(); yearComboBox = new javax.swing.JComboBox(); setLayout(new java.awt.BorderLayout()); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); jToolBar1.add(jSeparator3); generateButton.setText(_("Generate")); generateButton.setFocusable(false); generateButton .setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); generateButton .setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(generateButton); jToolBar1.add(jSeparator1); add(jToolBar1, java.awt.BorderLayout.PAGE_START); contentPanel.setLayout(new java.awt.BorderLayout()); tablePanel.setLayout(new javax.swing.BoxLayout(tablePanel, javax.swing.BoxLayout.Y_AXIS)); jScrollPane1.setViewportView(tablePanel); contentPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER); filtersPanel .setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); yearLabel.setText(_("Year") + ":"); filtersPanel.add(yearLabel); yearComboBox.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { yearComboBoxItemStateChanged(evt); } }); filtersPanel.add(yearComboBox); contentPanel.add(filtersPanel, java.awt.BorderLayout.PAGE_START); add(contentPanel, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents private void yearComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_yearComboBoxItemStateChanged if (yearComboBox.getSelectedIndex() >= 0) { year = (Integer) yearComboBox.getSelectedItem(); } }//GEN-LAST:event_yearComboBoxItemStateChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel contentPanel; private javax.swing.JPanel filtersPanel; private javax.swing.JButton generateButton; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JToolBar.Separator jSeparator1; private javax.swing.JToolBar.Separator jSeparator3; private javax.swing.JToolBar jToolBar1; private javax.swing.JPanel tablePanel; private javax.swing.JComboBox yearComboBox; private javax.swing.JLabel yearLabel; // End of variables declaration//GEN-END:variables /* * (non-Javadoc) * * @see de.aidger.view.tabs.Tab#getTabName() */ @Override public String getTabName() { return _("Financial Category Controlling"); } /* * (non-Javadoc) * * @see de.aidger.view.tabs.Tab#isScrollable() */ @Override public boolean isScrollable() { return false; } }