This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository lima. See http://git.chorem.org/lima.git commit 79ebf7d220ed2688a10b0ad1e421fabd7d706e2c 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 | 44 +++++++++++++++------- 1 file changed, 31 insertions(+), 13 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 e8484d0..a76504d 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 @@ -50,19 +50,20 @@ 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 { setDescriptionFieldIfNone(entry, account); + update = revertAccountChange(entry, previousAccount); } } @@ -70,15 +71,32 @@ public class AccountColumn extends AbstractColumn<FinancialTransactionTableModel } protected void setDescriptionFieldIfNone(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>.