Author: echatellier Date: 2012-04-13 18:06:28 +0200 (Fri, 13 Apr 2012) New Revision: 3370 Url: http://chorem.org/repositories/revision/lima/3370 Log: Fix leaf account display Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java Removed: trunk/lima-business/src/main/java/org/chorem/lima/business/ejbinterface/ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/AccountServiceImpl.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -160,28 +160,7 @@ return result; } - /** Permer d'obtenir la liste des comptes à partir d'une de ses propriétés */ @Override - public List<Account> getAllAccountByProperty(String propertyName, - String value) throws LimaException { - List<Account> account = null; - - TopiaContext transaction = beginTransaction(rootContext); - try { - - AccountDAO accountDAO = - LimaCallaoDAOHelper.getAccountDAO(transaction); - account = accountDAO.findAllByProperty(propertyName, value); - } catch (Exception ex) { - doCatch(transaction, ex); - } finally { - doFinally(transaction); - } - - return account; - } - - @Override public Account getMasterAccount(String accountNumber) throws LimaException { Account account = null; TopiaContext transaction = beginTransaction(rootContext); @@ -208,13 +187,19 @@ @Override public Account getAccountByNumber(String number) throws LimaException { - List<Account> accountsList = getAllAccountByProperty( - Account.PROPERTY_ACCOUNT_NUMBER, number); - Account account = null; - if (accountsList.size() > 0) { - account = accountsList.get(0); + TopiaContext transaction = beginTransaction(rootContext); + try { + + AccountDAO accountDAO = + LimaCallaoDAOHelper.getAccountDAO(transaction); + account = accountDAO.findByAccountNumber(number); + } catch (Exception ex) { + doCatch(transaction, ex); + } finally { + doFinally(transaction); } + return account; } Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/AccountService.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -35,9 +35,9 @@ * * @author chatellier * @version $Revision$ - * <p/> - * Last update : $Date$ - * By : $Author$ + * + * Last update : $Date$ + * By : $Author$ */ public interface AccountService { @@ -49,9 +49,6 @@ */ long getAccountCount() throws LimaException; - List<Account> getAllAccountByProperty(String propertyName, - String value) throws LimaException; - /** * Obtain the master account for the given account number. * <p/> Modified: trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java =================================================================== --- trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-callao/src/main/java/org/chorem/lima/entity/AccountDAO.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -27,11 +27,11 @@ import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.StringTokenizer; - import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -44,11 +44,29 @@ /** * Retourne tous les comptes qui n'ont pas eux meme de sous compte. */ - public List<Account> findAllLeafAccounts() throws TopiaException { - String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + + public List<Account> findAllLeafAccounts() throws TopiaException { + // FIXME echatellier 20120413 la requete ne fonctionne pas + // et retourne vide + /*String query = "FROM " + Account.class.getName() + " a WHERE a NOT IN (" + "FROM " + Account.class.getName() + " b where b.accountNumber like concat(a.accountNumber,'%'))"; - List<Account> accounts = context.find(query); - return accounts; + List<Account> accounts = context.find(query);*/ + + // code temporaire non performant en attandant: + List<Account> allAccounts = findAll(); + Iterator<Account> itAccount = allAccounts.iterator(); + while (itAccount.hasNext()) { + Account acc = itAccount.next(); + Iterator<Account> itAccount2 = allAccounts.iterator(); + while (itAccount2.hasNext()) { + Account acc2 = itAccount2.next(); + if (!acc2.getAccountNumber().equals(acc.getAccountNumber()) && + acc2.getAccountNumber().startsWith(acc.getAccountNumber())) { + itAccount.remove(); + break; + } + } + } + return allAccounts; } /** Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.ui.combobox.AccountRenderer; -import org.chorem.lima.ui.combobox.SubAccountComboBoxModel; +import org.chorem.lima.ui.combobox.LeafAccountComboBoxModel; import org.chorem.lima.util.AccountToString; import org.chorem.lima.widgets.JWideComboBox; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; @@ -45,21 +45,30 @@ import java.awt.event.MouseEvent; import java.util.EventObject; +/** + * Editor des cellules de tableau de type "Account". + * Affiche une wide combo box pour selectionner un compte. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ public class AccountTableCellEditor extends AbstractCellEditor implements TableCellEditor, KeyListener { - protected static final Log log = LogFactory.getLog(EntryBookTableCellEditor.class); + protected static final Log log = LogFactory.getLog(AccountTableCellEditor.class); private final JWideComboBox comboBox; private static final long serialVersionUID = 1L; -// private static AccountTableCellEditor editor; private static boolean keyPressed; /** constructor */ public AccountTableCellEditor() { comboBox = new JWideComboBox(); - SubAccountComboBoxModel accountComboBoxModel = new SubAccountComboBoxModel(); + LeafAccountComboBoxModel accountComboBoxModel = new LeafAccountComboBoxModel(); comboBox.setModel(accountComboBoxModel); AccountRenderer accountRenderer = new AccountRenderer(); comboBox.setRenderer(accountRenderer); @@ -140,11 +149,4 @@ } -// public static AccountTableCellEditor getInstance() { -// if (editor == null) { -// editor = new AccountTableCellEditor(); -// } -// return editor; -// } - } Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java (from rev 3366, trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/LeafAccountComboBoxModel.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -0,0 +1,113 @@ +/* + * #%L + * Lima Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +package org.chorem.lima.ui.combobox; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ServiceListener; +import org.chorem.lima.business.api.AccountService; +import org.chorem.lima.business.monitorable.AccountServiceMonitorable; +import org.chorem.lima.business.monitorable.ImportServiceMonitorable; +import org.chorem.lima.entity.Account; +import org.chorem.lima.service.LimaServiceFactory; + +import javax.swing.AbstractListModel; +import javax.swing.ComboBoxModel; +import java.util.ArrayList; +import java.util.List; + +/** + * Account combo box model containing only leaf account (without sub accounts). + */ +public class LeafAccountComboBoxModel extends AbstractListModel implements ComboBoxModel, ServiceListener { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(LeafAccountComboBoxModel.class); + + protected Object selectedAccount; + + protected List<Account> datasCache; + + protected AccountService accountService; + + public LeafAccountComboBoxModel() { + accountService = + LimaServiceFactory.getService(AccountServiceMonitorable.class); + LimaServiceFactory.addServiceListener(accountService, this); + LimaServiceFactory.addServiceListener(ImportServiceMonitorable.class, this); + datasCache = getDataList(); + } + + @Override + public Object getSelectedItem() { + return selectedAccount; + } + + @Override + public void setSelectedItem(Object anItem) { + selectedAccount = anItem; + fireContentsChanged(this, -1, -1); + } + + @Override + public Object getElementAt(int index) { + return datasCache.get(index); + } + + @Override + public int getSize() { + return datasCache.size(); + } + + public List<Account> getDataList() { + List<Account> result = new ArrayList<Account>(); + try { + result = accountService.getAllLeafAccounts(); + } catch (LimaException eee) { + if (log.isDebugEnabled()) { + log.debug("Can't get list subaccounts", eee); + } + } + return result; + + } + + public void refresh() { + datasCache = getDataList(); + fireContentsChanged(this, 0, datasCache.size()); + } + + @Override + public void notifyMethod(String serviceName, String methodName) { + if (serviceName.contains("Account") || + methodName.contains("importAll")) { + refresh(); + } + } + +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/combobox/SubAccountComboBoxModel.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -1,114 +0,0 @@ -/* - * #%L - * Lima Swing - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.lima.ui.combobox; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.LimaException; -import org.chorem.lima.business.ServiceListener; -import org.chorem.lima.business.api.AccountService; -import org.chorem.lima.business.monitorable.AccountServiceMonitorable; -import org.chorem.lima.business.monitorable.ImportServiceMonitorable; -import org.chorem.lima.entity.Account; -import org.chorem.lima.service.LimaServiceFactory; - -import javax.swing.AbstractListModel; -import javax.swing.ComboBoxModel; -import java.util.ArrayList; -import java.util.List; - -/** - * Account combo box model. - */ -public class SubAccountComboBoxModel extends AbstractListModel implements ComboBoxModel, ServiceListener { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(SubAccountComboBoxModel.class); - - protected Object selectedAccount; - - protected List<Account> datasCache; - - protected AccountService accountService; - - public SubAccountComboBoxModel() { - accountService = - LimaServiceFactory.getService(AccountServiceMonitorable.class); - LimaServiceFactory.addServiceListener(accountService, this); - LimaServiceFactory.addServiceListener(ImportServiceMonitorable.class, this); - datasCache = getDataList(); - } - - @Override - public Object getSelectedItem() { - return selectedAccount; - } - - @Override - public void setSelectedItem(Object anItem) { - selectedAccount = anItem; - fireContentsChanged(this, -1, -1); - } - - @Override - public Object getElementAt(int index) { - return datasCache.get(index); - } - - @Override - public int getSize() { - return datasCache.size(); - } - - public List<Account> getDataList() { - List<Account> result = new ArrayList<Account>(); - try { - result = accountService.getAllLeafAccounts(); - } catch (LimaException eee) { - if (log.isDebugEnabled()) { - log.debug("Can't get list subaccounts", eee); - } - } - return result; - - } - - public void refresh() { - datasCache = getDataList(); - fireContentsChanged(this, 0, datasCache.size()); - } - - @Override - public void notifyMethod(String serviceName, String methodeName) { - if (serviceName.contains("Account") || - methodeName.contains("importAll")) { - refresh(); - } - } - - -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java 2012-04-13 15:26:32 UTC (rev 3369) +++ trunk/lima-swing/src/main/java/org/chorem/lima/widgets/JWideComboBox.java 2012-04-13 16:06:28 UTC (rev 3370) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as