r2931 - in trunk: lima-business/src/main/java/org/chorem/lima/business/ejb lima-business/src/main/java/org/chorem/lima/business/utils lima-callao/src/main/xmi lima-swing/src/main/java/org/chorem/lima/ui/account lima-swing/src/main/java/org/chorem/lima/ui/account/model lima-swing/src/main/java/org/chorem/lima/ui/combobox lima-swing/src/main/java/org/chorem/lima/ui/entrybook lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports lima-swing/src/main/java/org/chorem/lima/ui/financialtransa
Author: jpepin Date: 2010-06-03 18:45:18 +0200 (Thu, 03 Jun 2010) New Revision: 2931 Url: http://chorem.org/repositories/revision/lima/2931 Log: Nettoyage classes dans l'UI. Affichage des entr?\195?\169es dans l'?\195?\169dition de journal regroup?\195?\169 par transaction. Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookTypeListModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTypeListModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/ClosurePeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/ Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java trunk/lima-callao/src/main/xmi/accounting.zargo trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.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/FiscalPeriodViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerTable.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/ReportServiceImpl.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -20,6 +20,8 @@ package org.chorem.lima.business.ejb; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; import javax.ejb.Stateless; @@ -33,11 +35,16 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.business.ReportService; import org.chorem.lima.business.ReportServiceLocal; +import org.chorem.lima.business.utils.EntryComparator; +import org.chorem.lima.business.utils.EntryFinancialTransactionComparator; +import org.chorem.lima.business.utils.EntryFinancialTransactionDateComparator; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountDAO; +import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryDAO; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.LimaCallaoDAOHelper; import org.nuiton.topia.TopiaContext; @@ -316,7 +323,12 @@ .addParam("endDate", endDate); //IMPORTANT : LOADING ENTRIES AND IS COLUMN FOR NO LAZY EXCEPTION query.addLoad(Entry.ACCOUNT, Entry.FINANCIAL_TRANSACTION); - reportsDatas.setListEntry(entryDAO.findAllByQuery(query)); + List<Entry> entries = entryDAO.findAllByQuery(query); + //TODO 20100603 PEPIN imbriqué les deux conditions de comparator + // tri sur date, tri sur topiaid + Collections.sort(entries, new EntryFinancialTransactionDateComparator()); + Collections.sort(entries, new EntryFinancialTransactionComparator()); + reportsDatas.setListEntry(entries); query.setSelect("E."+Entry.DEBIT, "SUM(E."+Entry.AMOUNT+")"); query.addGroup("E."+Entry.DEBIT); Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionComparator.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,32 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.business.utils; + +import java.util.Comparator; + +import org.chorem.lima.entity.Entry; + +public class EntryFinancialTransactionComparator implements Comparator<Entry>{ + + @Override + public int compare(Entry o1, Entry o2) { + return o1.getFinancialTransaction().getTopiaId().compareTo(o2.getFinancialTransaction().getTopiaId()); + } + +} Added: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java (rev 0) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryFinancialTransactionDateComparator.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,33 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.business.utils; + +import java.util.Comparator; + +import org.chorem.lima.entity.Entry; + +public class EntryFinancialTransactionDateComparator implements Comparator<Entry>{ + + @Override + public int compare(Entry o1, Entry o2) { + return o1.getFinancialTransaction().getTransactionDate() + .compareTo(o2.getFinancialTransaction().getTransactionDate()); + } + +} Modified: trunk/lima-callao/src/main/xmi/accounting.zargo =================================================================== (Binary files differ) Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java (from rev 2922, trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,271 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.account; + +import static org.nuiton.i18n.I18n._; + +import java.util.List; + +import javax.swing.tree.TreePath; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.AccountImpl; +import org.chorem.lima.service.LimaServiceFactory; +import org.jdesktop.swingx.treetable.AbstractTreeTableModel; + +/** + * Tree table model for account edition. + * + * @author ore + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class AccountTreeTableModel extends AbstractTreeTableModel { + + /** log. */ + private static final Log log = LogFactory.getLog(AccountViewHandler.class); + + /** Account service. */ + protected final AccountService accountService; + + /** + * Model constructor. Init account service used here. + */ + public AccountTreeTableModel() { + // root + super(new AccountImpl()); + // Gets factory service + accountService = LimaServiceFactory.getInstance().getAccountService(); + } + + /** + * @deprecated can't be used + */ + public Account getData() { + return (Account) root; + } + + @Override + public int getColumnCount() { + return 2; + } + + @Override + public String getColumnName(int column) { + String res = null; + switch (column) { + case 0: + res = _("lima.account.number"); + break; + case 1: + res = _("lima.account.label"); + break; + } + return res; + } + + @Override + public int getChildCount(Object node) { + int result = 0; + if (node instanceof Account) { + if (node == getRoot()) { + try { + result = accountService.getChildrenAccounts(null).size(); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + else { + Account parentAccount = (Account) node; + try { + List<Account> subaccounts = + accountService.getChildrenAccounts(parentAccount); + result = subaccounts.size(); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + } + return result; + } + + @Override + public Object getChild(Object parent, int index) { + Object result = null; + if (parent == getRoot()) { + try { + List<Account> allAccounts = + accountService.getChildrenAccounts(null); + result = allAccounts.get(index); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + else { + Account parentAccount = (Account) parent; + + // FIXME sub account is a collection ? + try { + List<Account> subaccounts = + accountService.getChildrenAccounts(parentAccount); + result = subaccounts.get(index); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + return result; + } + + @Override + public int getIndexOfChild(Object parent, Object child) { + int result = 0; + Account parentAccount = (Account) parent; + Account childAccount = (Account) child; + + if (parent == getRoot()) { + try { + List<Account> allAccounts = + accountService.getChildrenAccounts(null); + result = allAccounts.indexOf(child); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + else { + // FIXME sub account is a collection ? + try { + List<Account> subaccounts = + accountService.getChildrenAccounts(parentAccount); + result = subaccounts.indexOf(childAccount); + } catch (LimaException e) { + //FIXME + e.printStackTrace(); + } + } + return result; + } + + @Override + public Object getValueAt(Object node, int column) { + Object result = "n/a"; + if (node instanceof Account) { + Account account = (Account) node; + switch (column) { + case 0: + result = account.getAccountNumber(); + break; + case 1: + result = account.getLabel(); + break; + } + } + return result; + } + + @Override + public boolean isCellEditable(Object node, int column) { + return false; + } + + @Override + public boolean isLeaf(Object node) { + return getChildCount(node) == 0; + } + + /** + * Add account (path can be null). + * + * @param path + * @param account + * @throws LimaException + */ + public void addAccount(TreePath path, Account account) throws LimaException { + // Calling account service + Account parentAccount = (Account)path.getLastPathComponent(); + if (parentAccount == getRoot()) { + parentAccount = null; + } + + accountService.createAccount(parentAccount, account); + int index = getIndexOfChild(path.getLastPathComponent(), account); + modelSupport.fireTreeStructureChanged(path); + modelSupport.fireChildAdded(path, index, account); + } + + /** + * Add account (path can be null). + * + * @param path + * @param account + * @throws LimaException + */ + public void addSubLedger(TreePath path, Account account) throws LimaException { + // Calling account service + Account parentAccount = (Account)path.getLastPathComponent(); + if (parentAccount == getRoot()) { + parentAccount = null; + } + accountService.createSubLedger(parentAccount, account); + int index = getIndexOfChild(path.getLastPathComponent(), account); + modelSupport.fireTreeStructureChanged(path); + modelSupport.fireChildAdded(path, index, account); + } + + /** + * Update account. + * + * @param path + * @param account + * @throws LimaException + */ + public void updateAccount(TreePath path, Account account) throws LimaException { + // Calling account service + accountService.updateAccount(account); + //refresh the tree of the node + modelSupport.fireTreeStructureChanged(path.getParentPath()); + } + + /** + * Remove account. + * + * @param path + * @param account + * @throws LimaException + */ + public void removeAccount(TreePath path, Account account) throws LimaException { + // Calling account service + int index = getIndexOfChild( + path.getParentPath().getLastPathComponent(), account); + accountService.removeAccount(account); + modelSupport.fireChildRemoved(path.getParentPath(), index, account); + } + +} 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-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -31,7 +31,7 @@ <JScrollPane> <org.jdesktop.swingx.JXTreeTable id="accountsTreeTable" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - treeTableModel="{new org.chorem.lima.ui.account.model.AccountTreeTableModel()}" + treeTableModel="{new org.chorem.lima.ui.account.AccountTreeTableModel()}" highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" /> <javax.swing.ListSelectionModel javaBean="getAccountsTreeTable().getSelectionModel()" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -29,7 +29,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; -import org.chorem.lima.ui.account.model.AccountTreeTableModel; import org.chorem.lima.ui.account.AccountForm; import org.chorem.lima.ui.account.AccountView; import org.chorem.lima.ui.account.SubLedgerForm; Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTreeTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -1,272 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.account.model; - -import static org.nuiton.i18n.I18n._; - -import java.util.List; - -import javax.swing.tree.TreePath; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.AccountService; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountImpl; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.ui.account.AccountViewHandler; -import org.jdesktop.swingx.treetable.AbstractTreeTableModel; - -/** - * Tree table model for account edition. - * - * @author ore - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class AccountTreeTableModel extends AbstractTreeTableModel { - - /** log. */ - private static final Log log = LogFactory.getLog(AccountViewHandler.class); - - /** Account service. */ - protected final AccountService accountService; - - /** - * Model constructor. Init account service used here. - */ - public AccountTreeTableModel() { - // root - super(new AccountImpl()); - // Gets factory service - accountService = LimaServiceFactory.getInstance().getAccountService(); - } - - /** - * @deprecated can't be used - */ - public Account getData() { - return (Account) root; - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public String getColumnName(int column) { - String res = null; - switch (column) { - case 0: - res = _("lima.account.number"); - break; - case 1: - res = _("lima.account.label"); - break; - } - return res; - } - - @Override - public int getChildCount(Object node) { - int result = 0; - if (node instanceof Account) { - if (node == getRoot()) { - try { - result = accountService.getChildrenAccounts(null).size(); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - else { - Account parentAccount = (Account) node; - try { - List<Account> subaccounts = - accountService.getChildrenAccounts(parentAccount); - result = subaccounts.size(); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - } - return result; - } - - @Override - public Object getChild(Object parent, int index) { - Object result = null; - if (parent == getRoot()) { - try { - List<Account> allAccounts = - accountService.getChildrenAccounts(null); - result = allAccounts.get(index); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - else { - Account parentAccount = (Account) parent; - - // FIXME sub account is a collection ? - try { - List<Account> subaccounts = - accountService.getChildrenAccounts(parentAccount); - result = subaccounts.get(index); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - return result; - } - - @Override - public int getIndexOfChild(Object parent, Object child) { - int result = 0; - Account parentAccount = (Account) parent; - Account childAccount = (Account) child; - - if (parent == getRoot()) { - try { - List<Account> allAccounts = - accountService.getChildrenAccounts(null); - result = allAccounts.indexOf(child); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - else { - // FIXME sub account is a collection ? - try { - List<Account> subaccounts = - accountService.getChildrenAccounts(parentAccount); - result = subaccounts.indexOf(childAccount); - } catch (LimaException e) { - //FIXME - e.printStackTrace(); - } - } - return result; - } - - @Override - public Object getValueAt(Object node, int column) { - Object result = "n/a"; - if (node instanceof Account) { - Account account = (Account) node; - switch (column) { - case 0: - result = account.getAccountNumber(); - break; - case 1: - result = account.getLabel(); - break; - } - } - return result; - } - - @Override - public boolean isCellEditable(Object node, int column) { - return false; - } - - @Override - public boolean isLeaf(Object node) { - return getChildCount(node) == 0; - } - - /** - * Add account (path can be null). - * - * @param path - * @param account - * @throws LimaException - */ - public void addAccount(TreePath path, Account account) throws LimaException { - // Calling account service - Account parentAccount = (Account)path.getLastPathComponent(); - if (parentAccount == getRoot()) { - parentAccount = null; - } - - accountService.createAccount(parentAccount, account); - int index = getIndexOfChild(path.getLastPathComponent(), account); - modelSupport.fireTreeStructureChanged(path); - modelSupport.fireChildAdded(path, index, account); - } - - /** - * Add account (path can be null). - * - * @param path - * @param account - * @throws LimaException - */ - public void addSubLedger(TreePath path, Account account) throws LimaException { - // Calling account service - Account parentAccount = (Account)path.getLastPathComponent(); - if (parentAccount == getRoot()) { - parentAccount = null; - } - accountService.createSubLedger(parentAccount, account); - int index = getIndexOfChild(path.getLastPathComponent(), account); - modelSupport.fireTreeStructureChanged(path); - modelSupport.fireChildAdded(path, index, account); - } - - /** - * Update account. - * - * @param path - * @param account - * @throws LimaException - */ - public void updateAccount(TreePath path, Account account) throws LimaException { - // Calling account service - accountService.updateAccount(account); - //refresh the tree of the node - modelSupport.fireTreeStructureChanged(path.getParentPath()); - } - - /** - * Remove account. - * - * @param path - * @param account - * @throws LimaException - */ - public void removeAccount(TreePath path, Account account) throws LimaException { - // Calling account service - int index = getIndexOfChild( - path.getParentPath().getLastPathComponent(), account); - accountService.removeAccount(account); - modelSupport.fireChildRemoved(path.getParentPath(), index, account); - } - -} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTypeListModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTypeListModel.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/model/AccountTypeListModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -1,81 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.account.model; - -import static org.nuiton.i18n.I18n._; - -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; - -/** - * Combo box model with accounts types. - * (actif, passif, produit, charge). - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class AccountTypeListModel extends AbstractListModel implements ComboBoxModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = -6817328905036446359L; - - protected Object selectedObject; - - /** Data. TODO put string in another place, don't use hard coded string. */ - protected Object[] data = new Object[]{ _("lima.account.type1"), _("lima.account.type2"), _("lima.account.type3"), _("lima.account.type4")}; - - public AccountTypeListModel() { - super(); - } - - /* - * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object) - */ - @Override - public void setSelectedItem(Object anItem) { - selectedObject = anItem; - } - - /* - * @see javax.swing.ComboBoxModel#getSelectedItem() - */ - @Override - public Object getSelectedItem() { - return selectedObject; - } - - /* - * @see javax.swing.ListModel#getSize() - */ - @Override - public int getSize() { - return data.length; - } - - /* - * @see javax.swing.ListModel#getElementAt(int) - */ - @Override - public Object getElementAt(int index) { - return data[index]; - } -} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookTypeListModel.java (from rev 2920, trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTypeListModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookTypeListModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/EntryBookTypeListModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,73 @@ +package org.chorem.lima.ui.combobox; + + +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +import static org.nuiton.i18n.I18n._; +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxModel; + +/** + * Combo box model with entrybook types. + * (achats, ventes, trésorerie, général, situation). + * + */ +public class EntryBookTypeListModel extends AbstractListModel implements ComboBoxModel { + + protected Object selectedObject; + + /** Data. TODO put string in another place, don't use hard coded string. */ + protected Object[] data = new Object[]{ _("lima.entrybook.type1"), _("lima.entrybook.type2"), _("lima.entrybook.type3"), _("lima.entrybook.type4"), _("lima.entrybook.type5")}; + + public EntryBookTypeListModel() { + super(); + } + + /* + * @see javax.swing.ComboBoxModel#setSelectedItem(java.lang.Object) + */ + @Override + public void setSelectedItem(Object anItem) { + selectedObject = anItem; + } + + /* + * @see javax.swing.ComboBoxModel#getSelectedItem() + */ + @Override + public Object getSelectedItem() { + return selectedObject; + } + + /* + * @see javax.swing.ListModel#getSize() + */ + @Override + public int getSize() { + return data.length; + } + + /* + * @see javax.swing.ListModel#getElementAt(int) + */ + @Override + public Object getElementAt(int index) { + return data[index]; + } +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookForm.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -57,7 +57,7 @@ <JLabel text="lima.entrybook.type"/> </cell> <cell> - <JComboBox id="typeComboBox" model='{new org.chorem.lima.ui.entrybook.model.EntryBookTypeListModel()}' + <JComboBox id="typeComboBox" model='{new org.chorem.lima.ui.combobox.EntryBookTypeListModel()}' selectedItem="{getEntryBook().getType()}" onActionPerformed="getEntryBook().setType((String)getTypeComboBox().getSelectedItem())"/> </cell> Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookTableModel.java (from rev 2920, trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/model/EntryBookTableModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,215 @@ +/* + * *##% Lima Main + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.ui.entrybook; + +import static org.nuiton.i18n.I18n._; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.EntryBookService; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.service.LimaServiceFactory; + +/** + * Entry book table model. + * + * @author ore + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class EntryBookTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 7578692417919755647L; + + /** log. */ + private static final Log log = LogFactory.getLog(EntryBookTableModel.class); + + /** Services. */ + protected EntryBookService entryBookService; + + /** + * Constructor. + */ + public EntryBookTableModel() { + entryBookService = LimaServiceFactory.getInstance().getEntryBookService(); + } + + /* + * @return + * + public List<JournalDTO> getData() { + return data; + }*/ + + @Override + public int getRowCount() { + int result = 0; + + try { + result = entryBookService.getAllEntryBooks().size(); + } catch (LimaException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return result; + } + + @Override + public int getColumnCount() { + return 3; + } + + @Override + public String getColumnName(int column) { + String res = "n/a"; + switch (column) { + case 0: + res = _("lima.entrybook.code"); + break; + case 1: + res = _("lima.entrybook.label"); + break; + case 2: + res = _("lima.entrybook.type"); + break; + } + return res; + } + + public EntryBook getEntryBookAtRow(int row) throws LimaException { + EntryBook entryBook = null; + entryBook = entryBookService.getAllEntryBooks().get(row); + + return entryBook; + } + + /* + * @param row + * @return + * + @Override + public Object getRow(int row) { + return data.get(row); + }*/ + + @Override + public Object getValueAt(int row, int column) { + + Object result = null; + try { + EntryBook entryBook = getEntryBookAtRow(row); + + switch (column) { + case 0: + result = entryBook.getCode(); + break; + case 1: + result = entryBook.getLabel(); + break; + case 2: + result = entryBook.getType(); + break; + } + } catch (LimaException eee) { + if (log.isDebugEnabled()){ + log.debug("Can't get EntryBook",eee); + } + } + + return result; + } + + + + @Override + public void setValueAt(Object value, int row, int column) { + + try { + EntryBook entryBook = getEntryBookAtRow(row); + + switch (column) { + case 0: + entryBook.setCode((String)value); + break; + case 1: + entryBook.setLabel((String)value); + break; + case 2: + entryBook.setType((String)value); + break; + } + + // update on remote service + entryBookService.updateEntryBook(entryBook); + } catch (LimaException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + // TODO why false ? + return false; + } + + /** + * @param entryBook + * @throws LimaException + */ + public void addEntryBook(EntryBook entryBook) throws LimaException { + /* Calling journal service */ + entryBookService.createEntryBook(entryBook); + int row = entryBookService.getAllEntryBooks().indexOf(entryBook); + fireTableRowsInserted(row, row); + } + + /** + * + * @param entryBook + * @throws LimaException + */ + public void updateEntryBook(EntryBook entryBook) throws LimaException { + /* Calling journal service */ + entryBookService.updateEntryBook(entryBook); + int row = entryBookService.getAllEntryBooks().indexOf(entryBook); + fireTableRowsUpdated(row, row); + } + + /** + * + * @param entryBook + * @throws LimaException + */ + public void removeEntryBook(EntryBook entryBook) throws LimaException { + /* Calling journal service */ + int row = entryBookService.getAllEntryBooks().indexOf(entryBook); + entryBookService.removeEntryBook(entryBook); + fireTableRowsDeleted(row, row); + } +} 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-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -30,7 +30,7 @@ <cell fill="both" weightx="1" weighty="1" rows='4'> <JScrollPane> <org.jdesktop.swingx.JXTable id="entryBooksTable" rowHeight="24" - model="{new org.chorem.lima.ui.entrybook.model.EntryBookTableModel()}" + model="{new org.chorem.lima.ui.entrybook.EntryBookTableModel()}" highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" columnControlVisible="true"/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybook/EntryBookViewHandler.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -27,7 +27,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.EntryBookImpl; -import org.chorem.lima.ui.entrybook.model.EntryBookTableModel; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTable; Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,96 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.entrybooksreports; + +import java.awt.Color; +import java.awt.Component; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.FinancialTransaction; +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; + + +/** + * Table des transaction qui ajoute des comportement (keys). + * + * @author ore + * @author Rémi Chapelet + */ +public class EntryBooksReportsTable extends JXTable { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3133690382049594727L; + + /** log. */ + private static final Log log = LogFactory.getLog(EntryBooksReportsTable.class); + + protected EntryBooksReportsViewHandler handler; + + protected EntryBooksReportsTableModel model; + + private Highlighter colorReportsDatas; + + private FinancialTransaction oldRow; + + private Boolean highlighterReportsDatasBoolean; + + /** + */ + public EntryBooksReportsTable(EntryBooksReportsViewHandler handler, EntryBooksReportsTableModel model) { + + this.handler = handler; + this.model = model; + highlighterReportsDatasBoolean=true; + //highlight financial financial transactions + addColorReportsDatas(); + + } + + /** + * Cette méthode permet de colorer toutes les reportsdatas dans le tableau + * afin de bien distinguer les entête de comptes et les entrées comptables. + * On récupère la première cellule, on vérifie que c'est pas null + */ + protected void addColorReportsDatas() { + if (colorReportsDatas != null) { + removeHighlighter(colorReportsDatas); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + Entry entry = model.getElementAt(adapter.row); + FinancialTransaction financialTransaction = entry.getFinancialTransaction(); + if (financialTransaction != oldRow){ + highlighterReportsDatasBoolean = !highlighterReportsDatasBoolean; + } + oldRow = financialTransaction; + return highlighterReportsDatasBoolean; + } + }; + colorReportsDatas = + new ColorHighlighter(predicate, new Color(222,222,222), null); + addHighlighter(colorReportsDatas); + } +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -171,6 +171,10 @@ return result; } + public Entry getElementAt(int row){ + return cacheDataList.getListEntry().get(row); + } + @Override public boolean isCellEditable(int rowIndex, int columnIndex) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -19,7 +19,7 @@ <EntryBooksReportsViewHandler id="handler" javaBean="new EntryBooksReportsViewHandler(this)" /> <Boolean id="selectedRow" javaBean="false" /> <org.chorem.lima.ui.combobox.EntryBookComboBoxModel id="modelEntryBook"/> - <org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTableModel id="modelEntryBooksReportsTable"/> + <org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTableModel id="modelTable"/> <script> <![CDATA[ @@ -32,12 +32,12 @@ // set begindate to JAN 1 - 0:00.000 of this years Date beginDate = calendarBegin.getTime(); beginDate = DateUtils.truncate(beginDate, Calendar.YEAR); - getModelEntryBooksReportsTable().setBeginDate(beginDate); + getModelTable().setBeginDate(beginDate); // get end date Calendar calendarEnd = Calendar.getInstance(); Date endDate = calendarEnd.getTime(); - getModelEntryBooksReportsTable().setEndDate(endDate); + getModelTable().setEndDate(endDate); getBeginDatePicker().setDate(beginDate); getEndDatePicker().setDate(endDate); @@ -50,7 +50,7 @@ </cell> <cell> <org.jdesktop.swingx.JXDatePicker id="beginDatePicker" - onActionPerformed="getModelEntryBooksReportsTable().setBeginDate(beginDatePicker.getDate()); + onActionPerformed="getModelTable().setBeginDate(beginDatePicker.getDate()); getHandler().updateFooterLabel()" /> </cell> <cell> @@ -58,7 +58,7 @@ </cell> <cell> <org.jdesktop.swingx.JXDatePicker id="endDatePicker" - onActionPerformed="getModelEntryBooksReportsTable().setEndDate(endDatePicker.getDate()); + onActionPerformed="getModelTable().setEndDate(endDatePicker.getDate()); getHandler().updateFooterLabel()"/> </cell> <cell> @@ -68,7 +68,7 @@ <JComboBox id="entryBookComboBox" model="{getModelEntryBook()}" renderer="{new org.chorem.lima.ui.combobox.EntryBookRenderer()}" - onItemStateChanged="getModelEntryBooksReportsTable().setEntryBook((EntryBook) event.getItem()); + onItemStateChanged="getModelTable().setEntryBook((EntryBook) event.getItem()); getHandler().updateFooterLabel()" editable="false" /> @@ -77,12 +77,11 @@ <row> <cell fill="both" weightx="1" weighty="1" columns="7"> <JScrollPane> - <org.jdesktop.swingx.JXTable id="entryBooksReportsTable" rowHeight="24" - model="{getModelEntryBooksReportsTable()}" - highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - columnControlVisible="true"/> - <javax.swing.ListSelectionModel javaBean="getEntryBooksReportsTable().getSelectionModel()"/> + <org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTable + id="table" sortable="false" rowHeight="24" + constructorParams="getHandler(), getModelTable()" model="{getModelTable()}" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> + <javax.swing.ListSelectionModel javaBean="getTable().getSelectionModel()"/> </JScrollPane> </cell> </row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -51,12 +51,12 @@ } - /* - * set text and amounts of labels credit, debit, solde + + /** + * set text and amounts of labels credit, debit, solde */ public void updateFooterLabel(){ - EntryBooksReportsTableModel tablemodel = - (EntryBooksReportsTableModel) view.getEntryBooksReportsTable().getModel(); + EntryBooksReportsTableModel tablemodel = view.getModelTable(); ReportsDatas cacheDataList = tablemodel.cacheDataList; Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java (from rev 2930, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTable.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,202 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.financialtransaction; + +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.ui.celleditor.AccountTableCellEditor; +import org.chorem.lima.ui.celleditor.DateTableCellEditor; +import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; +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; + + +/** + * Table des transaction qui ajoute des comportement (keys). + * + * @author ore + * @author Rémi Chapelet + */ +public class FinancialTransactionTable extends JXTable implements KeyListener { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3133690382049594727L; + + /** log. */ + private static final Log log = LogFactory.getLog(FinancialTransactionTable.class); + + protected FinancialTransactionViewHandler handler; + + private Highlighter colorTransaction; + + private ColorHighlighter colorBalance; + + /** + */ + public FinancialTransactionTable(FinancialTransactionViewHandler handler) { + + this.handler = handler; + + addKeyListener(this); + + //Get new date editor + setDefaultEditor(Date.class, new DateTableCellEditor()); + //Get new entry book editor + setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); + //Get new account editor + setDefaultEditor(Account.class, new AccountTableCellEditor()); + + //highlight financial financial transactions + addColorTransaction(); + // highlight unbalanced financial transactions + addColorNonBalancedTransaction(); + } + + /** + * 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 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. + * 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() { + if (colorBalance != null) { + removeHighlighter(colorBalance); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + boolean isHighlighted = false; + 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); + addHighlighter(colorTransaction); + } + + /** + * for each action combination key are think + * for extend keyboard and laptop keyboard + */ + @Override + public void keyPressed(KeyEvent e) { + + //TODO combinaison de touches dans la config + + // delete selected row with the key : delete or ctrl clear + // ou de l'entree + if ((e.getKeyCode() == KeyEvent.VK_DELETE ) + || (e.getKeyCode() == KeyEvent.VK_CLEAR + && e.getModifiers() == KeyEvent.CTRL_MASK)){ + handler.deleteSelectedRow(); + } + + // 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(); + } + + // 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 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 = 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) { + handler.addEmptyEntry(); + // positionne la sélection sur la nouvelle ligne créée + this.setColumnSelectionInterval(0, 0); + this.setRowSelectionInterval(max_y + 1, max_y + 1); + } + } + + } + + /* + * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) + */ + @Override + public void keyTyped(KeyEvent e) { + + } + + /* + * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) + */ + @Override + public void keyReleased(KeyEvent e) { + + } +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java (from rev 2929, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,526 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.financialtransaction; + +import static org.nuiton.i18n.I18n._; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.List; + +import javax.swing.table.AbstractTableModel; + +import org.apache.commons.lang.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.EntryBookService; +import org.chorem.lima.business.FinancialPeriodService; +import org.chorem.lima.business.LimaBusinessException; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.FinancialTransactionService; +import org.chorem.lima.business.utils.EntryComparator; +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FinancialTransactionImpl; +import org.chorem.lima.entity.FinancialTransaction; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.util.ErrorHelper; + +/** + * Basic transaction table model. + * + * Le modele est filtré sur {@link #selectedEntryBook} et + * {@link #selectedFinancialPeriod} (montée en charge !). + * + * @author ore + * @author chatellier + * @version $Revision: 2897 $ + * + * Last update : $Date: 2010-05-14 13:22:26 +0200 (ven. 14 mai 2010) $ + * By : $Author: jpepin $ + */ +public class FinancialTransactionTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 3914954536809622358L; + + /** log. */ + private static final Log log = LogFactory + .getLog(FinancialTransactionTableModel.class); + + /** Transaction service. */ + protected final FinancialTransactionService financialTransactionService; + + /** EntryBook service. */ + protected final EntryBookService entryBookService; + + /** FinancialPeriod service. */ + protected final FinancialPeriodService financialPeriodService; + + /** selected financial period */ + protected FinancialPeriod selectedFinancialPeriod; + + /** data cache */ + protected List<Object> cacheDataList; + + /** collection + + + /** + * Model constructor. + * + * Just init service proxies. + */ + public FinancialTransactionTableModel() { + /* Services */ + financialTransactionService = LimaServiceFactory.getInstance() + .getTransactionService(); + entryBookService = LimaServiceFactory.getInstance(). + getEntryBookService(); + financialPeriodService = LimaServiceFactory.getInstance(). + getFinancialPeriodService(); + } + + /** + * Le model est une combinaison de Transaction/Entries. + * + * + * @return + */ + protected List<Object> getDataList() { + + List<Object> results = new ArrayList<Object>(); + try { + List<FinancialTransaction> financialtransactions = + financialTransactionService.getAllFinancialTransactionsForFinancialPeriod( + selectedFinancialPeriod); + for (FinancialTransaction financialtransaction : financialtransactions) { + results.add(financialtransaction); + List<Entry> entries = (List<Entry>) financialtransaction.getEntry(); + Collections.sort(entries, new EntryComparator()); + results.addAll(entries); + } + } + catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.debug("Can't update model", eee); + } + + ErrorHelper.showErrorDialog("Can't get transaction list", eee); + } + + return results; + } + + @Override + public int getColumnCount() { + return 9; + } + + @Override + public Class<?> getColumnClass(int column) { + + Class<?> result = null; + + switch (column) { + case 0: + result = Date.class; + break; + case 1: + result = EntryBook.class; + break; + case 2: + result = String.class; + break; + case 3: + result = Account.class; + break; + case 4: + result = String.class; + break; + case 5: + result = String.class; + break; + case 6: + result = Double.class; + break; + case 7: + result = Double.class; + break; + case 8: + result = Double.class; + break; + } + + return result; + } + + @Override + public String getColumnName(int column) { + String result = "n/a"; + + switch (column) { + case 0: + result = _("lima.transaction.column.date"); + break; + case 1: + result = _("lima.transaction.column.entrybook"); + break; + case 2: + result = _("lima.transaction.column.voucher"); + break; + case 3: + result = _("lima.transaction.column.account"); + break; + case 4: + result = _("lima.transaction.column.description"); + break; + case 5: + result = _("lima.transaction.column.position"); + break; + case 6: + result = _("lima.transaction.column.debit"); + break; + case 7: + result = _("lima.transaction.column.credit"); + break; + case 8: + result = _("lima.transaction.column.balance"); + break; + } + + return result; + } + + @Override + public int getRowCount() { + int result = 0; + + // just prevent too much result + if (selectedFinancialPeriod != null) { + //cacheDataList = getDataList(); + result = cacheDataList.size(); + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + + return result; + } + + @Override + public Object getValueAt(int row, int column) { + Object result = null; + + // just prevent too much result + if (selectedFinancialPeriod != null) { + result = cacheDataList.get(row); + + if (result instanceof FinancialTransaction) { + FinancialTransaction currentRow = (FinancialTransaction)result; + Double amountDebit = currentRow.getAmountDebit(); + Double amountCredit = currentRow.getAmountCredit(); + + switch (column) { + case 0: + result = currentRow.getTransactionDate(); + break; + case 1: + result = null; // voucher + break; + case 2: + result = null; //entrybook + break; + case 3: + result = null; // account + break; + case 4: + result = null; // description + break; + case 5 : + result = null; // position + break; + case 6: + result = amountDebit; + break; + case 7: + result = amountCredit; + break; + case 8: + result = amountDebit - amountCredit; + break; + } + } + else if (result instanceof Entry) { + Entry currentEntry = (Entry)result; + switch (column) { + case 0: + result = null; // date + break; + case 1 : // entry book + if (currentEntry.getEntryBook() != null){ + result = currentEntry.getEntryBook().getCode(); + } + else { + result = null; + } + break; + case 2: + result = currentEntry.getVoucher(); + break; + case 3: // account + if (currentEntry.getAccount() != null){ + result = currentEntry.getAccount().getAccountNumber(); + } + else { + result = null; + } + break; + case 4: + result = currentEntry.getDescription(); + break; + case 5 : + result = currentEntry.getPosition(); + break; + case 6: + result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; + break; + case 7: + result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); + break; + case 8: + result = null; // balance + break; + } + + } + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + + return result; + } + + + public void setFinancialPeriod(FinancialPeriod financialPeriod){ + + selectedFinancialPeriod = financialPeriod; + cacheDataList = getDataList(); + fireTableDataChanged(); + } + + /** + * To set cells editable or not + * different condition for entry or financial transaction + */ + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + boolean editableCell=false; + Object currentRow = cacheDataList.get(rowIndex); + // cells editable for the entry row, all cells exclude the date + if ((currentRow instanceof Entry) && !(columnIndex==0)) { + editableCell=true; + } + // cells editable for the financialtransaction row, no cells exclude the date + if ((currentRow instanceof FinancialTransaction) && (columnIndex==0)){ + editableCell=true; + } + return editableCell; + } + + /** + * @throws LimaException + */ + public void addFinancialTransaction() throws LimaException{ + /* Calling transaction service */ + FinancialTransaction financialTransaction = new FinancialTransactionImpl(); + //if a period and an entrybook is selected + if (selectedFinancialPeriod != null){ + financialTransaction.setFinancialPeriod(selectedFinancialPeriod); + // get today + Calendar actualCalendar = Calendar.getInstance(); + // get the financial period date + Date transactionDate = selectedFinancialPeriod.getBeginDate(); + // change the day + transactionDate = DateUtils.setDays(transactionDate, + actualCalendar.get(Calendar.DAY_OF_MONTH)); + // set date to the financial transaction + financialTransaction.setTransactionDate(transactionDate); + // create it + financialTransactionService.createFinancialTransaction(financialTransaction); + //on recharge la liste + cacheDataList = getDataList(); + int row = getDataList().indexOf(financialTransaction); + fireTableRowsInserted(row, row); + //fireTableDataChanged(); + } + else { + throw new LimaBusinessException("No financial period selected"); + } + } + + + + /** + * @throws LimaException + */ + public void addEmptyEntry(Object value, int row) throws LimaException { + FinancialTransaction currentTransaction = null; + Object currentRow = cacheDataList.get(row); + Entry entry = new EntryImpl(); + //check if current row is a transaction or an entry + if (currentRow instanceof FinancialTransaction) { + currentTransaction = (FinancialTransaction)currentRow; + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + //get back the parent transaction of the entry + currentTransaction = currentEntry.getFinancialTransaction(); + } + //create it + entry.setFinancialTransaction(currentTransaction); + financialTransactionService.createEntry(entry); + //on recharge la liste + cacheDataList = getDataList(); + fireTableDataChanged(); + } + + /** + * to modifiy financialtransaction or entry + */ + @Override + public void setValueAt(Object value, int row, int column) { + int financialTransactionRow=0; + // just prevent too much result + if (selectedFinancialPeriod != null) { + Object currentRow = cacheDataList.get(row); + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentFinancialTransaction = + (FinancialTransaction)currentRow; + switch (column) { + case 0: + //update + currentFinancialTransaction.setTransactionDate((Date)value); + break; + } + // notify service for modification + try { + financialTransactionService. + updateFinancialTransaction(currentFinancialTransaction); + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't update financial transaction", e); + } + } + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((FinancialTransaction) currentRow)); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + switch (column) { + case 1 : + currentEntry.setEntryBook((EntryBook)value); + break; + case 2 : + currentEntry.setVoucher((String)value); + break; + case 3: + currentEntry.setAccount((Account)value); + break; + case 4: + currentEntry.setDescription((String)value); + break; + case 5 : + currentEntry.setPosition((String)value); + break; + case 6: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(true); + break; + case 7: + currentEntry.setAmount((Double)value); + currentEntry.setDebit(false); + break; + } + try { + financialTransactionService.updateEntry(currentEntry); + + } catch (LimaException e) { + if (log.isDebugEnabled()){ + log.debug("Can't update entry", e); + } + } + //update the financial transaction in entire + financialTransactionRow = + getDataList().indexOf(((Entry) currentRow). + getFinancialTransaction()); + } + //on recharge la liste + cacheDataList = getDataList(); + fireTableRowsUpdated(financialTransactionRow, getRowCount()-1); + } + else { + if (log.isDebugEnabled()) { + log.debug("No fiscalPeriod selected skip table model update"); + } + } + } + + public Object getElementAt(int row){ + + Object currentRow = cacheDataList.get(row); + return currentRow; + } + + + /** + * Delete selected row in table (could be transaction or entry). + * + * Called by model. + * @param Object, int + * @throws LimaException + */ + public void removeObject(Object object, int row) throws LimaException { + Object currentRow = cacheDataList.get(row); + if (currentRow instanceof FinancialTransaction) { + FinancialTransaction currentTransaction = + (FinancialTransaction)currentRow; + financialTransactionService.removeFinancialTransaction(currentTransaction); + } + else if (currentRow instanceof Entry) { + Entry currentEntry = (Entry)currentRow; + financialTransactionService.removeEntry(currentEntry); + } + //on recharge la liste + cacheDataList = getDataList(); + fireTableRowsDeleted(row, getRowCount()); + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -76,9 +76,9 @@ <row> <cell fill="both" weightx="1" weighty="1" rows="3" columns="7"> <JScrollPane> - <org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTableModel + <org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel id="financialTransactionTableModel" /> - <org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTable + <org.chorem.lima.ui.financialtransaction.FinancialTransactionTable id="financialTransactionTable" sortable="false" rowHeight="22" constructorParams="getHandler()" model="{getFinancialTransactionTableModel()}" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -29,8 +29,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.ui.financialtransaction.FinancialTransactionView; -import org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTable; -import org.chorem.lima.ui.financialtransaction.table.FinancialTransactionTableModel; /** * Handler associated with financial transaction view. Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTable.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTable.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -1,203 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.financialtransaction.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.ui.celleditor.AccountTableCellEditor; -import org.chorem.lima.ui.celleditor.DateTableCellEditor; -import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; -import org.chorem.lima.ui.financialtransaction.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; - - -/** - * Table des transaction qui ajoute des comportement (keys). - * - * @author ore - * @author Rémi Chapelet - */ -public class FinancialTransactionTable extends JXTable implements KeyListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3133690382049594727L; - - /** log. */ - private static final Log log = LogFactory.getLog(FinancialTransactionTable.class); - - protected FinancialTransactionViewHandler handler; - - private Highlighter colorTransaction; - - private ColorHighlighter colorBalance; - - /** - */ - public FinancialTransactionTable(FinancialTransactionViewHandler handler) { - - this.handler = handler; - - addKeyListener(this); - - //Get new date editor - setDefaultEditor(Date.class, new DateTableCellEditor()); - //Get new entry book editor - setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); - //Get new account editor - setDefaultEditor(Account.class, new AccountTableCellEditor()); - - //highlight financial financial transactions - addColorTransaction(); - // highlight unbalanced financial transactions - addColorNonBalancedTransaction(); - } - - /** - * 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 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. - * 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() { - if (colorBalance != null) { - removeHighlighter(colorBalance); - } - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - boolean isHighlighted = false; - 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); - addHighlighter(colorTransaction); - } - - /** - * for each action combination key are think - * for extend keyboard and laptop keyboard - */ - @Override - public void keyPressed(KeyEvent e) { - - //TODO combinaison de touches dans la config - - // delete selected row with the key : delete or ctrl clear - // ou de l'entree - if ((e.getKeyCode() == KeyEvent.VK_DELETE ) - || (e.getKeyCode() == KeyEvent.VK_CLEAR - && e.getModifiers() == KeyEvent.CTRL_MASK)){ - handler.deleteSelectedRow(); - } - - // 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(); - } - - // 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 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 = 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) { - handler.addEmptyEntry(); - // positionne la sélection sur la nouvelle ligne créée - this.setColumnSelectionInterval(0, 0); - this.setRowSelectionInterval(max_y + 1, max_y + 1); - } - } - - } - - /* - * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) - */ - @Override - public void keyTyped(KeyEvent e) { - - } - - /* - * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) - */ - @Override - public void keyReleased(KeyEvent e) { - - } -} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/table/FinancialTransactionTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -1,526 +0,0 @@ -/* *##% Lima Swing - * Copyright (C) 2008 - 2010 CodeLutin - * - * 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 2 - * 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * ##%*/ - -package org.chorem.lima.ui.financialtransaction.table; - -import static org.nuiton.i18n.I18n._; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import org.apache.commons.lang.time.DateUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.EntryBookService; -import org.chorem.lima.business.FinancialPeriodService; -import org.chorem.lima.business.LimaBusinessException; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.FinancialTransactionService; -import org.chorem.lima.business.utils.EntryComparator; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.EntryImpl; -import org.chorem.lima.entity.FinancialPeriod; -import org.chorem.lima.entity.FinancialTransactionImpl; -import org.chorem.lima.entity.FinancialTransaction; -import org.chorem.lima.service.LimaServiceFactory; -import org.chorem.lima.util.ErrorHelper; - -/** - * Basic transaction table model. - * - * Le modele est filtré sur {@link #selectedEntryBook} et - * {@link #selectedFinancialPeriod} (montée en charge !). - * - * @author ore - * @author chatellier - * @version $Revision: 2897 $ - * - * Last update : $Date: 2010-05-14 13:22:26 +0200 (ven. 14 mai 2010) $ - * By : $Author: jpepin $ - */ -public class FinancialTransactionTableModel extends AbstractTableModel { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3914954536809622358L; - - /** log. */ - private static final Log log = LogFactory - .getLog(FinancialTransactionTableModel.class); - - /** Transaction service. */ - protected final FinancialTransactionService financialTransactionService; - - /** EntryBook service. */ - protected final EntryBookService entryBookService; - - /** FinancialPeriod service. */ - protected final FinancialPeriodService financialPeriodService; - - /** selected financial period */ - protected FinancialPeriod selectedFinancialPeriod; - - /** data cache */ - protected List<Object> cacheDataList; - - /** collection - - - /** - * Model constructor. - * - * Just init service proxies. - */ - public FinancialTransactionTableModel() { - /* Services */ - financialTransactionService = LimaServiceFactory.getInstance() - .getTransactionService(); - entryBookService = LimaServiceFactory.getInstance(). - getEntryBookService(); - financialPeriodService = LimaServiceFactory.getInstance(). - getFinancialPeriodService(); - } - - /** - * Le model est une combinaison de Transaction/Entries. - * - * - * @return - */ - protected List<Object> getDataList() { - - List<Object> results = new ArrayList<Object>(); - try { - List<FinancialTransaction> financialtransactions = - financialTransactionService.getAllFinancialTransactionsForFinancialPeriod( - selectedFinancialPeriod); - for (FinancialTransaction financialtransaction : financialtransactions) { - results.add(financialtransaction); - List<Entry> entries = (List<Entry>) financialtransaction.getEntry(); - Collections.sort(entries, new EntryComparator()); - results.addAll(entries); - } - } - catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.debug("Can't update model", eee); - } - - ErrorHelper.showErrorDialog("Can't get transaction list", eee); - } - - return results; - } - - @Override - public int getColumnCount() { - return 9; - } - - @Override - public Class<?> getColumnClass(int column) { - - Class<?> result = null; - - switch (column) { - case 0: - result = Date.class; - break; - case 1: - result = EntryBook.class; - break; - case 2: - result = String.class; - break; - case 3: - result = Account.class; - break; - case 4: - result = String.class; - break; - case 5: - result = String.class; - break; - case 6: - result = Double.class; - break; - case 7: - result = Double.class; - break; - case 8: - result = Double.class; - break; - } - - return result; - } - - @Override - public String getColumnName(int column) { - String result = "n/a"; - - switch (column) { - case 0: - result = _("lima.transaction.column.date"); - break; - case 1: - result = _("lima.transaction.column.entrybook"); - break; - case 2: - result = _("lima.transaction.column.voucher"); - break; - case 3: - result = _("lima.transaction.column.account"); - break; - case 4: - result = _("lima.transaction.column.description"); - break; - case 5: - result = _("lima.transaction.column.position"); - break; - case 6: - result = _("lima.transaction.column.debit"); - break; - case 7: - result = _("lima.transaction.column.credit"); - break; - case 8: - result = _("lima.transaction.column.balance"); - break; - } - - return result; - } - - @Override - public int getRowCount() { - int result = 0; - - // just prevent too much result - if (selectedFinancialPeriod != null) { - //cacheDataList = getDataList(); - result = cacheDataList.size(); - } - else { - if (log.isDebugEnabled()) { - log.debug("No fiscalPeriod selected skip table model update"); - } - } - - return result; - } - - @Override - public Object getValueAt(int row, int column) { - Object result = null; - - // just prevent too much result - if (selectedFinancialPeriod != null) { - result = cacheDataList.get(row); - - if (result instanceof FinancialTransaction) { - FinancialTransaction currentRow = (FinancialTransaction)result; - Double amountDebit = currentRow.getAmountDebit(); - Double amountCredit = currentRow.getAmountCredit(); - - switch (column) { - case 0: - result = currentRow.getTransactionDate(); - break; - case 1: - result = null; // voucher - break; - case 2: - result = null; //entrybook - break; - case 3: - result = null; // account - break; - case 4: - result = null; // description - break; - case 5 : - result = null; // position - break; - case 6: - result = amountDebit; - break; - case 7: - result = amountCredit; - break; - case 8: - result = amountDebit - amountCredit; - break; - } - } - else if (result instanceof Entry) { - Entry currentEntry = (Entry)result; - switch (column) { - case 0: - result = null; // date - break; - case 1 : // entry book - if (currentEntry.getEntryBook() != null){ - result = currentEntry.getEntryBook().getCode(); - } - else { - result = null; - } - break; - case 2: - result = currentEntry.getVoucher(); - break; - case 3: // account - if (currentEntry.getAccount() != null){ - result = currentEntry.getAccount().getAccountNumber(); - } - else { - result = null; - } - break; - case 4: - result = currentEntry.getDescription(); - break; - case 5 : - result = currentEntry.getPosition(); - break; - case 6: - result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; - break; - case 7: - result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); - break; - case 8: - result = null; // balance - break; - } - - } - } - else { - if (log.isDebugEnabled()) { - log.debug("No fiscalPeriod selected skip table model update"); - } - } - - return result; - } - - - public void setFinancialPeriod(FinancialPeriod financialPeriod){ - - selectedFinancialPeriod = financialPeriod; - cacheDataList = getDataList(); - fireTableDataChanged(); - } - - /** - * To set cells editable or not - * different condition for entry or financial transaction - */ - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - boolean editableCell=false; - Object currentRow = cacheDataList.get(rowIndex); - // cells editable for the entry row, all cells exclude the date - if ((currentRow instanceof Entry) && !(columnIndex==0)) { - editableCell=true; - } - // cells editable for the financialtransaction row, no cells exclude the date - if ((currentRow instanceof FinancialTransaction) && (columnIndex==0)){ - editableCell=true; - } - return editableCell; - } - - /** - * @throws LimaException - */ - public void addFinancialTransaction() throws LimaException{ - /* Calling transaction service */ - FinancialTransaction financialTransaction = new FinancialTransactionImpl(); - //if a period and an entrybook is selected - if (selectedFinancialPeriod != null){ - financialTransaction.setFinancialPeriod(selectedFinancialPeriod); - // get today - Calendar actualCalendar = Calendar.getInstance(); - // get the financial period date - Date transactionDate = selectedFinancialPeriod.getBeginDate(); - // change the day - transactionDate = DateUtils.setDays(transactionDate, - actualCalendar.get(Calendar.DAY_OF_MONTH)); - // set date to the financial transaction - financialTransaction.setTransactionDate(transactionDate); - // create it - financialTransactionService.createFinancialTransaction(financialTransaction); - //on recharge la liste - cacheDataList = getDataList(); - int row = getDataList().indexOf(financialTransaction); - fireTableRowsInserted(row, row); - //fireTableDataChanged(); - } - else { - throw new LimaBusinessException("No financial period selected"); - } - } - - - - /** - * @throws LimaException - */ - public void addEmptyEntry(Object value, int row) throws LimaException { - FinancialTransaction currentTransaction = null; - Object currentRow = cacheDataList.get(row); - Entry entry = new EntryImpl(); - //check if current row is a transaction or an entry - if (currentRow instanceof FinancialTransaction) { - currentTransaction = (FinancialTransaction)currentRow; - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - //get back the parent transaction of the entry - currentTransaction = currentEntry.getFinancialTransaction(); - } - //create it - entry.setFinancialTransaction(currentTransaction); - financialTransactionService.createEntry(entry); - //on recharge la liste - cacheDataList = getDataList(); - fireTableDataChanged(); - } - - /** - * to modifiy financialtransaction or entry - */ - @Override - public void setValueAt(Object value, int row, int column) { - int financialTransactionRow=0; - // just prevent too much result - if (selectedFinancialPeriod != null) { - Object currentRow = cacheDataList.get(row); - if (currentRow instanceof FinancialTransaction) { - FinancialTransaction currentFinancialTransaction = - (FinancialTransaction)currentRow; - switch (column) { - case 0: - //update - currentFinancialTransaction.setTransactionDate((Date)value); - break; - } - // notify service for modification - try { - financialTransactionService. - updateFinancialTransaction(currentFinancialTransaction); - } catch (LimaException e) { - if (log.isDebugEnabled()){ - log.debug("Can't update financial transaction", e); - } - } - //update the financial transaction in entire - financialTransactionRow = - getDataList().indexOf(((FinancialTransaction) currentRow)); - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - switch (column) { - case 1 : - currentEntry.setEntryBook((EntryBook)value); - break; - case 2 : - currentEntry.setVoucher((String)value); - break; - case 3: - currentEntry.setAccount((Account)value); - break; - case 4: - currentEntry.setDescription((String)value); - break; - case 5 : - currentEntry.setPosition((String)value); - break; - case 6: - currentEntry.setAmount((Double)value); - currentEntry.setDebit(true); - break; - case 7: - currentEntry.setAmount((Double)value); - currentEntry.setDebit(false); - break; - } - try { - financialTransactionService.updateEntry(currentEntry); - - } catch (LimaException e) { - if (log.isDebugEnabled()){ - log.debug("Can't update entry", e); - } - } - //update the financial transaction in entire - financialTransactionRow = - getDataList().indexOf(((Entry) currentRow). - getFinancialTransaction()); - } - //on recharge la liste - cacheDataList = getDataList(); - fireTableRowsUpdated(financialTransactionRow, getRowCount()-1); - } - else { - if (log.isDebugEnabled()) { - log.debug("No fiscalPeriod selected skip table model update"); - } - } - } - - public Object getElementAt(int row){ - - Object currentRow = cacheDataList.get(row); - return currentRow; - } - - - /** - * Delete selected row in table (could be transaction or entry). - * - * Called by model. - * @param Object, int - * @throws LimaException - */ - public void removeObject(Object object, int row) throws LimaException { - Object currentRow = cacheDataList.get(row); - if (currentRow instanceof FinancialTransaction) { - FinancialTransaction currentTransaction = - (FinancialTransaction)currentRow; - financialTransactionService.removeFinancialTransaction(currentTransaction); - } - else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry)currentRow; - financialTransactionService.removeEntry(currentEntry); - } - //on recharge la liste - cacheDataList = getDataList(); - fireTableRowsDeleted(row, getRowCount()); - } - -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/AddPeriod.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -15,7 +15,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ##% --> <JDialog modal="true"> - <org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel id="modelFiscalPeriodTable"/> + <org.chorem.lima.ui.fiscalperiod.FiscalPeriodTableModel id="modelFiscalPeriodTable"/> <script> <![CDATA[ import org.chorem.lima.entity.FiscalPeriod; Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/ClosurePeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/ClosurePeriodView.jaxx 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/ClosurePeriodView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -1,19 +0,0 @@ -<!-- ##% Lima Swing - Copyright (C) 2008 - 2010 CodeLutin - 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 2 - 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, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - ##% --> -<JFrame title="lima.export" width="620" height="300" iconImage='{Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/lima.png"))}'> - -</JFrame> \ No newline at end of file Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTable.java (from rev 2920, trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/model/FiscalPeriodTable.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTable.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTable.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,74 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.fiscalperiod; + +import java.awt.Color; +import java.awt.Component; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.FiscalPeriodService; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; +import org.chorem.lima.ui.financialperiod.FinancialPeriodTableModel; +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; +import org.jdesktop.swingx.decorator.HighlighterFactory; + +public class FiscalPeriodTable extends JXTable { + +private static final Log log = LogFactory.getLog(FinancialPeriodTableModel.class); + + protected FiscalPeriodViewHandler handler; + + protected FiscalPeriodTableModel model; + + protected FiscalPeriodService financialPeriodService; + + private Highlighter colorTransaction; + + public FiscalPeriodTable(FiscalPeriodViewHandler handler) { + + this.handler = handler; + model = this.handler.getView().getModelFiscalPeriodTable(); + financialPeriodService = LimaServiceFactory.getInstance().getFiscalPeriodService(); + addHighlighter(HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))); + //highlight financial financial transactions + addBlockColor(); + } + + protected void addBlockColor() { + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + FiscalPeriod fiscalPeriod = (FiscalPeriod) model.getElementAt(adapter.row); + // true if locked + return (fiscalPeriod.getLocked()); + } + }; + colorTransaction = + new ColorHighlighter(predicate, null, new Color(222,0,0)); + addHighlighter(colorTransaction); + } + +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java (from rev 2920, 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/FiscalPeriodTableModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodTableModel.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -0,0 +1,213 @@ +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.fiscalperiod; + +import static org.nuiton.i18n.I18n._; + +import java.text.SimpleDateFormat; +import java.util.List; +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.FiscalPeriod; +import org.chorem.lima.service.LimaServiceFactory; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FiscalPeriodTableModel extends AbstractTableModel { + + /** serialVersionUID. */ + private static final long serialVersionUID = 77027335135838258L; + + private static final Log log = LogFactory.getLog(FiscalPeriodTableModel.class); + + protected FiscalPeriodService fiscalPeriodService; + + public FiscalPeriodTableModel() { + fiscalPeriodService = LimaServiceFactory.getInstance().getFiscalPeriodService(); + } + + /* + * @see javax.swing.table.TableModel#getRowCount() + */ + @Override + public int getRowCount() { + + int result = 0; + try { + result = fiscalPeriodService.getAllFiscalPeriods().size(); + } + catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't get row count",eee); + } + } + return result; + } + + /* + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + return 2; + } + + + public Object getElementAt(int row){ + + Object currentRow=null; + try { + currentRow = fiscalPeriodService.getAllFiscalPeriods().get(row); + } catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't get elenment at table",eee); + } + } + return currentRow; + } + + /* + * @see javax.swing.table.TableModel#getColumnName(int) + */ + @Override + public String getColumnName(int columnIndex) { + + String result = "n/a"; + + switch(columnIndex) { + case 0 : + result = _("lima.tab.fiscalperiod"); + break; + case 1: + result = _("lima.closure"); + break; + } + + return result; + } + /* + * @see javax.swing.table.TableModel#getColumnClass(int) + */ + @Override + public Class<?> getColumnClass(int columnIndex) { + // both String + return String.class; + } + + /* + * @see javax.swing.table.TableModel#isCellEditable(int, int) + */ + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return false; + } + + /* + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + + Object result = "n/a"; + + List<FiscalPeriod> periods; + try { + periods = fiscalPeriodService.getAllFiscalPeriods(); + FiscalPeriod fiscalPeriod = periods.get(rowIndex); + + if (fiscalPeriod != null){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy"); + + switch (columnIndex) { + case 0: + result = simpleDateFormat. + format(fiscalPeriod.getBeginDate()) + + " - " + simpleDateFormat. + format(fiscalPeriod.getEndDate()); + break; + case 1: + if(fiscalPeriod.getLocked()){ + result = _("lima.close"); + } + else{ + result = _("lima.open"); + } + break; + } + } + + + + } catch (LimaException eee) { + if(log.isDebugEnabled()){ + log.debug("Can't update table",eee); + } + } + + return result; + } + + /* + * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) + */ + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + + } + + + public FiscalPeriod getFiscalPeriodAtRow(int row) throws LimaException { + FiscalPeriod fiscalPeriod = null; + fiscalPeriod = fiscalPeriodService.getAllFiscalPeriods().get(row); + return fiscalPeriod; + } + + + /** + * @param period + */ + public void addFiscalPeriod(FiscalPeriod period) throws LimaException { + + int currentRowCount = getRowCount(); + + // Calling fiscal period service + fiscalPeriodService.createFiscalPeriod(period); + fireTableRowsInserted(currentRowCount, currentRowCount); + } + + public void removeAllFiscalPeriods() throws LimaException { + fiscalPeriodService.removeAllFiscalPeriods(); + fireTableDataChanged(); + } + + public void blockFiscalPeriod(FiscalPeriod fiscalPeriod) throws LimaException { + fiscalPeriodService.blockFiscalPeriod(fiscalPeriod); + fireTableDataChanged(); + } +} 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-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2010-06-03 16:45:18 UTC (rev 2931) @@ -19,7 +19,7 @@ <FiscalPeriodViewHandler id="handler" javaBean="new FiscalPeriodViewHandler(this)" /> <Boolean id="selectedPeriod" javaBean="false" /> - <org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel id="modelFiscalPeriodTable"/> + <org.chorem.lima.ui.fiscalperiod.FiscalPeriodTableModel id="modelFiscalPeriodTable"/> <script> <![CDATA[ @@ -39,7 +39,7 @@ <row> <cell fill="both" weightx="1" weighty="1"> <JScrollPane> - <org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTable + <org.chorem.lima.ui.fiscalperiod.FiscalPeriodTable id="fiscalPeriodTable" rowHeight="24" constructorParams="getHandler()" model="{getModelFiscalPeriodTable()}" selectionMode="{ListSelectionModel.SINGLE_INTERVAL_SELECTION}" Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodViewHandler.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -29,7 +29,6 @@ import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.ui.fiscalperiod.model.FiscalPeriodTableModel; import org.chorem.lima.ui.fiscalperiod.AddPeriod; import org.chorem.lima.ui.fiscalperiod.FiscalPeriodView; import org.chorem.lima.util.ErrorHelper; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerTable.java 2010-06-03 14:46:55 UTC (rev 2930) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerTable.java 2010-06-03 16:45:18 UTC (rev 2931) @@ -46,8 +46,6 @@ protected LedgerViewHandler handler; - protected LedgerTableModel model; - private Highlighter colorReportsDatas; /**
participants (1)
-
jpepin@users.chorem.org