r3679 - in trunk/lima-swing/src/main: java/org/chorem/lima/ui/celleditor java/org/chorem/lima/ui/financialtransaction resources
Author: Bavencoff Date: 2013-06-07 18:09:48 +0200 (Fri, 07 Jun 2013) New Revision: 3679 Url: http://chorem.org/projects/lima/repository/revisions/3679 Log: user experience Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EmptyCellRenderer.java 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/FinancialTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java trunk/lima-swing/src/main/resources/log4j.properties Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -0,0 +1,22 @@ +package org.chorem.lima.ui.celleditor; + +import org.chorem.lima.entity.Account; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class AccountTableCellRenderer extends EmptyCellRenderer { + + + @Override + public void setValue(Object value) { + Object result = value; + if (value != null && value instanceof Account) { + Account account = (Account) value; + result = account.getAccountNumber() + " - " + account.getLabel(); + } + super.setValue(result); + } + + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellEditor.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -26,28 +26,31 @@ package org.chorem.lima.ui.celleditor; 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.LimaContext; import org.jdesktop.swingx.JXDatePicker; -import javax.swing.AbstractCellEditor; -import javax.swing.JFormattedTextField; -import javax.swing.JTable; -import javax.swing.SwingUtilities; +import javax.swing.*; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; import javax.swing.table.TableCellEditor; -import java.awt.Component; +import java.awt.*; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; -import java.awt.event.MouseEvent; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; -import java.util.EventObject; /** @author ore */ public class DateTableCellEditor extends AbstractCellEditor implements TableCellEditor, FocusListener, AncestorListener { + private static final Log log = LogFactory.getLog(DateTableCellEditor.class); + private static final long serialVersionUID = 1L; private final JXDatePicker datePicker; @@ -61,6 +64,11 @@ datePicker = new JXDatePicker(LimaContext.getContext().getConfig().getLocale()); datePicker.getEditor().addFocusListener(this); datePicker.getEditor().addAncestorListener(this); + datePicker.setFormats( + DateFormat.getDateInstance(DateFormat.SHORT), + new SimpleDateFormat("dd/MM/yyyy"), + new SimpleDateFormat("dd/MM") + ); //comportmentEditingCell = LimaConfig.getInstance().getComportmentEditingCell(); } @@ -75,34 +83,35 @@ @Override public Object getCellEditorValue() { - if (!datePicker.getEditor().getText().isEmpty()) { - String[] str = datePicker.getEditor().getText().split("/"); - //day - if (str.length > 0) { - if (str[0].contains(" ")) { - String[] string = str[0].split(" "); - date = DateUtils.setDays(date, Integer.valueOf(string[1])); - } else { - date = DateUtils.setDays(date, Integer.valueOf(str[0])); - } - } - //month - if (str.length > 1) { - date = DateUtils.setMonths(date, Integer.valueOf(str[1]) - 1); - } - //year - if (str.length > 2) { - date = DateUtils.setYears(date, Integer.valueOf(str[2])); - } + if (log.isDebugEnabled()) { + log.debug("getDate : input Date : " + datePicker.getDate() + "; text : " + datePicker.getEditor().getText()); } - datePicker.setDate(date); + try { + datePicker.commitEdit(); + } catch (ParseException e) { + e.printStackTrace(); + } + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(datePicker.getDate()); + int year = calendar.get(Calendar.YEAR); + if (year == 1970) { + calendar.setTime(date); + year = calendar.get(Calendar.YEAR); + Date newDate = DateUtils.setYears(datePicker.getDate(), year); + datePicker.setDate(newDate); + } + + if (log.isDebugEnabled()) { + log.debug("getDate : output Date : " + datePicker.getDate()); + } return datePicker.getDate(); } - @Override + /*@Override public boolean isCellEditable(EventObject evt) { return !(evt instanceof MouseEvent) || ((MouseEvent) evt).getClickCount() == 2; - } + } */ @Override public void focusGained(FocusEvent e) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EmptyCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EmptyCellRenderer.java 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EmptyCellRenderer.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -91,13 +91,12 @@ if (value instanceof String) { if (String.valueOf(value) == null || String.valueOf(value).isEmpty()) { mycell.setBackground(new Color(255, 198, 209)); - } else { - mycell.setText(value.toString()); } } else { mycell.setBackground(new Color(255, 198, 209)); } } + setValue(value); return mycell; } 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 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTable.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -30,6 +30,7 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.ui.celleditor.AccountTableCellEditor; +import org.chorem.lima.ui.celleditor.AccountTableCellRenderer; import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; import org.chorem.lima.ui.celleditor.DateTableCellEditor; @@ -68,10 +69,6 @@ protected final FinancialTransactionViewHandler handler; - private int x_tab; - - private int y_tab; - public FinancialTransactionTable(final FinancialTransactionViewHandler handler) { this.handler = handler; @@ -97,7 +94,7 @@ setDefaultRenderer(String.class, new EmptyCellRenderer()); //get new Account renderer for empty cells - setDefaultRenderer(Account.class, new EmptyCellRenderer()); + setDefaultRenderer(Account.class, new AccountTableCellRenderer()); setShowHorizontalLines(true); setShowVerticalLines(true); @@ -142,69 +139,7 @@ colorTransaction = new ColorHighlighter(predicate, null, new Color(240, 30, 30)); addHighlighter(colorTransaction); - /*//highlight financial financial transactions - predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - return adapter.getValueAt(adapter.row, 0) instanceof Date; - } - }; - Highlighter colorTransaction = - new ColorHighlighter(predicate, new Color(222, 222, 222), null); - addHighlighter(colorTransaction); - // highlight unbalanced financial transactions - predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - boolean isHighlighted = false; - Object valueDebit = adapter.getValueAt(adapter.row, 4); - Object valueCredit = adapter.getValueAt(adapter.row, 5); - Object value = adapter.getValueAt(adapter.row, 6); - if (value instanceof BigDecimal) { - BigDecimal currentBalance = (BigDecimal) value; - DecimalFormat decimalFormat = new DecimalFormat(); - Double currentBalanceDouble = decimalFormat.parse(currentBalance.toString(), new ParsePosition(0)).doubleValue(); - Double debitDouble = decimalFormat.parse(valueDebit.toString(), new ParsePosition(0)).doubleValue(); - Double creditDouble = decimalFormat.parse(valueCredit.toString(), new ParsePosition(0)).doubleValue(); - - if (!currentBalanceDouble.toString().equals("0.0") || (valueDebit.equals(BigDecimal.ZERO) || debitDouble.toString().equals("0.0")) - && (valueCredit.equals(BigDecimal.ZERO) || creditDouble.toString().equals("0.0"))) { - isHighlighted = true; - } - } - return isHighlighted; - } - }; - - //To color in red entry with debit and credit equals to zero - colorTransaction = - new ColorHighlighter(predicate, null , new Color(255, 0, 0)); - addHighlighter(colorTransaction); - - HighlightPredicate debitCreditZero = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - - Object valueDebit = adapter.getValueAt(adapter.row, 4); - Object valueCredit = adapter.getValueAt(adapter.row, 5); - boolean isEntry = !(adapter.getValueAt(adapter.row, 0) instanceof Date); - - DecimalFormat decimalFormat = new DecimalFormat(); - Double debitDouble = decimalFormat.parse(valueDebit.toString(), new ParsePosition(0)).doubleValue(); - Double creditDouble = decimalFormat.parse(valueCredit.toString(), new ParsePosition(0)).doubleValue(); - return (isEntry && (valueDebit.equals(BigDecimal.ZERO) || debitDouble.toString().equals("0.0")) - && (valueCredit.equals(BigDecimal.ZERO) || creditDouble.toString().equals("0.0"))); - } - }; - - Highlighter entryDebitCreditZero = - new ColorHighlighter(debitCreditZero, new Color(255, 198, 209), null); - addHighlighter(entryDebitCreditZero);*/ - } public FinancialTransactionViewHandler getHandler() { @@ -223,15 +158,15 @@ /*Allow to block access to the first row when key enter pressed, if selection on * last row*/ - if (e.getKeyCode() == KeyEvent.VK_ENTER){ + /* if (e.getKeyCode() == KeyEvent.VK_ENTER){ int selectedRow = table.getSelectedRow(); if( selectedRow == table.getRowCount()-1){ - /*-2, cause we have a row count beginning at one and we want to back to the line before*/ + *//*-2, cause we have a row count beginning at one and we want to back to the line before*//* table.setRowSelectionInterval(table.getRowCount()-2, table.getRowCount()-2); } else { table.setRowSelectionInterval(selectedRow, selectedRow); } - } + }*/ /* * Touche tab @@ -244,33 +179,49 @@ if (log.isDebugEnabled()) { log.debug("Key tab used"); } - int max_x = getColumnCount(); - int max_y = getRowCount(); - x_tab = getSelectedColumn(); - y_tab = getSelectedRow(); + int nbColumn = getColumnCount(); + int nbRows = getRowCount(); + int column = getSelectedColumn(); + int row = getSelectedRow(); - boolean end = false; + if (column >= 0 && row >= 0) { - FinancialTransaction transaction = tableModel.getTransactionAt(y_tab); - if (x_tab >= max_x - 1) { - if (y_tab + 1 > max_y || transaction != tableModel.getTransactionAt(y_tab + 1)) { - BigDecimal credit = transaction.getAmountCredit(); - BigDecimal debit = transaction.getAmountDebit(); - if (credit.compareTo(debit) != 0) { - table.handler.addEntry(); - x_tab = 1; - y_tab++; - end = true; - } else if (y_tab + 1 > max_y) { - table.handler.addFinancialTransaction(); - x_tab = 0; - y_tab++; - end = true; + boolean end = false; + + FinancialTransaction transaction = tableModel.getTransactionAt(row); + do { + if (column >= nbColumn - 1) { + if (row >= nbRows - 1 || transaction != tableModel.getTransactionAt(row + 1)) { + BigDecimal credit = transaction.getAmountCredit(); + BigDecimal debit = transaction.getAmountDebit(); + if (credit.compareTo(debit) != 0) { + table.handler.addEntry(); + column = 1; + row++; + end = true; + } else if (row >= nbRows - 1) { + table.handler.addFinancialTransaction(); + column = 0; + row++; + end = true; + } else { + column = 0; + row++; + } + } else { + column = 0; + row++; + } + } else { + column++; } - } + } while (!end && !tableModel.isCellEditable(row,column)); + setRowSelectionInterval(row, row); + setColumnSelectionInterval(column, column); + editCellAt(column, row); + + e.consume(); } - setRowSelectionInterval(y_tab, y_tab); - setColumnSelectionInterval(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 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionTableModel.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -178,12 +178,7 @@ result = entry.getVoucher(); break; case 2: // account - if (entry.getAccount() == null) { - result = null; - } else { - Account acc = entry.getAccount(); - result = accountDecorator.toString(acc); - } + result = entry.getAccount(); break; case 3: result = entry.getDescription(); @@ -260,16 +255,18 @@ Entry entry = entries.get(row); FinancialTransaction transaction = entry.getFinancialTransaction(); String description; + boolean updateEntries = false; boolean updateTransaction = false; switch (column) { case 0: //update transaction.setTransactionDate((Date) value); + updateTransaction = true; break; case 1: String voucher = ((String) value).trim(); - int firstEntryRow = getFirstEntry(row); + int firstEntryRow = indexOf(transaction); if (row == firstEntryRow) { // let's update the voucher of all entries of @@ -278,7 +275,7 @@ entryNext.setVoucher(voucher); } - updateTransaction = true; + updateEntries = true; } else { // not on first row, just update this entry voucher @@ -288,25 +285,28 @@ case 2: Account account = (Account) value; entry.setAccount(account); - // let's copy the account description - description = account.getLabel(); - firstEntryRow = getFirstEntry(row); - if (row == firstEntryRow) { - // let's update the description of all entries of - // the transaction + if (account != null) { - for (Entry entryNext : transaction.getEntry()) { - entryNext.setDescription(description); + // let's copy the account description + description = account.getLabel(); + firstEntryRow = indexOf(transaction); + if (row == firstEntryRow) { + // let's update the description of all entries of + // the transaction + + for (Entry entryNext : transaction.getEntry()) { + entryNext.setDescription(description); + } + updateEntries = true; + } else { + // not on first row, just update this entry description + entry.setDescription(description); } - updateTransaction = true; - } else { - // not on first row, just update this entry description - entry.setDescription(description); } break; case 3: description = ((String) value).trim(); - firstEntryRow = getFirstEntry(row); + firstEntryRow = indexOf(transaction); if (row == firstEntryRow) { // let's update the description of all entries of @@ -315,7 +315,7 @@ for (Entry entryNext : transaction.getEntry()) { entryNext.setDescription(description); } - updateTransaction = true; + updateEntries = true; } else { // not on first row, just update this entry description @@ -323,19 +323,22 @@ } break; case 4: - - entry.setAmount((BigDecimal) value); - entry.setDebit(true); + if (((BigDecimal) value).signum() > 0 ) { + entry.setAmount((BigDecimal) value); + entry.setDebit(true); + } break; case 5: - entry.setAmount((BigDecimal) value); - entry.setDebit(false); + if (((BigDecimal) value).signum() > 0 ) { + entry.setAmount((BigDecimal) value); + entry.setDebit(false); + } break; } // some modification must update all other // first row modification update following rows - if (updateTransaction) { + if (updateEntries) { // FIXME echatellier 20120413 make a single service call for (Entry entryTmp : transaction.getEntry()) { financialTransactionService.updateEntry(entryTmp); @@ -343,6 +346,9 @@ } else { financialTransactionService.updateEntry(entry); } + if (updateTransaction) { + financialTransactionService.updateFinancialTransaction(transaction); + } /* // FIXME echatellier 20120413 une modification des dates fait que l'ordre // devient faux Modified: 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 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionView.jaxx 2013-06-07 16:09:48 UTC (rev 3679) @@ -66,7 +66,7 @@ <JMenuItem text="lima.common.remove" enabled="{isSelectedRow()}" onActionPerformed="handler.deleteSelectedTransaction()" - accelerator="{KeyStroke.getKeyStroke(KeyEvent.VK_DELETE , KeyEvent.SHIFT_DOWN_MASK)}" /> + accelerator="{KeyStroke.getKeyStroke(KeyEvent.VK_DELETE , KeyEvent.CTRL_DOWN_MASK + KeyEvent.SHIFT_DOWN_MASK)}" /> <JMenuItem text="lima.common.copy" enabled="{isSelectedRow()}" onActionPerformed="handler.copyTransaction(financialTransactionTable.getSelectedRow())" @@ -84,7 +84,7 @@ <JMenuItem text="lima.common.remove" enabled="{isSelectedRow()}" onActionPerformed="handler.deleteSelectedEntry()" - accelerator="{KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)}" /> + accelerator="{KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK)}" /> <JMenuItem text="lima.common.copy" enabled="{isSelectedRow()}" onActionPerformed="handler.copyEntry(financialTransactionTable.getSelectedRow())" 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 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/FinancialTransactionViewHandler.java 2013-06-07 16:09:48 UTC (rev 3679) @@ -47,6 +47,7 @@ import javax.swing.JComboBox; import javax.swing.JOptionPane; import javax.swing.ListSelectionModel; +import javax.swing.table.TableCellEditor; import java.awt.event.ItemEvent; import java.math.BigDecimal; import java.util.ArrayList; @@ -239,7 +240,8 @@ //new transaction with only entrybook and date FinancialTransaction transaction = new FinancialTransactionImpl(); - transaction.setEntryBook(transactionTemp.getEntryBook()); + EntryBook entryBook = (EntryBook)view.getEntryBookComboBox().getSelectedItem(); + transaction.setEntryBook(entryBook); transaction.setTransactionDate(transactionTemp.getTransactionDate()); transaction = financialTransactionService.createFinancialTransaction(transaction); @@ -370,12 +372,6 @@ int addIndex = tableModel.size(); tableModel.addRow(entry, addIndex); - entry = new EntryImpl(); - entry.setFinancialTransaction(fTransaction); - entry = financialTransactionService.createEntry(entry); - fTransaction.addEntry(entry); - tableModel.addRow(entry, addIndex + 1); - //select the new line ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(addIndex, addIndex); @@ -394,17 +390,14 @@ // real selected row or selected transaction row ? int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow != -1) { - Entry lastEntryOfTransaction; //First case, where line selected is an entry : take its transaction //to select the last entry of the transaction - Entry entryOrTransaction = tableModel.getEntryAt(indexSelectedRow); - //if (entryOrTransaction instanceof Entry) { - lastEntryOfTransaction = financialTransactionService.getLastEntry(entryOrTransaction.getFinancialTransaction()); - /*} else { //Second case, we have an instance of transaction, so select the last entry of it - lastEntryOfTransaction = financialTransactionService.getLastEntry((FinancialTransaction)entryOrTransaction); - } */ + Entry entryAt = tableModel.getEntryAt(indexSelectedRow); + Entry lastEntry = financialTransactionService.getLastEntry(entryAt.getFinancialTransaction()); + FinancialTransaction transaction = tableModel.getTransactionAt(indexSelectedRow); + if (log.isDebugEnabled()) { log.debug("Selected row : " + indexSelectedRow); } @@ -412,9 +405,9 @@ String defaultVoucher = null; String defaultDescription = null; - if (lastEntryOfTransaction != null) { - defaultVoucher = lastEntryOfTransaction.getVoucher(); - defaultDescription = lastEntryOfTransaction.getDescription(); + if (lastEntry != null) { + defaultVoucher = lastEntry.getVoucher(); + defaultDescription = lastEntry.getDescription(); } // creates the new entry @@ -431,10 +424,10 @@ BigDecimal tvaTax = null; //Calculation of tva tax only if first entry is a sale - if (lastEntryOfTransaction != null && lastEntryOfTransaction.getAccount()!= null){ - defaultAccount = lastEntryOfTransaction.getAccount().getAccountNumber(); + if (lastEntry != null && lastEntry.getAccount()!= null){ + defaultAccount = lastEntry.getAccount().getAccountNumber(); if (defaultAccount.equals("410") || defaultAccount.equals("418")){ - tvaTax = (lastEntryOfTransaction.getAmount()).multiply(tvaPercentAdd); + tvaTax = (lastEntry.getAmount()).multiply(tvaPercentAdd); } } @@ -448,24 +441,18 @@ log.info("tva : " + tvaTax); } - // check if current row is a transaction or an entry - FinancialTransaction currentTransaction = null; - Object currentRow = tableModel.getEntryAt(indexSelectedRow); - if (currentRow instanceof FinancialTransaction) { - currentTransaction = (FinancialTransaction) currentRow; - } else if (currentRow instanceof Entry) { - Entry currentEntry = (Entry) currentRow; - //get back the parent transaction of the entry - currentTransaction = currentEntry.getFinancialTransaction(); - } + BigDecimal credit = transaction.getAmountCredit(); + BigDecimal debit = transaction.getAmountDebit(); + entry.setDebit(credit.compareTo(debit) > 0); + entry.setAmount(credit.subtract(debit).abs()); // create it in service - entry.setFinancialTransaction(currentTransaction); + entry.setFinancialTransaction(transaction); Entry newEntry = financialTransactionService.createEntry(entry); - currentTransaction.addEntry(newEntry); + transaction.addEntry(newEntry); // add it in ui - int addIndex = tableModel.indexOf(lastEntryOfTransaction) + 1; + int addIndex = tableModel.indexOf(lastEntry) + 1; tableModel.addRow(newEntry, addIndex); //select the new line @@ -484,10 +471,15 @@ public void deleteSelectedTransaction() { FinancialTransactionTable table = view.getFinancialTransactionTable(); FinancialTransactionTableModel tableModel = view.getFinancialTransactionTableModel(); + ListSelectionModel selectionModel = table.getSelectionModel(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow >= 0) { FinancialTransaction transaction = tableModel.getTransactionAt(indexSelectedRow); + TableCellEditor cellEditor = table.getCellEditor(); + if (cellEditor != null) { + cellEditor.cancelCellEditing(); + } int response = JOptionPane.showConfirmDialog( view, _("lima.ui.financialtransaction.messageremovetransaction"), _("lima.ui.financialtransaction.titleremovetransaction"), JOptionPane.YES_NO_OPTION); @@ -503,6 +495,15 @@ financialTransactionService.removeFinancialTransaction(transaction); + if (tableModel.size() > 0) { + if (indexSelectedRow >= tableModel.size()) { + indexSelectedRow = tableModel.size() - 1; + } + selectionModel.setSelectionInterval( + indexSelectedRow, indexSelectedRow); + table.changeSelection(indexSelectedRow, 1, false, false); + } + } } @@ -511,10 +512,15 @@ public void deleteSelectedEntry() { FinancialTransactionTable table = view.getFinancialTransactionTable(); FinancialTransactionTableModel tableModel = view.getFinancialTransactionTableModel(); + ListSelectionModel selectionModel = table.getSelectionModel(); int indexSelectedRow = table.getSelectedRow(); if (indexSelectedRow >= 0) { Entry entry = tableModel.getEntryAt(indexSelectedRow); + TableCellEditor cellEditor = table.getCellEditor(); + if (cellEditor != null) { + cellEditor.cancelCellEditing(); + } int response = JOptionPane.showConfirmDialog( view, _("lima.ui.financialtransaction.messageremoveentry"), _("lima.ui.financialtransaction.titleremoveentry"), JOptionPane.YES_NO_OPTION); @@ -527,6 +533,17 @@ if (transaction.sizeEntry() == 0) { financialTransactionService.removeFinancialTransaction(transaction); } + + if (tableModel.size() > 0) { + if (indexSelectedRow >= tableModel.size()) { + indexSelectedRow = tableModel.size() - 1; + } else { + indexSelectedRow++; + } + selectionModel.setSelectionInterval( + indexSelectedRow, indexSelectedRow); + table.changeSelection(indexSelectedRow, 1, false, false); + } } } } Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2013-06-06 14:53:06 UTC (rev 3678) +++ trunk/lima-swing/src/main/resources/log4j.properties 2013-06-07 16:09:48 UTC (rev 3679) @@ -62,4 +62,5 @@ log4j.logger.org.chorem.lima.business.ejb.ReportServiceImpl=DEBUG log4j.logger.org.chorem.lima.ui.MainViewHandler=DEBUG log4j.logger.org.chorem.lima.business.ejb.FinancialStatementServiceImpl=DEBUG -log4j.logger.org.chorem.lima.ui.importexport.ImportExport=DEBUG \ No newline at end of file +log4j.logger.org.chorem.lima.ui.importexport.ImportExport=DEBUG +log4j.logger.org.chorem.lima.ui.celleditor.DateTableCellEditor=DEBUG \ No newline at end of file
participants (1)
-
Bavencoffļ¼ users.chorem.org