Author: sbavencoff Date: 2014-07-09 11:02:03 +0200 (Wed, 09 Jul 2014) New Revision: 3839 Url: http://forge.chorem.org/projects/lima/repository/revisions/3839 Log: refs #557 : fix locked entry book exception Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/LockedEntryBookException.java Removed: trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntryException.java Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/CreditColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DebitColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DescriptionColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/VoucherColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 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-business/src/main/java/org/chorem/lima/business/AccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/AccountingRules.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -79,9 +79,9 @@ * Entry rules * * @param entry - * @throws FinancialTransactionException + * @throws LockedEntryBookException */ - void updateEntryRules(Entry entry, Entry entryOld) throws EntryException; + void updateEntryRules(Entry entry, Entry entryOld) throws LockedEntryBookException; void updateFinancialTransactionDateRules(FinancialTransaction financialTransaction, FinancialTransaction financialTransactionOld) throws FinancialTransactionException; Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/accountingrules/DefaultAccountingRules.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -29,13 +29,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.FiscalPeriodException; import org.chorem.lima.business.InvalidAccountNumberException; import org.chorem.lima.business.LimaInterceptor; +import org.chorem.lima.business.UsedAccountException; import org.chorem.lima.business.UsedEntryBookException; -import org.chorem.lima.business.UsedAccountException; import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.ClosedPeriodicEntryBook; @@ -240,7 +240,7 @@ * - third, the new choice entrybook belong to a blocked closedPeriodicEntryBook */ @Override - public void updateEntryRules(Entry entry, Entry entryOld) throws EntryException { + public void updateEntryRules(Entry entry, Entry entryOld) throws LockedEntryBookException { FinancialPeriodTopiaDao financialPeriodTopiaDao = getDaoHelper().getFinancialPeriodDao(); FinancialPeriod financialPeriod = financialPeriodTopiaDao.findByDate(entry.getFinancialTransaction().getTransactionDate()); @@ -253,7 +253,7 @@ closedPeriodicEntryBookTopiaDao.findByEntryBookAndFinancialPeriod( entryOld.getFinancialTransaction().getEntryBook(), financialPeriod); if (closedPeriodicEntryBook.isLocked()) { - throw new EntryException(entryOld, "lima-Business.defaultaccountingrules.updateentryerror"); + throw new LockedEntryBookException(closedPeriodicEntryBook); } } @@ -264,7 +264,7 @@ // Check 2 & 3 cases if (closedPeriodicEntryBook2.isLocked()) { - throw new EntryException(entry, "lima-Business.defaultaccountingrules.updateentryerror"); + throw new LockedEntryBookException(closedPeriodicEntryBook2); } } Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/ejb/FinancialTransactionServiceImpl.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -35,7 +35,7 @@ import org.chorem.lima.beans.FinancialTransactionCondition; import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.business.AccountingRules; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.LimaConfig; import org.chorem.lima.business.LimaException; @@ -485,7 +485,7 @@ * update entry, calculate amount of the financial transaction. */ @Override - public void updateEntry(Entry entry) throws EntryException { + public void updateEntry(Entry entry) throws LockedEntryBookException { AccountingRules accountingRules = LimaConfig.getInstance().getAccountingRules(); Deleted: trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntryException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntryException.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/EntryException.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -1,55 +0,0 @@ -package org.chorem.lima.business; - -/* - * #%L - * Lima :: business API - * %% - * Copyright (C) 2008 - 2014 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% - */ - -import org.chorem.lima.entity.Entry; - -/** - * @author Sylvain Bavencoff <bavencoff@codelutin.com> - */ -public class EntryException extends LimaException { - - protected Entry entry; - - public EntryException(String message) { - super(message); - } - - public EntryException(String message, Throwable cause) { - super(message, cause); - } - - public EntryException(Entry entry, String message) { - super(message); - this.entry = entry; - } - - public EntryException(Entry entry, String message, Throwable cause) { - super(message, cause); - this.entry = entry; - } - - public Entry getEntry() { - return entry; - } -} Added: trunk/lima-business-api/src/main/java/org/chorem/lima/business/LockedEntryBookException.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/LockedEntryBookException.java (rev 0) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/LockedEntryBookException.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -0,0 +1,18 @@ +package org.chorem.lima.business; + +import org.chorem.lima.business.utils.ClosedPeriodicEntryBookException; +import org.chorem.lima.entity.ClosedPeriodicEntryBook; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class LockedEntryBookException extends ClosedPeriodicEntryBookException { + + public LockedEntryBookException(ClosedPeriodicEntryBook closedPeriodicEntryBook) { + super(closedPeriodicEntryBook, ""); + } + + public LockedEntryBookException(ClosedPeriodicEntryBook closedPeriodicEntryBook, Throwable cause) { + super(closedPeriodicEntryBook, "", cause); + } +} Modified: trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java =================================================================== --- trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-business-api/src/main/java/org/chorem/lima/business/api/FinancialTransactionService.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -27,7 +27,7 @@ import org.chorem.lima.beans.FinancialTransactionCondition; import org.chorem.lima.beans.LetteringFilter; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Entry; @@ -76,7 +76,7 @@ Entry createEntry(Entry entry) throws FinancialTransactionException; - void updateEntry(Entry entry) throws EntryException; + void updateEntry(Entry entry) throws LockedEntryBookException; void removeEntry(Entry entry) throws FinancialTransactionException; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -25,6 +25,8 @@ */ import com.google.common.collect.Lists; +import org.chorem.lima.LimaConfig; +import org.chorem.lima.util.ErrorHelper; import javax.swing.table.AbstractTableModel; import java.util.Collection; @@ -44,13 +46,17 @@ protected List<Column<AbstractLimaTableModel<E>>> columns; protected Comparator<E> comparator; - + + protected ErrorHelper errorHelper; + public AbstractLimaTableModel() { values = Lists.newArrayList(); columns = Lists.newArrayList(); + errorHelper = new ErrorHelper(LimaConfig.getInstance()); + initColumn(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/FinancialTransactionTableModel.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -26,7 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.utils.EntryComparator; @@ -46,6 +46,8 @@ import java.util.Collection; import java.util.List; +import static org.nuiton.i18n.I18n.t; + /** * @author Sylvain Bavencoff <bavencoff@codelutin.com> */ @@ -216,11 +218,23 @@ return e1.getFinancialTransaction().equals(e2.getFinancialTransaction()); } - public void updateEntry(Entry entry) throws EntryException { + public boolean updateEntry(Entry entry) { + boolean updated = false; + if (log.isDebugEnabled()) { log.debug("Update Entry"); } - financialTransactionService.updateEntry(entry); + try { + financialTransactionService.updateEntry(entry); + updated = true; + } catch (LockedEntryBookException e) { + errorHelper.showErrorMessage(t("lima.ui.entry.update.closed.entryBook.error", + e.getClosedPeriodicEntryBook().getEntryBook().getCode(), + e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); + } + return updated; } public void updateTransaction(FinancialTransaction transaction) throws FinancialTransactionException { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; @@ -56,11 +55,11 @@ && account != null && !entry.getAccount().getAccountNumber().equals(account.getAccountNumber())); if (update) { - try { - entry.setAccount(account); - tableModel.updateEntry(entry); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + Account previousAccount = entry.getAccount(); + entry.setAccount(account); + if (!tableModel.updateEntry(entry)) { + entry.setAccount(previousAccount); + update = false; } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/CreditColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/CreditColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/CreditColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -54,13 +53,16 @@ BigDecimal credit= (BigDecimal) value; boolean update = (credit.signum() > 0 && (entry.isDebit() || entry.getAmount().compareTo(credit) != 0)); if (update) { - try { - entry.setAmount(credit); - entry.setDebit(false); - tableModel.updateEntry(entry); + BigDecimal previousAmount = entry.getAmount(); + boolean previousDebit = entry.isDebit(); + entry.setAmount(credit); + entry.setDebit(false); + if(tableModel.updateEntry(entry)) { tableModel.fireTransaction(entry.getFinancialTransaction()); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } else { + entry.setAmount(previousAmount); + entry.setDebit(previousDebit); + update = false; } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DebitColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DebitColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DebitColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -54,13 +53,16 @@ BigDecimal debit = (BigDecimal) value; boolean update = (debit.signum() > 0 && (!entry.isDebit() || entry.getAmount().compareTo(debit) != 0)); if (update) { - try { - entry.setAmount(debit); - entry.setDebit(true); - tableModel.updateEntry(entry); + BigDecimal previousAmount = entry.getAmount(); + boolean previousDebit = entry.isDebit(); + entry.setAmount(debit); + entry.setDebit(true); + if(tableModel.updateEntry(entry)) { tableModel.fireTransaction(entry.getFinancialTransaction()); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } else { + entry.setAmount(previousAmount); + entry.setDebit(previousDebit); + update = false; } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DescriptionColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DescriptionColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DescriptionColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -52,11 +51,11 @@ boolean update = (entry.getDescription() == null ||entry.getDescription().compareTo(description) != 0); if (update) { - try { - entry.setDescription(description); - tableModel.updateEntry(entry); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + String previousDescription = entry.getDescription(); + entry.setDescription(description); + if (!tableModel.updateEntry(entry)) { + entry.setDescription(previousDescription); + update = false; } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -25,11 +25,12 @@ package org.chorem.lima.ui.financialtransaction; +import com.google.common.collect.Maps; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.EntryBookService; @@ -48,7 +49,14 @@ import org.chorem.lima.ui.common.FinancialTransactionTableModel; import org.chorem.lima.util.ErrorHelper; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.TableColumnModelEvent; @@ -62,6 +70,7 @@ import java.math.BigDecimal; import java.util.Date; import java.util.List; +import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -341,27 +350,30 @@ TableCellEditor editor = table.getCellEditor(); editor.stopCellEditing(); } - try { - Entry entry = tableModel.get(rowSelected); - FinancialTransaction transaction = entry.getFinancialTransaction(); - BigDecimal credit = transaction.getAmountCredit(); - BigDecimal debit = transaction.getAmountDebit(); - if (entry.isDebit()) { - debit = debit.subtract(entry.getAmount()); - } else { - credit = credit.subtract(entry.getAmount()); - } + Entry entry = tableModel.get(rowSelected); + FinancialTransaction transaction = entry.getFinancialTransaction(); + BigDecimal credit = transaction.getAmountCredit(); + BigDecimal debit = transaction.getAmountDebit(); + if (entry.isDebit()) { + debit = debit.subtract(entry.getAmount()); + } else { + credit = credit.subtract(entry.getAmount()); + } - BigDecimal balance = credit.subtract(debit); - entry.setAmount(balance.abs()); - entry.setDebit(balance.signum() > 0); - tableModel.updateEntry(entry); + BigDecimal balance = credit.subtract(debit); + + BigDecimal previousAmount = entry.getAmount(); + boolean previousDebit = entry.isDebit(); + entry.setAmount(balance.abs()); + entry.setDebit(balance.signum() > 0); + if (tableModel.updateEntry(entry)) { int firstRow = tableModel.indexOf(transaction); int lastRow = firstRow + transaction.sizeEntry() - 1; tableModel.fireTableRowsUpdated(firstRow, lastRow); view.setBalance(true); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } else { + entry.setAmount(previousAmount); + entry.setDebit(previousDebit); } } } @@ -683,20 +695,25 @@ int selectedRow = table.getSelectedRow(); int selectedColumn = table.getSelectedColumn(); if (selectedRow >= 0 && (selectedColumn == 1 || selectedColumn == 3)) { + + Entry entrySource = tableModel.get(selectedRow); + FinancialTransaction transaction = entrySource.getFinancialTransaction(); + + Map<Entry, String> previousValuesMap = Maps.newHashMap(); try { - Entry entrySource = tableModel.get(selectedRow); - FinancialTransaction transaction = entrySource.getFinancialTransaction(); for (Entry entryTarget : transaction.getEntry()) { if (entrySource != entryTarget) { switch (selectedColumn) { case 1: if (!StringUtils.equals(entryTarget.getVoucher(), entrySource.getVoucher())) { + previousValuesMap.put(entryTarget, entryTarget.getVoucher()); entryTarget.setVoucher(entrySource.getVoucher()); financialTransactionService.updateEntry(entryTarget); } break; case 3: if (!StringUtils.equals(entryTarget.getDescription(), entrySource.getDescription())) { + previousValuesMap.put(entryTarget, entryTarget.getDescription()); entryTarget.setDescription(entrySource.getDescription()); financialTransactionService.updateEntry(entryTarget); } @@ -708,8 +725,25 @@ int lastRow = firstRow + transaction.sizeEntry() - 1; tableModel.fireTableRowsUpdated(firstRow, lastRow); table.editCellAt(selectedRow, selectedColumn); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } catch (LockedEntryBookException e) { + errorHelper.showErrorMessage(t("lima.ui.entries.assign.closed.entryBook.error", + e.getClosedPeriodicEntryBook().getEntryBook().getCode(), + e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); + // restaure prévious values + for (Map.Entry<Entry, String> mapEntry : previousValuesMap.entrySet()) { + Entry entry = mapEntry.getKey(); + String previousValue = mapEntry.getValue(); + switch (selectedColumn) { + case 1: + entry.setVoucher(previousValue); + break; + case 3: + entry.setDescription(previousValue); + break; + } + } } } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -53,11 +52,10 @@ boolean update = (entry.getLettering() == null || entry.getLettering().compareTo(letter) != 0); if (update) { - try { - entry.setLettering(letter); - tableModel.updateEntry(entry); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + String previousLettering = entry.getLettering(); + entry.setLettering(letter); + if (!tableModel.updateEntry(entry)) { + entry.setLettering(previousLettering); } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/VoucherColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/VoucherColumn.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/VoucherColumn.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -24,7 +24,6 @@ * #L% */ -import org.chorem.lima.business.EntryException; import org.chorem.lima.entity.Entry; import org.chorem.lima.ui.common.AbstractColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -53,11 +52,10 @@ boolean update = (entry.getVoucher() == null || entry.getVoucher().compareTo(voucher) != 0); if (update) { - try { - entry.setVoucher(voucher); - tableModel.updateEntry(entry); - } catch (EntryException e) { - errorHelper.showErrorMessage(e.getMessage()); + String previousVoucher = entry.getVoucher(); + entry.setVoucher(voucher); + if (!tableModel.updateEntry(entry)) { + entry.setVoucher(previousVoucher); } } return update; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedViewHandler.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -28,7 +28,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; -import org.chorem.lima.business.EntryException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryImpl; @@ -37,7 +36,13 @@ import org.chorem.lima.ui.financialtransaction.FinancialTransactionDefaultTable; import org.chorem.lima.util.ErrorHelper; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JOptionPane; +import javax.swing.KeyStroke; +import javax.swing.ListSelectionModel; import javax.swing.table.TableCellEditor; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; @@ -304,21 +309,22 @@ TableCellEditor editor = table.getCellEditor(); editor.stopCellEditing(); } - try { - Entry entry = tableModel.get(rowSelected); - FinancialTransaction transaction = entry.getFinancialTransaction(); - BigDecimal credit = transaction.getAmountCredit(); - BigDecimal debit = transaction.getAmountDebit(); - if (entry.isDebit()) { - debit = debit.subtract(entry.getAmount()); - } else { - credit = credit.subtract(entry.getAmount()); - } + Entry entry = tableModel.get(rowSelected); + FinancialTransaction transaction = entry.getFinancialTransaction(); + BigDecimal credit = transaction.getAmountCredit(); + BigDecimal debit = transaction.getAmountDebit(); + if (entry.isDebit()) { + debit = debit.subtract(entry.getAmount()); + } else { + credit = credit.subtract(entry.getAmount()); + } - BigDecimal balance = credit.subtract(debit); - entry.setAmount(balance.abs()); - entry.setDebit(balance.signum() > 0); - tableModel.updateEntry(entry); + BigDecimal balance = credit.subtract(debit); + BigDecimal previousAmount = entry.getAmount(); + boolean previousDebit = entry.isDebit(); + entry.setAmount(balance.abs()); + entry.setDebit(balance.signum() > 0); + if (tableModel.updateEntry(entry)) { int firstRow = tableModel.indexOf(transaction); int lastRow = firstRow + transaction.sizeEntry() - 1; tableModel.fireTableRowsUpdated(firstRow, lastRow); @@ -328,10 +334,10 @@ selectionModel.setSelectionInterval(rowSelected, rowSelected); table.changeSelection(rowSelected, 1, false, false); table.editCellAt(rowSelected, 1); - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } else { + entry.setAmount(previousAmount); + entry.setDebit(previousDebit); } - } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2014-07-09 09:02:03 UTC (rev 3839) @@ -25,12 +25,13 @@ package org.chorem.lima.ui.lettering; +import com.google.common.collect.Maps; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; import org.chorem.lima.beans.LetteringFilterImpl; -import org.chorem.lima.business.EntryException; +import org.chorem.lima.business.LockedEntryBookException; import org.chorem.lima.business.FinancialTransactionException; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.api.EntryBookService; @@ -44,7 +45,12 @@ import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; -import javax.swing.*; +import javax.swing.AbstractAction; +import javax.swing.ActionMap; +import javax.swing.InputMap; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.KeyStroke; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; @@ -52,6 +58,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -481,16 +488,28 @@ LetteringTableModel tableModel = view.getTableModel(); + Map<Entry, String> previousLetterMap = Maps.newHashMap(); + try { for (int indexEntry : entrieSelected) { Entry entry = tableModel.get(indexEntry); + previousLetterMap.put(entry, entry.getLettering()); entry.setLettering(newLetters); financialTransactionService.updateEntry(entry); tableModel.fireTableRowsUpdated(indexEntry, indexEntry); } - } catch (EntryException e) { - errorHelper.showErrorMessage(t(e.getMessage())); + } catch (LockedEntryBookException e) { + errorHelper.showErrorMessage(t("lima.ui.entries.letter.closed.entryBook.error", + e.getClosedPeriodicEntryBook().getEntryBook().getCode(), + e.getClosedPeriodicEntryBook().getEntryBook().getLabel(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getBeginDate(), + e.getClosedPeriodicEntryBook().getFinancialPeriod().getEndDate())); + + // restaure prévious letters + for (Map.Entry<Entry, String> mapEntry : previousLetterMap.entrySet()) { + mapEntry.getKey().setLettering(mapEntry.getValue()); + } } } 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 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-07-09 09:02:03 UTC (rev 3839) @@ -359,6 +359,9 @@ lima.ui.common.remove=Remove lima.ui.common.solde= lima.ui.common.update=Update +lima.ui.entries.assign.closed.entryBook.error= +lima.ui.entries.letter.closed.entryBook.error= +lima.ui.entry.update.closed.entryBook.error= lima.ui.entryBook.delete.used.error=Can't delete entry book %2$s (%1$s) because exist financcial transactions in this entry book. lima.ui.entrybook.add= lima.ui.entrybook.code= 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 2014-07-09 07:30:32 UTC (rev 3838) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-07-09 09:02:03 UTC (rev 3839) @@ -341,6 +341,9 @@ lima.ui.common.remove=Supprimer lima.ui.common.solde=Solde lima.ui.common.update=Modifier +lima.ui.entries.assign.closed.entryBook.error=Impossible d'affecter cette valeur a l'ensemble des entrés de la transaction car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY +lima.ui.entries.letter.closed.entryBook.error=Impossible de modifier le lettrage des ces entrés car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY +lima.ui.entry.update.closed.entryBook.error=Impossible de modifier cette entré car le jounal %2$s (%1$s) est cloturé pour la période du %3$te %3$tB %3$tY au %4$te %4$tB %4$tY lima.ui.entryBook.delete.used.error=Imposible de supprimer le journal %2$s (%1$s) car Il existe des transactioins sur ce journal. lima.ui.entrybook.add=Ajout de journal lima.ui.entrybook.code=Code