Author: sbavencoff Date: 2013-12-31 16:03:48 +0100 (Tue, 31 Dec 2013) New Revision: 3721 Url: http://chorem.org/projects/lima/repository/revisions/3721 Log: Factoring code of table and model table. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateLimaTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/FiscalPeriodTableRenderer.java Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellRender.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryTableCellRenderer.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java =================================================================== --- trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-business/src/main/java/org/chorem/lima/business/utils/EntryComparator.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -36,7 +36,14 @@ @Override public int compare(Entry o1, Entry o2) { - return o1.getTopiaCreateDate().compareTo(o2.getTopiaCreateDate()); + int result = o1.getFinancialTransaction().getTransactionDate().compareTo(o2.getFinancialTransaction().getTransactionDate()); + if (result == 0) { + result = o1.getFinancialTransaction().getTopiaCreateDate().compareTo(o2.getFinancialTransaction().getTopiaCreateDate()); + } + if (result == 0) { + result = o1.getTopiaCreateDate().compareTo(o2.getTopiaCreateDate()); + } + return result; } } Modified: 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 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -29,7 +29,7 @@ /** * @author Sylvain Bavencoff <bavencoff@codelutin.com> */ -public class AccountTableCellRenderer extends EntryTableCellRenderer { +public class AccountTableCellRenderer extends DefaultLimaTableCellRenderer { @Override public void setValue(Object value) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -33,14 +33,10 @@ import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -public class BigDecimalTableCellRenderer extends EntryTableCellRenderer { +public class BigDecimalTableCellRenderer extends DefaultLimaTableCellRenderer { private static final long serialVersionUID = -2499433026151065390L; - public BigDecimalTableCellRenderer() { - // - } - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateLimaTableCellRenderer.java (from rev 3719, trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellRenderer.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateLimaTableCellRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateLimaTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -0,0 +1,44 @@ +package org.chorem.lima.ui.celleditor; + +/* + * #%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 java.text.DateFormat; +import java.util.Date; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class DateLimaTableCellRenderer extends DefaultLimaTableCellRenderer { + + @Override + protected void setValue(Object value) { + if (value instanceof Date) { + DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM); + super.setValue(format.format((Date) value)); + } else { + super.setValue(value); + } + } +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellRenderer.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DateTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -1,43 +0,0 @@ -package org.chorem.lima.ui.celleditor; - -/* - * #%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 java.text.DateFormat; -import java.util.Date; - -/** - * @author Sylvain Bavencoff <bavencoff@codelutin.com> - */ -public class DateTableCellRenderer extends EntryTableCellRenderer { - - protected void setValue(Object value) { - if (value instanceof Date) { - DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM); - super.setValue(format.format((Date) value)); - } else { - super.setValue(value); - } - } -} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/DefaultLimaTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -0,0 +1,100 @@ +package org.chorem.lima.ui.celleditor; + +import org.chorem.lima.ui.common.FinancialTransactionTableModel; +import org.chorem.lima.ui.common.TableModelWithGroup; +import org.chorem.lima.ui.financialtransaction.FinancialTransactionTable; +import sun.swing.DefaultLookup; + +import javax.swing.*; +import javax.swing.border.Border; +import javax.swing.border.EmptyBorder; +import javax.swing.table.TableCellRenderer; +import java.awt.*; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class DefaultLimaTableCellRenderer implements TableCellRenderer { + + private String text = null; + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + //Create a new JLabel to avoid colouring only when row is selected + JLabel myCell = new JLabel(); + myCell.setOpaque(true); + myCell.setBorder(new EmptyBorder(1, 1, 1, 1)); + myCell.setName("Table.entryCellRenderer"); + + Color background = Color.WHITE; + Color foreground = Color.BLACK; + + if (isSelected) { + foreground = table.getSelectionForeground(); + background = table.getSelectionBackground(); + } else { + Color alternateColor = new Color(204, 207, 223); + + if (table.getModel() instanceof TableModelWithGroup) { + TableModelWithGroup model = (TableModelWithGroup) table.getModel(); + if (model.indexGroupAt(row) % 2 != 0) { + background = alternateColor; + } + } else if (row % 2 != 0) { + background = alternateColor; + } + } + + if (table.isCellEditable(row, column) + && (value == null + || (value instanceof String) && ((String) value).isEmpty() + ) + ) { + background = new Color(255, 198, 209); + } + + if (table instanceof FinancialTransactionTable) { + FinancialTransactionTableModel model = (FinancialTransactionTableModel) ((FinancialTransactionTable)table).getModel(); + if (model.getBalanceTransactionInRow(row).signum() != 0) { + foreground = new Color(240, 30, 30); + } + } + + if (hasFocus) { + Border border = null; + if (isSelected) { + //FIXME tchemit-2013-08_02 Do not use sun. classes + border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.focusSelectedCellHighlightBorder"); + } + if (border == null) { + //FIXME tchemit-2013-08_02 Do not use sun. classes + border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.focusCellHighlightBorder"); + } + myCell.setBorder(border); + if (table.getModel().isCellEditable(row, column)) { + background = Color.WHITE; + foreground = Color.BLACK; + } + } else { + //FIXME tchemit-2013-08_02 Do not use sun. classes + Border border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.cellNoFocusBorder"); + if (border == null) { + border = new EmptyBorder(1, 1, 1, 1); + } + myCell.setBorder(border); + } + + myCell.setBackground(background); + myCell.setForeground(foreground); + setValue(value); + + myCell.setText(text); + + return myCell; + } + + protected void setValue(Object value) { + this.text = (value == null) ? "" : value.toString(); + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellRender.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellRender.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryBookTableCellRender.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -29,7 +29,7 @@ /** * @author Sylvain Bavencoff <bavencoff@codelutin.com> */ -public class EntryBookTableCellRender extends EntryTableCellRenderer { +public class EntryBookTableCellRender extends DefaultLimaTableCellRenderer { @Override public void setValue(Object value) { Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryTableCellRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryTableCellRenderer.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/EntryTableCellRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -24,105 +24,29 @@ * #L% */ -import org.chorem.lima.ui.common.TableModelWithGroup; +import org.chorem.lima.ui.common.FinancialTransactionTableModel; +import org.chorem.lima.ui.common.LineRenderer; import org.chorem.lima.ui.financialtransaction.FinancialTransactionTable; -import org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel; -import sun.swing.DefaultLookup; import javax.swing.*; -import javax.swing.border.Border; -import javax.swing.border.EmptyBorder; -import javax.swing.table.TableCellRenderer; import java.awt.*; -import java.io.Serializable; /** * @author Sylvain Bavencoff <bavencoff@codelutin.com> */ -public class EntryTableCellRenderer implements TableCellRenderer, Serializable { +public class EntryTableCellRenderer extends LineRenderer { - private String text = null; + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - //Create a new JLabel to avoid colouring only when row is selected - - JLabel myCell = new JLabel(); - myCell.setOpaque(true); - myCell.setBorder(new EmptyBorder(1, 1, 1, 1)); - myCell.setName("Table.entryCellRenderer"); - - Color background = Color.WHITE; - Color foreground = Color.BLACK; - - if (isSelected) { - foreground = table.getSelectionForeground(); - background = table.getSelectionBackground(); - } else { - //FIXME tchemit-2013-08_02 Do not use sun. classes - Color alternateColor = DefaultLookup.getColor(myCell, myCell.getUI(), "Table.alternateRowColor"); - if (alternateColor != null) { - - if (table.getModel() instanceof TableModelWithGroup) { - TableModelWithGroup model = (TableModelWithGroup) table.getModel(); - if (model.indexGroupAt(row) % 2 != 0) { - background = alternateColor; - } - } else if (row % 2 == 0) { - background = alternateColor; - } - } + if (table instanceof FinancialTransactionTable) { + FinancialTransactionTableModel model = (FinancialTransactionTableModel) table.getModel(); + if (!isSelected && model.getBalanceTransactionInRow(row).signum() != 0) { + component.setForeground(new Color(240, 30, 30)); } - - if (table.isCellEditable(row, column) - && (value == null - || (value instanceof String) && ((String) value).isEmpty() - ) - ) { - background = new Color(255, 198, 209); - } - - if (table instanceof FinancialTransactionTable) { - FinancialTransactionTableModel model = (FinancialTransactionTableModel) ((FinancialTransactionTable)table).getModel(); - if (model.getBalanceTransactionInRow(row).signum() != 0) { - foreground = new Color(240, 30, 30); - } - } - - if (hasFocus) { - Border border = null; - if (isSelected) { - //FIXME tchemit-2013-08_02 Do not use sun. classes - border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.focusSelectedCellHighlightBorder"); - } - if (border == null) { - //FIXME tchemit-2013-08_02 Do not use sun. classes - border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.focusCellHighlightBorder"); - } - myCell.setBorder(border); - if (table.getModel().isCellEditable(row, column)) { - background = Color.WHITE; - foreground = Color.BLACK; - } - } else { - //FIXME tchemit-2013-08_02 Do not use sun. classes - Border border = DefaultLookup.getBorder(myCell, myCell.getUI(), "Table.cellNoFocusBorder"); - if (border == null) { - border = new EmptyBorder(1, 1, 1, 1); - } - myCell.setBorder(border); - } - - myCell.setBackground(background); - myCell.setForeground(foreground); - setValue(value); - - myCell.setText(text); - - return myCell; } - protected void setValue(Object value) { - this.text = (value == null) ? "" : value.toString(); - } + return component; } +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/FiscalPeriodTableRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/FiscalPeriodTableRenderer.java 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/FiscalPeriodTableRenderer.java 2013-12-31 15:03:48 UTC (rev 3721) @@ -1,31 +0,0 @@ -package org.chorem.lima.ui.celleditor; - -import org.chorem.lima.entity.FiscalPeriod; -import org.chorem.lima.ui.fiscalperiod.FiscalPeriodTableModel; - -import javax.swing.*; -import javax.swing.table.DefaultTableCellRenderer; -import java.awt.*; - -/** - * @author Sylvain Bavencoff <bavencoff@codelutin.com> - */ -public class FiscalPeriodTableRenderer extends DefaultTableCellRenderer { - - public Component getTableCellRendererComponent(JTable table, Object value, - boolean isSelected, boolean hasFocus, int row, int column) { - - Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); - - if (table.getModel() instanceof FiscalPeriodTableModel) { - FiscalPeriodTableModel model = (FiscalPeriodTableModel) table.getModel(); - FiscalPeriod fiscalPeriod = model.getFiscalPeriodAt(row); - if (!isSelected && fiscalPeriod.getLocked()) { - component.setForeground(new Color(222, 0, 0)); - } - } - return component; - } - - -} Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2013-12-31 15:03:48 UTC (rev 3721) @@ -320,6 +320,7 @@ lima.ui.fiscalPeriod.buttonnext= lima.ui.fiscalperiod.addfiscalperiod.morethan12= lima.ui.fiscalperiod.addfiscalperiodtitle= +lima.ui.fiscalperiod.begin= lima.ui.fiscalperiod.block.addretainedearnings= lima.ui.fiscalperiod.block.confirmation= lima.ui.fiscalperiod.block.newyear= @@ -331,9 +332,14 @@ lima.ui.fiscalperiod.closure= lima.ui.fiscalperiod.delete.confirmation= lima.ui.fiscalperiod.delete.title= +lima.ui.fiscalperiod.end= lima.ui.fiscalperiod.entrybooks.create= lima.ui.fiscalperiod.fiscalperiod= +lima.ui.fiscalperiod.fiscalperiod.begin= +lima.ui.fiscalperiod.fiscalperiod.end= +lima.ui.fiscalperiod.fiscalperiod.status= lima.ui.fiscalperiod.open= +lima.ui.fiscalperiod.status= lima.ui.home.account=Chart of accounts lima.ui.home.chartaccounts.create=Create the chart of accounts lima.ui.home.chartaccounts.modify=Edit the chart of accounts @@ -403,6 +409,7 @@ lima.ui.lettering.selectEntry=Actual selection lima.ui.lettering.selectSolde=Balance lima.ui.mainview.title=Lutin Invoice Monitoring and Accounting +lima.ui.nonaffect= lima.ui.opening.accounts=<html><center>Select a default, <br/>import your personnal<br/> or cancel to create your own account chart.</center></html> lima.ui.opening.close=Close lima.ui.opening.end=Finish Modified: trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties =================================================================== --- trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2013-12-31 15:03:48 UTC (rev 3721) @@ -310,6 +310,7 @@ lima.ui.fiscalPeriod.buttonnext= lima.ui.fiscalperiod.addfiscalperiod.morethan12=La période sélectionnée n'est pas de 12 mois, voulez-vous continuer ? lima.ui.fiscalperiod.addfiscalperiodtitle=Nouvel exercice +lima.ui.fiscalperiod.begin=Début lima.ui.fiscalperiod.block.addretainedearnings=Reporter à nouveau? lima.ui.fiscalperiod.block.confirmation=Ètes vous sûre de vouloir clôturer cette période ? Cette action est irréversible \! lima.ui.fiscalperiod.block.newyear=Voulez vous créer un nouvel exercice? @@ -321,9 +322,11 @@ lima.ui.fiscalperiod.closure=Cloture lima.ui.fiscalperiod.delete.confirmation=Ètes vous sûre de vouloir supprimer cette période ? Cette action est irréversible \! lima.ui.fiscalperiod.delete.title=Suppression de l'exercice +lima.ui.fiscalperiod.end=Fin lima.ui.fiscalperiod.entrybooks.create=Création d'un nouveau journal lima.ui.fiscalperiod.fiscalperiod=Exercice lima.ui.fiscalperiod.open=Ouvert +lima.ui.fiscalperiod.status=Statut lima.ui.home.account=Plan comptable lima.ui.home.chartaccounts.create=Créer le plan des comptes lima.ui.home.chartaccounts.modify=Modifier le plan des comptes @@ -393,6 +396,7 @@ lima.ui.lettering.selectEntry=Sélection courante lima.ui.lettering.selectSolde=Solde lima.ui.mainview.title=Lutin Invoice Monitoring and Accounting +lima.ui.nonaffect= lima.ui.opening.accounts=<html><center>Veuillez sélectionner un plan par défault, <br/>importer un plan personnalisé<br/> ou annuler pour créer votre propre plan.</center></html> lima.ui.opening.close=Fermer lima.ui.opening.end=Terminer Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2013-12-31 15:00:00 UTC (rev 3720) +++ trunk/lima-swing/src/main/resources/log4j.properties 2013-12-31 15:03:48 UTC (rev 3721) @@ -42,7 +42,7 @@ log4j.logger.org.chorem.lima.ui.lettering.LetteringViewHandler=DEBUG log4j.logger.org.chorem.lima.ui.lettering.LettringSelectionModel=DEBUG log4j.logger.org.chorem.lima.ui.lettering.LetteringEditModel=DEBUG -log4j.logger.org.chorem.lima.ui.financialtransaction.FinancialTransactionTableModel=DEBUG +log4j.logger.org.chorem.lima.ui.common.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