Author: vsalaun Date: 2011-08-09 14:38:19 +0200 (Tue, 09 Aug 2011) New Revision: 3256 Url: http://chorem.org/repositories/revision/lima/3256 Log: #426 stop using path to set account inception Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 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 Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-08-09 10:35:40 UTC (rev 3255) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-08-09 12:38:19 UTC (rev 3256) @@ -190,23 +190,6 @@ 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); - modelSupport.fireTreeStructureChanged(path); - } /** * Add account @@ -217,25 +200,23 @@ */ public void addAccount(Account parentAccount, Account account) throws LimaException{ accountService.createAccount(parentAccount, account); - //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed + //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed + //modelSupport.fireTreeStructureChanged(path); modelSupport.fireNewRoot(); } /** - * Add account (path can be null). + * Add account * - * @param path + * @param parentAccount * @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; - } + public void addSubLedger(Account parentAccount, Account account) throws LimaException { accountService.createSubLedger(parentAccount, account); - modelSupport.fireTreeStructureChanged(path); + //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed + //modelSupport.fireTreeStructureChanged(path); + modelSupport.fireNewRoot(); } /** 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 2011-08-09 10:35:40 UTC (rev 3255) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2011-08-09 12:38:19 UTC (rev 3256) @@ -55,8 +55,7 @@ <row> <cell fill="horizontal"> <JButton id="addSubLedger" text="lima.charts.account.addSubLedger" - onActionPerformed="getHandler().addSubLedger()" - enabled="{isSelectedRow()}"/> + onActionPerformed="getHandler().addSubLedger()"/> </cell> </row> <row> 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 2011-08-09 10:35:40 UTC (rev 3255) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2011-08-09 12:38:19 UTC (rev 3256) @@ -99,42 +99,33 @@ newAccount = accountForm.getAccount(); Account parentAccount = new AccountImpl(); if (newAccount != null) { - // get current selection path - TreePath treePath = null; - int selectedRow = view.getAccountsTreeTable().getSelectedRow(); - if (selectedRow != -1) { - treePath = view.getAccountsTreeTable().getPathForRow(selectedRow); - } else { - //FIXME Get root created on model with Impl() - //Can best not create root in model, and verify if root is null ? - treePath = new TreePath(accountsTreeTableModel.getRoot()); - - String number = newAccount.getAccountNumber(); + //get the account number been created + String number = newAccount.getAccountNumber(); - for (int i = 1; i<=number.length(); i++) { + //search for the nearest account from the one been created + //e.g.: for 41019 search for 4, 41, 410, 4101 + //and stop when the account doesn't exist, use last account found instead + for (int i = 1; i<number.length(); i++) { + try { + //get the parent account from the new account subnumber + parentAccount = accountService.getAccountByNumber(number.substring(0, i)); + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i), eee); + } + if (parentAccount == null) { try { - parentAccount = accountService.getAccountByNumber(number.substring(0, i)); + //if the account is null, get the previous account searched then stop the loop + parentAccount = accountService.getAccountByNumber(number.substring(0, i-1)); + break; } catch (LimaException eee) { - log.debug("Can't search account : " + number.substring(0, i), eee); + log.debug("Can't search account : " + number.substring(0, i-1), eee); } - if (parentAccount == null) { - try { - parentAccount = accountService.getAccountByNumber(number.substring(0, i-1)); - break; - } catch (LimaException eee) { - log.debug("Can't search account : " + number.substring(0, i-1), eee); - } - } } } // add it try { - if (selectedRow != -1) { - accountsTreeTableModel.addAccount(treePath, newAccount); - } else { - accountsTreeTableModel.addAccount(parentAccount, newAccount); - } + accountsTreeTableModel.addAccount(parentAccount, newAccount); } catch (LimaBusinessException eee) { if (log.isErrorEnabled()) { log.error("Can't add account", eee); @@ -167,14 +158,33 @@ // null == cancel action if (newAccount != null) { - // get current selection path - TreePath treePath = null; - int selectedRow = view.getAccountsTreeTable().getSelectedRow(); - treePath = view.getAccountsTreeTable().getPathForRow(selectedRow); + Account parentAccount = new AccountImpl(); + String number = newAccount.getAccountNumber(); + + //search for the nearest account from the one been created + //e.g.: for 41019 search for 4, 41, 410, 4101 + //and stop when the account doesn't exist, use last account found instead + for (int i = 1; i<=number.length(); i++) { + try { + //get the parent account from the new account subnumber + parentAccount = accountService.getAccountByNumber(number.substring(0, i)); + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i), eee); + } + if (parentAccount == null) { + try { + //if the account is null, get the previous account searched then stop the loop + parentAccount = accountService.getAccountByNumber(number.substring(0, i-1)); + break; + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i-1), eee); + } + } + } + // add it try { - accountsTreeTableModel. - addSubLedger(treePath, newAccount); + accountsTreeTableModel.addSubLedger(parentAccount, newAccount); } catch (LimaBusinessException eee) { if (log.isErrorEnabled()) { log.error("Can't add subledger", eee);