Author: tchemit Date: 2011-09-22 17:26:44 +0200 (Thu, 22 Sep 2011) New Revision: 3301 Url: http://chorem.org/repositories/revision/lima/3301 Log: Continue to simplify and make working account screen... Reformat code optimize third parties add a lots of log (for the moment...) Modified: trunk/lima-swing/src/license/THIRD-PARTY.properties trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaDecoratorProvider.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaModelUtil.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaRendererUtil.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTable.java 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/UpdateAccountForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollBasicComboPopup.java trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollMetalComboUI.java trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-swing/src/license/THIRD-PARTY.properties =================================================================== --- trunk/lima-swing/src/license/THIRD-PARTY.properties 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/license/THIRD-PARTY.properties 2011-09-22 15:26:44 UTC (rev 3301) @@ -6,6 +6,7 @@ # - Apache Software License - Version 2.0 # - Apache Software License 2.0 # - BSD License +# - BSD style # - Bouncy Castle Licence # - Bouncy Castle License # - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 @@ -23,6 +24,7 @@ # - License Agreement for Java Transaction API Classes # - License Agreement for JavaMail(TM) API # - MIT License +# - MPL 1.1 # - Mozilla Public License # - The Apache Software License, Version 2.0 # - The H2 License, Version 1.0 @@ -33,14 +35,13 @@ # Please fill the missing licenses for dependencies : # # -#Thu Aug 18 08:57:41 CEST 2011 +#Thu Sep 22 16:27:42 CEST 2011 antlr--antlr--2.7.6=ANTLR 2 License com.sun.xml.bind--jaxb-impl--2.1.9=Common Development and Distribution License (CDDL) v1.0 / GPLv2 + classpath exception dual license commons-jxpath--commons-jxpath--1.3=The Apache Software License, Version 2.0 commons-net--commons-net--2.0=The Apache Software License, Version 2.0 commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 dom4j--dom4j--1.6.1=jdomlicence -javassist--javassist--3.8.0.GA=GNU Lesser General Public License javax.mail--mail--1.4.1=License Agreement for JavaMail(TM) API javax.transaction--jta--1.1=License Agreement for Java Transaction API Classes org.apache.commons--commons-email--1.2=The Apache Software License, Version 2.0 Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaDecoratorProvider.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaDecoratorProvider.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaDecoratorProvider.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -1,3 +1,27 @@ +/* + * #%L + * Lima :: Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 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; import org.chorem.lima.entity.EntryBook; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaModelUtil.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaModelUtil.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaModelUtil.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -1,3 +1,27 @@ +/* + * #%L + * Lima :: Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 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; /** Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaRendererUtil.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaRendererUtil.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/LimaRendererUtil.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -1,3 +1,27 @@ +/* + * #%L + * Lima :: Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 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; import jaxx.runtime.swing.renderer.DecoratorListCellRenderer; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTable.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTable.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -33,6 +33,7 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +@Deprecated public class AccountTreeTable extends JXTreeTable implements KeyListener, MouseListener { 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-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountTreeTableModel.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -30,12 +30,18 @@ import org.chorem.lima.business.AccountServiceMonitorable; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.ejbinterface.AccountService; import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.service.LimaServiceFactory; -import org.jdesktop.swingx.treetable.AbstractTreeTableModel; +import org.chorem.lima.util.ErrorHelper; +import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode; +import org.jdesktop.swingx.treetable.DefaultTreeTableModel; +import org.jdesktop.swingx.treetable.MutableTreeTableNode; +import org.jdesktop.swingx.treetable.TreeTableNode; import javax.swing.tree.TreePath; +import java.util.Arrays; +import java.util.Enumeration; import java.util.List; import static org.nuiton.i18n.I18n._; @@ -50,143 +56,236 @@ * Last update : $Date$ * By : $Author$ */ -public class AccountTreeTableModel extends AbstractTreeTableModel { +public class AccountTreeTableModel extends DefaultTreeTableModel { /** log. */ private static final Log log = LogFactory.getLog(AccountViewHandler.class); /** Account service. */ - protected final AccountServiceMonitorable accountService; + protected final AccountService accountService; - /** Model constructor. Init account service used here. */ - public AccountTreeTableModel() { - // root - super(new AccountImpl()); - // Gets factory service - accountService = - LimaServiceFactory.getService(AccountServiceMonitorable.class); - } + public class AccountTreeTableNode extends DefaultMutableTreeTableNode { + protected boolean loaded; - @Override - public int getColumnCount() { - return 2; - } + AccountTreeTableNode(Account userObject) { + super(userObject); + } - @Override - public String getColumnName(int column) { - String res = null; - switch (column) { - case 0: - res = _("lima.table.number"); - break; - case 1: - res = _("lima.table.label"); - break; + @Override + public Account getUserObject() { + return (Account) super.getUserObject(); } - return res; - } - @Override - public int getChildCount(Object node) { - int result = 0; - if (node == getRoot()) { - try { - result = accountService.getChildrenAccounts(null).size(); - } catch (LimaException eee) { - log.debug("Can't count child", eee); - } - } else { - Account parentAccount = (Account) node; - try { - result = accountService.getChildrenAccounts(parentAccount).size(); - } catch (LimaException eee) { - log.debug("Can't count child", eee); - } + @Override + public int getChildCount() { + loadChildrenIfRequired(); + return super.getChildCount(); } - 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 eee) { - log.debug("Can't get child", eee); + private void loadChildrenIfRequired() { + if (!loaded) { + loaded = true; + loadChilds(getUserObject()); } - } else { - Account parentAccount = (Account) parent; + } - // FIXME sub account is a collection ? + @Override + public void setParent(MutableTreeTableNode newParent) { + parent = newParent; + } + + private void loadChilds(Account account) { try { - List<Account> subaccounts = - accountService.getChildrenAccounts(parentAccount); - result = subaccounts.get(index); - } catch (LimaException eee) { - log.debug("Can't get child", eee); + if (log.isInfoEnabled()) { + log.info("Loading childs for account " + (account == null ? "Root node" : account.getAccountNumber())); + } + List<Account> childs = + accountService.getChildrenAccounts(account); + for (Account child : childs) { + add(new AccountTreeTableNode(child)); + } + } catch (LimaException e) { + ErrorHelper.showErrorDialog( + "Could not load child of account " + account, e); + } finally { + loaded = true; } } - return result; - } - @Override - public int getIndexOfChild(Object parent, Object child) { - int result = 0; - Account parentAccount = (Account) parent; - Account childAccount = (Account) child; + @Override + public Enumeration<? extends MutableTreeTableNode> children() { + loadChildrenIfRequired(); + return super.children(); + } - if (parent == getRoot()) { - try { - List<Account> allAccounts = - accountService.getChildrenAccounts(null); - result = allAccounts.indexOf(child); - } catch (LimaException eee) { - log.debug("Can't get index child", eee); - } - } else { - // FIXME sub account is a collection ? - try { - List<Account> subaccounts = - accountService.getChildrenAccounts(parentAccount); - result = subaccounts.indexOf(childAccount); - } catch (LimaException eee) { - log.debug("Can't get index child", eee); - } + @Override + public TreeTableNode getChildAt(int childIndex) { + loadChildrenIfRequired(); + return super.getChildAt(childIndex); } - 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; + @Override + public boolean isEditable(int column) { + return false; + } + + @Override + public Object getValueAt(int column) { + Account account = getUserObject(); + + Object result = null; + if (account != null) { + switch (column) { + case 0: + result = account.getAccountNumber(); + break; + case 1: + result = account.getLabel(); + if (log.isInfoEnabled()) { + log.info("Get label '" + result + + "' for account [" + + account.getAccountNumber() + "]"); + } + break; + } } + return result; } - return result; } - @Override - public boolean isCellEditable(Object node, int column) { - return false; - } + /** Model constructor. Init account service used here. */ + public AccountTreeTableModel() { - @Override - public boolean isLeaf(Object node) { - return getChildCount(node) == 0; + setColumnIdentifiers(Arrays.asList(_("lima.table.number"), + _("lima.table.label")) + ); + + setRoot(new AccountTreeTableNode(null)); + // Gets factory service + accountService = + LimaServiceFactory.getService(AccountServiceMonitorable.class); } +// @Override +// public int getColumnCount() { +// return 2; +// } + +// @Override +// public String getColumnName(int column) { +// String res = null; +// switch (column) { +// case 0: +// res = _("lima.table.number"); +// break; +// case 1: +// res = _("lima.table.label"); +// break; +// } +// return res; +// } + +// @Override +// public int getChildCount(Object node) { +// int result = 0; +// if (node == getRoot()) { +// try { +// result = accountService.getChildrenAccounts(null).size(); +// } catch (LimaException eee) { +// log.debug("Can't count child", eee); +// } +// } else { +// Account parentAccount = (Account) node; +// try { +// result = accountService.getChildrenAccounts(parentAccount).size(); +// } catch (LimaException eee) { +// log.debug("Can't count child", eee); +// } +// } +// 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 eee) { +// log.debug("Can't get child", eee); +// } +// } else { +// Account parentAccount = (Account) parent; +// +// // FIXME sub account is a collection ? +// try { +// List<Account> subaccounts = +// accountService.getChildrenAccounts(parentAccount); +// result = subaccounts.get(index); +// } catch (LimaException eee) { +// log.debug("Can't get child", eee); +// } +// } +// 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 eee) { +// log.debug("Can't get index child", eee); +// } +// } else { +// // FIXME sub account is a collection ? +// try { +// List<Account> subaccounts = +// accountService.getChildrenAccounts(parentAccount); +// result = subaccounts.indexOf(childAccount); +// } catch (LimaException eee) { +// log.debug("Can't get index child", eee); +// } +// } +// 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 * @@ -194,7 +293,8 @@ * @param account * @throws LimaException */ - public void addAccount(Account parentAccount, Account 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.fireTreeStructureChanged(path); @@ -208,7 +308,8 @@ * @param account * @throws LimaException */ - public void addSubLedger(Account parentAccount, Account account) throws LimaException { + public void addSubLedger(Account parentAccount, + Account account) throws LimaException { accountService.createSubLedger(parentAccount, account); //FIXME 2011.08.09 vsalaun quick tree refresh, it should refresh only the path changed //modelSupport.fireTreeStructureChanged(path); @@ -226,7 +327,7 @@ //FIXME Force fire for no update if error. Where is the cache ? try { accountService.updateAccount(account); - } catch (LimaBusinessException eee) { + } catch (LimaException eee) { //modelSupport.fireTreeStructureChanged(path); throw new LimaBusinessException("Can't update account : " + account.getAccountNumber(), eee); @@ -250,7 +351,8 @@ * @param account * @throws LimaException */ - public void removeAccount(TreePath path, Account account) throws LimaException { + public void removeAccount(TreePath path, + Account account) throws LimaException { // Calling account service int index = getIndexOfChild( path.getParentPath().getLastPathComponent(), 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 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountView.jaxx 2011-09-22 15:26:44 UTC (rev 3301) @@ -27,60 +27,62 @@ <import> javax.swing.ListSelectionModel + org.jdesktop.swingx.JXTreeTable org.jdesktop.swingx.decorator.HighlighterFactory </import> - <AccountViewHandler id="handler" javaBean="new AccountViewHandler(this)"/> + <AccountViewHandler id="handler" constructorParams="this"/> + <Boolean id="selectedRow" javaBean="false"/> <script> <![CDATA[ - + void $afterCompleteSetup() { + getHandler().init(); + } ]]> </script> <row> <cell fill="both" weightx="1" weighty="1" rows='5'> <JScrollPane> - <AccountTreeTable id="accountsTreeTable" - constructorParams="getHandler()" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - treeTableModel="{new AccountTreeTableModel()}" - highlighters="{HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}"/> - <ListSelectionModel - javaBean="getAccountsTreeTable().getSelectionModel()" - onValueChanged="setSelectedRow(accountsTreeTable.getSelectedRow() != -1)"/> + <JXTreeTable id="accountsTreeTable" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" + treeTableModel="{new AccountTreeTableModel()}" + highlighters="{HighlighterFactory.createSimpleStriping(new java.awt.Color(222,222,222))}"/> + <ListSelectionModel initializer='accountsTreeTable.getSelectionModel()' + onValueChanged="setSelectedRow(accountsTreeTable.getSelectedRow() != -1)"/> </JScrollPane> </cell> <cell fill="horizontal"> <JButton id="addButton" text="lima.charts.account.addAccount" - onActionPerformed="getHandler().addAccount()"/> + onActionPerformed="handler.addAccount()"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="addSubLedger" text="lima.charts.account.addSubLedger" - onActionPerformed="getHandler().addSubLedger()"/> + onActionPerformed="handler.addSubLedger()"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="updateButton" text="lima.common.update" - onActionPerformed="getHandler().updateAccount()" + onActionPerformed="handler.updateAccount()" enabled="{isSelectedRow()}"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="removeButton" text="lima.common.remove" - onActionPerformed="getHandler().removeAccount()" + onActionPerformed="handler.removeAccount()" enabled="{isSelectedRow()}"/> </cell> </row> <row> <cell fill="horizontal"> <JButton id="importButton" text="lima.importexport.import" - onActionPerformed="getHandler().importAccountsChart()"/> + onActionPerformed="handler.importAccountsChart()"/> </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-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/AccountViewHandler.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -25,6 +25,7 @@ package org.chorem.lima.ui.account; +import org.apache.commons.lang.ObjectUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountServiceMonitorable; @@ -32,6 +33,7 @@ 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; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.AccountImpl; import org.chorem.lima.enums.AccountsChartEnum; @@ -44,6 +46,10 @@ import javax.swing.JOptionPane; import javax.swing.tree.TreePath; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import static org.nuiton.i18n.I18n._; @@ -61,9 +67,9 @@ /** log. */ private static final Log log = LogFactory.getLog(AccountViewHandler.class); - protected AccountView view; + protected final AccountView view; - protected AccountServiceMonitorable accountService; + protected AccountService accountService; protected AccountViewHandler(AccountView view) { this.view = view; @@ -72,9 +78,36 @@ accountService = LimaServiceFactory.getService(AccountServiceMonitorable.class); } - /** - * Add new account with account form. - */ + public void init() { + JXTreeTable table = view.getAccountsTreeTable(); + table.addKeyListener(new KeyAdapter() { + /** + * for each action combination key are think + * for extend keyboard and laptop keyboard + */ + @Override + public void keyPressed(KeyEvent e) { + JXTreeTable source = (JXTreeTable) e.getSource(); + // clear row selection with the key: escape + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + if (!source.isEditing()) { + source.clearSelection(); + } + } + } + }); + table.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + JXTreeTable source = (JXTreeTable) e.getSource(); + if (source.rowAtPoint(e.getPoint()) == -1) { + source.clearSelection(); + } + } + }); + } + + /** Add new account with account form. */ public void addAccount() { JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); @@ -196,21 +229,23 @@ * Verifiy if it's an account or a subledger */ public void updateAccount() { - JXTreeTable accountsTreeTable = view.getAccountsTreeTable(); - AccountTreeTableModel accountsTreeTableModel = - (AccountTreeTableModel) accountsTreeTable.getTreeTableModel(); + JXTreeTable table = view.getAccountsTreeTable(); + AccountTreeTableModel tableModel = + (AccountTreeTableModel) table.getTreeTableModel(); // get selected account - int selectedRow = view.getAccountsTreeTable().getSelectedRow(); - TreePath treePath = view.getAccountsTreeTable().getPathForRow(selectedRow); // not null - Account selectedObject = (Account) treePath.getLastPathComponent(); + 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 = view.getAccountsTreeTable().getPathForRow(selectedRow); + treePath = table.getPathForRow(selectedRow); } else { - treePath = new TreePath(accountsTreeTableModel.getRoot()); + treePath = new TreePath(tableModel.getRoot()); } //test if selectedrow is account or ledger if (selectedObject.getGeneralLedger() == null) { @@ -236,7 +271,7 @@ if (selectedObject != null) { // update it try { - accountsTreeTableModel. + tableModel. updateAccount(selectedObject); } catch (LimaException eee) { if (log.isErrorEnabled()) { @@ -246,7 +281,6 @@ } } } - } /** Ask for user to remove for selected account, and remove it if confirmed. */ @@ -330,9 +364,118 @@ @Override public void notifyMethod(String serviceName, String methodeName) { - if (methodeName.contains("importAccounts") || methodeName.contains("importAll") || methodeName.contains("importAsCSV")) { + if (methodeName.contains("importAccounts") || + methodeName.contains("importAll") || + methodeName.contains("importAsCSV")) { refresh(); } } + + 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); + } + 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) { + boolean hasChanged = false; + String oldMasterAccountNumber = account.getMasterAccount() == null ? + "" : + account.getMasterAccount().getAccountNumber(); + + if (ObjectUtils.notEqual(oldMasterAccountNumber, newMasterAccountNumber)) { + + // master account has changed + hasChanged = true; + + // obtain new master account + try { + if (log.isInfoEnabled()) { + log.info("setMaster : " + + newMasterAccountNumber + " to : " + + account.getAccountNumber()); + } + Account masterAccount = accountService + .getAccountByNumber(newMasterAccountNumber); + account.setMasterAccount(masterAccount); + } catch (LimaException eee) { + log.debug("Can't search account for update : " + + newMasterAccountNumber, eee); + } + } + return hasChanged; + } + + protected boolean updateLabel(Account account, String newLabel) { + boolean hasChanged = false; + String oldLabel = account.getLabel(); + if (ObjectUtils.notEqual(oldLabel, newLabel)) { + + // label has changed + hasChanged = true; + account.setLabel(newLabel); + } + return hasChanged; + } + + protected boolean updateThirdParty(Account account, String newThirdParty) { + boolean hasChanged = false; + String oldThirdParty = account.getThirdParty(); + if (ObjectUtils.notEqual(oldThirdParty, newThirdParty)) { + + // thirdparty has changed + hasChanged = true; + account.setThirdParty(newThirdParty); + } + + return hasChanged; + } } 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-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateAccountForm.jaxx 2011-09-22 15:26:44 UTC (rev 3301) @@ -24,7 +24,7 @@ --> <JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="performCancel();"> + onWindowClosing="getHandler().performCancel(this);"> <import> javax.swing.text.Document @@ -37,14 +37,22 @@ <Account id="account" javaBean='null'/> + <AccountViewHandler id='handler' + initializer='getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler()'/> <script> <![CDATA[ getRootPane().setDefaultButton(ok); - protected void performCancel() { + + /*protected void performCancel() { setAccount(null); dispose(); } + + public AccountViewHandler getHandler() { + return getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler(); + } + protected void performOk() { if (getMasterAccountTextField().getText().length() != 0) { AccountServiceMonitorable accountService = @@ -70,7 +78,7 @@ setAccount(null); } dispose(); - } + }*/ ]]> </script> @@ -78,7 +86,7 @@ <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" editable='{false}' @@ -87,18 +95,18 @@ </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()" + <!--Document javaBean="getDescriptionTextField().getDocument()" onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/> + onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/--> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.masteraccount"/> + <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="masterAccountTextField" @@ -107,10 +115,10 @@ </row> <row> <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + <JButton text="lima.common.cancel" onActionPerformed="getHandler().performCancel(this)"/> </cell> <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="performOk()"/> + <JButton id="ok" text="lima.common.ok" onActionPerformed="getHandler().performOk(this)"/> </cell> </row> </Table> 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-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/account/UpdateSubLedgerForm.jaxx 2011-09-22 15:26:44 UTC (rev 3301) @@ -24,7 +24,7 @@ --> <JDialog modal="true" defaultCloseOperation="{JDialog.DO_NOTHING_ON_CLOSE}" - onWindowClosing="performCancel();"> + onWindowClosing="getHandler().performCancel(this);"> <import> javax.swing.text.Document @@ -37,11 +37,15 @@ <Account id="account" javaBean='null'/> + <AccountViewHandler id='handler' + initializer='getContextValue(AccountView.class,JAXXUtil.PARENT).getHandler()'/> + <script> <![CDATA[ getRootPane().setDefaultButton(ok); - protected void performCancel() { + + /*protected void performCancel() { setAccount(null); dispose(); } @@ -70,14 +74,14 @@ setAccount(null); } dispose(); - } + }*/ ]]> </script> <Table> <row> <cell fill="horizontal"> - <JLabel text="lima.common.code"/> + <JLabel text="lima.common.code" labelFor='{numberTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="numberTextField" @@ -89,33 +93,33 @@ </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 + <!--Document javaBean="getDescriptionTextField().getDocument()" onInsertUpdate='getAccount().setLabel(getDescriptionTextField().getText())' - onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().getText())'/> + onRemoveUpdate='getAccount().setLabel(getDescriptionTextField().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()}"/> - <Document + <!--Document javaBean="getThirdPartyTextField().getDocument()" onInsertUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())' - onRemoveUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())'/> + onRemoveUpdate='getAccount().setThirdParty(getThirdPartyTextField().getText())'/--> </cell> </row> <row> <cell fill="horizontal"> - <JLabel text="lima.common.masteraccount"/> + <JLabel text="lima.common.masteraccount" labelFor='{masterAccountTextField}'/> </cell> <cell fill="horizontal"> <JTextField id="masterAccountTextField" @@ -124,10 +128,10 @@ </row> <row> <cell fill="none"> - <JButton text="lima.common.cancel" onActionPerformed="performCancel()"/> + <JButton text="lima.common.cancel" onActionPerformed="getHandler().performCancel(this)"/> </cell> <cell fill="none"> - <JButton id="ok" text="lima.common.ok" onActionPerformed="performOk()"/> + <JButton id="ok" text="lima.common.ok" onActionPerformed="getHandler().performOk(this)"/> </cell> </row> </Table> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollBasicComboPopup.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollBasicComboPopup.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollBasicComboPopup.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -1,3 +1,27 @@ +/* + * #%L + * Lima :: Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 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.widgets; import javax.swing.JComboBox; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollMetalComboUI.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollMetalComboUI.java 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/java/org/chorem/lima/widgets/ScrollMetalComboUI.java 2011-09-22 15:26:44 UTC (rev 3301) @@ -1,3 +1,27 @@ +/* + * #%L + * Lima :: Swing + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2011 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 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.widgets; import javax.swing.plaf.basic.ComboPopup; Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2011-09-22 15:24:35 UTC (rev 3300) +++ trunk/lima-swing/src/main/resources/log4j.properties 2011-09-22 15:26:44 UTC (rev 3301) @@ -37,4 +37,5 @@ log4j.appender.file.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n # package level -log4j.logger.org.chorem.lima=INFO \ No newline at end of file +log4j.logger.org.chorem.lima=INFO +log4j.logger.org.nuiton.topia=INFO \ No newline at end of file