Author: vsalaun Date: 2011-08-09 12:35:40 +0200 (Tue, 09 Aug 2011) New Revision: 3255 Url: http://chorem.org/repositories/revision/lima/3255 Log: #426 add possibility to add an account without selecting a row 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/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-08 14:15:02 UTC (rev 3254) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-08-09 10:35:40 UTC (rev 3255) @@ -66,7 +66,7 @@ accountService = LimaServiceFactory.getInstance().getService( AccountServiceMonitorable.class); - } + } @Override @@ -207,6 +207,19 @@ accountService.createAccount(parentAccount, account); modelSupport.fireTreeStructureChanged(path); } + + /** + * Add account + * + * @param parentAccount + * @param account + * @throws LimaException + */ + 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 + modelSupport.fireNewRoot(); + } /** * Add account (path can be null). 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-08 14:15:02 UTC (rev 3254) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2011-08-09 10:35:40 UTC (rev 3255) @@ -31,6 +31,7 @@ import javax.swing.tree.TreePath; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.AccountServiceMonitorable; import org.chorem.lima.business.ImportServiceMonitorable; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; @@ -64,17 +65,21 @@ protected AccountView view; - //protected AccountServiceMonitorable accountService; + protected AccountServiceMonitorable accountService; protected AccountViewHandler(AccountView view) { this.view = view; // Gets factory service LimaServiceFactory.getInstance().getService( ImportServiceMonitorable.class).addListener(this); + accountService = + LimaServiceFactory.getInstance().getService( + AccountServiceMonitorable.class); } /** * Add new account with account form. + * @throws LimaException */ public void addAccount() { @@ -92,21 +97,44 @@ // null == cancel action 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) { + 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(); + + for (int i = 1; i<=number.length(); i++) { + try { + 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-1)); + break; + } catch (LimaException eee) { + log.debug("Can't search account : " + number.substring(0, i-1), eee); + } + } + } } // add it try { - accountsTreeTableModel.addAccount(treePath, newAccount); + if (selectedRow != -1) { + accountsTreeTableModel.addAccount(treePath, newAccount); + } else { + accountsTreeTableModel.addAccount(parentAccount, newAccount); + } } catch (LimaBusinessException eee) { if (log.isErrorEnabled()) { log.error("Can't add account", eee);
participants (1)
-
vsalaun@users.chorem.org