Author: mallon Date: 2012-08-06 18:03:49 +0200 (Mon, 06 Aug 2012) New Revision: 3568 Url: http://chorem.org/repositories/revision/lima/3568 Log: fixes #705 Desormais, la limitation du nombre de decimales portent tant sur l affichage que sur l edition elle-meme (Arrondis superieur, sur deux decimales, apres edition.). L entree dans l edition de la cellule se fait des selection de celle-ci (Il n est donc plus necessaire de saisir deux fois un chiffre pour declencher l edition.). Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-08-06 10:46:10 UTC (rev 3567) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-08-06 16:03:49 UTC (rev 3568) @@ -24,8 +24,6 @@ */ import jaxx.runtime.swing.editor.cell.NumberCellEditor; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; import javax.swing.JTable; @@ -33,42 +31,47 @@ import java.awt.Component; import java.awt.event.FocusEvent; import java.math.BigDecimal; +import java.math.RoundingMode; /** * @author sletellier <letellier@codelutin.com> */ -public class BigDecimalTableCellEditor extends NumberCellEditor<BigDecimal>{ +public class BigDecimalTableCellEditor extends NumberCellEditor<BigDecimal> { protected int row; - static private Log log = LogFactory.getLog(BigDecimalTableCellEditor.class); - public BigDecimalTableCellEditor() { super(BigDecimal.class, false); } @Override public void focusGained(FocusEvent e) { + //super.getNumberEditor().getTextField().setText(super.getCellEditorValue().toString()); + runEdition(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + this.row = row; + return super.getTableCellEditorComponent(table, value, isSelected, row, column); + } + + public void runEdition() { String comportmentEditingCell = LimaConfig.getInstance().getComportmentEditingCell(); - if (log.isDebugEnabled()) { - log.debug("comportmentEditingCell : " + comportmentEditingCell); - } JTextField numberEditorTextField = super.getNumberEditor().getTextField(); if (comportmentEditingCell.equals("ALL")) { numberEditorTextField.selectAll(); } else { int textFieldSize = numberEditorTextField.getText().length(); - if (log.isDebugEnabled()) { - log.debug("textFieldSize : " + textFieldSize); - } numberEditorTextField.select(textFieldSize, textFieldSize); } } @Override - public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - this.row = row; - return super.getTableCellEditorComponent(table, value, isSelected, row, column); + public BigDecimal getCellEditorValue() { + if (super.getCellEditorValue() != BigDecimal.ZERO) { + return super.getCellEditorValue().setScale(2, RoundingMode.HALF_UP); + } + return super.getCellEditorValue(); } - } 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-08-06 10:46:10 UTC (rev 3567) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2012-08-06 16:03:49 UTC (rev 3568) @@ -26,6 +26,8 @@ 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; @@ -79,6 +81,8 @@ addMouseListener(new MyMouseAdapter()); + //addListSelectionListener(); + //Get new date editor setDefaultEditor(Date.class, new DateTableCellEditor()); @@ -161,7 +165,24 @@ FinancialTransactionTable table = FinancialTransactionTable.this; @Override + public void keyTyped(KeyEvent e) { + if ( (getSelectedColumn() == 4 || getSelectedColumn() == 5) ) { + editCellAt(getSelectedRow(), getSelectedColumn()); + } + } + + @Override + public void keyReleased(KeyEvent e) { + if ( (getSelectedColumn() == 4 || getSelectedColumn() == 5) ) { + editCellAt(getSelectedRow(), getSelectedColumn()); + } + } + + @Override public void keyPressed(KeyEvent e) { + if ( (getSelectedColumn() == 4 || getSelectedColumn() == 5) ) { + editCellAt(getSelectedRow(), getSelectedColumn()); + } final FinancialTransactionViewHandler handler = getHandler(); Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-08-06 10:46:10 UTC (rev 3567) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-08-06 16:03:49 UTC (rev 3568) @@ -45,4 +45,5 @@ log4j.logger.org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel=DEBUG log4j.logger.org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor=DEBUG log4j.logger.org.chorem.lima.business.accountingrules.DefaultAccountingRules=DEBUG -log4j.logger.org.chorem.lima.business.ejb.FinancialTransactionServiceImpl=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.business.ejb.FinancialTransactionServiceImpl=DEBUG +log4j.logger.org.chorem.lima.business.ui.celleditor.BigDecimalTableCellEditor=DEBUG \ No newline at end of file