r3306 - in trunk/lima-swing: . src/main/java/org/chorem/lima src/main/java/org/chorem/lima/ui/account src/main/resources src/main/resources/META-INF src/main/resources/i18n
Author: tchemit Date: 2011-09-27 10:38:55 +0200 (Tue, 27 Sep 2011) New Revision: 3306 Url: http://chorem.org/repositories/revision/lima/3306 Log: Evolution #448: [Plan comptable] Ouverture longue Evolution #446: [Plan comptable] Cr?\195?\169ation des num?\195?\169ros de compte interm?\195?\169diaires lors de la cr?\195?\169ation d'un nouveau compte Ajout de la configuration pour auditer l'application via nuiton-profiling Added: trunk/lima-swing/src/main/resources/META-INF/ trunk/lima-swing/src/main/resources/META-INF/aop.xml Modified: trunk/lima-swing/pom.xml trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx 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 trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-swing/pom.xml =================================================================== --- trunk/lima-swing/pom.xml 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/pom.xml 2011-09-27 08:38:55 UTC (rev 3306) @@ -48,6 +48,11 @@ <groupId>org.nuiton</groupId> <artifactId>nuiton-utils</artifactId> </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-profiling</artifactId> + </dependency> <dependency> <groupId>org.nuiton.topia</groupId> @@ -341,6 +346,7 @@ <jnlp.codebase>file://${project.build.directory}/jnlp</jnlp.codebase> </properties> <build> + <defaultGoal>verify</defaultGoal> <plugins> <plugin> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2011-09-27 08:38:55 UTC (rev 3306) @@ -37,8 +37,12 @@ import org.chorem.lima.ui.MainViewHandler; import org.chorem.lima.ui.opening.OpeningView; import org.chorem.lima.util.ErrorHelper; +import org.nuiton.profiling.NuitonTrace; +import org.nuiton.util.FileUtil; import javax.swing.SwingUtilities; +import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -134,11 +138,9 @@ log.warn(_("lima.warning.nimbus.landf")); } } - return context; } - protected static void launch(LimaContext context) throws Exception { splash.drawVersion(config.getVersion()); @@ -181,7 +183,17 @@ ui.setVisible(true); } }); + } + protected static void saveTraces(File file) { + String stats = NuitonTrace.getStatisticsCSVAndClear(); + try { + FileUtil.writeString(file, stats, "utf-8"); + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not save traces to file " + file, e); + } + } } public static class ShutdownHook extends Thread { @@ -194,6 +206,12 @@ public void run() { try { super.run(); + File file = new File("lima-trace.csv"); + saveTraces(file); + String stats = NuitonTrace.getStatisticsCSVAndClear(); + if (log.isInfoEnabled()) { + log.info(stats); + } LimaContext.get().close(); LimaServiceFactory.destroy(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountForm.jaxx 2011-09-27 08:38:55 UTC (rev 3306) @@ -23,23 +23,27 @@ #L% --> -<JDialog modal="true" - defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="performCancel();"> +<JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" + onWindowClosing="dispose()"> <import> javax.swing.text.Document org.chorem.lima.entity.Account </import> + <AccountViewHandler id='handler' + initializer='getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler()'/> + <Account id="account" javaBean='null'/> <script> <![CDATA[ getRootPane().setDefaultButton(ok); - protected void performCancel() { - setAccount(null); - dispose(); + + @Override + public void dispose() { + setAccount(null); + super.dispose(); } ]]> </script> @@ -48,34 +52,35 @@ <row> <cell fill="horizontal"> - <JLabel text="lima.charts.account.number"/> + <JLabel text="lima.charts.account.number" labelFor='{numberTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="numberTextField" - text="{getAccount().getAccountNumber()}"/> - <Document javaBean="getNumberTextField().getDocument()" - onInsertUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' - onRemoveUpdate='getAccount().setAccountNumber(getNumberTextField().getText())'/> + text="{account.getAccountNumber()}"/> + <Document initializer="numberTextField.getDocument()" + onInsertUpdate='account.setAccountNumber(numberTextField.getText())' + onRemoveUpdate='account.setAccountNumber(numberTextField.getText())'/> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.label"/> + <JLabel text="lima.common.label" labelFor='{descriptionTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="descriptionTextField" text="{getAccount().getLabel()}"/> - <Document javaBean="getDescriptionTextField().getDocument()" - onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/> + <Document initializer="descriptionTextField.getDocument()" + onInsertUpdate='account.setLabel(descriptionTextField.getText())' + onRemoveUpdate='account.setLabel(descriptionTextField.getText())'/> </cell> </row> <row> - <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + <cell columns="2"> + <JPanel layout='{new GridLayout(1,0)}'> + <JButton text="lima.common.cancel" onActionPerformed="dispose()"/> + <JButton id="ok" text="lima.common.ok" + onActionPerformed="handler.doAddAccount(this)"/> + </JPanel> </cell> - <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="dispose()"/> - </cell> </row> </Table> </JDialog> \ No newline at end of file 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-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-09-27 08:38:55 UTC (rev 3306) @@ -142,26 +142,26 @@ break; case 1: result = account.getLabel(); - if (log.isInfoEnabled()) { - log.info("Get label '" + result + - "' for account [" + - account.getAccountNumber() + "]"); - } break; } } return result; } + + @Override + public int getColumnCount() { + return 2; + } } /** Model constructor. Init account service used here. */ public AccountTreeTableModel() { setColumnIdentifiers(Arrays.asList(_("lima.table.number"), - _("lima.table.label")) - ); + _("lima.table.label"))); setRoot(new AccountTreeTableNode(null)); + // Gets factory service accountService = LimaServiceFactory.getService(AccountServiceMonitorable.class); @@ -339,7 +339,7 @@ } /** Refresh accountschart. */ - public void refreshTree() throws LimaException { + public void refreshTree() { modelSupport.fireNewRoot(); } @@ -348,15 +348,27 @@ * Remove account. * * @param path - * @param account * @throws LimaException */ - public void removeAccount(TreePath path, - Account account) throws LimaException { + public void removeAccount(TreePath path) throws LimaException { + // Calling account service + AccountTreeTableNode node = getLastPathComponent(path); + Account account = node.getUserObject(); int index = getIndexOfChild( - path.getParentPath().getLastPathComponent(), account); + path.getParentPath().getLastPathComponent(), node); accountService.removeAccount(account); - modelSupport.fireChildRemoved(path.getParentPath(), index, account); + modelSupport.fireChildRemoved(path.getParentPath(), index, node); } + + public Account getAccount(TreePath path) { + AccountTreeTableNode lastPathComponent = getLastPathComponent(path); + Account account = lastPathComponent.getUserObject(); + return account; + } + + public AccountTreeTableNode getLastPathComponent(TreePath path) { + AccountTreeTableNode lastPathComponent = (AccountTreeTableNode) path.getLastPathComponent(); + return lastPathComponent; + } } 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-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2011-09-27 08:38:55 UTC (rev 3306) @@ -24,7 +24,6 @@ --> <Table> - <import> javax.swing.ListSelectionModel org.jdesktop.swingx.JXTreeTable @@ -38,7 +37,7 @@ <script> <![CDATA[ void $afterCompleteSetup() { - getHandler().init(); + handler.init(); } ]]> </script> @@ -56,33 +55,33 @@ </cell> <cell fill="horizontal"> <JButton id="addButton" text="lima.charts.account.addAccount" - onActionPerformed="handler.addAccount()"/> + onActionPerformed="handler.launchAddAccountForm()"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="addSubLedger" text="lima.charts.account.addSubLedger" - onActionPerformed="handler.addSubLedger()"/> + onActionPerformed="handler.launchAddSubLedgerForm()"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="updateButton" text="lima.common.update" - onActionPerformed="handler.updateAccount()" + onActionPerformed="handler.launchUpdateAccountForm()" enabled="{isSelectedRow()}"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="removeButton" text="lima.common.remove" - onActionPerformed="handler.removeAccount()" + onActionPerformed="handler.doRemoveAccount()" enabled="{isSelectedRow()}"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="importButton" text="lima.importexport.import" - onActionPerformed="handler.importAccountsChart()"/> + onActionPerformed="handler.doImportAccountsChart()"/> </cell> </row> </Table> \ No newline at end of file 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-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2011-09-27 08:38:55 UTC (rev 3306) @@ -30,7 +30,6 @@ 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; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.ejbinterface.AccountService; @@ -75,11 +74,12 @@ this.view = view; // Gets factory service LimaServiceFactory.addServiceListener(ImportServiceMonitorable.class, this); - accountService = LimaServiceFactory.getService(AccountServiceMonitorable.class); + accountService = + LimaServiceFactory.getService(AccountServiceMonitorable.class); } public void init() { - JXTreeTable table = view.getAccountsTreeTable(); + JXTreeTable table = getTreeTable(); table.addKeyListener(new KeyAdapter() { /** * for each action combination key are think @@ -107,192 +107,184 @@ }); } - /** Add new account with account form. */ - public void addAccount() { + public void launchAddAccountForm() { - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel) accountsTreeTable.getTreeTableModel(); - Account newAccount = new AccountImpl(); AccountForm accountForm = new AccountForm(view); accountForm.setAccount(newAccount); // jaxx constructor don't call super() ? accountForm.setLocationRelativeTo(view); accountForm.setVisible(true); + } + public void launchAddSubLedgerForm() { - // null == cancel action - newAccount = accountForm.getAccount(); - Account parentAccount = new AccountImpl(); - if (newAccount != null) { - //get the account number been created - String number = newAccount.getAccountNumber(); + Account newAccount = new AccountImpl(); + SubLedgerForm subledgerForm = new SubLedgerForm(view); + subledgerForm.setAccount(newAccount); + // jaxx constructor don't call super() ? + subledgerForm.setLocationRelativeTo(view); + subledgerForm.setVisible(true); + } - //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); + /** + * Open update account (or subledger) form with selected account + * from the tree. + */ + public void launchUpdateAccountForm() { + + Account selectedObject = getSelectedAccount(); + + if (selectedObject != null) { + + if (selectedObject.getGeneralLedger() == null) { + UpdateAccountForm accountForm = new UpdateAccountForm(view); + accountForm.setAccount(selectedObject); + // jaxx constructor don't call super() ? + accountForm.setLocationRelativeTo(view); + accountForm.setVisible(true); + } else { + UpdateSubLedgerForm subLedgerForm = new UpdateSubLedgerForm(view); + subLedgerForm.setAccount(selectedObject); + // jaxx constructor don't call super() ? + subLedgerForm.setLocationRelativeTo(view); + subLedgerForm.setVisible(true); + } + } + } + + /** + * Add new account with account form. + * + * @param dialog the account form + */ + public void doAddAccount(AccountForm dialog) { + try { + Account newAccount = dialog.getAccount(); + + Account masterAccount = null; + + if (newAccount.getAccountNumber().length() > 1) { + + // a master account is required + masterAccount = getMasterAccount(newAccount); + + if (masterAccount == null) { + + // bye-bye :( + return; } - 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.addAccount(parentAccount, newAccount); - } catch (LimaBusinessException eee) { - if (log.isErrorEnabled()) { - log.error("Can't add account", eee); - } - DialogHelper.showErrorMessageDialog(view, eee); - + getTreeTableModel().addAccount(masterAccount, newAccount); } catch (LimaException ex) { if (log.isErrorEnabled()) { log.error("Can't add account", ex); } - ErrorHelper.showErrorDialog(_("lima.account.addaccounterror"), ex); + ErrorHelper.showErrorDialog(view, _("lima.account.addaccounterror"), ex); } + } finally { + dialog.dispose(); } } - public void addSubLedger() { + public void doAddSubLedger(SubLedgerForm dialog) { - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel) accountsTreeTable.getTreeTableModel(); - Account newAccount = new AccountImpl(); - SubLedgerForm subledgerForm = new SubLedgerForm(view); - subledgerForm.setAccount(newAccount); - // jaxx constructor don't call super() ? - subledgerForm.setLocationRelativeTo(view); - subledgerForm.setVisible(true); - newAccount = subledgerForm.getAccount(); + try { + Account newAccount = dialog.getAccount(); - // null == cancel action - if (newAccount != null) { - Account parentAccount = new AccountImpl(); - String number = newAccount.getAccountNumber(); + Account masterAccount = null; - //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 (newAccount.getAccountNumber().length() > 1) { + + // a master account is required + masterAccount = getMasterAccount(newAccount); + + if (masterAccount == null) { + + // bye-bye :( + return; } - 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(parentAccount, newAccount); - } catch (LimaBusinessException eee) { - if (log.isErrorEnabled()) { - log.error("Can't add subledger", eee); - } - DialogHelper.showErrorMessageDialog(view, eee); + getTreeTableModel().addSubLedger(masterAccount, newAccount); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't add subledger", eee); } - DialogHelper.showErrorMessageDialog(view, eee); + ErrorHelper.showErrorDialog(view, "Can't add subledger", eee); } + } finally { + dialog.dispose(); } } - /** - * Open account form with selected account. - * Verifiy if it's an account or a subledger - */ - public void updateAccount() { - JXTreeTable table = view.getAccountsTreeTable(); - AccountTreeTableModel tableModel = - (AccountTreeTableModel) table.getTreeTableModel(); + public void doUpdateAccount(UpdateAccountForm dialog) { - // get selected account - int selectedRow = table.getSelectedRow(); - TreePath treePath = table.getPathForRow(selectedRow); // not null - AccountTreeTableModel.AccountTreeTableNode lastPathComponent = - (AccountTreeTableModel.AccountTreeTableNode) treePath.getLastPathComponent(); - Account selectedObject = lastPathComponent.getUserObject(); - //update Account or update SubLedger - if (selectedObject != null) { - // get current selection path - if (selectedRow != -1) { - treePath = table.getPathForRow(selectedRow); - } else { - treePath = new TreePath(tableModel.getRoot()); + Account account = dialog.getAccount(); + + String newMasterAccountNumber = + dialog.getMasterAccountTextField().getText(); + String newLabel = dialog.getDescriptionTextField().getText(); + + boolean hasChanged = + updateMasterAccount(account, newMasterAccountNumber); + hasChanged |= updateLabel(account, newLabel); + + try { + if (hasChanged) { + + // can update account + updateAccount(account); } - //test if selectedrow is account or ledger - if (selectedObject.getGeneralLedger() == null) { - UpdateAccountForm accountForm = new UpdateAccountForm(view); - accountForm.setAccount(selectedObject); - // jaxx constructor don't call super() ? - accountForm.setLocationRelativeTo(view); - accountForm.setVisible(true); - // null == cancel action - selectedObject = accountForm.getAccount(); + + } finally { + + // close dialog + dialog.dispose(); + } + } + + public void doUpdateSubLedger(UpdateSubLedgerForm dialog) { + + Account account = dialog.getAccount(); + + String newMasterAccountNumber = + dialog.getMasterAccountTextField().getText(); + String newLabel = dialog.getDescriptionTextField().getText(); + String newThirdParty = dialog.getThirdPartyTextField().getText(); + + boolean hasChanged = updateMasterAccount(account, + newMasterAccountNumber); + hasChanged |= updateLabel(account, newLabel); + hasChanged |= updateThirdParty(account, newThirdParty); + + try { + if (hasChanged) { + + // can update subLedger + updateAccount(account); } - // else is a subledger - else { - UpdateSubLedgerForm subLedgerForm = new UpdateSubLedgerForm(view); - subLedgerForm.setAccount(selectedObject); - // jaxx constructor don't call super() ? - subLedgerForm.setLocationRelativeTo(view); - subLedgerForm.setVisible(true); - // null == cancel action - selectedObject = subLedgerForm.getAccount(); - } - //if action confirmed - if (selectedObject != null) { - // update it - try { - tableModel. - updateAccount(selectedObject); - } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't add update", eee); - } - DialogHelper.showErrorMessageDialog(view, eee); - } - } + + } finally { + + // close dialog + dialog.dispose(); } } /** Ask for user to remove for selected account, and remove it if confirmed. */ - public void removeAccount() { + public void doRemoveAccount() { // maybe this code can be factorised - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel) accountsTreeTable.getTreeTableModel(); + JXTreeTable treeTable = getTreeTable(); // Any row selected - int selectedRow = view.getAccountsTreeTable().getSelectedRow(); + int selectedRow = treeTable.getSelectedRow(); if (selectedRow != -1) { int n = JOptionPane.showConfirmDialog(view, _("lima.charts.account.question.remove"), @@ -301,12 +293,11 @@ JOptionPane.QUESTION_MESSAGE); if (n == JOptionPane.YES_OPTION) { // update view of treetable - TreePath treePath = view.getAccountsTreeTable(). - getPathForRow(selectedRow); - Account account = (Account) treePath.getLastPathComponent(); + TreePath treePath = + treeTable.getPathForRow(selectedRow); try { - accountsTreeTableModel.removeAccount(treePath, account); + getTreeTableModel().removeAccount(treePath); } catch (LimaException eee) { if (log.isErrorEnabled()) { log.error("Can't delete account", eee); @@ -317,23 +308,8 @@ } } - public void refresh() { - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel) accountsTreeTable.getTreeTableModel(); - try { - accountsTreeTableModel.refreshTree(); - } catch (LimaException eee) { - if (log.isDebugEnabled()) { - log.debug("Can't refresh model", eee); - } - } - //refresh view - view.repaint(); - } + public void doImportAccountsChart() { - public void importAccountsChart() { - AccountImportForm form = new AccountImportForm(); // form.setLocationRelativeTo(view); @@ -367,65 +343,17 @@ if (methodeName.contains("importAccounts") || methodeName.contains("importAll") || methodeName.contains("importAsCSV")) { - refresh(); - } - } + // refresh model + getTreeTableModel().refreshTree(); - public void performOk(UpdateAccountForm dialog) { - - - Account account = dialog.getAccount(); - - String newMasterAccountNumber = - dialog.getMasterAccountTextField().getText(); - String newLabel = dialog.getDescriptionTextField().getText(); - - boolean hasChanged = - updateMasterAccount(account, newMasterAccountNumber); - hasChanged |= updateLabel(account, newLabel); - - if (!hasChanged) { - - // nothing has changed - dialog.setAccount(null); + //FIXME tchemit-2011-09-23 Should never do this... refresh view + view.repaint(); } - dialog.dispose(); } - public void performCancel(UpdateAccountForm dialog) { - dialog.setAccount(null); - dialog.dispose(); - } - - public void performOk(UpdateSubLedgerForm dialog) { - - - Account account = dialog.getAccount(); - - String newMasterAccountNumber = - dialog.getMasterAccountTextField().getText(); - String newLabel = dialog.getDescriptionTextField().getText(); - String newThirdParty = dialog.getThirdPartyTextField().getText(); - - boolean hasChanged = updateMasterAccount(account, newMasterAccountNumber); - hasChanged |= updateLabel(account, newLabel); - hasChanged |= updateThirdParty(account, newThirdParty); - - if (!hasChanged) { - - // nothing has changed - dialog.setAccount(null); - } - dialog.dispose(); - } - - public void performCancel(UpdateSubLedgerForm dialog) { - dialog.setAccount(null); - dialog.dispose(); - } - - protected boolean updateMasterAccount(Account account, String newMasterAccountNumber) { + protected boolean updateMasterAccount(Account account, + String newMasterAccountNumber) { boolean hasChanged = false; String oldMasterAccountNumber = account.getMasterAccount() == null ? "" : @@ -478,4 +406,69 @@ return hasChanged; } + + protected void updateAccount(Account selectedObject) { + try { + getTreeTableModel().updateAccount(selectedObject); + } catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't add update", eee); + } + DialogHelper.showErrorMessageDialog(view, eee); + } + } + + protected JXTreeTable getTreeTable() { + return view.getAccountsTreeTable(); + } + + protected AccountTreeTableModel getTreeTableModel() { + AccountTreeTableModel model = + (AccountTreeTableModel) getTreeTable().getTreeTableModel(); + return model; + } + + protected Account getMasterAccount(Account account) { + + String number = account.getAccountNumber(); + + Account masterAccount; + + + //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 + try { + + masterAccount = accountService.getMasterAccount(number); + + } catch (LimaException eee) { + if (log.isErrorEnabled()) { + log.error("Can't obtain master account for account number " + number, eee); + } + ErrorHelper.showErrorDialog(view, "Can't obtain master account for account number " + number, eee); + return null; + } + + if (masterAccount == null) { + ErrorHelper.showErrorDialog(_("lima.error.no.masteraccount", number)); + return null; + } + return masterAccount; + } + + protected Account getSelectedAccount() { + + JXTreeTable table = getTreeTable(); + + Account selectedObject = null; + int selectedRow = table.getSelectedRow(); + if (selectedRow > -1) { + TreePath treePath = table.getPathForRow(selectedRow); + AccountTreeTableModel.AccountTreeTableNode lastPathComponent = + (AccountTreeTableModel.AccountTreeTableNode) treePath.getLastPathComponent(); + selectedObject = lastPathComponent.getUserObject(); + } + return selectedObject; + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/SubLedgerForm.jaxx 2011-09-27 08:38:55 UTC (rev 3306) @@ -23,23 +23,27 @@ #L% --> -<JDialog modal="true" - defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="performCancel();"> +<JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" + onWindowClosing="dispose()"> <import> javax.swing.text.Document org.chorem.lima.entity.Account </import> + <AccountViewHandler id='handler' + initializer='getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler()'/> + <Account id="account" javaBean='null'/> <script> <![CDATA[ getRootPane().setDefaultButton(ok); - protected void performCancel() { - setAccount(null); - dispose(); + + @Override + public void dispose() { + setAccount(null); + super.dispose(); } ]]> </script> @@ -47,49 +51,48 @@ <Table> <row> <cell fill="horizontal"> - <JLabel text="lima.common.code"/> + <JLabel text="lima.common.code" labelFor='{numberTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="numberTextField" - text="{getAccount().getAccountNumber()}"/> - <Document javaBean="getNumberTextField().getDocument()" - onInsertUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' - onRemoveUpdate='getAccount().setAccountNumber(getNumberTextField().getText())'/> + text="{account.getAccountNumber()}"/> + <Document initializer="numberTextField.getDocument()" + onInsertUpdate='account.setAccountNumber(numberTextField.getText())' + onRemoveUpdate='account.setAccountNumber(numberTextField.getText())'/> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.label"/> + <JLabel text="lima.common.label" labelFor='{descriptionTextField}'/> </cell> <cell fill="horizontal"> - <JTextField id="descriptionTextField" text="{getAccount().getLabel()}"/> - <Document - javaBean="getDescriptionTextField().getDocument()" - onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/> + <JTextField id="descriptionTextField" text="{account.getLabel()}"/> + <Document initializer="descriptionTextField.getDocument()" + onInsertUpdate='account.setLabel(descriptionTextField.getText())' + onRemoveUpdate='account.setLabel(descriptionTextField.getText())'/> </cell> </row> - <!-- Lien Fiche contact--> <row> <cell fill="horizontal"> - <JLabel text="lima.identity.contact"/> + <JLabel text="lima.identity.contact" labelFor='{thirdPartyTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="thirdPartyTextField" - text="{getAccount().getThirdParty()}"/> + text="{account.getThirdParty()}"/> <Document - javaBean="getThirdPartyTextField().getDocument()" - onInsertUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())' - onRemoveUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())'/> + javaBean="thirdPartyTextField.getDocument()" + onInsertUpdate='account.setThirdParty(thirdPartyTextField.getText())' + onRemoveUpdate='account.setThirdParty(thirdPartyTextField.getText())'/> </cell> </row> <row> - <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + <cell columns="2"> + <JPanel layout='{new GridLayout(1,0)}'> + <JButton text="lima.common.cancel" onActionPerformed="dispose()"/> + <JButton id="ok" text="lima.common.ok" + onActionPerformed="handler.doAddSubLedger(this)"/> + </JPanel> </cell> - <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="dispose()"/> - </cell> </row> </Table> </JDialog> \ No newline at end of file Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx 2011-09-27 08:38:55 UTC (rev 3306) @@ -22,17 +22,11 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JDialog modal="true" - defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="getHandler().performCancel(this);"> +<JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" + onWindowClosing="dispose()"> <import> - javax.swing.text.Document org.chorem.lima.entity.Account - org.chorem.lima.entity.AccountImpl - org.chorem.lima.business.AccountServiceMonitorable - org.chorem.lima.business.LimaException - org.chorem.lima.service.LimaServiceFactory </import> <Account id="account" javaBean='null'/> @@ -41,44 +35,13 @@ initializer='getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler()'/> <script> <![CDATA[ - getRootPane().setDefaultButton(ok); - /*protected void performCancel() { - setAccount(null); - dispose(); + @Override + public void dispose() { + setAccount(null); + super.dispose(); } - - public AccountViewHandler getHandler() { - return getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler(); - } - - protected void performOk() { - if (getMasterAccountTextField().getText().length() != 0) { - AccountServiceMonitorable accountService = - LimaServiceFactory.getService( - AccountServiceMonitorable.class); - Account masterAccount = new AccountImpl(); - try { - System.out.println("setMaster : " - + getMasterAccountTextField().getText() + " to : " - + getAccount().getAccountNumber()); - masterAccount = accountService - .getAccountByNumber(getMasterAccountTextField().getText()); - } catch (LimaException eee) { - log.debug("Can't search account for update : " - + getMasterAccountTextField().getText(), eee); - } - if (masterAccount != null) { - getAccount().setMasterAccount(masterAccount); - } else { - getAccount().setMasterAccount(null); - } - } else { - setAccount(null); - } - dispose(); - }*/ ]]> </script> @@ -86,7 +49,7 @@ <row> <cell fill="horizontal"> - <JLabel text="lima.charts.account.number" labelFor='{numberTextField}'/> + <JLabel text="lima.charts.account.number" labelFor='{numberTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="numberTextField" editable='{false}' @@ -95,18 +58,16 @@ </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.label" labelFor='{descriptionTextField}'/> + <JLabel text="lima.common.label" labelFor='{descriptionTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="descriptionTextField" text="{getAccount().getLabel()}"/> - <!--Document javaBean="getDescriptionTextField().getDocument()" - onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/--> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> + <JLabel text="lima.common.masteraccount" + labelFor='{masterAccountTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="masterAccountTextField" @@ -114,12 +75,13 @@ </cell> </row> <row> - <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="getHandler().performCancel(this)"/> + <cell columns="2"> + <JPanel layout='{new GridLayout(1,0)}'> + <JButton text="lima.common.cancel" onActionPerformed="dispose()"/> + <JButton id="ok" text="lima.common.ok" + onActionPerformed="handler.doUpdateAccount(this)"/> + </JPanel> </cell> - <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="getHandler().performOk(this)"/> - </cell> </row> </Table> </JDialog> \ No newline at end of file Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx 2011-09-27 08:38:55 UTC (rev 3306) @@ -22,17 +22,11 @@ <http://www.gnu.org/licenses/gpl-3.0.html>. #L% --> -<JDialog modal="true" - defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="getHandler().performCancel(this);"> +<JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" + onWindowClosing="dispose()"> <import> - javax.swing.text.Document org.chorem.lima.entity.Account - org.chorem.lima.entity.AccountImpl - org.chorem.lima.business.AccountServiceMonitorable - org.chorem.lima.business.LimaException - org.chorem.lima.service.LimaServiceFactory </import> <Account id="account" javaBean='null'/> @@ -42,39 +36,13 @@ <script> <![CDATA[ - getRootPane().setDefaultButton(ok); - /*protected void performCancel() { - setAccount(null); - dispose(); + @Override + public void dispose() { + setAccount(null); + super.dispose(); } - protected void performOk() { - if (getMasterAccountTextField().getText().length() != 0) { - AccountServiceMonitorable accountService = - LimaServiceFactory.getService( - AccountServiceMonitorable.class); - Account masterAccount = new AccountImpl(); - try { - System.out.println("setMaster : " - + getMasterAccountTextField().getText() + " to : " - + getAccount().getAccountNumber()); - masterAccount = accountService - .getAccountByNumber(getMasterAccountTextField().getText()); - } catch (LimaException eee) { - log.debug("Can't search account for update : " - + getMasterAccountTextField().getText(), eee); - } - if (masterAccount != null) { - getAccount().setMasterAccount(masterAccount); - } else { - getAccount().setMasterAccount(null); - } - } else { - setAccount(null); - } - dispose(); - }*/ ]]> </script> @@ -84,11 +52,8 @@ <JLabel text="lima.common.code" labelFor='{numberTextField}'/> </cell> <cell fill="horizontal"> - <JTextField id="numberTextField" - text="{getAccount().getAccountNumber()}"/> - <Document javaBean="getNumberTextField().getDocument()" - onInsertUpdate='getAccount().setAccountNumber(getNumberTextField().getText())' - onRemoveUpdate='getAccount().setAccountNumber(getNumberTextField().getText())'/> + <JTextField id="numberTextField" editable='{false}' + text="{account.getAccountNumber()}"/> </cell> </row> <row> @@ -97,10 +62,6 @@ </cell> <cell fill="horizontal"> <JTextField id="descriptionTextField" text="{getAccount().getLabel()}"/> - <!--Document - javaBean="getDescriptionTextField().getDocument()" - onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/--> </cell> </row> <!-- Lien Fiche contact--> @@ -109,17 +70,13 @@ <JLabel text="lima.identity.contact" labelFor='{thirdPartyTextField}'/> </cell> <cell fill="horizontal"> - <JTextField id="thirdPartyTextField" - text="{getAccount().getThirdParty()}"/> - <!--Document - javaBean="getThirdPartyTextField().getDocument()" - onInsertUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())' - onRemoveUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())'/--> + <JTextField id="thirdPartyTextField" text="{getAccount().getThirdParty()}"/> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> + <JLabel text="lima.common.masteraccount" + labelFor='{masterAccountTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="masterAccountTextField" @@ -127,12 +84,13 @@ </cell> </row> <row> - <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="getHandler().performCancel(this)"/> + <cell columns="2"> + <JPanel layout='{new GridLayout(1,0)}'> + <JButton text="lima.common.cancel" onActionPerformed="dispose()"/> + <JButton id="ok" text="lima.common.ok" + onActionPerformed="handler.doUpdateSubLedger(this)"/> + </JPanel> </cell> - <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="getHandler().performOk(this)"/> - </cell> </row> </Table> </JDialog> \ No newline at end of file Added: trunk/lima-swing/src/main/resources/META-INF/aop.xml =================================================================== --- trunk/lima-swing/src/main/resources/META-INF/aop.xml (rev 0) +++ trunk/lima-swing/src/main/resources/META-INF/aop.xml 2011-09-27 08:38:55 UTC (rev 3306) @@ -0,0 +1,16 @@ +<!DOCTYPE aspectj PUBLIC + "-//AspectJ//DTD//EN" + "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> +<aspectj> + <weaver options="-verbose"/> + <aspects> + <concrete-aspect name="org.nuiton.profiling.NuitonTraceTestAspect" + extends="org.nuiton.profiling.NuitonTrace"> + <pointcut name="executeMethod" + expression=" + execution(* org.nuiton..*(..)) + || execution(* org.chorem..*(..)) + || execution(* org.hibernate..*(..))"/> + </concrete-aspect> + </aspects> +</aspectj> \ No newline at end of file Property changes on: trunk/lima-swing/src/main/resources/META-INF/aop.xml ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2011-09-27 08:38:55 UTC (rev 3306) @@ -142,6 +142,7 @@ lima.enum.comboboxperiod.fiscalperiod=Fiscal period lima.enum.comboboxperiod.period=Period lima.error.errorpane.htmlmessage=<html><body><b>An application error happened</b>\:<br/>%s</body></html> +lima.error.no.masteraccount=there is no master account for account with number %s lima.financialstatement.accounts=Account list on debit and on credit lima.financialstatement.addfinancialStatementHeadererror=Can't add financialStatementHeader lima.financialstatement.check=Check accounts passing to movement Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-09-27 08:28:48 UTC (rev 3305) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2011-09-27 08:38:55 UTC (rev 3306) @@ -1,5 +1,5 @@ = -lima.account.addaccounterror=Erreur lors l'ajout d'un compte +lima.account.addaccounterror=Erreur lors de l'ajout d'un compte lima.accountsreports.listerror=Erreur lors de la récupération des données de la liste lima.action.commandline.help=Afficher l'aide en console lima.action.fullscreen=Plein Ecran @@ -142,6 +142,7 @@ lima.enum.comboboxperiod.fiscalperiod=Exercice lima.enum.comboboxperiod.period=Période lima.error.errorpane.htmlmessage=<html><body><b>Une erreur s'est produite</b>\:<br/>%s</body></html> +lima.error.no.masteraccount=Il n'existe pas de compte parent pour le numéro de compte %s lima.financialstatement.accounts=Liste de comptes au crédit et au débit lima.financialstatement.addfinancialStatementHeadererror=Erreur lors de l'ajout de l'entête sur la déclaration financière lima.financialstatement.check=Vérification des comptes aux postes
participants (1)
-
tchemit@users.chorem.org