09/19: refs #1293 Ajout de la possibilité de choisir une consultation de compte pour un exercice, une période financière ou un interval de dates
This is an automated email from the git hooks/post-receive script. New commit to branch feature/1293-addAccountViewerTab in repository lima. See http://git.chorem.org/lima.git commit 367ef5f73641745d3e01ddf924c1fdbe0e64b7f5 Author: dcosse <cosse@codelutin.com> Date: Sun Sep 20 00:38:53 2015 +0200 refs #1293 Ajout de la possibilité de choisir une consultation de compte pour un exercice, une période financière ou un interval de dates --- .../accountViewer/AccountViewerSelectionModel.java | 12 +- .../lima/ui/accountViewer/AccountViewerView.css | 24 +- .../lima/ui/accountViewer/AccountViewerView.jaxx | 168 +++++----- .../ui/accountViewer/AccountViewerViewHandler.java | 350 +++++++++++++-------- .../accountViewer/FinancialPeriodListRenderer.java | 68 ++++ .../chorem/lima/ui/accountViewer/PeriodChoice.java | 34 ++ .../ui/combobox/FiscalPeriodComboBoxModel.java | 2 +- .../lima/ui/common/FiscalPeriodComboBoxModel.java | 12 + .../resources/i18n/lima-swing_en_GB.properties | 3 + .../resources/i18n/lima-swing_fr_FR.properties | 3 + 10 files changed, 466 insertions(+), 210 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java index 5199a0b..4a24d0c 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerSelectionModel.java @@ -38,7 +38,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ protected Entry entry; protected int lineSelected; - protected boolean balancedSelectionMode; + protected boolean letteredSelectionMode; protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public AccountViewerSelectionModel(AccountViewerTableModel letteringTableModel){ @@ -52,7 +52,7 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ @Override public void setSelectionInterval(int row, int column) { - if (balancedSelectionMode) { + if (letteredSelectionMode) { if (!letteringNotExist(row)) { //lettred entries @@ -151,12 +151,12 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ firePropertyChange(propertyName, null, newValue); } - public void setBalancedSelectionMode(boolean balancedSelectionMode) { - this.balancedSelectionMode = balancedSelectionMode; + public void setLetteredSelectionMode(boolean letteredSelectionMode) { + this.letteredSelectionMode = letteredSelectionMode; clearSelection(); } - public boolean getBalancedSelectionMode() { - return balancedSelectionMode; + public boolean getLetteredSelectionMode() { + return letteredSelectionMode; } } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css index f0bd618..07b91f7 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.css @@ -48,15 +48,37 @@ } #beginPeriodLabel { + visible : {PeriodChoice.DATE.equals(periodChoice)}; text : "lima.lettering.period.begin"; labelFor : {beginPeriodPicker}; } +#beginPeriodPicker { + visible : {PeriodChoice.DATE.equals(periodChoice)}; +} + #endPeriodLabel { + visible : {PeriodChoice.DATE.equals(periodChoice)}; text : "lima.lettering.period.end"; labelFor : {endPeriodPicker}; } +#endPeriodPicker { + visible : {PeriodChoice.DATE.equals(periodChoice)}; +} + +#fiscalPeriodComboBox { + visible : {PeriodChoice.FISCAL_PERIOD.equals(periodChoice)}; + toolTipText : "lima.entries.fiscalYear"; + renderer : "{new org.chorem.lima.ui.common.FiscalPeriodListRenderer()}"; +} + +#financialPeriodComboBox { + preferredSize : {new Dimension(200, 22)}; + toolTipText : "lima.entries.financialPeriod"; + renderer : "{new org.chorem.lima.ui.accountViewer.FinancialPeriodListRenderer()}"; +} + #refresh { toolTipText : "lima.lettering.refresh"; actionIcon : "refresh"; @@ -69,5 +91,5 @@ #balanceStatusLabel { horizontalTextPosition:{JLabel.RIGHT}; - border: {BorderFactory.createEmptyBorder(0, 0, 0, 20)} + border: {BorderFactory.createEmptyBorder(0, 0, 0, 20)}; } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx index 8b46423..e615d60 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerView.jaxx @@ -20,83 +20,103 @@ <JPanel layout="{new BorderLayout()}"> - <import> - java.awt.Dimension - org.chorem.lima.util.WrapToolBarLayout - org.chorem.lima.ui.common.FinancialPeriodComboBoxModel - org.chorem.lima.util.BigDecimalToString - org.chorem.lima.ui.lettering.TypeEntry - org.chorem.lima.entity.Account - javax.swing.ListSelectionModel - org.jdesktop.swingx.JXDatePicker - static org.nuiton.i18n.I18n.t - org.chorem.lima.ui.combobox.AccountComboBox - </import> - - <AccountViewerViewHandler id="handler" constructorParams="this"/> - - <AccountViewerEditModel id='editModel'/> - - <script> - <![CDATA[ + <import> + java.awt.Dimension + org.chorem.lima.util.WrapToolBarLayout + org.chorem.lima.ui.common.FinancialPeriodComboBoxModel + org.chorem.lima.util.BigDecimalToString + org.chorem.lima.ui.lettering.TypeEntry + org.chorem.lima.entity.Account + javax.swing.ListSelectionModel + org.jdesktop.swingx.JXDatePicker + static org.nuiton.i18n.I18n.t + org.chorem.lima.ui.combobox.AccountComboBox + org.chorem.lima.ui.LimaRendererUtil + org.chorem.lima.entity.FinancialPeriod + </import> + + <AccountViewerViewHandler id="handler" constructorParams="this"/> + + <AccountViewerEditModel id='editModel'/> + + <script> + <![CDATA[ void $afterCompleteSetup() { handler.init(); } ]]> - </script> - - <JToolBar styleClass="toolbar" - constraints="BorderLayout.PAGE_START" - layout="{new WrapToolBarLayout()}"> - - <JLabel id="accountLabel"/> - <AccountComboBox id="accountComboBox" - constraints="BorderLayout.CENTER" - onPropertyChange="{getHandler().accountComboBoxChange(event);}"/> - <JButton id="back" - onActionPerformed="handler.back(accountComboBox)"/> - <JButton id="next" - onActionPerformed="handler.next(accountComboBox)"/> - - <JToolBar.Separator/> - - <JLabel id="beginPeriodLabel"/> - <JAXXDatePicker id="beginPeriodPicker" - constructorParams="handler.getLocale()" - formats="{handler.getDateFormat()}" - onPropertyChange="handler.setDateStart(beginPeriodPicker.getDate())"/> - - <JLabel id="endPeriodLabel"/> - <JAXXDatePicker id="endPeriodPicker" - constructorParams="handler.getLocale()" - formats="{handler.getDateFormat()}" - onPropertyChange="handler.setDateEnd(endPeriodPicker.getDate())"/> - - <JToolBar.Separator/> - - <JLabel id='balancedSelectionModeLabel' actionIcon='selection-mode'/> - <EnumEditor id='balancedSelectionMode' - genericType='SelectionMode' - constructorParams='SelectionMode.class' - onItemStateChanged="handler.onSelectionModeChanged(balancedSelectionMode.getSelectedItem())" /> - - <JButton id="refresh" - onActionPerformed="handler.updateAllEntries()"/> - - </JToolBar> - <JScrollPane constraints="BorderLayout.CENTER"> - <AccountViewerTableModel id="tableModel"/> - <AccountViewerSelectionModel id='accountViewerSelectionModel' constructorParams='tableModel' - onValueChanged="handler.balanceAndActions()"/> - - <AccountViewerTable id="table" - constructorParams="handler" - model="{tableModel}" - selectionModel="{accountViewerSelectionModel}"/> - </JScrollPane> - - <JPanel constraints="BorderLayout.SOUTH" layout="{new BorderLayout()}"> - <JLabel id='balanceStatusLabel' constraints="BorderLayout.EAST"/> - </JPanel> + </script> + + <JToolBar styleClass="toolbar" + constraints="BorderLayout.PAGE_START" + layout="{new WrapToolBarLayout()}"> + + <JLabel id="accountLabel"/> + <AccountComboBox id="accountComboBox" + constraints="BorderLayout.CENTER" + onPropertyChange="handler.onAccountChange(event)"/> + + <JButton id="back" + onActionPerformed="handler.onBackChange(accountComboBox)"/> + <JButton id="next" + onActionPerformed="handler.onNextChange(accountComboBox)"/> + + <JToolBar.Separator/> + + <JLabel id='periodChoiceLabel' actionIcon='choose-fiscal-year'/> + <EnumEditor id='periodChoice' + genericType='PeriodChoice' + constructorParams='PeriodChoice.class' + onItemStateChanged="handler.onPeriodChoiceChanged(periodChoice.getSelectedItem())"/> + + <JLabel id="beginPeriodLabel"/> + + <org.chorem.lima.ui.combobox.FiscalPeriodComboBoxModel id="fiscalPeriodComboBoxModel"/> + <JComboBox id="fiscalPeriodComboBox" + model="{fiscalPeriodComboBoxModel}" + onItemStateChanged="handler.onFiscalPeriodChange(event)"/> + + <org.chorem.lima.ui.common.FinancialPeriodComboBoxModel id="financialPeriodComboBoxModel"/> + <JComboBox id="financialPeriodComboBox" + model="{financialPeriodComboBoxModel}" + onItemStateChanged="handler.onFinancialPeriodChange(event)"/> + + <JAXXDatePicker id="beginPeriodPicker" + constructorParams="handler.getLocale()" + formats="{handler.getDateFormat()}" + onPropertyChange="handler.onDateStartChange(beginPeriodPicker.getDate())"/> + + <JLabel id="endPeriodLabel"/> + + <JAXXDatePicker id="endPeriodPicker" + constructorParams="handler.getLocale()" + formats="{handler.getDateFormat()}" + onPropertyChange="handler.onDateEndChange(endPeriodPicker.getDate())"/> + <JToolBar.Separator/> + + <JLabel id='selectionModeLabel' actionIcon='selection-mode'/> + <EnumEditor id='letteredSelectionMode' + genericType='SelectionMode' + constructorParams='SelectionMode.class' + onItemStateChanged="handler.onSelectionModeChanged(letteredSelectionMode.getSelectedItem())"/> + + <JButton id="refresh" + onActionPerformed="handler.updateAllEntries(null)"/> + + </JToolBar> + <JScrollPane constraints="BorderLayout.CENTER"> + <AccountViewerTableModel id="tableModel"/> + <AccountViewerSelectionModel id='accountViewerSelectionModel' constructorParams='tableModel' + onValueChanged="handler.balanceAndActions()"/> + + <AccountViewerTable id="table" + constructorParams="handler" + model="{tableModel}" + selectionModel="{accountViewerSelectionModel}"/> + </JScrollPane> + + <JPanel constraints="BorderLayout.SOUTH" layout="{new BorderLayout()}"> + <JLabel id='balanceStatusLabel' constraints="BorderLayout.EAST"/> + </JPanel> </JPanel> \ No newline at end of file diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java index f74ba39..50a17a0 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerViewHandler.java @@ -40,6 +40,7 @@ import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.entity.Account; import org.chorem.lima.entity.Entry; import org.chorem.lima.entity.EntryImpl; +import org.chorem.lima.entity.FinancialPeriod; import org.chorem.lima.entity.FinancialTransaction; import org.chorem.lima.entity.FinancialTransactionImpl; import org.chorem.lima.entity.FiscalPeriod; @@ -58,7 +59,9 @@ import java.beans.PropertyChangeListener; import java.math.BigDecimal; import java.text.DateFormat; import java.util.Calendar; +import java.util.Collection; import java.util.Date; +import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -116,7 +119,7 @@ public class AccountViewerViewHandler { public void init() { filter = new LetteringFilterImpl(); editModel = view.getEditModel(); - loadComboAndRows(); + initViewWithDefaultFinancialPeriod(); editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @Override @@ -154,27 +157,10 @@ public class AccountViewerViewHandler { SwingUtil.fixTableColumnWidth(view.getTable(), 4, 50); initializationComplete = true; - updateAllEntries(); + updateAllEntries(null); updateSoldStatus(); } - public void updateSoldStatus() { - if (initializationComplete) { - view.getBalanceStatusLabel().setText(t("lima.lettering.accountViewerBalanceStatus", - getDateFormat().format(editModel.getFiscalPeriodBeginDate()), - getDateFormat().format(filter.getDateEnd()), - - BigDecimalToString.format(editModel.getGlobalDebit()), - BigDecimalToString.format(editModel.getGlobalCredit()), - BigDecimalToString.format(editModel.getGlobalSold()), - - BigDecimalToString.format(editModel.getDebit()), - BigDecimalToString.format(editModel.getCredit()), - BigDecimalToString.format(editModel.getSold()))); - } - } - - protected void initShortCuts() { InputMap inputMap= view.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); @@ -193,40 +179,160 @@ public class AccountViewerViewHandler { @Override public void actionPerformed(ActionEvent e) { - updateAllEntries(); + updateAllEntries(null); } }); } - public void loadComboAndRows(){ + public void onAccountChange(PropertyChangeEvent event) { + if (initializationComplete) { + if (event.getPropertyName().equals(AccountComboBox.PROPERTY_SELECTED_ITEM) && event.getNewValue() != null && event.getNewValue() instanceof Account) { + setAccount((Account) event.getNewValue()); + } + } + } - //By default, we have the beginning of the fiscal period (Or of current - //date if no fiscal period) and the end of the current fiscal period - FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); - Date defaultDateBegFiscalPeriod, defaultDateEndCurrent; + protected void onPeriodChoiceChanged(PeriodChoice periodChoice) { + if (initializationComplete) { + switch (periodChoice) { + case FINANCIAL_PERIOD: + view.getFiscalPeriodComboBox().setVisible(false); + view.getFinancialPeriodComboBox().setVisible(true); + view.getBeginPeriodPicker().setVisible(false); + view.getEndPeriodPicker().setVisible(false); + initViewWithDefaultFinancialPeriod(); + break; + case FISCAL_PERIOD: + view.getFiscalPeriodComboBox().setVisible(true); + view.getFinancialPeriodComboBox().setVisible(false); + view.getBeginPeriodPicker().setVisible(false); + view.getEndPeriodPicker().setVisible(false); + initFiscalPeriodModel(); + break; + case DATE: + view.getFiscalPeriodComboBox().setVisible(false); + view.getFinancialPeriodComboBox().setVisible(false); + view.getBeginPeriodPicker().setVisible(true); + view.getEndPeriodPicker().setVisible(true); + break; + } + updateAllEntries(null); + } + } - Calendar calendar = Calendar.getInstance(); - int lastCurrentMonthDay = calendar.getActualMaximum(Calendar.DATE); - int firstCurrentMonthDay = calendar.getActualMinimum(Calendar.DATE); + /** + * Select previous value in combo box. + * + * @param accountComboBox account combo box + */ + public void onBackChange(AccountComboBox accountComboBox) { + if (initializationComplete) { + JComboBox comboBox = accountComboBox.getCombobox(); + int row = comboBox.getSelectedIndex(); - if (fiscalPeriod != null){ - defaultDateBegFiscalPeriod = fiscalPeriod.getBeginDate(); - defaultDateEndCurrent = fiscalPeriod.getEndDate(); - } else{ - defaultDateBegFiscalPeriod = DateUtils.setDays(new Date(), firstCurrentMonthDay); - defaultDateEndCurrent = DateUtils.setDays(new Date(), lastCurrentMonthDay); + if (row > 0) { + comboBox.setSelectedIndex(row - 1); + } + view.getAccountViewerSelectionModel().clearSelection(); } + } - view.getBeginPeriodPicker().setDate(defaultDateBegFiscalPeriod); - view.getEndPeriodPicker().setDate(defaultDateEndCurrent); + /** + * Select next value in combo box. + * + * @param accountComboBox combo box + */ + public void onNextChange(AccountComboBox accountComboBox) { + if (initializationComplete) { + JComboBox comboBox = accountComboBox.getCombobox(); + int size = comboBox.getItemCount(); + int row = comboBox.getSelectedIndex(); - editModel.setFiscalPeriodBeginDate(defaultDateBegFiscalPeriod); + if (row < size - 1) { + comboBox.setSelectedIndex(row + 1); + } + view.getAccountViewerSelectionModel().clearSelection(); + } + } - filter.setDateStart(defaultDateBegFiscalPeriod); - filter.setDateEnd(defaultDateEndCurrent); + protected void onFiscalPeriodChange(java.awt.event.ItemEvent event) { + if (initializationComplete) { + FiscalPeriod fiscalPeriod = (FiscalPeriod) event.getItem(); + updateAllEntriesForFiscalPeriodChange(fiscalPeriod); + } } - public void updateAllEntries() { + + protected void onFinancialPeriodChange(java.awt.event.ItemEvent event) { + if (initializationComplete) { + FinancialPeriod financialPeriod = (FinancialPeriod) event.getItem(); + updateAllEntriesForFinancialPeriodChange(financialPeriod); + } + } + + public void onDateStartChange(Date date) { + if (initializationComplete) { + filter.setDateStart(date); + updateAllEntriesForDateChange(); + } + } + + public void onDateEndChange(Date date) { + if (initializationComplete) { + filter.setDateEnd(date); + updateAllEntriesForDateChange(); + } + } + + public void onSelectionModeChanged(SelectionMode selectionMode) { + + switch (selectionMode) { + case LETTERED: + view.getAccountViewerSelectionModel().setLetteredSelectionMode(true); + break; + case MANUAL: + view.getAccountViewerSelectionModel().setLetteredSelectionMode(false); + break; + default: + view.getAccountViewerSelectionModel().setLetteredSelectionMode(true); + } + } + + public void updateSoldStatus() { + if (initializationComplete) { + view.getBalanceStatusLabel().setText(t("lima.lettering.accountViewerBalanceStatus", + getDateFormat().format(editModel.getFiscalPeriodBeginDate()), + getDateFormat().format(filter.getDateEnd()), + + BigDecimalToString.format(editModel.getGlobalDebit()), + BigDecimalToString.format(editModel.getGlobalCredit()), + BigDecimalToString.format(editModel.getGlobalSold()), + + BigDecimalToString.format(editModel.getDebit()), + BigDecimalToString.format(editModel.getCredit()), + BigDecimalToString.format(editModel.getSold()))); + } + } + + + public void updateAllEntriesForFiscalPeriodChange(FiscalPeriod fiscalPeriod) { + filter.setDateStart(fiscalPeriod.getBeginDate()); + filter.setDateEnd(fiscalPeriod.getEndDate()); + + updateAllEntries(fiscalPeriod); + } + + public void updateAllEntriesForFinancialPeriodChange(FinancialPeriod financialPeriod) { + filter.setDateStart(financialPeriod.getBeginDate()); + filter.setDateEnd(financialPeriod.getEndDate()); + updateAllEntries(null); + } + + public void updateAllEntriesForDateChange() { + updateAllEntries(null); + } + + public void updateAllEntries(FiscalPeriod fiscalPeriod) { if (initializationComplete && filter.getAccount() != null @@ -236,7 +342,7 @@ public class AccountViewerViewHandler { List<Entry> entriesAndResume = Lists.newArrayList(); List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); - FiscalPeriod fiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); + fiscalPeriod = fiscalPeriod == null ? fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()) : fiscalPeriod; if (CollectionUtils.isNotEmpty(entries)) { // can be null if there are no fiscal period for the begin date @@ -255,6 +361,58 @@ public class AccountViewerViewHandler { onBalanceChanged(null); } + public void initFiscalPeriodModel() { + FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); + if (fiscalPeriod != null) { + view.getFiscalPeriodComboBox().setSelectedItem(fiscalPeriod); + view.getBeginPeriodPicker().setDate(fiscalPeriod.getBeginDate()); + view.getEndPeriodPicker().setDate(fiscalPeriod.getEndDate()); + } + } + + public void initViewWithDefaultFinancialPeriod() { + List<FinancialPeriod> financialPeriods = financialPeriodService.getAllFinancialPeriods(); + view.getFinancialPeriodComboBoxModel().setObjects(financialPeriods); + + FiscalPeriod fiscalPeriod = fiscalPeriodService.getLastFiscalPeriod(); + + FinancialPeriod defaultFinancialPeriod = getDefaultFinancialPeriod(financialPeriods, fiscalPeriod); + + Calendar calendar = Calendar.getInstance(); + int lastCurrentMonthDay = calendar.getActualMaximum(Calendar.DATE); + int firstCurrentMonthDay = calendar.getActualMinimum(Calendar.DATE); + + Date defaultDateBeginFinancialPeriod, defaultDateEndCurrent; + defaultDateBeginFinancialPeriod = defaultFinancialPeriod == null ? DateUtils.setDays(new Date(), firstCurrentMonthDay) : defaultFinancialPeriod.getBeginDate(); + defaultDateEndCurrent = defaultFinancialPeriod == null ? DateUtils.setDays(new Date(), lastCurrentMonthDay) : defaultFinancialPeriod.getEndDate(); + + view.getFinancialPeriodComboBoxModel().setSelectedItem(defaultFinancialPeriod); + + view.getBeginPeriodPicker().setDate(defaultDateBeginFinancialPeriod); + view.getEndPeriodPicker().setDate(defaultDateEndCurrent); + + filter.setDateStart(defaultDateBeginFinancialPeriod); + filter.setDateEnd(defaultDateEndCurrent); + + editModel.setFiscalPeriodBeginDate(fiscalPeriod != null ? fiscalPeriod.getBeginDate() : defaultDateBeginFinancialPeriod); + } + + protected FinancialPeriod getDefaultFinancialPeriod(List<FinancialPeriod> financialPeriods, FiscalPeriod fiscalPeriod) { + FinancialPeriod defaultFinancialPeriod = null; + + if ((fiscalPeriod != null && fiscalPeriod.getFinancialPeriod() != null)) { + + Collection<FinancialPeriod> fiscalPeriodFinancialPeriods = financialPeriodService.getFinancialPeriods(fiscalPeriod.getBeginDate(), fiscalPeriod.getEndDate()); + Iterator<FinancialPeriod> financialPeriodIterator = fiscalPeriodFinancialPeriods.iterator(); + if (financialPeriodIterator.hasNext()) { + defaultFinancialPeriod = financialPeriodIterator.next(); + } + } + + defaultFinancialPeriod = defaultFinancialPeriod != null ? defaultFinancialPeriod : CollectionUtils.isNotEmpty(financialPeriods) ? financialPeriods.get(0) : null; + return defaultFinancialPeriod; + } + protected void addPreviousSoldEntryToEntries(List<Entry> entriesAndResume, List<Entry> entries, LetteringFilter previousPeriodFilter) { // no previous sold to add if selected starting date is same as fiscal period one if (!DateUtils.isSameDay(filter.getDateStart(), previousPeriodFilter.getDateStart()) && CollectionUtils.isNotEmpty(entries)) { @@ -382,13 +540,6 @@ public class AccountViewerViewHandler { } } - protected Calendar getDayMinus1Calendar(LetteringFilter previousPeriodFilter) { - Calendar cal = Calendar.getInstance(); - cal.setTime(previousPeriodFilter.getDateEnd()); - cal.add(Calendar.DATE, -1); - return cal; - } - protected LetteringFilter computePreviousPeriodFilter(FiscalPeriod fiscalPeriod) { LetteringFilter previousPeriodFilter = null; @@ -415,86 +566,6 @@ public class AccountViewerViewHandler { return actualPeriodFilter; } - public void accountComboBoxChange(PropertyChangeEvent event) { - if (event.getPropertyName().equals(AccountComboBox.PROPERTY_SELECTED_ITEM) && event.getNewValue() != null && event.getNewValue() instanceof Account) { - setAccount((Account) event.getNewValue()); - } - } - - /** - * Select previous value in combo box. - * - * @param accountComboBox account combo box - */ - public void back(AccountComboBox accountComboBox) { - JComboBox comboBox = accountComboBox.getCombobox(); - int row = comboBox.getSelectedIndex(); - - if (row > 0) { - comboBox.setSelectedIndex(row - 1); - } - view.getAccountViewerSelectionModel().clearSelection(); - } - - /** - * Select next value in combo box. - * - * @param accountComboBox combo box - */ - public void next(AccountComboBox accountComboBox) { - JComboBox comboBox = accountComboBox.getCombobox(); - int size = comboBox.getItemCount(); - int row = comboBox.getSelectedIndex(); - - if (row < size - 1) { - comboBox.setSelectedIndex(row + 1); - } - view.getAccountViewerSelectionModel().clearSelection(); - } - - public void setDateStart(Date date) { - if (initializationComplete) { - filter.setDateStart(date); - updateAllEntries(); - } - } - - public void setDateEnd(Date date) { - if (initializationComplete) { - filter.setDateEnd(date); - updateAllEntries(); - } - } - - public void setAccount(Account account) { - if (filter != null) { - filter.setAccount(account); - updateAllEntries(); - } - } - - public Account getAccount() { - Account account = null; - if (filter != null) { - account = filter.getAccount(); - } - return account; - } - - public void onSelectionModeChanged(SelectionMode selectionMode) { - - switch (selectionMode) { - case LETTERED: - view.getAccountViewerSelectionModel().setBalancedSelectionMode(true); - break; - case MANUAL: - view.getAccountViewerSelectionModel().setBalancedSelectionMode(false); - break; - default: - view.getAccountViewerSelectionModel().setBalancedSelectionMode(true); - } - } - protected class DebitCreditSold { private BigDecimal debit; private BigDecimal credit; @@ -535,6 +606,29 @@ public class AccountViewerViewHandler { } } + public void setAccount(Account account) { + if (filter != null) { + filter.setAccount(account); + updateAllEntries(null); + } + } + + public Account getAccount() { + Account account = null; + if (filter != null) { + account = filter.getAccount(); + } + return account; + } + + protected Calendar getDayMinus1Calendar(LetteringFilter previousPeriodFilter) { + Calendar cal = Calendar.getInstance(); + cal.setTime(previousPeriodFilter.getDateEnd()); + cal.add(Calendar.DATE, -1); + return cal; + } + + protected DateFormat getDateFormat() { Locale locale = LimaSwingConfig.getInstance().getLocale(); DateFormat result = DateFormat.getDateInstance(DateFormat.SHORT, locale); diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/FinancialPeriodListRenderer.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/FinancialPeriodListRenderer.java new file mode 100644 index 0000000..cb1498c --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/FinancialPeriodListRenderer.java @@ -0,0 +1,68 @@ +/* + * #%L + * Lima :: Swing + * %% + * Copyright (C) 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 + * 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.accountViewer; + +import org.chorem.lima.LimaSwingConfig; +import org.chorem.lima.entity.FinancialPeriod; + +import javax.swing.*; +import java.awt.*; +import java.text.DateFormat; +import java.util.Locale; + +/** + * Financial period list renderer. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class FinancialPeriodListRenderer extends DefaultListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = -1L; + + // afiche le mois en lettre et le numero de la période, pour eviter les confusions entre deux mois identique pour des exercice de plus de 12 mois + + @Override + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + + FinancialPeriod financialPeriod = (FinancialPeriod)value; + Object newValue = financialPeriod; + if (financialPeriod != null) { + newValue = String.format("%s - %s", getDateFormat().format(financialPeriod.getBeginDate()), getDateFormat().format(financialPeriod.getEndDate())); + } + return super.getListCellRendererComponent(list, newValue, index, isSelected, + cellHasFocus); + } + + protected DateFormat getDateFormat() { + Locale locale = LimaSwingConfig.getInstance().getLocale(); + DateFormat result = DateFormat.getDateInstance(DateFormat.SHORT, locale); + return result; + } + +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/PeriodChoice.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/PeriodChoice.java new file mode 100644 index 0000000..cc8ade3 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/PeriodChoice.java @@ -0,0 +1,34 @@ +package org.chorem.lima.ui.accountViewer; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created by davidcosse on 15/09/15. + */ +public enum PeriodChoice { + + FINANCIAL_PERIOD, FISCAL_PERIOD, DATE; + + @Override + public String toString() { + + String result; + + switch (this) { + case FINANCIAL_PERIOD: + result = t("lima.filter.condition.periodChoice.financialPeriod"); + break; + case FISCAL_PERIOD: + result = t("lima.filter.condition.periodChoice.fiscalPeriod"); + break; + case DATE: + result = t("lima.filter.condition.periodChoice.date"); + break; + default: + result = t("lima.filter.condition.periodChoice.financialPeriod"); + } + + return result; + + } +} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java index 9a2a118..36986d0 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/combobox/FiscalPeriodComboBoxModel.java @@ -86,7 +86,7 @@ public class FiscalPeriodComboBoxModel extends AbstractListModel implements Comb return selectedFiscalPeriod; } - //get unblocked fiscal periods data list + //get unblocked fiscal periods data list public List<FiscalPeriod> getDataList() { List<FiscalPeriod> result = fiscalPeriodService.getAllUnblockedFiscalPeriods(); diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/common/FiscalPeriodComboBoxModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/common/FiscalPeriodComboBoxModel.java index d0ff510..27c38f2 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/common/FiscalPeriodComboBoxModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/common/FiscalPeriodComboBoxModel.java @@ -38,4 +38,16 @@ public class FiscalPeriodComboBoxModel extends GenericComboBoxModel<FiscalPeriod /** serialVersionUID. */ private static final long serialVersionUID = 3017195549616278980L; + /*By default, selection of the first financial period (Because a +* transaction concern one financial period) +*/ + @Override + public Object getElementAt(int index) { + if (getSelectedItem() == null){ + setSelectedItem(objects.get(0)); + return objects.get(0); + } + return objects.get(index); + } + } diff --git a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties index 588228c..9ad9420 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties @@ -226,6 +226,9 @@ lima.filter=Filter lima.filter.account=Add account filter lima.filter.condition.all=Valid all criteria lima.filter.condition.one=Valid at least one criteria +lima.filter.condition.periodChoice.date= +lima.filter.condition.periodChoice.financialPeriod= +lima.filter.condition.periodChoice.fiscalPeriod= lima.filter.condition.selectionMode=Balance entry selection lima.filter.condition.selectionMode.lettered=Lettered lima.filter.condition.selectionMode.manual=Manual diff --git a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties index 7a29d75..7a84f05 100644 --- a/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties +++ b/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties @@ -236,6 +236,9 @@ lima.filter.account=Ajouter un filtre sur les comptes lima.filter.condition.all=Valide toutes les conditions lima.filter.condition.delete=Supprimer la condition lima.filter.condition.one=Valide au moins une condition +lima.filter.condition.periodChoice.date=Dates +lima.filter.condition.periodChoice.financialPeriod=Périodes fiscales +lima.filter.condition.periodChoice.fiscalPeriod=Execrices lima.filter.condition.selectionMode=Sélection des écritures lettrées lima.filter.condition.selectionMode.lettered=Lettré lima.filter.condition.selectionMode.manual=Manuelle -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.
participants (1)
-
chorem.org scm