/*
* 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.controlling;
import static de.aidger.utils.Translation._;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import de.aidger.model.models.Course;
import de.aidger.model.models.FinancialCategory;
import de.aidger.model.reports.BalanceCourse;
import de.aidger.model.reports.BalanceCourse.BudgetCost;
import de.aidger.utils.reports.BalanceHelper;
import de.aidger.view.models.UICourse;
import siena.SienaException;
/**
*
* @author aidGer Team
*/
public class ControllingFinancialCategory extends javax.swing.JPanel {
/**
* The table model of the content table.
*/
private final DefaultTableModel controllingTableModel = new DefaultTableModel(
null, new String[] { _("Course"), _("Used budget") }) {
boolean[] editable = { false, false, false };
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return editable[columnIndex];
}
};
/**
* The total budget of this financial category
*/
private double totalBudget = 0;
/**
* The used budget of this financial category
*/
private double usedBudget = 0;
/**
* The financial category of this report
*/
private FinancialCategory financialCategory = null;
/** Creates new form ControllingFinancialCategory */
public ControllingFinancialCategory(FinancialCategory financialCategory) {
this.financialCategory = financialCategory;
for (Integer budgetCost : financialCategory.getBudgetCosts()) {
totalBudget += budgetCost;
}
fillTable(generateRowData());
initComponents();
}
/**
* Generates the data for all the rows of the report
*/
private List<Object[]> generateRowData() {
List<Object[]> rows = new ArrayList<Object[]>();
try {
List<Course> courses = new Course().getCourses(financialCategory);
for (Course course : courses) {
double budget = 0;
new BalanceHelper();
BalanceCourse balanceCourse = BalanceHelper
.getBalanceCourse(course);
// Cost units don't matter here, so add the budget of each of them to a total budget.
List<BudgetCost> budgetCosts = balanceCourse.getBudgetCosts();
for (BudgetCost budgetCost : budgetCosts) {
budget += budgetCost.getUnroundedValue();
}
// The row for one course with its used budget
Object[] rowDataArray = {
new UICourse(course).toString(),
new BigDecimal(budget).setScale(2,
BigDecimal.ROUND_HALF_EVEN) };
rows.add(rowDataArray);
usedBudget += budget;
}
} catch (SienaException e) {
e.printStackTrace();
}
return rows;
}
/**
* Fills the table with all courses of this financial category
*/
private void fillTable(List<Object[]> rows) {
for (Object[] row : rows) {
controllingTableModel.addRow(row);
}
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jTable1 = new javax.swing.JTable();
jPanel1 = new javax.swing.JPanel();
totalBudgetLabel = new javax.swing.JLabel();
totalBudgetValueLabel = new javax.swing.JLabel();
usedBudgetValueLabel = new javax.swing.JLabel();
usedBudgetLabel = new javax.swing.JLabel();
setBorder(javax.swing.BorderFactory
.createTitledBorder(financialCategory.getName()));
setLayout(new java.awt.BorderLayout());
jTable1.setModel(controllingTableModel);
add(jTable1, java.awt.BorderLayout.PAGE_START);
totalBudgetLabel.setText(_("Total budget") + ":");
totalBudgetValueLabel.setText(new BigDecimal(totalBudget).setScale(2,
BigDecimal.ROUND_HALF_EVEN).toString());
usedBudgetValueLabel.setText(new BigDecimal(usedBudget).setScale(2,
BigDecimal.ROUND_HALF_EVEN).toString());
usedBudgetLabel.setText(_("Used budget") + ":");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
javax.swing.GroupLayout.Alignment.TRAILING,
jPanel1Layout.createSequentialGroup().addContainerGap(256,
Short.MAX_VALUE).addGroup(
jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.TRAILING).addComponent(
totalBudgetLabel).addComponent(usedBudgetLabel))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(usedBudgetValueLabel).addComponent(
totalBudgetValueLabel)).addContainerGap()));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(
jPanel1Layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGroup(
jPanel1Layout.createSequentialGroup().addComponent(
totalBudgetLabel).addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(usedBudgetLabel)).addGroup(
jPanel1Layout.createSequentialGroup().addComponent(
totalBudgetValueLabel).addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(usedBudgetValueLabel))).addContainerGap(
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
add(jPanel1, java.awt.BorderLayout.CENTER);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanel1;
private javax.swing.JTable jTable1;
private javax.swing.JLabel totalBudgetLabel;
private javax.swing.JLabel totalBudgetValueLabel;
private javax.swing.JLabel usedBudgetLabel;
private javax.swing.JLabel usedBudgetValueLabel;
// End of variables declaration//GEN-END:variables
}