r3436 - in trunk/lima-swing/src/main: java/org/chorem/lima/ui/accountsreports java/org/chorem/lima/ui/celleditor java/org/chorem/lima/ui/common java/org/chorem/lima/ui/entrybooksreports java/org/chorem/lima/ui/financialtransactionsearch resources/i18n
Author: echatellier Date: 2012-06-01 16:01:39 +0200 (Fri, 01 Jun 2012) New Revision: 3436 Url: http://chorem.org/repositories/revision/lima/3436 Log: Entry book report refactoring Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountListRenderer.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountRenderer.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsPeriodSearchPanel.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBookComboBox.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/AccountSearchComboBox.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 Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsView.jaxx 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsView.jaxx 2012-06-01 14:01:39 UTC (rev 3436) @@ -76,7 +76,7 @@ <cell fill='horizontal' anchor="west"> <AccountComboBoxModel id="accountComboboxModel" /> <AccountComboBox id="accountComboBox" model="{accountComboboxModel}" - renderer="{new org.chorem.lima.ui.common.AccountRenderer()}" + renderer="{new org.chorem.lima.ui.common.AccountListRenderer()}" onItemStateChanged="handler.accountChanged(event)" /> </cell> <cell> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/AccountTableCellEditor.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.ui.combobox.LeafAccountComboBoxModel; -import org.chorem.lima.ui.common.AccountRenderer; +import org.chorem.lima.ui.common.AccountListRenderer; import org.chorem.lima.util.AccountToString; import org.chorem.lima.widgets.JWideComboBox; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; @@ -70,7 +70,7 @@ comboBox = new JWideComboBox(); LeafAccountComboBoxModel accountComboBoxModel = new LeafAccountComboBoxModel(); comboBox.setModel(accountComboBoxModel); - AccountRenderer accountRenderer = new AccountRenderer(); + AccountListRenderer accountRenderer = new AccountListRenderer(); comboBox.setRenderer(accountRenderer); AutoCompleteDecorator.decorate(comboBox, AccountToString.getInstance()); comboBox.getEditor().getEditorComponent().addKeyListener(this); Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountListRenderer.java (from rev 3429, trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountRenderer.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountListRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountListRenderer.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -0,0 +1,64 @@ +/* + * #%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.common; + +import org.chorem.lima.entity.Account; + +import javax.swing.DefaultListCellRenderer; +import javax.swing.JLabel; +import javax.swing.JList; +import java.awt.Component; + +public class AccountListRenderer extends DefaultListCellRenderer { + + private static final long serialVersionUID = 1L; + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, + boolean isSelected, + boolean cellHasFocus) { + + JLabel label = (JLabel) super.getListCellRendererComponent(list, + value, + index, + isSelected, + cellHasFocus + ); + if (value != null) { + Account account = (Account) value; + String accountLabel = account.getLabel(); + int nbChars = 30; + if (accountLabel != null && accountLabel.length() > nbChars) { + accountLabel = accountLabel.substring(0, nbChars) + "…"; + } + label.setText(account.getAccountNumber() + " - " + accountLabel); + } + return this; + } + +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountRenderer.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AccountRenderer.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -1,64 +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.common; - -import org.chorem.lima.entity.Account; - -import javax.swing.DefaultListCellRenderer; -import javax.swing.JLabel; -import javax.swing.JList; -import java.awt.Component; - -public class AccountRenderer extends DefaultListCellRenderer { - - private static final long serialVersionUID = 1L; - - @Override - public Component getListCellRendererComponent(JList list, - Object value, - int index, - boolean isSelected, - boolean cellHasFocus) { - - JLabel label = (JLabel) super.getListCellRendererComponent(list, - value, - index, - isSelected, - cellHasFocus - ); - if (value != null) { - Account account = (Account) value; - String accountLabel = account.getLabel(); - int nbChars = 30; - if (accountLabel != null && accountLabel.length() > nbChars) { - accountLabel = accountLabel.substring(0, nbChars) + "…"; - } - label.setText(account.getAccountNumber() + " - " + accountLabel); - } - return this; - } - -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBookComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBookComboBox.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBookComboBox.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,69 +25,41 @@ package org.chorem.lima.ui.entrybooksreports; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; + +import javax.swing.JComboBox; + import org.chorem.lima.entity.EntryBook; -import org.chorem.lima.ui.LimaRendererUtil; -import org.chorem.lima.ui.combobox.EntryBookComboBoxModel; import org.chorem.lima.util.EntryBookToString; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; -import javax.swing.JComboBox; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; - public class EntryBookComboBox extends JComboBox implements KeyListener { private static final long serialVersionUID = 1L; - private static final Log log = - LogFactory.getLog(EntryBookComboBox.class); - - protected EntryBooksReportsViewHandler handler; - - public EntryBookComboBox(EntryBooksReportsViewHandler handler) { - this.handler = handler; - EntryBookComboBoxModel entryBookComboBoxModel = new EntryBookComboBoxModel(); - setModel(entryBookComboBoxModel); - setRenderer(LimaRendererUtil.newDecoratorListCellRenderer(EntryBook.class)); - setEditable(true); + public EntryBookComboBox() { AutoCompleteDecorator.decorate(this, EntryBookToString.getInstance()); getEditor().getEditorComponent().addKeyListener(this); - addActionListener(this); } public void back() { int row = getSelectedIndex(); - log.debug(row); if (row > 0) { getEditor().setItem(getItemAt(row - 1)); - handler.setEntryBook((EntryBook) getSelectedItem()); } } public void next() { int size = getModel().getSize(); int row = getSelectedIndex(); - log.debug(row); if (row < size - 1) { getEditor().setItem(getItemAt(row + 1)); - handler.setEntryBook((EntryBook) getSelectedItem()); } } @Override - public void actionPerformed(ActionEvent e) { - Object object = getSelectedItem(); - if (object instanceof EntryBook) { - handler.setEntryBook((EntryBook) getSelectedItem()); - } - } - - - @Override public void keyPressed(KeyEvent e) { } @@ -96,7 +68,7 @@ public void keyReleased(KeyEvent e) { Object object = getSelectedItem(); if (object instanceof EntryBook) { - handler.setEntryBook((EntryBook) getSelectedItem()); + fireActionEvent(); } // delegate popup list menu if (e.getKeyChar() == KeyEvent.VK_ENTER) { @@ -108,5 +80,4 @@ public void keyTyped(KeyEvent e) { } - } Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsPeriodSearchPanel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsPeriodSearchPanel.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsPeriodSearchPanel.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -1,162 +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.entrybooksreports; - -import org.apache.commons.lang3.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.LimaRendererUtil; -import org.chorem.lima.ui.combobox.FinancialPeriodComboBoxModel; -import org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel; -import org.jdesktop.swingx.JXDatePicker; - -import javax.swing.JComboBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Calendar; -import java.util.Date; - -import static org.nuiton.i18n.I18n._; - -public class EntryBooksReportsPeriodSearchPanel extends JPanel { - - private static final Log log = - LogFactory.getLog(EntryBooksReportsPeriodSearchPanel.class); - - protected EntryBooksReportsViewHandler handler; - - public EntryBooksReportsPeriodSearchPanel(EntryBooksReportsViewHandler handler) { - this.handler = handler; - - //init date - refresh(ComboBoxDatesEnum.FISCAL_PERIOD); - } - - 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(); - - removeAll(); - add(beginDateLabel); - add(beginDatePicker); - add(endDateLabel); - add(endDatePicker); - break; - - case FISCAL_PERIOD: - FiscalPeriodComboBoxModel fiscalModel = new FiscalPeriodComboBoxModel(true); - ListCellRenderer renderer = - LimaRendererUtil.newDecoratorListCellRenderer(FiscalPeriod.class); - - final JComboBox fiscalPeriod = new JComboBox(fiscalModel); - fiscalPeriod.setRenderer(renderer); - 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); - - removeAll(); - add(fiscalPeriod); - break; - - case FINANCIAL_PERIOD: - FinancialPeriodComboBoxModel financialModel = new FinancialPeriodComboBoxModel(true); - renderer = - LimaRendererUtil.newDecoratorListCellRenderer(FinancialPeriod.class); - final JComboBox financialPeriod = new JComboBox(financialModel); - financialPeriod.setRenderer(renderer); - 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); - removeAll(); - add(financialPeriod); - break; - } - - } - -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTable.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2008 - 2010 CodeLutin + * Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -49,8 +49,6 @@ /** serialVersionUID. */ private static final long serialVersionUID = 1L; - protected EntryBooksReportsViewHandler handler; - protected EntryBooksReportsTableModel model; private Highlighter colorReportsDatas; @@ -61,9 +59,8 @@ /** */ - public EntryBooksReportsTable(EntryBooksReportsViewHandler handler, EntryBooksReportsTableModel model) { + public EntryBooksReportsTable(EntryBooksReportsTableModel model) { - this.handler = handler; this.model = model; addKeyListener(this); Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsTableModel.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -38,7 +38,6 @@ import static org.nuiton.i18n.I18n._; - /** * Entry book table model. * By : $Author$ @@ -52,15 +51,15 @@ private static final Log log = LogFactory.getLog(EntryBooksReportsTableModel.class); /** data cache */ - protected ReportsDatas cacheDataList; + protected ReportsDatas reportData; @Override public int getRowCount() { int result = 0; // just prevent too much result - if (cacheDataList != null && cacheDataList.getListEntry() != null) { - result = cacheDataList.getListEntry().size(); + if (reportData != null && reportData.getListEntry() != null) { + result = reportData.getListEntry().size(); } return result; @@ -135,8 +134,8 @@ @Override public Object getValueAt(int row, int column) { Object result = null; - if (cacheDataList.getListEntry() != null) { - Entry currentRow = cacheDataList.getListEntry().get(row); + if (reportData.getListEntry() != null) { + Entry currentRow = reportData.getListEntry().get(row); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMMM yyyy"); @@ -178,18 +177,11 @@ } public Entry getElementAt(int row) { - return cacheDataList.getListEntry().get(row); + return reportData.getListEntry().get(row); } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - // Just read, no write - return false; - } - - public void refresh(ReportsDatas datasList) { - cacheDataList = datasList; + public void setReportDatas(ReportsDatas datasList) { + reportData = datasList; fireTableDataChanged(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsView.jaxx 2012-06-01 14:01:39 UTC (rev 3436) @@ -5,7 +5,7 @@ $Id$ $HeadURL$ %% - Copyright (C) 2008 - 2010 CodeLutin + Copyright (C) 2008 - 2012 CodeLutin, Chatellier Eric %% This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -27,27 +27,17 @@ <import> javax.swing.ListSelectionModel org.chorem.lima.enums.ComboBoxDatesEnum - org.chorem.lima.ui.combobox.EntryBookComboBoxModel - org.chorem.lima.ui.entrybooksreports.EntryBookComboBox - org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTable - org.chorem.lima.ui.entrybooksreports.EntryBooksReportsTableModel + org.jdesktop.swingx.JXDatePicker </import> - <EntryBooksReportsViewHandler id="handler" - javaBean="new EntryBooksReportsViewHandler(this)"/> - <Boolean id="selectedRow" javaBean="false"/> - <org.chorem.lima.ui.combobox.EntryBookComboBoxModel id="modelEntryBook"/> - <EntryBooksReportsTableModel id="modelTable"/> - <script> - <![CDATA[ - EntryBooksReportsPeriodSearchPanel periodSearchPanel = new EntryBooksReportsPeriodSearchPanel(handler); - EntryBookComboBox comboBox = new EntryBookComboBox(handler); - + <EntryBooksReportsViewHandler id="handler" constructorParams="this"/> + + <script><![CDATA[ void $afterCompleteSetup() { + handler.init(); } - - ]]> - </script> + ]]></script> + <row weightx="1" weighty="0" anchor="center"> <cell fill='both'> <Table> @@ -55,11 +45,26 @@ <cell anchor="west"> <JComboBox id="periodComboBox" javaBean="new JComboBox(ComboBoxDatesEnum.descriptions())" - onActionPerformed="periodSearchPanel.refresh(ComboBoxDatesEnum.valueOfDescription((String) periodComboBox.getSelectedItem())); - validate(); repaint()"/> + onActionPerformed="handler.periodTypeChanged()"/> </cell> <cell> - <EntryBooksReportsPeriodSearchPanel javaBean="periodSearchPanel"/> + <CardLayout id="periodTypeLayout" /> + <JPanel id="periodTypeContainer" layout="{periodTypeLayout}"> + <org.chorem.lima.ui.common.FiscalPeriodComboBoxModel id="fiscalPeriodModel" /> + <JComboBox id="fiscalPeriodComboBox" model="{fiscalPeriodModel}" + renderer="{new org.chorem.lima.ui.common.FiscalPeriodListRenderer()}" + onItemStateChanged="handler.periodsChanged(event)" constraints='"FISCAL_PERIOD"' /> + <org.chorem.lima.ui.common.FinancialPeriodComboBoxModel id="financialPeriodModel" /> + <JComboBox id="financialPeriodComboBox" model="{financialPeriodModel}" + renderer="{new org.chorem.lima.ui.common.FinancialPeriodListRenderer()}" + onItemStateChanged="handler.periodsChanged(event)" constraints='"FINANCIAL_PERIOD"' /> + <JPanel constraints='"PERIOD"'> + <JLabel text="lima.common.begindate" /> + <JXDatePicker id="periodBeginDatePicker" onActionPerformed="handler.periodDatesChanged()" /> + <JLabel text="lima.common.enddate" /> + <JXDatePicker id="periodEndDatePicker" onActionPerformed="handler.periodDatesChanged()" /> + </JPanel> + </JPanel> </cell> </row> </Table> @@ -68,15 +73,18 @@ <JLabel id="entryBookSelectorLabel" text="lima.common.entrybook"/> </cell> <cell anchor="west"> - <JComboBox javaBean='comboBox'/> + <org.chorem.lima.ui.common.EntryBookComboBoxModel id="entryBookModel" /> + <EntryBookComboBox id="entryBookCombo" model="{entryBookModel}" + renderer="{new org.chorem.lima.ui.common.EntryBookListRenderer()}" + onItemStateChanged="handler.entryBookChanged(event)"/> </cell> <cell> <JButton id="back" text="lima.common.buttonback" - onActionPerformed="comboBox.back()"/> + onActionPerformed="entryBookCombo.back()"/> </cell> <cell> <JButton id="next" text="lima.common.buttonnext" - onActionPerformed="comboBox.next()"/> + onActionPerformed="entryBookCombo.next()"/> </cell> <cell> <EnumEditor id='DocumentEditor' @@ -90,13 +98,11 @@ <row> <cell fill="both" weightx="1" weighty="1" columns="7"> <JScrollPane> - <EntryBooksReportsTable - id="table" sortable="false" rowHeight="24" - constructorParams="getHandler(), getModelTable()" - model="{getModelTable()}" + <EntryBooksReportsTableModel id="entryBookReportsTableModel" /> + <EntryBooksReportsTable id="reportTable" sortable="false" rowHeight="24" + constructorParams="entryBookReportsTableModel" + model="{entryBookReportsTableModel}" selectionMode="{ListSelectionModel.SINGLE_SELECTION}"/> - <ListSelectionModel - javaBean="getTable().getSelectionModel()"/> </JScrollPane> </cell> </row> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -28,22 +28,27 @@ import static org.nuiton.i18n.I18n._; import java.awt.Desktop; +import java.awt.event.ItemEvent; import java.io.IOException; -import java.math.BigDecimal; import java.net.URI; import java.net.URISyntaxException; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.List; +import javax.swing.JComboBox; import javax.swing.JOptionPane; +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.beans.ReportsDatas; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.DocumentService; +import org.chorem.lima.business.api.EntryBookService; +import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.HttpServerService; @@ -52,122 +57,187 @@ import org.chorem.lima.business.utils.DocumentsEnum; import org.chorem.lima.business.utils.FormatsEnum; import org.chorem.lima.entity.EntryBook; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FiscalPeriod; +import org.chorem.lima.enums.ComboBoxDatesEnum; import org.chorem.lima.service.LimaServiceFactory; /** * Handler associated with accounts reports view. + * * By : $Author$ */ public class EntryBooksReportsViewHandler implements ServiceListener { - protected EntryBooksReportsView view; - - protected EntryBooksReportsTable table; - - protected EntryBooksReportsTableModel tableModel; - /** log. */ private static final Log log = LogFactory.getLog(EntryBooksReportsViewHandler.class); + protected EntryBooksReportsView view; + /** Services. */ protected ReportService reportService; - protected DocumentService documentService; - + protected EntryBookService entryBookService; protected FiscalPeriodService fiscalPeriodService; + protected FinancialPeriodService financialPeriodService; - /** Account. */ - protected EntryBook selectedEntryBook; - - /** Begin Date. */ - protected Date selectedBeginDate; - - /** EndDate. */ - protected Date selectedEndDate; - - protected int port; - private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); - protected EntryBooksReportsViewHandler(EntryBooksReportsView view) { + public EntryBooksReportsViewHandler(EntryBooksReportsView view) { this.view = view; reportService = LimaServiceFactory.getService(ReportService.class); - port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); documentService = LimaServiceFactory.getService(DocumentService.class); + reportService = LimaServiceFactory.getService(ReportService.class); + entryBookService = LimaServiceFactory.getService(EntryBookService.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); + financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); LimaServiceFactory.addServiceListener(ImportService.class, this); LimaServiceFactory.addServiceListener(FinancialTransactionService.class, this); } - public void setBeginDate(Date date) { - selectedBeginDate = date; - refresh(); + /** + * Init data models and displayed objects. + */ + public void init() { + + // init data models + List<EntryBook> entryBooks = entryBookService.getAllEntryBooks(); + view.getEntryBookModel().setObjects(entryBooks); + List<FiscalPeriod> fiscalPeriod = fiscalPeriodService.getAllUnblockedFiscalPeriods(); + view.getFiscalPeriodModel().setObjects(fiscalPeriod); + List<FinancialPeriod> financialPeriod = financialPeriodService.getUnblockedFinancialPeriods(); + view.getFinancialPeriodModel().setObjects(financialPeriod); + + // init date periods + initDatePeriods(); } + + /** + * Init date pickers objects with contextual dates. + */ + private void initDatePeriods() { - public void setEndDate(Date date) { - selectedEndDate = date; - refresh(); + // get begin date + Date beginDate = DateUtils.truncate(new Date(), Calendar.YEAR); + view.getPeriodBeginDatePicker().setDate(beginDate); + + // get end date + Date endDate = new Date(); + view.getPeriodEndDatePicker().setDate(endDate); } + public void periodTypeChanged() { + JComboBox periodComboBox = view.getPeriodComboBox(); + ComboBoxDatesEnum type = ComboBoxDatesEnum.valueOfDescription((String) periodComboBox.getSelectedItem()); - public void setEntryBook(EntryBook entryBook) { - selectedEntryBook = entryBook; - refresh(); + // show corresponding component in layout + view.getPeriodTypeLayout().show(view.getPeriodTypeContainer(), type.name()); } - public ReportsDatas getDataList() { + protected void periodsChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + refreshData(); + } + } + + protected void entryBookChanged(ItemEvent event) { + if (event.getStateChange() == ItemEvent.SELECTED) { + refreshData(); + } + } + + protected void periodDatesChanged() { + refreshData(); + } + + /*public ReportsDatas getDataList() { ReportsDatas results = null; if (selectedEntryBook != null) { results = reportService.generateEntryBooksReports( selectedEntryBook, selectedBeginDate, selectedEndDate); } return results; - } + }*/ - public void refresh() { + /** + * Refresh table data depending on item selected on combo boxes. + */ + protected void refreshData() { + + Date beginDate = null; + Date endDate = null; - if (selectedBeginDate != null && selectedEndDate != null && selectedEntryBook != null) { - tableModel = view.getModelTable(); + JComboBox periodComboBox = view.getPeriodComboBox(); + ComboBoxDatesEnum type = ComboBoxDatesEnum.valueOfDescription((String) periodComboBox.getSelectedItem()); + switch (type) { + case PERIOD: + beginDate = view.getPeriodBeginDatePicker().getDate(); + endDate = view.getPeriodEndDatePicker().getDate(); + break; + case FINANCIAL_PERIOD: { + FinancialPeriod period = (FinancialPeriod)view.getFinancialPeriodComboBox().getSelectedItem(); + if (period != null) { + beginDate = period.getBeginDate(); + endDate = period.getEndDate(); + } + break; + } + case FISCAL_PERIOD: { + FiscalPeriod period = (FiscalPeriod)view.getFiscalPeriodComboBox().getSelectedItem(); + if (period != null) { + beginDate = period.getBeginDate(); + endDate = period.getEndDate(); + } + break; + } + } + + EntryBook entryBook = (EntryBook)view.getEntryBookCombo().getModel().getSelectedItem(); + + if (beginDate != null && endDate != null && entryBook != null) { + ReportsDatas results = reportService.generateEntryBooksReports(entryBook, + beginDate, endDate); + + EntryBooksReportsTableModel dataModel = view.getEntryBookReportsTableModel(); + dataModel.setReportDatas(results); + } + } - ReportsDatas datasList = getDataList(); + public void createDocument() { - tableModel.refresh(datasList); + // FIXME echatellier 20120601 duplicated code + Date beginDate = null; + Date endDate = null; - /** - * set text and amounts of labels credit, debit, solde - */ - - if (datasList != null) { - // set amounts credit, debit and solde - view.amountCreditLabel.setText( - String.valueOf(datasList.getAmountCredit())); - view.amountDebitLabel.setText( - String.valueOf(datasList.getAmountDebit())); - BigDecimal amountSolde = datasList.getAmountSolde(); - view.amountSoldeLabel.setText(String.valueOf(amountSolde)); - - if (BigDecimal.ZERO.equals(amountSolde)) { - view.soldeLabel.setText(_("lima.common.solde")); - } else { - // set label solde: credit or debit - if (datasList.getSoldeDebit()) { - view.soldeLabel.setText(_("lima.common.soldedebit")); - } else { - view.soldeLabel.setText(_("lima.common.soldecredit")); - } + JComboBox periodComboBox = view.getPeriodComboBox(); + ComboBoxDatesEnum type = ComboBoxDatesEnum.valueOfDescription((String) periodComboBox.getSelectedItem()); + switch (type) { + case PERIOD: + beginDate = view.getPeriodBeginDatePicker().getDate(); + endDate = view.getPeriodEndDatePicker().getDate(); + break; + case FINANCIAL_PERIOD: { + FinancialPeriod period = (FinancialPeriod)view.getFinancialPeriodComboBox().getSelectedItem(); + if (period != null) { + beginDate = period.getBeginDate(); + endDate = period.getEndDate(); } + break; } + case FISCAL_PERIOD: { + FiscalPeriod period = (FiscalPeriod)view.getFiscalPeriodComboBox().getSelectedItem(); + if (period != null) { + beginDate = period.getBeginDate(); + endDate = period.getEndDate(); + } + break; + } } - } + + if (beginDate != null && endDate != null) { - - public void createDocument() { - - if (selectedBeginDate != null && selectedEndDate != null) { - //looks for all blocked fiscal periods List<FiscalPeriod> blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); @@ -175,8 +245,8 @@ boolean error = true; for (FiscalPeriod blockedFiscalPeriod : blockedFiscalPeriods) { - if (blockedFiscalPeriod.getBeginDate().equals(selectedBeginDate) - && blockedFiscalPeriod.getEndDate().equals(selectedEndDate) + if (blockedFiscalPeriod.getBeginDate().equals(beginDate) + && blockedFiscalPeriod.getEndDate().equals(endDate) && blockedFiscalPeriod.getLocked()) { error = false; } @@ -187,24 +257,25 @@ JOptionPane.showMessageDialog( view, _("lima.entrybooksreports.documentcreationfiscalerror"), - _("lima.common.error"), + _("lima.entrybooksreports.documentcreationfiscaltitle"), JOptionPane.ERROR_MESSAGE); } else { + int port = LimaServiceFactory.getService(HttpServerService.class).getHttpPort(); FormatsEnum selectedEnum = (FormatsEnum) view.getDocumentEditor().getSelectedItem(); String address = LimaConfig.getInstance().getHostAdress(); try { String url = "http://" + address + ":" + port + "/?beginDate=" - + dateFormat.format(selectedBeginDate) - + "&endDate=" + dateFormat.format(selectedEndDate) + + dateFormat.format(beginDate) + + "&endDate=" + dateFormat.format(endDate) + "&format=" + selectedEnum.getExtension() + "&model=" + DocumentsEnum.ENTRYBOOKS.getFileName(); Desktop.getDesktop().browse(new URI(url)); String url2 = "http://" + address + ":" + port + "/?beginDate=" - + dateFormat.format(selectedBeginDate) - + "&endDate=" + dateFormat.format(selectedEndDate) + + dateFormat.format(beginDate) + + "&endDate=" + dateFormat.format(endDate) + "&format=" + selectedEnum.getExtension() + "&model=" + DocumentsEnum.GENERAL_ENTRYBOOK.getFileName(); Desktop.getDesktop().browse(new URI(url2)); @@ -219,10 +290,9 @@ } @Override - public void notifyMethod(String serviceName, String methodeName) { - if (serviceName.contains("FinancialTransaction") || methodeName.contains("importEntryBook") || methodeName.contains("importAll")) { - refresh(); + public void notifyMethod(String serviceName, String methodName) { + if (serviceName.contains("FinancialTransaction") || methodName.contains("importEntryBook") || methodName.contains("importAll")) { + refreshData(); } } - } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/AccountSearchComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/AccountSearchComboBox.java 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/AccountSearchComboBox.java 2012-06-01 14:01:39 UTC (rev 3436) @@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.entity.Account; import org.chorem.lima.ui.combobox.AccountComboBoxModel; -import org.chorem.lima.ui.common.AccountRenderer; +import org.chorem.lima.ui.common.AccountListRenderer; import org.chorem.lima.util.AccountToString; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; @@ -50,7 +50,7 @@ public AccountSearchComboBox(FinancialTransactionSearchViewHandler handler) { this.handler = handler; AccountComboBoxModel accountComboBoxModel = new AccountComboBoxModel(); - AccountRenderer accountRenderer = new AccountRenderer(); + AccountListRenderer accountRenderer = new AccountListRenderer(); setModel(accountComboBoxModel); setRenderer(accountRenderer); setEditable(true); 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 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-06-01 14:01:39 UTC (rev 3436) @@ -95,6 +95,7 @@ lima.entries.writetransaction=Write entries lima.entrybooksreports.documentcreationerror=Enable to create document lima.entrybooksreports.documentcreationfiscalerror=Can't create document on an open fiscal year +lima.entrybooksreports.documentcreationfiscaltitle= lima.entrybooksreports.listerror=Can't get entries list lima.enum.comboboxaccount.account=Account lima.enum.comboboxaccount.accountlist=Account list 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 2012-06-01 09:27:45 UTC (rev 3435) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-06-01 14:01:39 UTC (rev 3436) @@ -95,6 +95,7 @@ lima.entries.writetransaction=Saisir des écritures lima.entrybooksreports.documentcreationerror=Erreur lors de la création du document lima.entrybooksreports.documentcreationfiscalerror=Impossible de créer un document quand la période fiscale est ouverte +lima.entrybooksreports.documentcreationfiscaltitle= lima.entrybooksreports.listerror=Erreur lors de la récupération des données de la liste lima.enum.comboboxaccount.account=Compte lima.enum.comboboxaccount.accountlist=Liste de comptes
participants (1)
-
echatellier@users.chorem.org