Author: jpepin Date: 2010-05-06 11:57:19 +0200 (Thu, 06 May 2010) New Revision: 2884 Url: http://chorem.org/repositories/revision/lima/2884 Log: Coloration des transactions financieres, ajout de comportements au clavier, resolution bug suppression d'une transaction financiere contenant des entr?\195?\169es, ajout r?\195?\168gles de v?\195?\169rification Removed: trunk/lima-swing/src/main/java/org/chorem/lima/bilan/ trunk/lima-swing/src/main/java/org/chorem/lima/combobox/ trunk/lima-swing/src/main/java/org/chorem/lima/listener/ trunk/lima-swing/src/main/java/org/chorem/lima/table/ trunk/lima-swing/src/main/java/org/chorem/lima/tree/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/period/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/report/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/subledger/ Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/pom.xml trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -19,7 +19,9 @@ package org.chorem.lima.business; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.nuiton.topia.TopiaContext; @@ -36,5 +38,6 @@ public void blockFiscalPeriodRules(FiscalPeriod fiscalPeriod, TopiaContext transaction) throws LimaException; public void removeAccountRules(Account account, TopiaContext transaction) throws LimaException; public void removeEntryBookRules(EntryBook entryBook, TopiaContext topiaTransaction) throws LimaException; - + public void checkFinancialPeriodBlockedWithEntry(Entry entry) throws LimaException; + public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LimaException; } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -27,8 +27,10 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ejb.AccountServiceImpl; import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; @@ -137,6 +139,26 @@ } /** + * check if financial period of an entry is blocked + */ + @Override + public void checkFinancialPeriodBlockedWithEntry(Entry entry) throws LimaException { + if (entry.getFinancialTransaction().getFinancialPeriod().getLocked()){ + throw new LimaBusinessException("The financial period is blocked"); + } + } + + /** + * check if financial period of a financial transaction is blocked + */ + @Override + public void checkFinancialPeriodBlockedWithFinancialTransaction(FinancialTransaction financialTransaction) throws LimaException { + if (financialTransaction.getFinancialPeriod().getLocked()){ + throw new LimaBusinessException("The financial period is blocked"); + } + } + + /** * Generic code used to rollback a transaction. * * TODO : replace this by JTA Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/FranceAccountingRules.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -157,6 +157,7 @@ } } + /** * Generic code used to rollback a transaction. * Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -27,16 +27,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountingRules; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; import org.chorem.lima.business.FinancialTransactionService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.EntryBookDAO; import org.chorem.lima.entity.EntryDAO; import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionDAO; @@ -45,7 +44,6 @@ import org.nuiton.topia.TopiaException; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.framework.TopiaQuery; -import org.nuiton.topia.framework.TopiaQuery.Op; /** * Cette classe permet la création d'une transaction comptable dans l'application. @@ -63,6 +61,8 @@ LogFactory.getLog(FinancialTransactionServiceImpl.class); private TopiaContext rootContext; + + protected AccountingRules accountingRules; public FinancialTransactionServiceImpl() { LimaConfig config = LimaConfig.getInstance(); @@ -73,6 +73,7 @@ log.error("Can't init topia context", ex); } } + accountingRules = config.getAccountingRules(); } /** @@ -82,7 +83,9 @@ @Override public void createFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction); + TopiaContext topiaContext = null; try { // basic check done, make check in database @@ -216,6 +219,7 @@ entry.getEntryBook(); entry.getAccount(); entry.getFinancialTransaction(); + entry.getFinancialTransaction().getFinancialPeriod(); } } } @@ -233,7 +237,8 @@ @Override public void updateFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction); TopiaContext topiaTransaction = null; try { @@ -255,13 +260,15 @@ @Override public void removeFinancialTransaction(FinancialTransaction financialtransaction) throws LimaException { - // TODO EC-20100408 add some checks ? (balance, status, etc... ? ) - + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithFinancialTransaction(financialtransaction); + TopiaContext topiaTransaction = null; try { topiaTransaction = rootContext.beginTransaction(); FinancialTransactionDAO transactionDAO = LimaCallaoDAOHelper.getFinancialTransactionDAO(topiaTransaction); - transactionDAO.delete(financialtransaction); + FinancialTransaction financialTransaction2 = transactionDAO.findByTopiaId(financialtransaction.getTopiaId()); + transactionDAO.delete(financialTransaction2); // commit topiaTransaction.commitTransaction(); } @@ -278,6 +285,10 @@ @Override public void removeEntry(Entry entry) throws LimaException { + + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithEntry(entry); + TopiaContext topiaContext = null; try { // basic check done, make check in database @@ -299,6 +310,10 @@ @Override public void updateEntry(Entry entry) throws LimaException { + + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithEntry(entry); + TopiaContext topiaContext = null; try { // TODO move it into JTA @@ -325,50 +340,10 @@ */ @Override - public void createEntry(Entry entry /*String description, String amount, boolean debit, - String lettering, String detail, Transaction transaction, - Account account*/) throws LimaException { - /*String result = isCorrectEntry(transaction, account); - if (result.equals(ServiceHelper.RESPOND_SUCCESS)) { - result = ServiceHelper.RESPOND_ERROR; - try { - // Acces BDD - TopiaContext topiaContext = rootContext.beginTransaction(); - // Chargement du DAO - EntryDAO entryDAO = LimaCallaoDAOHelper - .getEntryDAO(topiaContext); - // Creation de l'entrée comptable - Entry newEntry = entryDAO.create(); - newEntry.setDescription(description); - // On formate le nombre - newEntry.setAmount(numberUtil.format(amount)); - newEntry.setDebit(debit); - newEntry.setLettering(lettering); - newEntry.setDetail(detail); - newEntry.setTransaction(transaction); - newEntry.setAccount(account); - // Création BDD - topiaContext.commitTransaction(); - // Fermeture BDD - topiaContext.closeContext(); - if (log.isInfoEnabled()) { - log.info("Ajout avec succes de l'entrée comptable."); - } - // Création du log - Date logDate = new Date(); - logServiceImpl.addLog(logDate, transaction.getTransDate(), - ServiceHelper.LOG_ADD, transaction.getVoucherRef(), - transaction.getDescription(), detail, amount, debit, - lettering); - - // Il renvoie soit l'identifiant topiaId ou SUCCESS. - result = newEntry.getTopiaId(); - //result = ServiceHelper.RESPOND_SUCCESS; - } catch (TopiaException e) { - log.error(e); - } - } - return result;*/ + public void createEntry(Entry entry) throws LimaException { + + //check if the financial period is blocked + accountingRules.checkFinancialPeriodBlockedWithEntry(entry); TopiaContext topiaContext = null; try { Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Modified: trunk/lima-swing/pom.xml =================================================================== --- trunk/lima-swing/pom.xml 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/pom.xml 2010-05-06 09:57:19 UTC (rev 2884) @@ -114,7 +114,6 @@ </includes> </resource> </resources> - <plugins> <plugin> <groupId>org.nuiton.jaxx</groupId> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -38,12 +38,8 @@ import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.entrybook.EntryBookView; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; -import org.chorem.lima.ui.report.BalanceView; -import org.chorem.lima.ui.report.BilanView; -import org.chorem.lima.ui.report.ReportsView; -import org.chorem.lima.ui.report.ResultView; +import org.chorem.lima.ui.transaction.FinancialTransactionView; import org.chorem.lima.ui.transaction.LetteringView; -import org.chorem.lima.ui.transaction.TransactionView; import org.chorem.lima.util.ErrorHelper; /** @@ -278,14 +274,14 @@ public void showBilanView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - BilanView bilanView = new BilanView(mainView); - mainView.showTab(_("lima.tab.bilan"), bilanView); + // BilanView bilanView = new BilanView(mainView); + // mainView.showTab(_("lima.tab.bilan"), bilanView); } public void showBalanceView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - BalanceView balanceView = new BalanceView(mainView); - mainView.showTab(_("lima.tab.balance"), balanceView); + // BalanceView balanceView = new BalanceView(mainView); + // mainView.showTab(_("lima.tab.balance"), balanceView); } public void showFiscalPeriodView(JAXXContext rootContext) { @@ -331,7 +327,7 @@ public void showTransactionView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - TransactionView transactionView = new TransactionView(mainView); + FinancialTransactionView transactionView = new FinancialTransactionView(mainView); mainView.showTab(_("lima.tab.transaction"), transactionView); } @@ -350,14 +346,14 @@ public void showReportsView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - ReportsView reportsView = new ReportsView(mainView); - mainView.showTab(_("lima.tab.reports"), reportsView); + //ReportsView reportsView = new ReportsView(mainView); + // mainView.showTab(_("lima.tab.reports"), reportsView); } public void showResultView(JAXXContext rootContext) { MainView mainView = getUI(rootContext); - ResultView resultView = new ResultView(mainView); - mainView.showTab(_("lima.tab.result"), resultView); + //ResultView resultView = new ResultView(mainView); + // mainView.showTab(_("lima.tab.result"), resultView); } /** Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2010-05-06 09:57:19 UTC (rev 2884) @@ -32,7 +32,7 @@ <org.jdesktop.swingx.JXTreeTable id="accountsTreeTable" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" treeTableModel="{new org.chorem.lima.ui.account.model.AccountTreeTableModel()}" - highlighters='{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping()}' /> + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" /> <javax.swing.ListSelectionModel javaBean="getAccountsTreeTable().getSelectionModel()" onValueChanged="setSelectedRow(accountsTreeTable.getSelectedRow() != -1)"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx 2010-05-06 09:57:19 UTC (rev 2884) @@ -31,7 +31,7 @@ <JScrollPane> <org.jdesktop.swingx.JXTable id="entryBooksTable" rowHeight="24" model="{new org.chorem.lima.ui.entrybook.model.EntryBookTableModel()}" - highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" columnControlVisible="true"/> <javax.swing.ListSelectionModel javaBean="getEntryBooksTable().getSelectionModel()" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2010-05-06 09:57:19 UTC (rev 2884) @@ -40,7 +40,7 @@ <JScrollPane> <org.jdesktop.swingx.JXTable id="fiscalPeriodTable" model="{new org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel()}" - highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping()}" + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" rowHeight="24" selectionMode="{ListSelectionModel.SINGLE_INTERVAL_SELECTION}" columnControlVisible="true" /> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTableModel.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -24,15 +24,12 @@ import java.util.Date; import java.util.List; -import javax.swing.JLabel; import javax.swing.table.AbstractTableModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; @@ -128,13 +125,11 @@ Object result = "n/a"; - // a refaire, c'est pas optimisé List<FiscalPeriod> periods; try { periods = fiscalPeriodService.getAllFiscalPeriods(); FiscalPeriod fiscalPeriod = periods.get(rowIndex); - String[] monthName = {_("lima.date.january"), _("lima.date.february"), _("lima.date.march"), _("lima.date.april"), _("lima.date.may"), _("lima.date.june"), _("lima.date.july"), _("lima.date.august"), Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionView.jaxx 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionView.jaxx 2010-05-06 09:57:19 UTC (rev 2884) @@ -81,8 +81,7 @@ <org.chorem.lima.ui.transaction.table.FinancialTransactionTable id="financialTransactionTable" sortable="false" rowHeight="22" constructorParams="getHandler()" model="{getFinancialTransactionTableModel()}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping(Color.WHITE,new Color(250,250,250))}" /> + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> <javax.swing.ListSelectionModel javaBean="getFinancialTransactionTable().getSelectionModel()" onValueChanged="setSelectedRow(financialTransactionTable.getSelectedRow() != -1)"/> </JScrollPane> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/FinancialTransactionViewHandler.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -46,14 +46,14 @@ private static final Log log = LogFactory.getLog(FinancialTransactionViewHandler.class); - protected TransactionView view; + protected FinancialTransactionView view; - protected FinancialTransactionViewHandler(TransactionView view) { + protected FinancialTransactionViewHandler(FinancialTransactionView view) { this.view = view; } //add a new transaction - protected void addFinancialTransaction() { + public void addFinancialTransaction() { FinancialTransactionTable table = (FinancialTransactionTable)view.getFinancialTransactionTable(); FinancialTransactionTableModel model = Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTable.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -18,16 +18,24 @@ package org.chorem.lima.ui.transaction.table; +import java.awt.Color; +import java.awt.Component; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.Date; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.ui.transaction.FinancialTransactionHelper; import org.chorem.lima.ui.transaction.FinancialTransactionViewHandler; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.ColorHighlighter; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; /** @@ -45,40 +53,26 @@ private static final Log log = LogFactory.getLog(FinancialTransactionTable.class); protected FinancialTransactionViewHandler handler; - + private ColorHighlighter colorEmptyLine; - private ColorHighlighter colorTransaction; + private Highlighter colorTransaction; private ColorHighlighter colorBalance; /** */ - public FinancialTransactionTable(FinancialTransactionViewHandler handler/*, - TransactionTableModel model, + public FinancialTransactionTable(FinancialTransactionViewHandler handler/* TransactionSortedTableColumnModel columnModel*/) { //super(model, columnModel); this.handler = handler; - /* * New Table Header */ - // header renderer getTableHeader().setDefaultRenderer(TransactionHeaderRenderer.getInstance()); + //header renderer getTableHeader().setDefaultRenderer(TransactionHeaderRenderer.getInstance()); //getTableHeader().addMouseListener(new TransactionHeaderListener(this)); - /* - * Mod : il est possible d'activer cette option. - * Lorsque l'utilisateur clique sur une ligne du tableau, on ajoute - * automatiquement une nouvelle ligne (une entrée comptable) - */ - //addMouseListener(getEmptyLineSelectionListener()); - - /* - * Mod : il est possible d'activer cette option. - * Lorsque l'utilisateur appuie sur une touche "insert" ou autres, le - * programme insère une ligne comptable. - */ addKeyListener(this); // cell rendering @@ -110,20 +104,18 @@ setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); //Get new account editor setDefaultEditor(Account.class, new AccountTableCellEditor()); - - // Color transactions - // addColorTransaction(); - // addColorNonBalancedTransaction(); + + //highlight financial financial transactions + addColorTransaction(); + // highlight unbalanced financial transactions + addColorNonBalancedTransaction(); } - /** - * - */ public void addColorEmptyLine() { // Renvoie une couleur jaune pour chaque nouvelle ligne créée - /*removeColorEmptyLine(); - if (TransactionFlattenTableModel.isFlattenModel(getModel())) { + //removeColorEmptyLine(); + /* if (TransactionFlattenTableModel.isFlattenModel(getModel())) { final int posNext = ((TransactionFlattenTableModel) getModel()).getEmptyLinePosition(); HighlightPredicate predicate = new HighlightPredicate() { @@ -149,28 +141,33 @@ /** * Cette méthode permet de colorer toutes les transactions dans le tableau * afin de bien distinguer les transactions et entrées comptables. + * On récupère la première cellule, on vérifie que c'est une date */ - /* protected void addColorTransaction() { - if (colorTransaction != null) { - removeHighlighter(colorTransaction); - } - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - return getModel().getElementAt(adapter.row) instanceof Transaction; - } - }; - colorTransaction = new ColorHighlighter(predicate, new Color(222, 222, - 222), null, null, null); + protected void addColorTransaction() { + if (colorTransaction != null) { + removeHighlighter(colorTransaction); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + return adapter.getValueAt(adapter.row, 0) instanceof Date; + } + }; + colorTransaction = + new ColorHighlighter(predicate, new Color(222,222,222), null); addHighlighter(colorTransaction); - }*/ + } + + /** - * Permet de surligner une transaction dans le tableau lorsque cette dernière - * n'est pas équilibrée. + * Permet de surligner une transaction dans le tableau lorsque + * cette dernière n'est pas équilibrée. + * On récupère la dernière cellule de la ligne + * et on vérifie si la valeur est différente de 0 */ -/* protected void addColorNonBalancedTransaction() { + protected void addColorNonBalancedTransaction() { if (colorBalance != null) { removeHighlighter(colorBalance); } @@ -179,32 +176,31 @@ public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { boolean isHighlighted = false; - Object value = getModel().getElementAt(adapter.row); - if (value instanceof Transaction) { - Transaction currentTransaction = (Transaction) value; - if (!TransactionHelper.isBalanced(currentTransaction)) { + Object value = adapter.getValueAt(adapter.row, 8); + if (value instanceof Double) { + Double currentBalance = (Double) value; + if (currentBalance != 0) { isHighlighted = true; } } return isHighlighted; } }; - colorTransaction = new ColorHighlighter(predicate, new Color(255, 198, - 209), null, null, null); + colorTransaction = + new ColorHighlighter(predicate, new Color(255, 198, 209), null); addHighlighter(colorTransaction); - }*/ - - /* @Override - public TransactionTableModel getModel() { - return (TransactionTableModel) this.dataModel; } - @Override + /* @Override + public FinancialTransactionTableModel getModel() { + return (FinancialTransactionTableModel) this.dataModel; + }*/ + + /* @Override public TransactionSortedTableColumnModel getColumnModel() { return (TransactionSortedTableColumnModel) this.columnModel; - } + }*/ -*/ /* public EmptyLineSelectionListener getEmptyLineSelectionListener() { if (emptyLineSelectionListener == null) { @@ -213,52 +209,52 @@ return emptyLineSelectionListener; } */ + /** + * for each action combination key are think + * for extend keyboard and laptop keyboard + */ @Override public void keyPressed(KeyEvent e) { - // VK_DELETE suppression de la transaction en cours + // delete selected row with the key : delete or ctrl clear // ou de l'entree - if (e.getKeyCode() == KeyEvent.VK_DELETE) { - // handler.deleteSelectedRow(); + if ((e.getKeyCode() == KeyEvent.VK_DELETE ) + || (e.getKeyCode() == KeyEvent.VK_CLEAR + && e.getModifiers() == KeyEvent.CTRL_MASK)){ + handler.deleteSelectedRow(); } - // Touche : insert ou ctrl+I - // Ajoute une transaction - if ((e.getKeyCode() == KeyEvent.VK_INSERT) - || (e.getKeyCode() == KeyEvent.VK_I && e.getModifiers() == KeyEvent.CTRL_MASK)) { - - // TODO EC 20100408 String result = table.getModel().addEmptyTransaction(); + // add entry with the key combination : insert or ctrl + enter + if ((e.getKeyCode() == KeyEvent.VK_INSERT ) + || (e.getKeyCode() == KeyEvent.VK_ENTER + && e.getModifiers() == KeyEvent.CTRL_MASK)) { + handler.addEmptyEntry(); } - - // Touche '+' OU 'ctrl+Entr' - // Ajoute une entrée comptable ou transaction - if (e.getKeyCode() == KeyEvent.VK_PLUS - || (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == KeyEvent.CTRL_MASK)) { - /*int max_y = table.getRowCount(); - addLine(table); - table.setColumnSelectionInterval(0, 0); - table.setRowSelectionInterval(max_y, max_y);*/ + + // add financial transaction with the key combination : ctrl + tab + if (e.getKeyCode() == KeyEvent.VK_TAB + && e.getModifiers() == KeyEvent.CTRL_MASK) { + handler.addFinancialTransaction(); } /** * Touche tab - * Ajoute une entrée comptable ou transaction seulement si tab est sur + * Ajoute une entrée comptable si tab est sur * la dernière cellule. */ if (e.getKeyChar() == KeyEvent.VK_TAB) { // Vérifie si la cellule sélectionnée est la dernière - /*int x = table.getSelectedColumn(); - int y = table.getSelectedRow(); - int max_x = table.getColumnCount() - 1; - int max_y = table.getRowCount() - 1; + + int x = this.getSelectedColumn(); + int y = this.getSelectedRow(); + int max_x = this.getColumnCount() - 1; + int max_y = this.getRowCount() - 1; if (x == max_x && y == max_y) { - boolean result = addLine(table); + handler.addEmptyEntry(); // positionne la sélection sur la nouvelle ligne créée - if (result) { - table.setColumnSelectionInterval(0, 0); - table.setRowSelectionInterval(max_y + 1, max_y + 1); - } - }*/ + this.setColumnSelectionInterval(0, 0); + this.setRowSelectionInterval(max_y + 1, max_y + 1); + } } } @@ -278,100 +274,4 @@ public void keyReleased(KeyEvent e) { } - - /** - * Permet d'ajouter une nouvelle ligne : transaction ou entrée - * @param table la table - * @return - */ - /*private boolean addLine(TransactionJXTable table) { - if (TransactionFlattenTableModel.isFlattenModel(table.getModel())) { - // Vérifie si le tableau est vide, alors ajout d'une transaction - if (table.getRowCount() == 0) { - String result = table.getModel().addEmptyTransaction(); - ErrorMessage.showMessage(result); - return true; - } - TransactionFlattenTableModel flattenModel = (TransactionFlattenTableModel) table - .getModel(); - int selectedRow = 0; - // Vérifie si une ligne est sélectionnée ou non - if (table.getSelectionModel().isSelectionEmpty()) { - // Not line selected - selectedRow = table.getRowCount() - 1; - } else { - // Line selected - selectedRow = table.getSelectedRow(); - } - // Récupère la position de la transaction rattachée - int parentIndex = flattenModel.getParentIndex(selectedRow); - - // Is transaction editable ? - Object o = flattenModel.getElementAt(parentIndex); - if (DTOHelper.isTransaction(o)) { - // Transaction n'est pas éditable - if (!ServiceHelper.isEditable((TransactionDTO) o)) { - return false; - } - } else { - //Entry n'est pas éditable - if (!ServiceHelper.isEditable((EntryDTO) o)) { - return false; - } - } - - // Vérifie si la transaction est équilibrée ou non (et qu'elle posséde des entrées) - TransactionDTO transaction = (TransactionDTO) flattenModel - .getElementAt(parentIndex); - if (DTOHelper.isBalanced(transaction) - && !transaction.getEntries().isEmpty()) { - String result = table.getModel().addEmptyTransaction(); - ErrorMessage.showMessage(result); - return true; - } - - // Vérifie si une ligne est sélectionnée ou non - if (table.getSelectionModel().isSelectionEmpty()) { - // Not line selected - // Click in not current transaction - if (flattenModel.getCurrentParentIndex() != parentIndex) { - int posNext = selectedRow + 1; - flattenModel.createEmptyLine(); - flattenModel.addEmptyLine(posNext); - // To end - flattenModel.setCurrentParentIndex(parentIndex); - } - - // New Line Color - table.addColorEmptyLine(); - } else { - // Line selected - // Click in not current transaction - if (flattenModel.getCurrentParentIndex() != parentIndex) { - int posNext = flattenModel - .emptyLineNextPosition(selectedRow); - - // Once traitement for transaction - if (flattenModel.isEmptyLineEmpty()) { - flattenModel.createEmptyLine(); - } else { - flattenModel.removeEmptyLine(); - selectedRow = table.getSelectedRow(); - parentIndex = flattenModel.getParentIndex(selectedRow); - posNext = flattenModel - .emptyLineNextPosition(selectedRow); - flattenModel.createEmptyLine(); - } - flattenModel.addEmptyLine(posNext); - // To end - flattenModel.setCurrentParentIndex(parentIndex); - } - - // New Line Color - table.addColorEmptyLine(); - } - return true; - } - return false; - }*/ } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-05-04 13:44:56 UTC (rev 2883) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/table/FinancialTransactionTableModel.java 2010-05-06 09:57:19 UTC (rev 2884) @@ -84,8 +84,15 @@ /** FinancialPeriod service. */ protected final FinancialPeriodService financialPeriodService; + /** selected financial period */ protected FinancialPeriod selectedFinancialPeriod; + /** data cache */ + protected List<Object> cacheDataList; + + /** collection + + /** * Model constructor. * @@ -113,11 +120,9 @@ List<Object> results = new ArrayList<Object>(); try { - List<FinancialTransaction> financialtransactions = transactionService.getAllFinancialTransactionsForFinancialPeriod( selectedFinancialPeriod); - for (FinancialTransaction financialtransaction : financialtransactions) { results.add(financialtransaction); results.addAll(financialtransaction.getEntry()); @@ -220,8 +225,8 @@ // just prevent too much result if (selectedFinancialPeriod != null) { - List<Object> datas = getDataList(); - result = datas.size(); + cacheDataList = getDataList(); + result = cacheDataList.size(); } else { if (log.isDebugEnabled()) { @@ -239,8 +244,7 @@ // just prevent too much result if (selectedFinancialPeriod != null) { // TODO EC-20100407 remove this ugly code - List<Object> datas = getDataList(); - result = datas.get(row); + result = cacheDataList.get(row); if (result instanceof FinancialTransaction) { FinancialTransaction currentRow = (FinancialTransaction)result; @@ -342,8 +346,7 @@ @Override public boolean isCellEditable(int rowIndex, int columnIndex) { boolean editableCell=false; - List<Object> datas = getDataList(); - Object currentRow = datas.get(rowIndex); + Object currentRow = cacheDataList.get(rowIndex); // cells editable for the entry row, all cells exclude the date if ((currentRow instanceof Entry) && !(columnIndex==0)) { editableCell=true; @@ -377,8 +380,8 @@ // create it transactionService.createFinancialTransaction(financialTransaction); int row = getDataList().indexOf(financialTransaction); - //FIXME Invalid range - fireTableRowsInserted(row, row); + fireTableRowsInserted(row, row); + //fireTableDataChanged(); } else { throw new LimaBusinessException("No financial period selected"); @@ -392,8 +395,7 @@ */ public void addEmptyEntry(Object value, int row) throws LimaException { FinancialTransaction currentTransaction = null; - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); + Object currentRow = cacheDataList.get(row); Entry entry = new EntryImpl(); //check if current row is a transaction or an entry if (currentRow instanceof FinancialTransaction) { @@ -407,7 +409,7 @@ //create it entry.setFinancialTransaction(currentTransaction); transactionService.createEntry(entry); - fireTableRowsUpdated(row, row); + fireTableDataChanged(); } @@ -420,8 +422,7 @@ // just prevent too much result if (selectedFinancialPeriod != null) { // TODO EC-20100407 remove this ugly code - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); + Object currentRow = cacheDataList.get(row); if (currentRow instanceof FinancialTransaction) { FinancialTransaction currentFinancialTransaction = (FinancialTransaction)currentRow; @@ -516,13 +517,12 @@ log.debug("Can't update entry", e); } } - //update the financial transaction in entire - int financialTransactionRow = - getDataList().indexOf(((Entry) currentRow). - getFinancialTransaction()); - fireTableRowsUpdated(financialTransactionRow, - financialTransactionRow); } + //update the financial transaction in entire + int financialTransactionRow = + getDataList().indexOf(((Entry) currentRow). + getFinancialTransaction()); + fireTableRowsUpdated(financialTransactionRow, getRowCount()-1); } else { if (log.isDebugEnabled()) { @@ -533,8 +533,7 @@ public Object getElementAt(int row){ - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); + Object currentRow = cacheDataList.get(row); return currentRow; } @@ -547,8 +546,7 @@ * @throws LimaException */ public void removeObject(Object object, int row) throws LimaException { - List<Object> datas = getDataList(); - Object currentRow = datas.get(row); + Object currentRow = cacheDataList.get(row); if (currentRow instanceof FinancialTransaction) { FinancialTransaction currentTransaction = (FinancialTransaction)currentRow; @@ -558,6 +556,7 @@ Entry currentEntry = (Entry)currentRow; transactionService.removeEntry(currentEntry); } - fireTableRowsDeleted(row, row); + fireTableRowsDeleted(row, getRowCount()); } + }