Author: jpepin Date: 2010-08-20 14:11:16 +0200 (Fri, 20 Aug 2010) New Revision: 3009 Url: http://chorem.org/repositories/revision/lima/3009 Log: D?\195?\169bogue ajout de ligne automatique. 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 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 2010-08-19 23:48:02 UTC (rev 3008) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2010-08-20 12:11:16 UTC (rev 3009) @@ -18,6 +18,8 @@ package org.chorem.lima.ui.financialtransaction; +import static org.nuiton.i18n.I18n._; + import java.awt.Color; import java.awt.Component; import java.awt.event.FocusEvent; @@ -28,11 +30,14 @@ import java.awt.event.MouseListener; import java.math.BigDecimal; import java.util.Date; +import java.util.concurrent.ExecutionException; +import javax.swing.SwingWorker; import javax.swing.table.TableColumn; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaException; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; @@ -40,6 +45,7 @@ import org.chorem.lima.ui.celleditor.AccountTableCellEditor; import org.chorem.lima.ui.celleditor.DateTableCellEditor; import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; +import org.chorem.lima.util.DialogHelper; import org.jdesktop.swingx.JXTable; import org.jdesktop.swingx.decorator.ColorHighlighter; import org.jdesktop.swingx.decorator.ComponentAdapter; @@ -66,6 +72,9 @@ private Highlighter colorTransaction; private ColorHighlighter colorBalance; + + private int x_tab; + private int y_tab; public FinancialTransactionTable(FinancialTransactionViewHandler handler) { @@ -148,7 +157,7 @@ //TODO combinaison de touches dans la config - // delete selected row with the key : delete or ctrl clear + // delete selected row with the key : delete or ctrl + clear // ou de l'entree if ((e.getKeyCode() == KeyEvent.VK_DELETE ) || (e.getKeyCode() == KeyEvent.VK_CLEAR @@ -164,11 +173,27 @@ } // add financial transaction with the key combination : ctrl + tab + if (e.getKeyCode() == KeyEvent.VK_C + && e.getModifiers() == KeyEvent.CTRL_MASK) { + handler.copyRow(); + } + + // copy : ctrl + c + + // add financial transaction with the key combination : ctrl + tab + if (e.getKeyCode() == KeyEvent.VK_V + && e.getModifiers() == KeyEvent.CTRL_MASK) { + handler.pasteRow(); + } + + // paste : ctrl + v + + // add financial transaction with the key combination : ctrl + tab if (e.getKeyCode() == KeyEvent.VK_TAB && e.getModifiers() == KeyEvent.CTRL_MASK) { handler.addFinancialTransaction(); } - + /** * Touche tab * Incrémente le curseur de case tant que la case n'est pas editable @@ -176,21 +201,24 @@ * la dernière cellule et si la transaction est non équilibré * sinon rajoute une transaction */ + if (e.getKeyChar() == KeyEvent.VK_TAB) { int max_x = this.getColumnCount(); int max_y = this.getRowCount(); - int x_tab = this.getSelectedColumn(); - int y_tab = this.getSelectedRow(); + x_tab = this.getSelectedColumn(); + y_tab = this.getSelectedRow(); + Boolean end = true; - if (x_tab < max_x - 1){ + if (x_tab < max_x - 1){ x_tab++; } + //end of row else { + x_tab=0; y_tab++; } - //skip all cell while not editable - while (!isCellEditable(y_tab, x_tab)){ - + //skip all cell while not editable or if end of table add entry or transaction or end of table + while (!isCellEditable(y_tab, x_tab) && end ){ //if end of row if (x_tab == max_x-1) { Object object = this.handler.tableModel.getElementAt(y_tab); @@ -205,35 +233,60 @@ } //if entry else { - Entry entry = (Entry) object; - FinancialTransaction financialTransaction = entry.getFinancialTransaction(); - Boolean balanced = - financialTransaction.getAmountCredit() == - financialTransaction.getAmountDebit(); - if (balanced){ - if (y_tab == max_y-1){ - handler.addFinancialTransaction(); - this.setColumnSelectionInterval(0, 0); - } - } - else { - handler.addEmptyEntry(); - this.setColumnSelectionInterval(1, 1); - } + log.debug("not end"); + //FIXME set value is doing after key pressed + // so update not terminated before get balanced + //Swing Worker stop the UI 500ms + // found best solution ? + final JXTable table = this; + final int y_t = y_tab; + final int m_t = max_y; + new SwingWorker<Void,Void>() { + @Override protected Void doInBackground() throws InterruptedException { + Thread.sleep(500); + return null; + } + @Override protected void done() { + Object object = handler.tableModel.getElementAt(y_tab-1); + FinancialTransaction financialTransaction = null; + if (object instanceof Entry){ + financialTransaction = ((Entry) object).getFinancialTransaction(); + } + else if (object instanceof FinancialTransaction){ + financialTransaction = (FinancialTransaction) object; + } + BigDecimal amountC = financialTransaction.getAmountCredit(); + BigDecimal amountD = financialTransaction.getAmountDebit(); + if (amountC == amountD){ + if (y_t == m_t-1){ + handler.addFinancialTransaction(); + table.setColumnSelectionInterval(0, 0); + } + } + else { + handler.addEmptyEntry(); + table.setColumnSelectionInterval(1, 1); + y_tab++; + // positionne la sélection sur la nouvelle ligne créée + table.setRowSelectionInterval(y_tab, y_tab); + x_tab=0; + } + } + }.execute(); } - y_tab++; - // positionne la sélection sur la nouvelle ligne créée - this.setRowSelectionInterval(y_tab, y_tab); - x_tab=0; + end = false; } else { if (x_tab < max_x){ + this.setRowSelectionInterval(y_tab, y_tab); this.setColumnSelectionInterval(x_tab, x_tab); x_tab++; } } } } + + } 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 2010-08-19 23:48:02 UTC (rev 3008) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2010-08-20 12:11:16 UTC (rev 3009) @@ -159,7 +159,7 @@ result = String.class; break; case 5: - result = BigDecimal.class; + result = String.class; break; case 6: result = BigDecimal.class; @@ -168,7 +168,7 @@ result = BigDecimal.class; break; case 8: - result = String.class; + result = BigDecimal.class; break; } @@ -198,16 +198,16 @@ result = _("lima.table.description"); break; case 5: - result = _("lima.table.debit"); + result = _("lima.table.letter"); break; case 6: - result = _("lima.table.credit"); + result = _("lima.table.debit"); break; case 7: - result = _("lima.table.balance"); + result = _("lima.table.credit"); break; case 8: - result = _("lima.table.letter"); + result = _("lima.table.balance"); break; } @@ -260,16 +260,16 @@ result = null; // description break; case 5 : - result = amountDebit; + result = null; // letter break; case 6: - result = amountCredit; + result = amountDebit; break; case 7: - result = amountDebit.subtract(amountCredit); + result = amountCredit; break; case 8: - result = null; + result = amountDebit.subtract(amountCredit); break; } } @@ -297,16 +297,16 @@ result = currentEntry.getDescription(); break; case 5 : - result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; + result = currentEntry.getLettering(); break; case 6: - result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); + result = currentEntry.getDebit() ? currentEntry.getAmount() : 0; break; case 7: - result = null; + result = currentEntry.getDebit() ? 0 : currentEntry.getAmount(); break; case 8: - result = currentEntry.getLettering(); + result = null; break; } @@ -329,11 +329,11 @@ boolean editableCell=false; Object currentRow = cacheDataList.get(rowIndex); // cells editable for the entry row, all cells exclude the date - if ((currentRow instanceof Entry) && !((columnIndex==0) || (columnIndex==1))) { + if ((currentRow instanceof Entry) && !((columnIndex==0) || (columnIndex==1) || (columnIndex==8))) { editableCell=true; } // cells editable for the financialtransaction row, no cells exclude the date - if ((currentRow instanceof FinancialTransaction) && ((columnIndex==0) || (columnIndex==1) || (columnIndex==8))){ + if ((currentRow instanceof FinancialTransaction) && ((columnIndex==0) || (columnIndex==1))){ editableCell=true; } return editableCell; @@ -494,16 +494,16 @@ currentEntry.setDescription((String)value); break; case 5 : + currentEntry.setLettering((String)value); + break; + case 6: currentEntry.setAmount((BigDecimal)value); currentEntry.setDebit(true); break; - case 6: + case 7: currentEntry.setAmount((BigDecimal)value); currentEntry.setDebit(false); break; - case 8: - currentEntry.setLettering((String)value); - break; } try { financialTransactionService.updateEntry(currentEntry); 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 2010-08-19 23:48:02 UTC (rev 3008) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2010-08-20 12:11:16 UTC (rev 3009) @@ -67,6 +67,7 @@ //copy entry public void copyRow(){ + table = view.getFinancialTransactionTable(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { @@ -76,6 +77,7 @@ //paste entry public void pasteRow(){ + table = view.getFinancialTransactionTable(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) {