r3726 - in trunk/lima-swing/src/main/java/org/chorem/lima/ui: common financialtransaction lettering
Author: sbavencoff Date: 2013-12-31 17:45:49 +0100 (Tue, 31 Dec 2013) New Revision: 3726 Url: http://chorem.org/projects/lima/repository/revisions/3726 Log: Factoring code of table and model table. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/AccountColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/CreditColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DateColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DebitColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DescriptionColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetterColumn.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/VoucherColumn.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/LineRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.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/LetteringTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTable.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -28,6 +28,8 @@ public AbstractLimaTable(H handler) { this.handler = handler; + lineRenderer = new LineRenderer(); + setShowHorizontalLines(true); setShowVerticalLines(true); setGridColor(new Color(232, 232, 246)); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -61,7 +61,7 @@ public void addAll(Collection<E> values) { int row = this.values.size(); this.values.addAll(values); - fireTableRowsInserted(row, row + values.size() -1); + fireTableRowsInserted(row, row + values.size() - 1); sort(); } @@ -69,6 +69,10 @@ values.clear(); } + public List<E> getValues() { + return values; + } + public void remove(E value) { int row = indexOf(value); values.remove(value); @@ -167,5 +171,4 @@ fireTableCellUpdated(row, column); } } - } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/LineRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/LineRenderer.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/LineRenderer.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -9,7 +9,7 @@ /** * @author Sylvain Bavencoff <bavencoff@codelutin.com> */ -public abstract class LineRenderer extends DefaultLimaTableCellRenderer { +public class LineRenderer extends DefaultLimaTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -25,7 +25,6 @@ */ import org.chorem.lima.entity.Entry; -import org.chorem.lima.ui.celleditor.EntryTableCellRenderer; import org.chorem.lima.ui.celleditor.StringTableCellEditor; import org.chorem.lima.ui.common.DefaultColumn; import org.chorem.lima.ui.common.FinancialTransactionTableModel; @@ -38,7 +37,6 @@ public class LetterColumn extends DefaultColumn<FinancialTransactionTableModel> { public LetterColumn() { - renderer = new EntryTableCellRenderer(); editor = new StringTableCellEditor(); } Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/AccountColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/AccountColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/AccountColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/AccountColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,58 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Account; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.celleditor.AccountTableCellRenderer; +import org.chorem.lima.ui.common.DefaultColumn; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class AccountColumn extends DefaultColumn<LetteringTableModel> { + + public AccountColumn() { + renderer = new AccountTableCellRenderer(); + } + + @Override + public Class<?> getColumnClass() { + return Account.class; + } + + @Override + public String getColumnName() { + return _("lima.table.account"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getAccount(); + } +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/CreditColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/CreditColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/CreditColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/CreditColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,59 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; +import org.chorem.lima.ui.common.DefaultColumn; + +import java.math.BigDecimal; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class CreditColumn extends DefaultColumn<LetteringTableModel> { + + public CreditColumn() { + renderer = new BigDecimalTableCellRenderer(); + } + + @Override + public Class<?> getColumnClass() { + return BigDecimal.class; + } + + @Override + public String getColumnName() { + return _("lima.table.credit"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getDebit() ? BigDecimal.ZERO : entry.getAmount(); + } +} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DateColumn.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DateColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DateColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,35 @@ +package org.chorem.lima.ui.lettering; + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.celleditor.DateLimaTableCellRenderer; +import org.chorem.lima.ui.common.DefaultColumn; + +import java.util.Date; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class DateColumn extends DefaultColumn<LetteringTableModel> { + + public DateColumn() { + renderer = new DateLimaTableCellRenderer(); + } + + @Override + public Class<?> getColumnClass() { + return Date.class; + } + + @Override + public String getColumnName() { + return _("lima.table.date"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getFinancialTransaction().getTransactionDate(); + } +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DebitColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DebitColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DebitColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DebitColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,59 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; +import org.chorem.lima.ui.common.DefaultColumn; + +import java.math.BigDecimal; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class DebitColumn extends DefaultColumn<LetteringTableModel> { + + public DebitColumn() { + renderer = new BigDecimalTableCellRenderer(); + } + + @Override + public Class<?> getColumnClass() { + return BigDecimal.class; + } + + @Override + public String getColumnName() { + return _("lima.table.debit"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getDebit() ? entry.getAmount() : BigDecimal.ZERO; + } +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DescriptionColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/DescriptionColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DescriptionColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/DescriptionColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,53 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.common.DefaultColumn; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class DescriptionColumn extends DefaultColumn<LetteringTableModel> { + + @Override + public Class<?> getColumnClass() { + return String.class; + } + + @Override + public String getColumnName() { + return _("lima.ui.financialtransaction.description"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getDescription(); + } + +} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetterColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/LetterColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetterColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetterColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,52 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.common.DefaultColumn; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class LetterColumn extends DefaultColumn<LetteringTableModel> { + + @Override + public Class<?> getColumnClass() { + return String.class; + } + + @Override + public String getColumnName() { + return _("lima.table.letter"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getLettering(); + } +} 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 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTable.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -25,101 +25,21 @@ package org.chorem.lima.ui.lettering; -import org.chorem.lima.entity.Account; -import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.ui.celleditor.AccountTableCellEditor; -import org.chorem.lima.ui.celleditor.BigDecimalTableCellEditor; -import org.chorem.lima.ui.celleditor.BigDecimalTableCellRenderer; -import org.chorem.lima.ui.celleditor.DateTableCellEditor; -import org.chorem.lima.ui.celleditor.EntryBookTableCellEditor; -import org.jdesktop.swingx.JXTable; +import org.chorem.lima.ui.common.AbstractLimaTable; -import javax.swing.*; -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.math.BigDecimal; -import java.util.Date; - /** * Table des transaction qui ajoute des comportement (keys). * * @author jpepin */ -public class LetteringTable extends JXTable { +public class LetteringTable extends AbstractLimaTable<LetteringViewHandler> { /** serialVersionUID. */ private static final long serialVersionUID = 3133690382049594727L; - protected final LetteringViewHandler handler; + public LetteringTable(LetteringViewHandler handler) { + super(handler); - public LetteringTable(LetteringTableModel letteringTableModel, final LetteringViewHandler handler) { - super(letteringTableModel); - - this.handler = handler; - - //To block reaction of the dual key 'ctrl+a' (Selection of all lines) - InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - ActionMap actionMap = getActionMap(); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "none"); - - // add action on Ctrl + L - String binding = "lettering"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK), binding); - actionMap.put(binding, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - handler.addLetter(); - } - }); - - // add action on Ctrl + Delete - binding = "un-lettering"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), binding); - actionMap.put(binding, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - handler.removeLetter(); - } - }); - - // add action on Ctrl + B - binding = "balance"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK), binding); - actionMap.put(binding, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - handler.roundAndCreateEntry(); - } - }); - - // refresh - binding = "refresh"; - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), binding); - actionMap.put(binding, new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - handler.updateAllEntries(); - } - }); - - - - //Get new date editor - setDefaultEditor(Date.class, new DateTableCellEditor()); - - //Get new account editor - setDefaultEditor(String.class, new DefaultCellEditor(new JTextField())); - - //Get new entry book editor - setDefaultEditor(EntryBook.class, new EntryBookTableCellEditor()); - //Get new account editor - setDefaultEditor(Account.class, new AccountTableCellEditor()); - - //Get new amount editor - setDefaultEditor(BigDecimal.class, new BigDecimalTableCellEditor()); - //Get new BigDecimal renderer - setDefaultRenderer(BigDecimal.class, new BigDecimalTableCellRenderer()); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -25,230 +25,30 @@ package org.chorem.lima.ui.lettering; -import org.chorem.lima.LimaContext; -import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.nuiton.util.decorator.Decorator; -import org.nuiton.util.decorator.DecoratorProvider; +import org.chorem.lima.ui.common.AbstractLimaTableModel; -import javax.swing.table.AbstractTableModel; -import java.math.BigDecimal; -import java.util.Date; -import java.util.List; - -import static org.nuiton.i18n.I18n._; - /** * Basic transaction table model. * <p/> - * Le modele est filtré sur {@link #selectedBeginDate} et - * {@link #selectedEndDate} (montée en charge !). * * @author ore * @author chatellier */ -public class LetteringTableModel extends AbstractTableModel{ +public class LetteringTableModel extends AbstractLimaTableModel<Entry> { /** serialVersionUID. */ private static final long serialVersionUID = 1L; - /** Begin Date. */ - protected Date selectedBeginDate; - - /** EndDate. */ - protected Date selectedEndDate; - - protected List<Entry> entries; - protected List<Date> datesEntree; - protected List<String> entryBooks; - - /** - * To decorate account objects. - */ - protected final Decorator<Account> accountDecorator; - - public LetteringTableModel() { - DecoratorProvider decoratorProvider = - LimaContext.get().getDecoratorProvider(); - accountDecorator = decoratorProvider.getDecoratorByType(Account.class); - } - - public List<Entry> getEntries(){ - return entries; - } - - public Date getDateEntree(int row) { - return datesEntree.get(row); - } - - public Integer getIndexOfEntry(Entry entrySearch){ - return entries.indexOf(entrySearch); - } - - public int getNumberOfEntries(){ - return entries.size(); - } - - public void updateEntries(List<Entry> entries,List<Date> datesEntree, List<String> entryBooks) { - - this.entries = entries; - setDate(datesEntree); - setJournal(entryBooks); - fireTableDataChanged(); - } - - protected void setDate(List<Date> datesEntree){ - this.datesEntree=datesEntree; - } - - protected void setJournal(List<String> entryBooks){ - this.entryBooks = entryBooks; - } - @Override - public int getColumnCount() { - return 7; + protected void initColumn() { + addColumn(new DateColumn()); + addColumn(new AccountColumn()); + addColumn(new VoucherColumn()); + addColumn(new DescriptionColumn()); + addColumn(new LetterColumn()); + addColumn(new DebitColumn()); + addColumn(new CreditColumn()); } - public Entry getEntryAt(int row) { - if (row == -1) { - return null; - } - - return entries.get(row); - } - - @Override - public Class<?> getColumnClass(int column) { - - Class<?> result = String.class; - - switch (column) { - case 0: - result = Date.class; - break; - case 1: - result = String.class; - break; - case 2: - result = String.class; - break; - case 3: - result = Account.class; - break; - case 4: - result = String.class; - break; - case 5: - result = BigDecimal.class; - break; - case 6: - result = BigDecimal.class; - break; - } - - return result; - } - - @Override - public String getColumnName(int column) { - String result = "n/a"; - - switch (column) { - case 0: - result = _("lima.table.date"); - break; - case 1: - result = _("lima.table.account"); - break; - case 2: - result = _("lima.table.voucher"); - break; - case 3: - result = _("lima.table.description"); - break; - case 4: - result = _("lima.table.letter"); - break; - case 5: - result = _("lima.table.debit"); - break; - case 6: - result = _("lima.table.credit"); - break; - } - - return result; - } - - @Override - public int getRowCount() { - if (entries != null){ - return entries.size(); - } - return 0; - } - - @Override - public Object getValueAt(int row, int column) { - Object result = null; - - if (entries.size() > 0){ - Entry currentEntry = entries.get(row); - switch (column) { - case 0: - result = datesEntree.get(row); // date - break; - case 1: // account - Account acc = currentEntry.getAccount(); - result = accountDecorator.toString(acc); - break; - case 2: - result = currentEntry.getVoucher(); - break; - case 3: - result = currentEntry.getDescription(); - break; - case 4: - result = currentEntry.getLettering(); - break; - case 5: - result = currentEntry.getDebit() ? currentEntry.getAmount() : BigDecimal.ZERO; - break; - case 6: - result = currentEntry.getDebit() ? BigDecimal.ZERO : currentEntry.getAmount(); - break; - } - } - return result; - } - - /** - * Only cell of "Letter" could be editable - */ - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - - public Object getElementAt(int row) { - return entries.get(row); - } - - /**add one entry*/ - public void addEntry(Entry entry, Date dateEntree) { - entries.add(entry); - datesEntree.add(dateEntree); - int row = entries.indexOf(entry); - fireTableRowsInserted(row, row); - } - - /**update selected entries*/ - public void updateLettersSelectedEntries(int[] entries, String letters) { - for (int rowEntry : entries){ - getEntryAt(rowEntry).setLettering(letters); - fireTableRowsUpdated(rowEntry, rowEntry); - } - } - } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2013-12-31 16:45:49 UTC (rev 3726) @@ -35,13 +35,12 @@ </import> <LetteringViewHandler id="handler" constructorParams="this"/> - <LetteringTableModel id="tableModel"/> + <LetteringEditModel id='editModel'/> - <LettringSelectionModel id='lettringSelectionModel' constructorParams=' tableModel' - onValueChanged="handler.balanceAndActions()"/> + <script> <![CDATA[ void $afterCompleteSetup() { @@ -155,10 +154,16 @@ <row> <cell fill="both" weightx="1" weighty="1" > <JScrollPane> - <LetteringTable - id="table" sortable="false" rowHeight="22" - constructorParams="getTableModel(), handler" - selectionModel="{lettringSelectionModel}" /> + <LetteringTableModel id="tableModel"/> + <LettringSelectionModel id='lettringSelectionModel' constructorParams='tableModel' + onValueChanged="handler.balanceAndActions()"/> + + <LetteringTable id="table" + sortable="false" + rowHeight="22" + constructorParams="handler" + model="{tableModel}" + selectionModel="{lettringSelectionModel}" /> </JScrollPane> </cell> </row> 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 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -36,13 +36,14 @@ import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; -import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.service.LimaServiceFactory; import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; import java.math.BigDecimal; -import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -82,6 +83,7 @@ public LetteringViewHandler(LetteringView view) { this.view = view; + initShortCuts(); financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); accountService = LimaServiceFactory.getService(AccountService.class); @@ -99,6 +101,56 @@ loadComboAndRows(); } + protected void initShortCuts() { + + InputMap inputMap= view.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + ActionMap actionMap = view.getActionMap(); + Object binding; + + //To block reaction of the dual key 'ctrl+a' (Selection of all lines) + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "none"); + + // add action on Ctrl + L + binding = "lettering"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_L, KeyEvent.CTRL_DOWN_MASK), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + addLetter(); + } + }); + + // add action on Ctrl + Delete + binding = "un-lettering"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + removeLetter(); + } + }); + + // add action on Ctrl + B + binding = "balance"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + roundAndCreateEntry(); + } + }); + + // refresh + binding = "refresh"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + updateAllEntries(); + } + }); + } + public void balanceAndActions() { if (log.isDebugEnabled()) { log.debug("balanceAndActions"); @@ -125,8 +177,8 @@ } /*Treatment only if one of values contains decimals*/ LetteringTableModel tableModel = view.getTableModel(); - Entry firstSelectedEntry = tableModel.getEntryAt(selectedRows[0]); - Entry secondSelectedEntry = tableModel.getEntryAt(selectedRows[1]); + Entry firstSelectedEntry = tableModel.get(selectedRows[0]); + Entry secondSelectedEntry = tableModel.get(selectedRows[1]); /*Get decimals*/ BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); @@ -169,7 +221,7 @@ public boolean letteringNotExist(int row){ boolean emptyOrNull = false; if (row != -1) { - Entry entry = view.getTableModel().getEntryAt(row); + Entry entry = view.getTableModel().get(row); String lettering = entry.getLettering(); emptyOrNull = (lettering==null||lettering.isEmpty()); } @@ -202,7 +254,7 @@ LetteringTableModel tableModel = view.getTableModel(); for (int i = 0; i < tableModel.getRowCount(); i ++){ if (view.getLettringSelectionModel().isSelectedIndex(i)){ - selectedEntry = tableModel.getEntryAt(i); + selectedEntry = tableModel.get(i); //Set values for calculation (By LetteringEditModel) of balance onBalanceChanged(selectedEntry); } @@ -319,22 +371,8 @@ if (filter.getAccount() != null && filter.getDateStart() != null && filter.getDateEnd() != null) { List<Entry> entries = findAllEntries(filter); - List<String> journalEntrees = new ArrayList<String>(); - List<Date> datesEntree = new ArrayList<Date>(); - for (Entry entry : entries){ - FinancialTransaction financialTransaction = entry.getFinancialTransaction(); - datesEntree.add(financialTransaction.getTransactionDate()); - if (financialTransaction.getEntryBook() == null || - financialTransaction.getEntryBook().getLabel() == null) { - journalEntrees.add(""); - } else { - journalEntrees.add(financialTransaction.getEntryBook().getLabel()); - } - - } - - view.getTableModel().updateEntries(entries, datesEntree, journalEntrees); + view.getTableModel().setValues(entries); } onBalanceChanged(null); } @@ -350,16 +388,16 @@ int[] selectedRows = view.getTable().getSelectedRows(); if (editModel.isEqualized() && selectedRows.length == 2) { /*Treatment only if one of values contains decimals*/ - Entry firstSelectedEntry = tableModel.getEntryAt(selectedRows[0]); - Entry secondSelectedEntry = tableModel.getEntryAt(selectedRows[1]); + Entry firstSelectedEntry = tableModel.get(selectedRows[0]); + Entry secondSelectedEntry = tableModel.get(selectedRows[1]); Entry[] newEntriesFormEqualizing = financialTransactionService.getEntriesFromEqualizing(firstSelectedEntry, secondSelectedEntry); /*Add new entries to the model and the table*/ Entry newSameAccountEntry = newEntriesFormEqualizing[0]; Entry newCostOrProductEntry = newEntriesFormEqualizing[1]; - tableModel.addEntry(newSameAccountEntry, newSameAccountEntry.getFinancialTransaction().getTransactionDate()); - tableModel.addEntry(newCostOrProductEntry, newCostOrProductEntry.getFinancialTransaction().getTransactionDate()); + tableModel.addValue(newSameAccountEntry); + tableModel.addValue(newCostOrProductEntry); /*Re-select the two entries (firstSelectedEntry and secondSelectedEntry) * and the new sameAccountEntry @@ -419,10 +457,14 @@ int[] entrieSelected = view.getTable().getSelectedRows(); - view.getTableModel().updateLettersSelectedEntries(entrieSelected, newLetters); + LetteringTableModel tableModel = view.getTableModel(); for (int indexEntry : entrieSelected){ - financialTransactionService.updateEntry(view.getTableModel().getEntryAt(indexEntry)); + Entry entry = tableModel.get(indexEntry); + entry.setLettering(newLetters); + financialTransactionService.updateEntry(entry); + tableModel.fireTableRowsUpdated(indexEntry, indexEntry); + } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java 2013-12-31 15:11:52 UTC (rev 3725) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -64,7 +64,7 @@ for(Entry entry : getEntries()){ if (StringUtils.isNotBlank(entry.getLettering())){ if (entry.getLettering().equals(currentLettring)){ - int entryToSelect = letteringTableModel.getIndexOfEntry(entry); + int entryToSelect = letteringTableModel.indexOf(entry); super.addSelectionInterval(entryToSelect, entryToSelect); } } @@ -77,7 +77,7 @@ //To clear the selection when it changes from lettered entry to unlettered for(Entry entry : getEntries()){ if (!StringUtils.isBlank(entry.getLettering())) { - int entryToSelect = letteringTableModel.getIndexOfEntry(entry); + int entryToSelect = letteringTableModel.indexOf(entry); super.removeSelectionInterval(entryToSelect, entryToSelect); } } @@ -97,14 +97,14 @@ * */ public boolean letteringNotExist(int row){ boolean emptyOrNull; - entry = letteringTableModel.getEntryAt(row); + entry = letteringTableModel.get(row); String lettering = entry.getLettering(); emptyOrNull = (lettering==null||lettering.isEmpty()); return emptyOrNull; } public List<Entry> getEntries(){ - return letteringTableModel.getEntries(); + return letteringTableModel.getValues(); } public String getCurrentLettring(){ @@ -112,7 +112,7 @@ } public Entry getCurrentEntrySelected(){ - return letteringTableModel.getEntryAt(lineSelected); + return letteringTableModel.get(lineSelected); } /**After rounding one of two entries, selection of its, and of the new entry, @@ -125,7 +125,7 @@ addSelectionInterval(indexSecondRoundedEntry, indexSecondRoundedEntry); } /*New entry*/ - int newEntryIndex = letteringTableModel.getIndexOfEntry(newResultRoundedEntry); + int newEntryIndex = letteringTableModel.indexOf(newResultRoundedEntry); addSelectionInterval(newEntryIndex, newEntryIndex); } Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/VoucherColumn.java (from rev 3725, trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransaction/VoucherColumn.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/VoucherColumn.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/VoucherColumn.java 2013-12-31 16:45:49 UTC (rev 3726) @@ -0,0 +1,52 @@ +package org.chorem.lima.ui.lettering; + +/* + * #%L + * Lima :: Swing + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2008 - 2013 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 3 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, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.ui.common.DefaultColumn; + +import static org.nuiton.i18n.I18n._; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class VoucherColumn extends DefaultColumn<LetteringTableModel> { + + @Override + public Class<?> getColumnClass() { + return String.class; + } + + @Override + public String getColumnName() { + return _("lima.table.voucher"); + } + + @Override + public Object getValueAt(int row) { + Entry entry = tableModel.get(row); + return entry.getVoucher(); + } +}
participants (1)
-
sbavencoff@users.chorem.org