r3540 - in trunk/lima-swing/src/main: java/org/chorem/lima/ui/celleditor java/org/chorem/lima/ui/lettering resources resources/i18n
Author: mallon Date: 2012-07-19 18:07:36 +0200 (Thu, 19 Jul 2012) New Revision: 3540 Url: http://chorem.org/repositories/revision/lima/3540 Log: fixes #706 Simplification de l'utilisation des mod?\195?\168les pour le panneau de lettrage (Suppression des mod?\195?\168les d?\195?\169l?\195?\169gu?\195?\169s, pose d'un listener sur le mod?\195?\168le de s?\195?\169lection.). Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties trunk/lima-swing/src/main/resources/log4j.properties Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/celleditor/BigDecimalTableCellEditor.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -25,17 +25,20 @@ import jaxx.runtime.swing.editor.cell.NumberCellEditor; -import javax.swing.*; -import java.awt.*; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; +import java.awt.Component; import java.awt.event.FocusEvent; import java.math.BigDecimal; /** * @author sletellier <letellier@codelutin.com> */ -public class BigDecimalTableCellEditor extends NumberCellEditor<BigDecimal> { +public class BigDecimalTableCellEditor extends NumberCellEditor<BigDecimal>{ protected int row; + protected JTextField textFieldNumberValue; /** * constructor @@ -59,10 +62,27 @@ public void focusGained(FocusEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { - numberEditor.getTextField().requestFocus(); - int length = numberEditor.getTextField().getText().length(); - numberEditor.getTextField().select(length, length); + textFieldNumberValue = numberEditor.getTextField(); + textFieldNumberValue.requestFocus(); + int length = textFieldNumberValue.getText().length(); + textFieldNumberValue.select(length, length); } }); } + + /**To limit number of decimals at two, and rounded up it + * */ + /*@Override + public void focusLost(FocusEvent e) {*/ + //getCellEditorValue().setScale(2, RoundingMode.HALF_UP); + /*SwingUtilities.invokeLater(new Runnable() { + public void run() {*/ + /* BigDecimal cellEditorValue = getCellEditorValue(); + cellEditorValue.setScale(2, RoundingMode.HALF_UP); + System.out.println("cellEditorValue : " + cellEditorValue); + numberEditor.getTextField().setText(cellEditorValue.toString()); + System.out.println("numberEditor.getTextField().getText() : " + numberEditor.getTextField().getText());*/ + /* } + });*/ + //} } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringEditModel.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -127,29 +127,6 @@ firePropertyChange(SOLDE_PROPERTY, oldSolde, this.solde); } - /**Allow to add / subtract credit / debit and balance - * @param amount debit or credit - * @param debit it indicate if amount is debit or not - * */ - public void balanceCalculation(BigDecimal amount, boolean debit){ - - BigDecimal debitVal = debit ? amount : BigDecimal.ZERO; - BigDecimal creditVal = debit ? BigDecimal.ZERO : amount; - - if (debitVal == BigDecimal.ZERO){ - - if (creditVal != BigDecimal.ZERO){ - setCredit(creditVal); - setSolde(creditVal, true); - } - }else if (creditVal == BigDecimal.ZERO){ - setDebit(debitVal); - setSolde(debitVal, false); - }else{ - resetDebitCreditBalance(); - } - } - public void resetDebitCreditBalance(){ setDebit(BigDecimal.ZERO); setCredit(BigDecimal.ZERO); Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringSelectionModel.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -1,128 +0,0 @@ -package org.chorem.lima.ui.lettering; -/* - * #%L - * Lima :: Swing - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.apache.commons.lang3.StringUtils; -import org.chorem.lima.entity.Entry; - -import javax.swing.DefaultListSelectionModel; -import java.util.List; - -/** - * @author sletellier <letellier@codelutin.com> - */ -public class LetteringSelectionModel extends DefaultListSelectionModel { - - protected LetteringTableModel letteringTableModel; - protected LetteringEditModel editModel; - protected int lineSelected; - - //protected List<Entry> selectedRows = new ArrayList<Entry>(); - - /**Table selection model when entry selected is lettered - * @param letteringTableModel model of the table - * @param editModel model managing update of debit / credit / balance - * */ - public LetteringSelectionModel(LetteringTableModel letteringTableModel, LetteringEditModel editModel) { - this.letteringTableModel = letteringTableModel; - this.editModel = editModel; - } - - //@Override - public void addSelectionInterval(int row, int column){ - setSelectionInterval(row, column); - } - - //@Override - public void removeSelectionInterval(int row, int column){ - } - - @Override - public void setSelectionInterval(int row, int column){ - - if ( isSelectionEmpty() || !isSelectedIndex(row)){ - super.clearSelection(); - lineSelected = row; - String currentLettring = getCurrentLettring(); - setValueIsAdjusting(true); - try { - //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.getIndexOfEntry(entry); - super.addSelectionInterval(entryToSelect, entryToSelect); - } - } - } - } finally { - setValueIsAdjusting(false); - } - updateBalanceAndLetteringButton(false); - } - } - - /**PropertyChange on editModel in the handler, and, there, - * set values it. - * @param lettering state of attributes lettered and unlettered in editModel - * */ - public void updateBalanceAndLetteringButton(boolean lettering){ - editModel.resetDebitCreditBalance(); - - Entry selectedEntry; - for (int i = 0; i < letteringTableModel.getRowCount(); i ++){ - if (isSelectedIndex(i)){ - selectedEntry = letteringTableModel.getEntryAt(i); - //Set values for calculation (By LetteringEditModel) of balance - editModel.balanceCalculation(selectedEntry.getAmount(), selectedEntry.getDebit()); - } - } - - //For U.I. buttons (Lettering and unlettering) - editModel.setUnLettred(!lettering); - editModel.setLettred(lettering); - } - - //to reinitialize model attribute - /*public void resetAttribute(){ - clearSelection(); - }*/ - - public List<Entry> getEntries(){ - return letteringTableModel.getEntries(); - } - - public String getCurrentLettring(){ - return getCurrentEntrySelected().getLettering(); - } - - public Entry getCurrentEntrySelected(){ - return letteringTableModel.getEntryAt(lineSelected); - } - - @Override - public int getSelectionMode() { - return MULTIPLE_INTERVAL_SELECTION; - } -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringView.jaxx 2012-07-19 16:07:36 UTC (rev 3540) @@ -38,13 +38,11 @@ <LetteringViewHandler id="handler" constructorParams="this"/> <LetteringTableModel id="tableModel"/> - <LetteringEditModel id='editModel'/> <LetteringFilter id='filterModel' initializer='new LetteringFilterImpl()'/> + <LetteringEditModel id='editModel'/> - <LetteringSelectionModel id='letteringSelectionModel' constructorParams='tableModel, editModel'/> - <UnlettringSelectionModel id='unletteringSelectionModel' constructorParams='tableModel, editModel'/> - <LettringAndUnlettringSelectionModel id='lettringAndUnlettringSelectionModel' - constructorParams='letteringSelectionModel, unletteringSelectionModel, tableModel, editModel'/> + <LettringSelectionModel id='lettringSelectionModel' constructorParams=' tableModel' + onValueChanged="handler.balanceAndActions()"/> <script> <![CDATA[ @@ -190,7 +188,7 @@ <LetteringTable id="table" sortable="false" rowHeight="22" constructorParams="getTableModel()" - selectionModel="{lettringAndUnlettringSelectionModel}" + selectionModel="{lettringSelectionModel}" /> </JScrollPane> </cell> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringViewHandler.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -26,6 +26,8 @@ package org.chorem.lima.ui.lettering; import org.apache.commons.lang3.time.DateUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.DateFilterImpl; import org.chorem.lima.beans.LetteringFilter; import org.chorem.lima.business.api.AccountService; @@ -41,6 +43,7 @@ import javax.swing.JComboBox; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -68,11 +71,16 @@ protected EntryBookService entryBookService; protected LetteringFilter filter; + + protected BigDecimal debit = BigDecimal.ZERO; + protected BigDecimal credit = BigDecimal.ZERO; + protected BigDecimal solde = BigDecimal.ZERO; + protected LettringSelectionModel lettringSelectionModel; protected LetteringEditModel editModel; + private static final Log log = LogFactory.getLog(LetteringViewHandler.class); public LetteringViewHandler(LetteringView view) { this.view = view; - financialPeriodService = LimaServiceFactory.getService(FinancialPeriodService.class); fiscalPeriodService = LimaServiceFactory.getService(FiscalPeriodService.class); accountService = LimaServiceFactory.getService(AccountService.class); @@ -85,17 +93,19 @@ */ public void init() { filter = view.getFilterModel(); + editModel = view.getEditModel(); + lettringSelectionModel = view.getLettringSelectionModel(); filter.setFiscalDateFilter(new DateFilterImpl()); - editModel=view.getEditModel(); loadComboAndRows(); filter.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { - editModel.resetDebitCreditBalance(); - view.getLettringAndUnlettringSelectionModel().clearSelection(); + onBalanceChanged(null); + view.getLettringSelectionModel().clearSelection(); updateAllEntries(); + onButtonModeChanged("all"); } }); @@ -105,21 +115,122 @@ @Override public void propertyChange(PropertyChangeEvent evt) { - editModel.resetDebitCreditBalance(); - view.getLettringAndUnlettringSelectionModel().clearSelection(); + onBalanceChanged(null); + view.getLettringSelectionModel().clearSelection(); updateAllEntries(); + onButtonModeChanged("all"); } }); editModel.addPropertyChangeListener(new PropertyChangeListener() { - @Override public void propertyChange(PropertyChangeEvent evt) { - updateBalanceAndLetteringButton(); + view.getCreditTextField().setText(editModel.getCredit().toString()); + view.getDebitTexttField().setText(editModel.getDebit().toString()); + view.getSoldeTextField().setText(editModel.getSolde().toString()); + view.getNoLettered().setEnabled(editModel.isUnLettred()); + view.getLettered().setEnabled(editModel.isLettred()); } }); } + public void balanceAndActions() { + if (!letteringNotExist(view.getTable().getSelectedRow())) { + //unlettred entries + onBalanceChanged(null); + setValuesForSelectedEntries(); + + //For U.I. buttons (Lettering and unlettering) + onButtonModeChanged("delettrer"); + } else { + //lettred entries + onBalanceChanged(null); + //treatment unuseful if no rows are selected + if (!view.getLettringSelectionModel().isSelectionEmpty()) { + setValuesForSelectedEntries(); + onButtonModeChanged("lettrer"); + } else { + onButtonModeChanged("all"); + } + } + } + + /**return true if lettering is null, or not null but empty + * @param row index of the line to test + * @return boolean + * */ + public boolean letteringNotExist(int row){ + boolean emptyOrNull = false; + if (row != -1) { + Entry entry = view.getTableModel().getEntryAt(row); + String lettering = entry.getLettering(); + emptyOrNull = (lettering==null||lettering.isEmpty()); + } + return emptyOrNull; + } + + public void onButtonModeChanged(String mode) { + if (mode.equals("delettrer")) { + editModel.setLettred(false); + editModel.setUnLettred(true); + } else if (mode.equals("lettrer")) { + if (log.isDebugEnabled()) { + log.debug("Lettred entry"); + } + editModel.setUnLettred(false); + editModel.setLettred(true); + }else { + editModel.setLettred(false); + editModel.setUnLettred(false); + } + } + + public void setValuesForSelectedEntries() { + Entry selectedEntry; + LetteringTableModel tableModel = view.getTableModel(); + for (int i = 0; i < tableModel.getRowCount(); i ++){ + if (view.getLettringSelectionModel().isSelectedIndex(i)){ + selectedEntry = tableModel.getEntryAt(i); + //Set values for calculation (By LetteringEditModel) of balance + onBalanceChanged(selectedEntry); + } + } + } + + public void onBalanceChanged(Entry balance) { + if (balance == null) { + editModel.setCredit(BigDecimal.ZERO); + editModel.setDebit(BigDecimal.ZERO); + editModel.setSolde(BigDecimal.ZERO, false); + } else { + balanceCalculation(balance.getAmount(), balance.getDebit()); + } + } + + /**Allow to add / subtract credit / debit and balance + * @param amount debit or credit + * @param debit it indicate if amount is debit or not + * */ + public void balanceCalculation(BigDecimal amount, boolean debit){ + + BigDecimal debitVal = debit ? amount : BigDecimal.ZERO; + BigDecimal creditVal = debit ? BigDecimal.ZERO : amount; + + if (debitVal == BigDecimal.ZERO){ + + if (creditVal != BigDecimal.ZERO){ + + editModel.setCredit(creditVal); + editModel.setSolde(creditVal, true); + } + }else if (creditVal == BigDecimal.ZERO){ + editModel.setDebit(debitVal); + editModel.setSolde(debitVal, false); + }else{ + onBalanceChanged(null); + } + } + public void loadComboAndRows(){ List<Account> allAccounts = accountService.getAllAccounts(); @@ -181,24 +292,10 @@ view.getTableModel().updateEntries(entries, datesEntree, journalEntrees); } - editModel.resetDebitCreditBalance(); - view.getLettringAndUnlettringSelectionModel().clearSelection(); + onBalanceChanged(null); + view.getLettringSelectionModel().clearSelection(); } - public void updateBalanceAndLetteringButton(){ - - view.creditTextField.setText(editModel.getCredit().toString()); - view.debitTexttField.setText(editModel.getDebit().toString()); - view.soldeTextField.setText(editModel.getSolde().toString()); - - view.lettered.setEnabled(editModel.isLettred()); - view.noLettered.setEnabled(editModel.isUnLettred()); - - //FIXME Allon-11/07/2012 : probleme de rafraichissement de la table, lors - //de la delegation de modele ('LetteringSelectionModele') - view.getTable().repaint(); - } - /** * Select previous value in combo box. * @@ -210,7 +307,7 @@ if (row > 0) { comboBox.setSelectedIndex(row - 1); } - view.getLettringAndUnlettringSelectionModel().clearSelection(); + view.getLettringSelectionModel().clearSelection(); } /** @@ -225,22 +322,25 @@ if (row < size - 1) { comboBox.setSelectedIndex(row + 1); } - view.getLettringAndUnlettringSelectionModel().clearSelection(); + view.getLettringSelectionModel().clearSelection(); } /**Add a group of three letters to n entries*/ public void addLetter() { String newLetters = financialTransactionService.getNextLetters(); + changeLetter(newLetters); editModel.setLettred(false); - editModel.resetDebitCreditBalance(); + editModel.setUnLettred(false); + onBalanceChanged(null); } /**Remove a group of three letters to n entries*/ public void removeLetter() { changeLetter(null); + editModel.setLettred(false); editModel.setUnLettred(false); - editModel.resetDebitCreditBalance(); + onBalanceChanged(null); } /**Add or remove a group of three letters to n entries*/ Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -1,176 +0,0 @@ -package org.chorem.lima.ui.lettering; -/* - * #%L - * Lima :: Swing - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.chorem.lima.entity.Entry; - -import javax.swing.ListSelectionModel; -import javax.swing.event.ListSelectionListener; - -/** - * @author sletellier <letellier@codelutin.com> - */ -public class LettringAndUnlettringSelectionModel implements ListSelectionModel { - - protected LetteringSelectionModel letteringSelectionModel; - protected UnlettringSelectionModel unlettringSelectionModel; - protected LetteringTableModel letteringTableModel; - protected LetteringEditModel editModel; - protected ListSelectionModel delegate; - protected Entry entry; - - public LettringAndUnlettringSelectionModel(LetteringSelectionModel letteringSelectionModel, - UnlettringSelectionModel unlettringSelectionModel, - LetteringTableModel letteringTableModel, LetteringEditModel letteringEditModel){ - this.letteringSelectionModel = letteringSelectionModel; - this.unlettringSelectionModel = unlettringSelectionModel; - this.letteringTableModel = letteringTableModel; - this.editModel = letteringEditModel; - delegate = unlettringSelectionModel; - } - - /**choice of model : two differents ui reactions, if lettering is present or not - * @param row index of the selected line - * @param column index of the selected column - * */ - @Override - public void setSelectionInterval(int row, int column) { - if (!letteringNotExist(row)) { - delegate = letteringSelectionModel; - clearSelection(); - } - else { - delegate = unlettringSelectionModel; - } - delegate.setSelectionInterval(row, column); - } - - /**return true if lettering is null, or not null but empty - * @param row index of the line to test - * @return boolean - * */ - public boolean letteringNotExist(int row){ - boolean emptyOrNull; - entry = letteringTableModel.getEntryAt(row); - String lettering = entry.getLettering(); - emptyOrNull = (lettering==null||lettering.isEmpty()); - return emptyOrNull; - } - - @Override - public void addSelectionInterval(int index0, int index1) { - delegate.addSelectionInterval(index0, index1); - } - - @Override - public void removeSelectionInterval(int index0, int index1) { - delegate.removeSelectionInterval(index0, index1); - } - - @Override - public int getMinSelectionIndex() { - return delegate.getMinSelectionIndex(); - } - - @Override - public int getMaxSelectionIndex() { - return delegate.getMaxSelectionIndex(); - } - - @Override - public boolean isSelectedIndex(int index) { - return delegate.isSelectedIndex(index); - } - - @Override - public int getAnchorSelectionIndex() { - return delegate.getAnchorSelectionIndex(); - } - - @Override - public void setAnchorSelectionIndex(int index) { - delegate.setAnchorSelectionIndex(index); - } - - @Override - public int getLeadSelectionIndex() { - return delegate.getLeadSelectionIndex(); - } - - @Override - public void setLeadSelectionIndex(int index) { - delegate.setLeadSelectionIndex(index); - } - - @Override - public void clearSelection() { - delegate.clearSelection(); - } - - @Override - public boolean isSelectionEmpty() { - return delegate.isSelectionEmpty(); - } - - @Override - public void insertIndexInterval(int index, int length, boolean before) { - delegate.insertIndexInterval(index, length, before); - } - - @Override - public void removeIndexInterval(int index0, int index1) { - delegate.removeIndexInterval(index0, index1); - } - - @Override - public void setValueIsAdjusting(boolean valueIsAdjusting) { - delegate.setValueIsAdjusting(valueIsAdjusting); - } - - @Override - public boolean getValueIsAdjusting() { - return delegate.getValueIsAdjusting(); - } - - @Override - public void setSelectionMode(int selectionMode) { - delegate.setSelectionMode(selectionMode); - } - - @Override - public int getSelectionMode() { - return delegate.getSelectionMode(); - } - - @Override - public void addListSelectionListener(ListSelectionListener x) { - delegate.addListSelectionListener(x); - } - - @Override - public void removeListSelectionListener(ListSelectionListener x) { - delegate.removeListSelectionListener(x); - } - -} Copied: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java (from rev 3538, trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringAndUnlettringSelectionModel.java) =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LettringSelectionModel.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -0,0 +1,146 @@ +package org.chorem.lima.ui.lettering; +/* + * #%L + * Lima :: Swing + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.apache.commons.lang3.StringUtils; +import org.chorem.lima.entity.Entry; + +import javax.swing.DefaultListSelectionModel; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.List; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class LettringSelectionModel extends DefaultListSelectionModel{ + + protected LetteringTableModel letteringTableModel; + protected Entry entry; + protected int lineSelected; + protected boolean letteringEntrySelected; + protected final PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + public LettringSelectionModel(LetteringTableModel letteringTableModel){ + this.letteringTableModel = letteringTableModel; + } + + @Override + public void addSelectionInterval(int row, int column) { + setSelectionInterval(row, column); + } + + @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.getIndexOfEntry(entry); + super.addSelectionInterval(entryToSelect, entryToSelect); + } + } + } + } + letteringEntrySelected = true; + } + else { + + //unlettred entries + //To clear the selection when it changes from lettered entry to unlettered + if (letteringEntrySelected) { + clearSelection(); + } + + if (isSelectionEmpty() || !isSelectedIndex(row)){ + super.addSelectionInterval(row, column); + }else { + super.removeSelectionInterval(row, column); + } + + letteringEntrySelected = false; + } + } + + /**return true if lettering is null, or not null but empty + * @param row index of the line to test + * @return boolean + * */ + public boolean letteringNotExist(int row){ + boolean emptyOrNull; + entry = letteringTableModel.getEntryAt(row); + String lettering = entry.getLettering(); + emptyOrNull = (lettering==null||lettering.isEmpty()); + return emptyOrNull; + } + + public List<Entry> getEntries(){ + return letteringTableModel.getEntries(); + } + + public String getCurrentLettring(){ + return getCurrentEntrySelected().getLettering(); + } + + public Entry getCurrentEntrySelected(){ + return letteringTableModel.getEntryAt(lineSelected); + } + + @Override + public int getSelectionMode() { + return MULTIPLE_INTERVAL_SELECTION; + } + + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.removePropertyChangeListener(propertyName, listener); + } + + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); + } + + protected void firePropertyChange(String propertyName, Object newValue) { + firePropertyChange(propertyName, null, newValue); + } +} Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/UnlettringSelectionModel.java 2012-07-19 16:07:36 UTC (rev 3540) @@ -1,103 +0,0 @@ -package org.chorem.lima.ui.lettering; -/* - * #%L - * Lima :: Swing - * $Id:$ - * $HeadURL:$ - * %% - * Copyright (C) 2012 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -import org.chorem.lima.entity.Entry; - -import javax.swing.DefaultListSelectionModel; - -public class UnlettringSelectionModel extends DefaultListSelectionModel { - - protected LetteringTableModel letteringTableModel; - protected LetteringEditModel editModel; - - /**Table selection model when entry selected is no lettered - * @param letteringTableModel model of the table - * @param editModel model managing update of debit / credit / balance - * */ - public UnlettringSelectionModel(LetteringTableModel letteringTableModel, LetteringEditModel editModel) { - this.letteringTableModel = letteringTableModel; - this.editModel = editModel; - editModel.resetDebitCreditBalance(); - } - - @Override - public void addSelectionInterval(int row, int column){ - setSelectionInterval(row, column); - } - - @Override - public void removeSelectionInterval(int row, int column){ - super.removeSelectionInterval(row, column); - updateBalanceAndLetteringButton(true); - } - - @Override - public void setSelectionInterval(int row, int column){ - - //Case where line is selected a second time (So, must deselect it on second click) - if (isSelectionEmpty() || !isSelectedIndex(row)){ - super.addSelectionInterval(row, column); - }else { - super.removeSelectionInterval(row, column); - } - updateBalanceAndLetteringButton(true); - } - - /**PropertyChange on editModel in the handler, and, there, - * set values it. - * @param lettering state of attributes lettered and unlettered in editModel - * */ - public void updateBalanceAndLetteringButton(boolean lettering){ - editModel.resetDebitCreditBalance(); - - //treatment unuseful if no rows are selected - if (!isSelectionEmpty()){ - Entry selectedEntry; - for (int i = 0; i < letteringTableModel.getRowCount(); i ++){ - if (isSelectedIndex(i)){ - selectedEntry = letteringTableModel.getEntryAt(i); - //Set values for calculation (By LetteringEditModel) of balance - editModel.balanceCalculation(selectedEntry.getAmount(), selectedEntry.getDebit()); - } - } - //For U.I. buttons (Lettering and unlettering) - editModel.setUnLettred(!lettering); - editModel.setLettred(lettering); - }else{ - editModel.setLettred(!lettering); - } - } - - /**to reinitialize model attribute*/ - /*public void resetAttribute(){ - clearSelection(); - }*/ - - @Override - public int getSelectionMode() { - return MULTIPLE_INTERVAL_SELECTION; - } - -} 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-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2012-07-19 16:07:36 UTC (rev 3540) @@ -75,11 +75,11 @@ lima.config.data.dir.description= lima.config.decimalseparator.description= lima.config.host.adress=Host adress -lima.config.state.file=State file of LIMA lima.config.i18n.dir.description= lima.config.locale.description=Localization used by LIMA lima.config.resources.dir.description= lima.config.scale.description= +lima.config.state.file=State file of LIMA lima.config.ui.flaunchui.description= lima.config.ui.fullscreen.description=FullScreen lima.documents=Documents… 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-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2012-07-19 16:07:36 UTC (rev 3540) @@ -75,11 +75,11 @@ lima.config.data.dir.description= lima.config.decimalseparator.description= lima.config.host.adress=Adresse du serveur distant -lima.config.state.file=Fichier d'état de l'application lima.config.i18n.dir.description= lima.config.locale.description=Locale utilisée par l'application lima.config.resources.dir.description= lima.config.scale.description= +lima.config.state.file=Fichier d'état de l'application lima.config.ui.flaunchui.description= lima.config.ui.fullscreen.description=Plein écran lima.documents=Documents… Modified: trunk/lima-swing/src/main/resources/log4j.properties =================================================================== --- trunk/lima-swing/src/main/resources/log4j.properties 2012-07-18 13:44:26 UTC (rev 3539) +++ trunk/lima-swing/src/main/resources/log4j.properties 2012-07-19 16:07:36 UTC (rev 3540) @@ -39,3 +39,6 @@ # package level log4j.logger.org.chorem.lima=INFO log4j.logger.org.chorem.lima.ui.financialtransaction.FinancialTransactionTable=DEBUG +log4j.logger.org.chorem.lima.ui.lettering.LetteringViewHandler=DEBUG +log4j.logger.org.chorem.lima.ui.lettering.LettringSelectionModel=DEBUG +log4j.logger.org.chorem.lima.ui.lettering.LetteringEditModel=DEBUG
participants (1)
-
mallon@users.chorem.org