Author: mallon Date: 2012-07-18 11:50:01 +0200 (Wed, 18 Jul 2012) New Revision: 3535 Url: http://chorem.org/repositories/revision/lima/3535 Log: Apr?\195?\168s la revue de code : Corrections sur les imports de type "javax.swing.*", des logs, des commentaires non-javadoc sur les m?\195?\169thodes publiques, et de la m?\195?\169thode de suppression des ?\195?\169l?\195?\169ments de la liste des deux mod?\195?\168les d?\195?\169l?\195?\169gu?\195?\169s dans le lettrage. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -26,8 +26,6 @@ package org.chorem.lima.ui.financialtransaction; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.FinancialTransaction; @@ -43,11 +41,13 @@ import org.jdesktop.swingx.decorator.HighlightPredicate; import org.jdesktop.swingx.decorator.Highlighter; -import javax.swing.*; +import javax.swing.SwingWorker; +import javax.swing.UIManager; import javax.swing.border.LineBorder; import javax.swing.plaf.BorderUIResource; import javax.swing.text.JTextComponent; -import java.awt.*; +import java.awt.Color; +import java.awt.Component; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -72,8 +72,6 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3133690382049594727L; - private static final Log log = LogFactory.getLog(FinancialTransactionViewHandler.class); - protected FinancialTransactionViewHandler handler; private int x_tab; @@ -84,7 +82,7 @@ this.handler = handler; //Change border of cell focus for a better visibility - UIManager.put("Table.focusCellHighlightBorder",new BorderUIResource(new LineBorder(new Color(0,0,0), 2))); + UIManager.put("Table.focusCellHighlightBorder", new BorderUIResource(new LineBorder(new Color(0, 0, 0), 2))); addKeyListener(new MyKeyAdapter()); @@ -157,14 +155,14 @@ final FinancialTransactionViewHandler handler = getHandler(); - /*Allow to block access to the first row when touch enter pressed, if selection on + /*Allow to block access to the first row when key enter pressed, if selection on * last row*/ if (e.getKeyCode() == KeyEvent.VK_ENTER){ - int selectedRow = table.getSelectedRow()+1; + int selectedRow = table.getSelectedRow(); if(selectedRow != table.getRowCount()){ - table.setRowSelectionInterval(table.getSelectedRow(), table.getSelectedRow()); + table.setRowSelectionInterval(selectedRow+1, selectedRow+1); } else { - table.setRowSelectionInterval(table.getSelectedRow()-1, table.getSelectedRow()-1); + table.setRowSelectionInterval(selectedRow, selectedRow); } } @@ -245,7 +243,6 @@ FinancialTransaction financialTransaction = (FinancialTransaction) object; if (CollectionUtils.isEmpty(financialTransaction.getEntry())) { handler.addEntry(); - //setColumnSelectionInterval(1, 1); setColumnSelectionInterval(0, 0); } } @@ -282,7 +279,6 @@ } } else { handler.addEntry(); - //setColumnSelectionInterval(1, 1); setColumnSelectionInterval(0, 0); y_tab++; // positionne la sélection sur la nouvelle ligne créée @@ -322,23 +318,17 @@ boolean result = super.editCellAt(row, column, e); int lengthCellValue; if (getEditorComponent() != null) - if (getEditorComponent() instanceof JXDatePicker) { - if (log.isInfoEnabled()) { - log.info("Test sur JXDatePicker"); - } - lengthCellValue = ((JXDatePicker)getEditorComponent()).getEditor().getText().length(); - if (lengthCellValue != -1) { - ((JXDatePicker)getEditorComponent()).getEditor().select(lengthCellValue, lengthCellValue); - } - } else if ( (getEditorComponent() instanceof JTextComponent)) { - if (log.isInfoEnabled()) { - log.info("Test sur JTextComponent / Number editor"); - } - lengthCellValue = ((JTextComponent)getEditorComponent()).getText().length(); - if (lengthCellValue != -1) { - ((JTextComponent)getEditorComponent()).select(lengthCellValue, lengthCellValue); - } + if (getEditorComponent() instanceof JXDatePicker) { + lengthCellValue = ((JXDatePicker)getEditorComponent()).getEditor().getText().length(); + if (lengthCellValue != -1) { + ((JXDatePicker)getEditorComponent()).getEditor().select(lengthCellValue, lengthCellValue); } + } else if ( (getEditorComponent() instanceof JTextComponent)) { + lengthCellValue = ((JTextComponent)getEditorComponent()).getText().length(); + if (lengthCellValue != -1) { + ((JTextComponent)getEditorComponent()).select(lengthCellValue, lengthCellValue); + } + } return result; } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -262,6 +262,26 @@ return result; } + /**Get the precedent entry of the entry passed in parameter*/ + public Entry getPrecedentEntry(Entry entry) { + for (Object transactionOrEntry : transactionAndEntries) { + if(transactionOrEntry instanceof Entry) { + if (transactionOrEntry.equals(entry)) { + //'-1' for precedent... + return (Entry)getObjectAt(transactionAndEntries.indexOf(transactionOrEntry)-1); + } + } + } + return null; + } + + public Object getObjectAt(int row) { + if (row == -1) { + return null; + } + return transactionAndEntries.get(row); + } + /** to modifiy financialtransaction or entry */ @Override public void setValueAt(Object value, int row, int column) { 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 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -44,7 +44,9 @@ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.*; +import javax.swing.JComboBox; +import javax.swing.JOptionPane; +import javax.swing.ListSelectionModel; import java.awt.event.ItemEvent; import java.math.BigDecimal; import java.util.ArrayList; @@ -348,34 +350,39 @@ // real selected row or selected transaction row ? int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { - int firstentryBookrow = tableModel.getFirstEntry(indexSelectedRow); + //int firstentryBookrow = tableModel.getFirstEntry(indexSelectedRow); + Entry precedentEntry = tableModel.getPrecedentEntry((Entry)tableModel.getObjectAt(indexSelectedRow)); + if (log.isInfoEnabled()) { + log.info("Selected row : " + indexSelectedRow); + } + String defaultVoucher = null; String defaultDescription = null; - String defaultAccount = null; + + if (precedentEntry != null) { + defaultVoucher = precedentEntry.getVoucher(); + defaultDescription = precedentEntry.getDescription(); + } + + // creates the new entry + Entry entry = new EntryImpl(); + entry.setVoucher(defaultVoucher); + entry.setDescription(defaultDescription); + + String defaultAccount; //Actual (2012) tva percentage : 19,6% BigDecimal tvaPercentAdd = new BigDecimal(0.196); BigDecimal tvaTax = null; - if (firstentryBookrow != -1) { - defaultVoucher = (String) tableModel.getValueAt(firstentryBookrow, 1); - defaultDescription = (String) tableModel.getValueAt(firstentryBookrow, 3); - //Calculation of tva tax only if first entry is a sale - defaultAccount = (String) tableModel.getValueAt(firstentryBookrow, 2); + //Calculation of tva tax only if first entry is a sale + if (precedentEntry.getAccount()!= null){ + defaultAccount = precedentEntry.getAccount().getAccountNumber(); if (defaultAccount.equals("410") || defaultAccount.equals("418")){ - if (log.isInfoEnabled()) { - log.info("Calcul de la TVA"); - } - tvaTax = ((BigDecimal)tableModel.getValueAt(firstentryBookrow, 4)).multiply(tvaPercentAdd); + tvaTax = (precedentEntry.getAmount()).multiply(tvaPercentAdd); } - } - // creates the new entry - Entry entry = new EntryImpl(); - entry.setVoucher(defaultVoucher); - entry.setDescription(defaultDescription); - //Set tva tax on the debit of the new entry if (tvaTax != null){ entry.setAmount(tvaTax); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -23,9 +23,6 @@ * #L% */ -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.math.BigDecimal; @@ -46,7 +43,6 @@ public static final String UNLETTRED_PROPERTY = "unLettred"; protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); - private static final Log log = LogFactory.getLog(LetteringViewHandler.class); protected LetteringTableModel model; protected boolean lettred; @@ -131,7 +127,10 @@ firePropertyChange(SOLDE_PROPERTY, oldSolde, this.solde); } - //Allow to add / subtract credit / debit and balance + /**Allow to add / subtract credit / debit and balance + * @param amount debit or credit + * @param debit it indicate if amount is debit or not + * */ public void balanceCalculation(BigDecimal amount, boolean debit){ BigDecimal debitVal = debit ? amount : BigDecimal.ZERO; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -24,11 +24,9 @@ */ import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Entry; -import javax.swing.*; +import javax.swing.DefaultListSelectionModel; import java.util.ArrayList; import java.util.List; @@ -37,14 +35,15 @@ */ public class LetteringSelectionModel extends DefaultListSelectionModel { - private static final Log log = LogFactory.getLog(LetteringSelectionModel.class); protected LetteringTableModel letteringTableModel; protected LetteringEditModel editModel; protected int lineSelected; protected List<Entry> selectedRows = new ArrayList<Entry>(); - //Modele de selection du tableau lors de la selection d une entree lettree - + /**Table selection model when entry selected is lettered + * @param letteringTableModel model of the table + * @param editModel model managing update of debit / credit / balance + * */ public LetteringSelectionModel(LetteringTableModel letteringTableModel, LetteringEditModel editModel) { this.letteringTableModel = letteringTableModel; this.editModel = editModel; @@ -52,31 +51,18 @@ //@Override public void addSelectionInterval(int row, int column){ - if (log.isInfoEnabled()) { - log.info("addSelectionInterval"); - } setSelectionInterval(row, column); } //@Override public void removeSelectionInterval(int row, int column){ - if (log.isInfoEnabled()) { - log.info("removeSelectionInterval"); - } - //setSelectionInterval(row, column); } @Override public void setSelectionInterval(int row, int column){ - if (log.isInfoEnabled()) { - log.info("setSelectionInterval"); - } if ( selectedRows.isEmpty() || !searchRowSelected(row)){ - if (log.isInfoEnabled()) { - log.info("Selection ligne..."); - } resetAttribute(); super.clearSelection(); @@ -105,7 +91,8 @@ } /**PropertyChange on editModel in the handler, and, there, - * set values on it. + * set values it. + * @param lettering state of attributes lettered and unlettered in editModel * */ public void updateBalanceAndLetteringButton(boolean lettering){ @@ -122,9 +109,7 @@ //to reinitialize model attribute public void resetAttribute(){ - for (int i = 0; i < selectedRows.size(); i ++){ - selectedRows.remove(i); - } + selectedRows.clear(); } /**search if the selected row is in the list Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTable.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTable.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -34,7 +34,11 @@ import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; import org.jdesktop.swingx.JXTable; -import javax.swing.*; +import javax.swing.DefaultCellEditor; +import javax.swing.InputMap; +import javax.swing.JComponent; +import javax.swing.JTextField; +import javax.swing.KeyStroke; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.math.BigDecimal; @@ -56,7 +60,7 @@ public LetteringTable(LetteringTableModel letteringTableModel) { super(letteringTableModel); - //To block reaction of the dual touch 'ctrl+a' (Selection of all lines) + //To block reaction of the dual key 'ctrl+a' (Selection of all lines) InputMap im = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "none"); 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 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -26,8 +26,6 @@ package org.chorem.lima.ui.lettering; import org.apache.commons.lang3.time.DateUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.DateFilterImpl; import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.business.api.AccountService; @@ -40,7 +38,7 @@ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; -import javax.swing.*; +import javax.swing.JComboBox; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.ArrayList; @@ -59,8 +57,6 @@ */ public class LetteringViewHandler{ - private static final Log log = LogFactory.getLog(LetteringViewHandler.class); - protected LetteringView view; protected LetteringTable table; @@ -134,7 +130,6 @@ view.getAccountComboBox().setSelectedItem(allAccounts.get(0)); } - //By default, we have the beginning of the fiscal period (Or of current //date if no fiscal period) and the end of the current date FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -23,11 +23,9 @@ * #L% */ -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Entry; -import javax.swing.*; +import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionListener; /** @@ -35,7 +33,6 @@ */ public class LettringAndUnlettringSelectionModel implements ListSelectionModel { - private static final Log log = LogFactory.getLog(LetteringViewHandler.class); protected LetteringSelectionModel letteringSelectionModel; protected UnlettringSelectionModel unlettringSelectionModel; protected LetteringTableModel letteringTableModel; @@ -53,7 +50,10 @@ delegate = unlettringSelectionModel; } - /**choice of model : two differents ui reactions, if lettering is present or not*/ + /**choice of model : two differents ui reactions, if lettering is present or not + * @param row index of the selected line + * @param column index of the selected column + * */ @Override public void setSelectionInterval(int row, int column) { @@ -71,7 +71,10 @@ } - /**return true if lettering is null, or not null but empty*/ + /**return true if lettering is null, or not null but empty + * @param row index of the line to test + * @return boolean + * */ public boolean letteringNotExist(int row){ boolean emptyOrNull; entry = letteringTableModel.getEntryAt(row); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-17 15:51:28 UTC (rev 3534) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-18 09:50:01 UTC (rev 3535) @@ -23,22 +23,22 @@ * #L% */ -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Entry; -import javax.swing.*; +import javax.swing.DefaultListSelectionModel; import java.util.ArrayList; import java.util.List; public class UnlettringSelectionModel extends DefaultListSelectionModel { - private static final Log log = LogFactory.getLog(UnlettringSelectionModel.class); protected LetteringTableModel letteringTableModel; protected List<Entry> selectedRows; protected LetteringEditModel editModel; - //Modele de selection du tableau lors de la selection d une entree non lettree + /**Table selection model when entry selected is no lettered + * @param letteringTableModel model of the table + * @param editModel model managing update of debit / credit / balance + * */ public UnlettringSelectionModel(LetteringTableModel letteringTableModel, LetteringEditModel editModel) { this.letteringTableModel = letteringTableModel; this.editModel = editModel; @@ -60,24 +60,10 @@ @Override public void setSelectionInterval(int row, int column){ - if (log.isInfoEnabled()) { - if (selectedRows.isEmpty()){ - log.info("Liste de lignes vide"); - }else{ - log.info("Liste de lignes pleines"); - } - if (searchRowSelected(row)){ - log.info("Ligne dans la liste"); - } - } - //Case where line is selected a second time (So, must deselect it on second click) if (selectedRows.isEmpty() || !searchRowSelected(row)){ selectedRows.add(letteringTableModel.getEntryAt(row)); super.addSelectionInterval(row, column); - if (log.isInfoEnabled()) { - log.info("New row selected"); - } }else { deleteLine(row, column); } @@ -87,7 +73,8 @@ /** * search the line in a list of selected rows * and delete it - * @param row line to delete + * @param row index of the line to delete + * @param column index of the column to delete * */ public void deleteLine(int row, int column){ for (Entry entrySearching : selectedRows){ @@ -96,11 +83,7 @@ break; } } - super.removeSelectionInterval(row, column); - if (log.isInfoEnabled()) { - log.info("Old row : deleting..."); - } } /**search if the selected row is in the list @@ -109,9 +92,6 @@ * @return true if line find * */ public boolean searchRowSelected(int row){ - if (log.isInfoEnabled()) { - log.info("Ligne recherchee : " + row); - } for (Entry entrySearching : selectedRows){ if (entrySearching == letteringTableModel.getEntryAt(row)){ return true; @@ -122,14 +102,11 @@ /**PropertyChange on editModel in the handler, and, there, * set values it. + * @param lettering state of attributes lettered and unlettered in editModel * */ public void updateBalanceAndLetteringButton(boolean lettering){ editModel.resetDebitCreditBalance(); - if (log.isInfoEnabled()) { - log.info("size of selectedRows (>?) : " + selectedRows.size()); - } - //treatment unuseful if no rows are selected if (selectedRows.size() != 0){ for (Entry entry : selectedRows){ @@ -141,20 +118,12 @@ editModel.setLettred(lettering); }else{ editModel.setLettred(!lettering); - if (log.isInfoEnabled()) { - log.info("size of selectedRows : " + selectedRows.size()); - } } } - //to reinitialize model attribute + /**to reinitialize model attribute*/ public void resetAttribute(){ - if (log.isInfoEnabled()) { - log.info("Contenu de la liste supprimé"); - } - for (int i = 0; i < selectedRows.size(); i ++){ - selectedRows.remove(i); - } + selectedRows.clear(); } @Override