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 b5244af9b7826be056f755dc15a769b55b804f5a Author: dcosse <cosse@codelutin.com> Date: Tue Sep 15 15:56:35 2015 +0200 refs #1241 Ajout de la possibilité de choisir entre deux modes de sélection des entrées (Manuelle ou Balancée) --- .../src/main/java/org/chorem/lima/ui/MainView.css | 2 +- .../ui/accountViewer/AccountViewerEditModel.java | 40 +---- .../accountViewer/AccountViewerSelectionModel.java | 98 ++++++------ .../lima/ui/accountViewer/AccountViewerView.css | 9 ++ .../lima/ui/accountViewer/AccountViewerView.jaxx | 8 +- .../ui/accountViewer/AccountViewerViewHandler.java | 177 +++++++-------------- .../lima/ui/accountViewer/SelectionMode.java | 29 ++++ .../resources/i18n/lima-swing_en_GB.properties | 4 + .../resources/i18n/lima-swing_fr_FR.properties | 4 + .../main/resources/icons/action-account-viewer.png | Bin 0 -> 1062 bytes .../main/resources/icons/action-selection-mode.png | Bin 0 -> 1106 bytes 11 files changed, 165 insertions(+), 206 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css index 177cf8b..0053bbc 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css +++ b/lima-swing/src/main/java/org/chorem/lima/ui/MainView.css @@ -238,7 +238,7 @@ #accountViewer { text : "lima.entries.accountViewer"; - actionIcon : "lettering"; + actionIcon : "account-viewer"; } #help { diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java index 5c4f64f..57accc3 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/AccountViewerEditModel.java @@ -40,18 +40,10 @@ public class AccountViewerEditModel implements Serializable { public static final String PROPERTY_GLOBAL_SOLD = "globalSold"; - public static final String PROPERTY_LETTRED = "lettred"; - - public static final String PROPERTY_UNLETTRED = "unLettred"; - - public static final String PROPERTY_EQUALIZED = "equalized"; - protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); protected AccountViewerTableModel model; - protected boolean lettred; - protected boolean unLettred; - protected boolean equalized; + protected BigDecimal debit = BigDecimal.ZERO; protected BigDecimal credit = BigDecimal.ZERO; protected BigDecimal sold = BigDecimal.ZERO; @@ -62,36 +54,6 @@ public class AccountViewerEditModel implements Serializable { protected Date fiscalPeriodBeginDate; -// public boolean isEqualized() { -// return equalized; -// } - -// public void setEqualized(boolean equalized) { -// boolean oldEqualized = isEqualized(); -// this.equalized = equalized; -// firePropertyChange(PROPERTY_EQUALIZED, oldEqualized, this.equalized); -// } - -// public boolean isLettred() { -// return lettred; -// } - -// public void setLettred(boolean lettered) { -// boolean oldLetter = isLettred(); -// this.lettred = lettered && (BigDecimal.ZERO.equals(sold) || sold.doubleValue() == 0); -// firePropertyChange(PROPERTY_LETTRED, oldLetter, this.lettred); -// } - -// public boolean isUnLettred() { -// return unLettred; -// } - -// public void setUnLettred(boolean unLettred) { -// boolean oldDeleter = isUnLettred(); -// this.unLettred = unLettred; -// firePropertyChange(PROPERTY_UNLETTRED, oldDeleter, this.unLettred); -// } - public BigDecimal getDebit() { return debit; } 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 fa1fea5..5199a0b 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 @@ -37,6 +37,8 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ protected AccountViewerTableModel letteringTableModel; protected Entry entry; protected int lineSelected; + + protected boolean balancedSelectionMode; protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); public AccountViewerSelectionModel(AccountViewerTableModel letteringTableModel){ @@ -50,43 +52,54 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ @Override public void setSelectionInterval(int row, int column) { - if (!letteringNotExist(row)) { - - //lettred entries - if ( isSelectionEmpty() || !isSelectedIndex(row)){ - clearSelection(); - lineSelected = row; - String currentLettring = getCurrentLettring(); - - //select entries with the same letter of the selected entry - for(Entry entry : getEntries()){ - if (StringUtils.isNotBlank(entry.getLettering())){ - if (entry.getLettering().equals(currentLettring)){ - int entryToSelect = letteringTableModel.indexOf(entry); - super.addSelectionInterval(entryToSelect, entryToSelect); + if (balancedSelectionMode) { + if (!letteringNotExist(row)) { + + //lettred entries + if ( isSelectionEmpty() || !isSelectedIndex(row)){ + clearSelection(); + lineSelected = row; + String currentLettring = getCurrentLettring(); + + //select entries with the same letter of the selected entry + for(Entry entry : getEntries()){ + if (StringUtils.isNotBlank(entry.getLettering())){ + if (entry.getLettering().equals(currentLettring)){ + int entryToSelect = letteringTableModel.indexOf(entry); + super.addSelectionInterval(entryToSelect, entryToSelect); + } } } } } - } - else { - - //unlettred entries - //To clear the selection when it changes from lettered entry to unlettered - for(Entry entry : getEntries()){ - if (!StringUtils.isBlank(entry.getLettering())) { - int entryToSelect = letteringTableModel.indexOf(entry); - super.removeSelectionInterval(entryToSelect, entryToSelect); + else { + + //unlettred entries + //To clear the selection when it changes from lettered entry to unlettered + for(Entry entry : getEntries()){ + if (!StringUtils.isBlank(entry.getLettering())) { + int entryToSelect = letteringTableModel.indexOf(entry); + super.removeSelectionInterval(entryToSelect, entryToSelect); + } } - } - if (isSelectionEmpty() || !isSelectedIndex(row)){ - super.addSelectionInterval(row, column); - }else { - super.removeSelectionInterval(row, column); - } + if (isSelectionEmpty() || !isSelectedIndex(row)){ + super.addSelectionInterval(row, column); + }else { + super.removeSelectionInterval(row, column); + } + } + } else { + super.addSelectionInterval(row, column); + //super.setSelectionInterval(row, column); } + + } + + @Override + public int getSelectionMode() { + return MULTIPLE_INTERVAL_SELECTION; } /**return true if lettering is null, or not null but empty @@ -113,24 +126,6 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ return letteringTableModel.get(lineSelected); } -// /**After rounding one of two entries, selection of its, and of the new entry, -// * resulting of rounding*/ -// public void selectRoundedAndNewEntries(int indexFirstRoundedEntry, int indexSecondRoundedEntry, Entry newResultRoundedEntry) { -// if (!isSelectedIndex(indexFirstRoundedEntry)) { -// addSelectionInterval(indexFirstRoundedEntry, indexFirstRoundedEntry); -// } -// if (!isSelectedIndex(indexSecondRoundedEntry)) { -// addSelectionInterval(indexSecondRoundedEntry, indexSecondRoundedEntry); -// } -// /*New entry*/ -// int newEntryIndex = letteringTableModel.indexOf(newResultRoundedEntry); -// addSelectionInterval(newEntryIndex, newEntryIndex); -// } - - @Override - public int getSelectionMode() { - return MULTIPLE_INTERVAL_SELECTION; - } public void addPropertyChangeListener(PropertyChangeListener listener) { pcs.addPropertyChangeListener(listener); @@ -155,4 +150,13 @@ public class AccountViewerSelectionModel extends DefaultListSelectionModel{ protected void firePropertyChange(String propertyName, Object newValue) { firePropertyChange(propertyName, null, newValue); } + + public void setBalancedSelectionMode(boolean balancedSelectionMode) { + this.balancedSelectionMode = balancedSelectionMode; + clearSelection(); + } + + public boolean getBalancedSelectionMode() { + return balancedSelectionMode; + } } 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..25f34fe 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 @@ -52,11 +52,20 @@ labelFor : {beginPeriodPicker}; } +#beginPeriodPicker { + patternLayout: {handler.DATE_FORMAT}; +} + #endPeriodLabel { text : "lima.lettering.period.end"; labelFor : {endPeriodPicker}; } +#endPeriodPicker { + patternLayout: {handler.DATE_FORMAT}; +} + + #refresh { toolTipText : "lima.lettering.refresh"; actionIcon : "refresh"; 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 25a1066..75a86df 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 @@ -62,16 +62,20 @@ <JLabel id="beginPeriodLabel"/> <JAXXDatePicker id="beginPeriodPicker" - patternLayout="dd/MM/yyy" onActionPerformed="handler.setDateStart(beginPeriodPicker.getDate())"/> <JLabel id="endPeriodLabel"/> <JAXXDatePicker id="endPeriodPicker" - patternLayout="dd/MM/yyy" onActionPerformed="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()"/> 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 bf37cb0..7e9ceca 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 @@ -75,12 +75,11 @@ import static org.nuiton.i18n.I18n.t; public class AccountViewerViewHandler { // fixme Date format should be app parameters - protected static String DATE_FORMAT = "dd/MM/yyyy"; + protected static String DATE_FORMAT = t("lima.ui.dateFormat"); protected AccountViewerView view; protected AccountViewerTable table; - /** Transaction service. */ protected FiscalPeriodService fiscalPeriodService; protected FinancialPeriodService financialPeriodService; protected AccountService accountService; @@ -89,13 +88,11 @@ public class AccountViewerViewHandler { protected LetteringFilterImpl filter; - protected BigDecimal debit = BigDecimal.ZERO; - protected BigDecimal credit = BigDecimal.ZERO; protected AccountViewerEditModel editModel; protected ErrorHelper errorHelper; - protected enum ButtonMode {DELETTRED, LETTRED, EQUALIZED, ALL} + protected SelectionMode selectionMode = SelectionMode.BALANCED; protected SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT); @@ -122,7 +119,6 @@ public class AccountViewerViewHandler { public void init() { filter = new LetteringFilterImpl(); editModel = view.getEditModel(); - //lettringSelectionModel = view.getLetteringSelectionModel(); loadComboAndRows(); editModel.addPropertyChangeListener(AccountViewerEditModel.PROPERTY_DEBIT, new PropertyChangeListener() { @@ -153,6 +149,8 @@ public class AccountViewerViewHandler { } }); + onSelectionModeChanged(selectionMode); + initializationComplete = true; updateAllEntries(); updateSoldStatus(); @@ -238,16 +236,20 @@ public class AccountViewerViewHandler { List<Entry> entries = financialTransactionService.getAllEntrieByDatesAndAccountAndLettering(filter); FiscalPeriod fiscalPeriod = fiscalPeriodService.getFiscalPeriodForDate(filter.getDateStart()); - LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(fiscalPeriod); - LetteringFilter actualPeriodFilter = computeActualPeriodFilter(fiscalPeriod); - setPreviousSold(previousPeriodFilter); - setActualSold(fiscalPeriod, actualPeriodFilter); - - // 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)) { - entriesAndResume.add(getFirstLinePreviousSoldEntry(entries, previousPeriodFilter)); + if (CollectionUtils.isNotEmpty(entries)) { + // can be null if there are no fiscal period for the begin date + if (fiscalPeriod != null) { + LetteringFilter previousPeriodFilter = computePreviousPeriodFilter(fiscalPeriod); + LetteringFilter actualPeriodFilter = computeActualPeriodFilter(fiscalPeriod); + setPreviousSold(previousPeriodFilter); + setActualSold(fiscalPeriod, actualPeriodFilter); + + // 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)) { + entriesAndResume.add(getFirstLinePreviousSoldEntry(entries, previousPeriodFilter)); + } + } } - entriesAndResume.addAll(entries); view.getTableModel().setValues(entriesAndResume); } @@ -304,62 +306,10 @@ public class AccountViewerViewHandler { if (log.isDebugEnabled()) { log.debug("balanceAndActions"); } - if (view.getTable().getSelectedRows().length == 0) { - onButtonModeChanged(ButtonMode.ALL); - onBalanceChanged(null); - } else if (!letteringNotExist(view.getTable().getSelectedRow())) { - - //lettred entries - onBalanceChanged(null); + onBalanceChanged(null); + if (view.getTable().getSelectedRows().length > 0 && !letteringNotExist(view.getTable().getSelectedRow()) || + view.getTable().getSelectedRows().length > 0 && !view.getAccountViewerSelectionModel().isSelectionEmpty()) { setValuesForSelectedEntries(); - - //For U.I. buttons (Lettering and unlettering) - onButtonModeChanged(ButtonMode.DELETTRED); - } else { - if (log.isDebugEnabled()) { - log.debug("unlettred entries"); - } - int[] selectedRows = view.getTable().getSelectedRows(); - if (selectedRows.length == 2) { - if (log.isDebugEnabled()) { - log.debug("2 rows selected"); - } - /*Treatment only if one of values contains decimals*/ - AccountViewerTableModel tableModel = view.getTableModel(); - Entry firstSelectedEntry = tableModel.get(selectedRows[0]); - Entry secondSelectedEntry = tableModel.get(selectedRows[1]); - - /*Get decimals*/ - BigDecimal firstSelectedEntryAmount = firstSelectedEntry.getAmount(); - BigDecimal secondSelectedEntryAmount = secondSelectedEntry.getAmount(); - - if ( secondSelectedEntry.isDebit() != firstSelectedEntry.isDebit() - && (firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ZERO) >0 - && firstSelectedEntryAmount.subtract(secondSelectedEntryAmount).abs().compareTo(BigDecimal.ONE) <0) ) { - onButtonModeChanged(ButtonMode.EQUALIZED); - } - }else { - if (log.isDebugEnabled()) { - log.debug("!2 rows selected"); - } - onButtonModeChanged(ButtonMode.ALL); - } - - //Unlettred entries - onBalanceChanged(null); - //treatment unuseful if no rows are selected - if (!view.getAccountViewerSelectionModel().isSelectionEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Rows selected"); - } - setValuesForSelectedEntries(); - onButtonModeChanged(ButtonMode.LETTRED); - } else { - if (log.isDebugEnabled()) { - log.debug("No Rows selected"); - } - onButtonModeChanged(ButtonMode.ALL); - } } } @@ -377,27 +327,6 @@ public class AccountViewerViewHandler { return emptyOrNull; } - public void onButtonModeChanged(ButtonMode buttonMode) { - - switch (buttonMode) { - case DELETTRED : - editModel.setLettred(false); - editModel.setUnLettred(true); - break; - case LETTRED: - editModel.setUnLettred(false); - editModel.setLettred(true); - break; - case EQUALIZED: - editModel.setEqualized(true); - break; - default: - editModel.setLettred(false); - editModel.setUnLettred(false); - editModel.setEqualized(false); - } - } - public void setValuesForSelectedEntries() { Entry selectedEntry; AccountViewerTableModel tableModel = view.getTableModel(); @@ -520,7 +449,46 @@ public class AccountViewerViewHandler { view.getAccountViewerSelectionModel().clearSelection(); } - private class DebitCreditSold { + public void setDateStart(Date date) { + filter.setDateStart(date); + updateAllEntries(); + } + + public void setDateEnd(Date date) { + 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 BALANCED: + 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; private BigDecimal sold; @@ -560,29 +528,4 @@ public class AccountViewerViewHandler { } } - public void setDateStart(Date date) { - filter.setDateStart(date); - updateAllEntries(); - } - - public void setDateEnd(Date date) { - 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; - } - } diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java new file mode 100644 index 0000000..8d69868 --- /dev/null +++ b/lima-swing/src/main/java/org/chorem/lima/ui/accountViewer/SelectionMode.java @@ -0,0 +1,29 @@ +package org.chorem.lima.ui.accountViewer; + +import static org.nuiton.i18n.I18n.t; + +/** + * Created by davidcosse on 15/09/15. + */ +public enum SelectionMode { + + BALANCED, MANUAL; + + @Override + public String toString() { + + String result = ""; + + switch (this) { + case MANUAL: + result = t("lima.filter.condition.selectionMode.manual"); + break; + case BALANCED: + result = t("lima.filter.condition.selectionMode.balanced"); + break; + } + + return result; + + } +} 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 4de6b2d..2b0a17d 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.selectionMode=Balance entry selection +lima.filter.condition.selectionMode.balanced=Balanced +lima.filter.condition.selectionMode.manual=Manual lima.filter.credit=Add filter on credit lima.filter.date.interval=Filter on date range lima.filter.date.one=Filter for one date @@ -542,6 +545,7 @@ lima.treasury.sie=SIE lima.treasury.systemType=System Type lima.treasury.vatNumber=VAT number lima.treasury.zipCode=Zip Code +lima.ui.dateFormat=MM/dd/yyy lima.update=Modify lima.update.shortcut=Update (Ctrl+M) lima.validate=Validate 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 a9baa5b..2b17f4e 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.selectionMode=Sélection des écritures balancées +lima.filter.condition.selectionMode.balanced=Balancée +lima.filter.condition.selectionMode.manual=Manuelle lima.filter.credit=Ajouter un filtre sur les crédits lima.filter.date=Ajouter un filtre sur les dates lima.filter.date.interval=Ajouter un filtre sur un interval de dates @@ -547,6 +550,7 @@ lima.treasury.serviceCode=Code service lima.treasury.sie=SIE lima.treasury.systemType=Régime lima.treasury.zipCode=Code Postal +lima.ui.dateFormat=dd/MM/yyy lima.update=Modifier lima.update.shortcut=Modifier (Ctrl+M) lima.validate=Valider diff --git a/lima-swing/src/main/resources/icons/action-account-viewer.png b/lima-swing/src/main/resources/icons/action-account-viewer.png new file mode 100644 index 0000000..f6f840b Binary files /dev/null and b/lima-swing/src/main/resources/icons/action-account-viewer.png differ diff --git a/lima-swing/src/main/resources/icons/action-selection-mode.png b/lima-swing/src/main/resources/icons/action-selection-mode.png new file mode 100644 index 0000000..594d3a1 Binary files /dev/null and b/lima-swing/src/main/resources/icons/action-selection-mode.png differ -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.