Author: vsalaun Date: 2011-05-23 16:15:17 +0200 (Mon, 23 May 2011) New Revision: 3141 Url: http://chorem.org/repositories/revision/lima/3141 Log: #268 possibilite de lettrer sur un excercice / une periode / ou entre deux dates choisies par l'utilisateur Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringPeriodSearchPanel.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringFinancialPeriodComboBox.java 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/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringFinancialPeriodComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringFinancialPeriodComboBox.java 2011-05-23 08:39:31 UTC (rev 3140) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringFinancialPeriodComboBox.java 2011-05-23 14:15:17 UTC (rev 3141) @@ -1,69 +0,0 @@ -/* - * #%L - * Lima Swing - * - * $Id$ - * $HeadURL$ - * %% - * 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 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% - */ - -package org.chorem.lima.ui.lettering; - -import javax.swing.JComboBox; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.entity.FinancialPeriod; - - -public class LetteringFinancialPeriodComboBox extends JComboBox { - - private static final long serialVersionUID = 1L; - - private static final Log log = - LogFactory.getLog(LetteringFinancialPeriodComboBox.class); - - protected LetteringViewHandler handler; - - public LetteringFinancialPeriodComboBox(LetteringViewHandler handler) { - this.handler = handler; - } - - public void back(){ - int row = this.getSelectedIndex(); - log.debug(row); - if (row > 0){ - this.setSelectedItem(this.getItemAt(row-1)); - repaint(); - handler.tableModel.setFinancialPeriod( (FinancialPeriod) this.getSelectedItem()); - } - } - - public void next(){ - int size = this.getModel().getSize(); - int row = this.getSelectedIndex(); - log.debug(row); - - if (row < size-1){ - this.setSelectedItem(this.getItemAt(row+1)); - repaint(); - handler.tableModel.setFinancialPeriod( (FinancialPeriod) this.getSelectedItem()); - } - } - -} Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringPeriodSearchPanel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringPeriodSearchPanel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringPeriodSearchPanel.java 2011-05-23 14:15:17 UTC (rev 3141) @@ -0,0 +1,135 @@ +package org.chorem.lima.ui.lettering; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Calendar; +import java.util.Date; +import static org.nuiton.i18n.I18n._; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.apache.commons.lang.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.enums.ComboBoxDatesEnum; +import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel; +import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer; +import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel; +import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer; +import org.jdesktop.swingx.JXDatePicker; + +public class LetteringPeriodSearchPanel extends JPanel { + + private static final Log log = + LogFactory.getLog(LetteringPeriodSearchPanel.class); + + protected LetteringViewHandler handler; + + public LetteringPeriodSearchPanel(LetteringViewHandler handler) { + this.handler = handler; + + //init date + refresh(ComboBoxDatesEnum.FISCAL_PERIOD); + } + + static final long serialVersionUID = 1L; + + public void refresh(ComboBoxDatesEnum comboBoxPeriodEnum){ + + switch (comboBoxPeriodEnum) { + case PERIOD: + // get begin date + Calendar calendarBegin = Calendar.getInstance(); + // set begindate to JAN 1 - 0:00.000 of this years + Date beginDate = calendarBegin.getTime(); + beginDate = DateUtils.truncate(beginDate, Calendar.YEAR); + //handler().setBeginDate(beginDate); + + // get end date + Calendar calendarEnd = Calendar.getInstance(); + Date endDate = calendarEnd.getTime(); + //handler().setEndDate(endDate); + JLabel beginDateLabel = new JLabel(_("lima.common.begindate")); + final JXDatePicker beginDatePicker = new JXDatePicker(beginDate); + ActionListener beginDateActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + handler.setBeginDate(beginDatePicker.getDate()); + handler.refresh(); + } + }; + handler.setBeginDate(beginDatePicker.getDate()); + beginDatePicker.addActionListener(beginDateActionListener); + + JLabel endDateLabel = new JLabel(_("lima.common.enddate")); + final JXDatePicker endDatePicker = new JXDatePicker(endDate); + ActionListener endDateActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + handler.setEndDate(endDatePicker.getDate()); + handler.refresh(); + } + }; + handler.setEndDate(endDatePicker.getDate()); + endDatePicker.addActionListener(endDateActionListener); + handler.refresh(); + + this.removeAll(); + this.add(beginDateLabel); + this.add(beginDatePicker); + this.add(endDateLabel); + this.add(endDatePicker); + break; + + case FISCAL_PERIOD: + FiscalPeriodComboBoxModel fiscalModel = new FiscalPeriodComboBoxModel(true); + FiscalPeriodComboBoxRenderer fiscalRenderer = new FiscalPeriodComboBoxRenderer(); + final JComboBox fiscalPeriod = new JComboBox(fiscalModel); + fiscalPeriod.setRenderer(fiscalRenderer); + fiscalPeriod.setEditable(false); + ActionListener fiscalPeriodActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FiscalPeriod fPeriod = (FiscalPeriod) fiscalPeriod.getSelectedItem(); + if (fPeriod != null){ + handler.setBeginDate(fPeriod.getBeginDate()); + handler.setEndDate(fPeriod.getEndDate()); + handler.refresh(); + } + } + }; + fiscalPeriod.addActionListener(fiscalPeriodActionListener); + + this.removeAll(); + this.add(fiscalPeriod); + break; + + case FINANCIAL_PERIOD: + FinancialPeriodComboBoxModel financialModel = new FinancialPeriodComboBoxModel(true); + FinancialPeriodComboBoxRenderer financialRenderer = new FinancialPeriodComboBoxRenderer(); + final JComboBox financialPeriod = new JComboBox(financialModel); + financialPeriod.setRenderer(financialRenderer); + financialPeriod.setEditable(false); + ActionListener financialPeriodActionListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + FinancialPeriod fPeriod = (FinancialPeriod) financialPeriod.getSelectedItem(); + if (fPeriod != null){ + handler.setBeginDate(fPeriod.getBeginDate()); + handler.setEndDate(fPeriod.getEndDate()); + handler.refresh(); + } + } + }; + financialPeriod.addActionListener(financialPeriodActionListener); + this.removeAll(); + this.add(financialPeriod); + break; + } + + } + +} 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 2011-05-23 08:39:31 UTC (rev 3140) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2011-05-23 14:15:17 UTC (rev 3141) @@ -42,7 +42,6 @@ import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.Letter; import org.chorem.lima.service.LimaServiceFactory; @@ -74,9 +73,12 @@ /** Transaction service. */ protected final FinancialTransactionServiceMonitorable financialTransactionService; - /** selected financial period */ - protected FinancialPeriod selectedFinancialPeriod; + /** Begin Date. */ + protected Date selectedBeginDate; + /** EndDate. */ + protected Date selectedEndDate; + /** data cache */ protected List<Object> cacheDataList; @@ -97,6 +99,14 @@ LimaServiceFactory.getInstance().getService( ImportServiceMonitorable.class).addListener(this); } + + public void setSelectedBeginDate(Date date) { + selectedBeginDate = date; + } + + public void setSelectedEndDate(Date date) { + selectedEndDate = date; + } /** * Le model est une combinaison de Transaction/Entries. @@ -106,11 +116,11 @@ */ protected List<Object> getDataList() { List<Object> results = new ArrayList<Object>(); - if (selectedFinancialPeriod != null){ + if (selectedBeginDate != null && selectedEndDate != null){ try { List<FinancialTransaction> financialtransactions = - financialTransactionService.getAllFinancialTransactionsForFinancialPeriod( - selectedFinancialPeriod); + financialTransactionService.getAllFinancialTransactionsFromDateToDate( + selectedBeginDate, selectedEndDate); for (FinancialTransaction financialtransaction : financialtransactions) { results.add(financialtransaction); List<Entry> entries = (List<Entry>) financialtransaction.getEntry(); @@ -124,7 +134,7 @@ } ErrorHelper.showErrorDialog("Can't get transaction list", eee); } - } + } return results; } @@ -345,12 +355,6 @@ return result; } - - public void setFinancialPeriod(FinancialPeriod financialPeriod){ - selectedFinancialPeriod = financialPeriod; - refresh(); - } - /** * To set cells editable or not * different condition for entry or financial transaction 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 2011-05-23 08:39:31 UTC (rev 3140) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2011-05-23 14:15:17 UTC (rev 3141) @@ -31,48 +31,25 @@ <![CDATA[ import org.chorem.lima.entity.FiscalPeriod; import org.chorem.lima.entity.FinancialPeriod; - import org.chorem.lima.ui.lettering.LetteringFinancialPeriodComboBox; - import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer; + import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxRenderer; + import org.chorem.lima.enums.ComboBoxDatesEnum; + LetteringPeriodSearchPanel periodSearchPanel = new LetteringPeriodSearchPanel(handler); + void $afterCompleteSetup() { - getHandler().refresh(); } ]]> </script> <row weightx="1" weighty="0" anchor="center"> - <cell anchor="east"> - <JLabel id="fiscalPeriodLabel" text="lima.charts.fiscalyear"/> - </cell> - <cell anchor="west"> - <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="modelFiscalPeriod"/> - <JComboBox id="fiscalPeriodComboBox" - model="{getModelFiscalPeriod()}" - renderer="{new org.chorem.lima.ui.combobox.FiscalPeriodComboBoxRenderer()}" - onActionPerformed="getModelFinancialPeriod().setFiscalPeriod((FiscalPeriod)fiscalPeriodComboBox.getSelectedItem())" - editable="false"/> - </cell> - <cell anchor="east"> - <JLabel id="financialPeriodLabel" text="lima.common.period" - /> - </cell> - <cell anchor="west"> - <org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel id="modelFinancialPeriod"/> - <LetteringFinancialPeriodComboBox id="financialPeriodComboBox" - constructorParams="getHandler()" - model="{getModelFinancialPeriod()}" renderer="{new FinancialPeriodComboBoxRenderer()}" - onActionPerformed="tableModel.setFinancialPeriod((FinancialPeriod)financialPeriodComboBox.getSelectedItem())"/> - </cell> + <cell fill='both'><Table><row> + <cell anchor="west"><JComboBox id="periodComboBox" javaBean="new JComboBox(ComboBoxDatesEnum.descriptions())" + onActionPerformed="periodSearchPanel.refresh(ComboBoxDatesEnum.valueOfDescription((String) periodComboBox.getSelectedItem())); + validate(); repaint()"/></cell> + <cell><LetteringPeriodSearchPanel javaBean="periodSearchPanel"/></cell> + </row></Table></cell> <cell> - <JButton id="back" text="lima.common.buttonback" - onActionPerformed="financialPeriodComboBox.back()"/> - </cell> - <cell> - <JButton id="next" text="lima.common.buttonnext" - onActionPerformed="financialPeriodComboBox.next()"/> - </cell> - <cell> <JButton text="lima.entries.lettering.add" onActionPerformed="handler.addLetter()" toolTipText="lima.tooltip.lettering" enabled="{isSelectedRow()}"/> </cell> 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 2011-05-23 08:39:31 UTC (rev 3140) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2011-05-23 14:15:17 UTC (rev 3141) @@ -26,6 +26,9 @@ package org.chorem.lima.ui.lettering; import static org.nuiton.i18n.I18n._; + +import java.util.Date; + import javax.swing.JComboBox; import javax.swing.JTextField; import org.apache.commons.logging.Log; @@ -76,10 +79,18 @@ financialTransactionService = LimaServiceFactory.getInstance().getService( FinancialTransactionServiceMonitorable.class); - } + } - + public void setBeginDate(Date date){ + tableModel = view.getTableModel(); + tableModel.setSelectedBeginDate(date); + } + public void setEndDate(Date date){ + tableModel = view.getTableModel(); + tableModel.setSelectedEndDate(date); + } + public void addLetter(){ Letter letter = null; Boolean valid = true;