This is an automated email from the git hooks/post-receive script. New commit to branch feature/1242-no-account-research-exception in repository lima. See http://git.chorem.org/lima.git commit 5cf4e2592433bca78dc06b142fb550679f7c3096 Author: dcosse <cosse@codelutin.com> Date: Mon Sep 28 17:15:06 2015 +0200 refs #1242 Refactoring pour plus de lisibilité --- .../ui/financialtransaction/AccountColumn.java | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java index ec431f3..d916219 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java @@ -48,35 +48,51 @@ public class AccountColumn extends AbstractColumn<FinancialTransactionTableModel @Override public boolean setValueAt(Object value, int row) { Entry entry = tableModel.get(row); - // In case of Account field being feed up but no account was selected - // the value is a String instead of Account. - Account account = value == null ? null : value instanceof Account ? (Account) value : null; - boolean update = ((entry.getAccount()) == null != (account == null)) - || (entry.getAccount() != null - && !entry.getAccount().getAccountNumber().equals(account.getAccountNumber())); + + Account selectedAccount = getSelectedAccount(value); + Account previousAccount = entry.getAccount(); + + boolean update = isValueChange(selectedAccount, previousAccount); + if (update) { - Account previousAccount = entry.getAccount(); - entry.setAccount(account); - if (!tableModel.updateEntry(entry)) { - update = revertAccountChange(entry, previousAccount); + entry.setAccount(selectedAccount); + boolean updateSucceed = !tableModel.updateEntry(entry); + if (updateSucceed) { + setDescriptionFieldIfNone(entry, selectedAccount); } else { - setDescripntionFieldIfNone(entry, account); + update = revertAccountChange(entry, previousAccount); } } return update; } - protected void setDescripntionFieldIfNone(Entry entry, Account account) { + protected Account getSelectedAccount(Object value) { + Account newAccount = null; + if (value != null && value instanceof Account) { + newAccount = (Account) value; + } + return newAccount; + } + + protected boolean isValueChange(Account newAccount, Account previousAccount) { + boolean update; + if (previousAccount == null) { + update = newAccount != null; + } else { + update = newAccount == null || !previousAccount.getAccountNumber().equals(newAccount.getAccountNumber()); + } + return update; + } + + protected void setDescriptionFieldIfNone(Entry entry, Account account) { if (StringUtils.isBlank(entry.getDescription()) && account != null && StringUtils.isNotBlank(account.getLabel())) { entry.setDescription(account.getLabel()); } } protected boolean revertAccountChange(Entry entry, Account previousAccount) { - boolean update; entry.setAccount(previousAccount); - update = false; - return update; + return false; } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.