Author: jpepin Date: 2010-08-16 15:11:52 +0200 (Mon, 16 Aug 2010) New Revision: 3004 Url: http://chorem.org/repositories/revision/lima/3004 Log: KeyListerner sur la touche tab : Saut automatique des cellules non ?\195?\169ditables. Ajout d'une entr?\195?\169e en fin de ligne si la transaction est non ?\195?\169quilibr?\195?\169. Ajout d'une nouvelle transaction en fin de ligne via tab si la derni?\195?\168re est ?\195?\169quilibr?\195?\169. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 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 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-13 15:27:33 UTC (rev 3003) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2010-08-16 13:11:52 UTC (rev 3004) @@ -28,7 +28,9 @@ 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.EntryBook; +import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.ui.celleditor.AccountTableCellEditor; import org.chorem.lima.ui.celleditor.DateTableCellEditor; import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; @@ -164,37 +166,78 @@ /** * Touche tab + * Incrémente le curseur de case tant que la case n'est pas editable * Ajoute une entrée comptable si tab est sur - * la dernière cellule. + * la dernière cellule et si la transaction est non équilibré + * sinon rajoute une transaction */ if (e.getKeyChar() == KeyEvent.VK_TAB) { - // Vérifie si la cellule sélectionnée est la dernière + int max_x = this.getColumnCount(); + int max_y = this.getRowCount(); + int x_tab = this.getSelectedColumn(); + int y_tab = this.getSelectedRow(); + + if (x_tab < max_x - 1){ + x_tab++; + } + else { + y_tab++; + } + //skip all cell while not editable + while (!isCellEditable(y_tab, x_tab)){ - int x = this.getSelectedColumn(); - int y = this.getSelectedRow(); - int max_x = this.getColumnCount() - 1; - int max_y = this.getRowCount() - 1; - if (x == max_x && y == max_y) { - handler.addEmptyEntry(); - // positionne la sélection sur la nouvelle ligne créée - this.setColumnSelectionInterval(0, 0); - this.setRowSelectionInterval(max_y + 1, max_y + 1); - } + //if end of row + if (x_tab == max_x-1) { + Object object = this.handler.tableModel.getElementAt(y_tab); + + //if transaction, add entry + if (object instanceof FinancialTransaction){ + FinancialTransaction financialTransaction = (FinancialTransaction) object; + if (financialTransaction.getEntry().size() == 0){ + handler.addEmptyEntry(); + this.setColumnSelectionInterval(1, 1); + } + } + //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); + } + } + y_tab++; + // positionne la sélection sur la nouvelle ligne créée + this.setRowSelectionInterval(y_tab, y_tab); + x_tab=0; + } + else { + if (x_tab < max_x){ + this.setColumnSelectionInterval(x_tab, x_tab); + x_tab++; + } + } + } } - } - /* - * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) - */ + @Override public void keyTyped(KeyEvent e) { } - /* - * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) - */ + @Override public void keyReleased(KeyEvent e) { 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-13 15:27:33 UTC (rev 3003) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2010-08-16 13:11:52 UTC (rev 3004) @@ -327,7 +327,7 @@ 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 @@ -336,7 +336,9 @@ } return editableCell; } + + /** * @throws LimaException */ @@ -550,7 +552,7 @@ } //on recharge la liste cacheDataList = getDataList(); - fireTableRowsDeleted(row, getRowCount()); + fireTableDataChanged(); } @Override Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-08-13 15:27:33 UTC (rev 3003) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-08-16 13:11:52 UTC (rev 3004) @@ -1,104 +0,0 @@ -<!-- ##% Lima Swing - Copyright (C) 2008 - 2010 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 2 - 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, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - ##% --> - -<Table> - <FinancialTransactionViewHandler id="handler" javaBean="new FinancialTransactionViewHandler(this)" /> - <Boolean id="selectedRow" javaBean="false" /> - <org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel id="modelFinancialPeriod"/> - <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> - <script> - <![CDATA[ - import org.chorem.lima.entity.FiscalPeriod; - import org.chorem.lima.entity.FinancialPeriod; - - void $afterCompleteSetup() { - getHandler().refresh(); - } - - ]]> - </script> - - <!-- <JPopupMenu id="MenuRightPanel"> - <JMenuItem text="lima.add.transaction" onActionPerformed='addEmptyTransaction()'/> - <JMenuItem text="lima.print"/> - </JPopupMenu> - <JPopupMenu id="MenuRightTransaction"> - <JMenuItem text="lima.add" onActionPerformed='addEmptyTransaction()'/> - <JMenuItem text="lima.print"/> - </JPopupMenu> --> - - <row weightx="1" weighty="0" anchor="center"> - <cell anchor="east"> - <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> - </cell> - <cell anchor="west"> - <JComboBox id="fiscalPeriodComboBox" - model="{getModelFiscalPeriod()}" - renderer="{new org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer()}" - onActionPerformed="getModelFinancialPeriod().setFiscalPeriod( (FiscalPeriod) fiscalPeriodComboBox.getSelectedItem()); - getHandler().refresh()" - editable="false"/> - </cell> - <cell anchor="east"> - <JLabel id="financialPeriodLabel" text="lima.transaction.period" - /> - </cell> - <cell anchor="west"> - <JComboBox id="financialPeriodComboBox" - model="{getModelFinancialPeriod()}" - renderer="{new org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer()}" - onActionPerformed="getFinancialTransactionTableModel().setFinancialPeriod( (FinancialPeriod) financialPeriodComboBox.getSelectedItem()); - getHandler().refresh()" - editable="false" - /> - </cell> - <cell> - <JButton text="lima.common.copy" - onActionPerformed="getHandler().copyRow()" enabled="{isSelectedRow()}"/> - </cell> - <cell> - <JButton text="lima.common.paste" - onActionPerformed="getHandler().pasteRow()" enabled="{isSelectedRow()}"/> - </cell> - <cell> - <JButton text="lima.add.transaction" - onActionPerformed="getHandler().addFinancialTransaction()"/> - </cell> - <cell> - <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()" enabled="{isSelectedRow()}"/> - </cell> - <cell> - <JButton text="lima.common.remove" - onActionPerformed="getHandler().deleteSelectedRow()" - enabled="{isSelectedRow()}"/> - </cell> - </row> - <row> - <cell fill="both" weightx="1" weighty="1" rows="3" columns="9"> - <JScrollPane> - <org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel - id="financialTransactionTableModel"/> - <org.chorem.lima.ui.financialtransaction.FinancialTransactionTable - id="financialTransactionTable" sortable="false" rowHeight="22" - constructorParams="getHandler()" model="{getFinancialTransactionTableModel()}" - selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> - <javax.swing.ListSelectionModel javaBean="getFinancialTransactionTable().getSelectionModel()" - onValueChanged="setSelectedRow(financialTransactionTable.getSelectedRow() != -1)"/> - </JScrollPane> - </cell> - </row> -</Table> \ No newline at end of file Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx (from rev 3003, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2010-08-16 13:11:52 UTC (rev 3004) @@ -0,0 +1,104 @@ +<!-- ##% Lima Swing + Copyright (C) 2008 - 2010 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 2 + 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + ##% --> + +<Table> + <FinancialTransactionViewHandler id="handler" javaBean="new FinancialTransactionViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + <org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel id="modelFinancialPeriod"/> + <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> + <script> + <![CDATA[ + import org.chorem.lima.entity.FiscalPeriod; + import org.chorem.lima.entity.FinancialPeriod; + + void $afterCompleteSetup() { + getHandler().refresh(); + } + + ]]> + </script> + + <!-- <JPopupMenu id="MenuRightPanel"> + <JMenuItem text="lima.add.transaction" onActionPerformed='addEmptyTransaction()'/> + <JMenuItem text="lima.print"/> + </JPopupMenu> + <JPopupMenu id="MenuRightTransaction"> + <JMenuItem text="lima.add" onActionPerformed='addEmptyTransaction()'/> + <JMenuItem text="lima.print"/> + </JPopupMenu> --> + + <row weightx="1" weighty="0" anchor="center"> + <cell anchor="east"> + <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> + </cell> + <cell anchor="west"> + <JComboBox id="fiscalPeriodComboBox" + model="{getModelFiscalPeriod()}" + renderer="{new org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer()}" + onActionPerformed="getModelFinancialPeriod().setFiscalPeriod( (FiscalPeriod) fiscalPeriodComboBox.getSelectedItem()); + getHandler().refresh()" + editable="false"/> + </cell> + <cell anchor="east"> + <JLabel id="financialPeriodLabel" text="lima.transaction.period" + /> + </cell> + <cell anchor="west"> + <JComboBox id="financialPeriodComboBox" + model="{getModelFinancialPeriod()}" + renderer="{new org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer()}" + onActionPerformed="getFinancialTransactionTableModel().setFinancialPeriod( (FinancialPeriod) financialPeriodComboBox.getSelectedItem()); + getHandler().refresh()" + editable="false" + /> + </cell> + <cell> + <JButton text="lima.common.copy" + onActionPerformed="getHandler().copyRow()" enabled="{isSelectedRow()}"/> + </cell> + <cell> + <JButton text="lima.common.paste" + onActionPerformed="getHandler().pasteRow()" enabled="{isSelectedRow()}"/> + </cell> + <cell> + <JButton text="lima.add.transaction" + onActionPerformed="getHandler().addFinancialTransaction()"/> + </cell> + <cell> + <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()" enabled="{isSelectedRow()}"/> + </cell> + <cell> + <JButton text="lima.common.remove" + onActionPerformed="getHandler().deleteSelectedRow()" + enabled="{isSelectedRow()}"/> + </cell> + </row> + <row> + <cell fill="both" weightx="1" weighty="1" rows="3" columns="9"> + <JScrollPane> + <org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel + id="financialTransactionTableModel"/> + <org.chorem.lima.ui.financialtransaction.FinancialTransactionTable + id="financialTransactionTable" sortable="false" rowHeight="22" + constructorParams="getHandler()" model="{getFinancialTransactionTableModel()}" + selectionMode="{ListSelectionModel.SINGLE_SELECTION}" /> + <javax.swing.ListSelectionModel javaBean="getFinancialTransactionTable().getSelectionModel()" + onValueChanged="setSelectedRow(financialTransactionTable.getSelectedRow() != -1)"/> + </JScrollPane> + </cell> + </row> +</Table> \ No newline at end of file