Author: echatellier Date: 2010-04-09 18:12:23 +0200 (Fri, 09 Apr 2010) New Revision: 2841 Log: Migration of transaction and lettering UI. Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java Removed: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringViewImpl.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/CriteriaWidgetImpl.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/SearchTransactionView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/CriteriaWidgetImpl.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/CriteriaWidgetImpl.java 2010-04-09 16:10:45 UTC (rev 2840) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/CriteriaWidgetImpl.java 2010-04-09 16:12:23 UTC (rev 2841) @@ -23,13 +23,13 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaContext; import static org.nuiton.i18n.I18n._; -import org.chorem.lima.combobox.JWideComboBox; -import org.chorem.lima.combobox.model.AccountComboBoxModel; import org.chorem.lima.combobox.renderer.AccountComboBoxRenderer; import org.chorem.lima.dto.AccountDTO; import org.chorem.lima.item.Item; import org.chorem.lima.service.util.ServiceHelper; -import org.chorem.lima.util.AccountToStringConverter; +import org.chorem.lima.ui.transaction.autocomplete.AccountToStringConverter; +import org.chorem.lima.ui.transaction.model.AccountComboBoxModel; +import org.chorem.lima.widgets.JWideComboBox; import org.jdesktop.swingx.JXDatePicker; import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringView.jaxx 2010-04-09 16:10:45 UTC (rev 2840) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringView.jaxx 2010-04-09 16:12:23 UTC (rev 2841) @@ -15,95 +15,86 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ##% --> -<Table insets='0,0,0,0' fill="both"> +<Table fill="both"> <script> - protected void addLettering() {}; - protected void removeLettering() {}; - protected void precedentAccount() {}; - protected void nextAccount() {}; + <![CDATA[ + import org.chorem.lima.entity.Account; + import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; + import org.jdesktop.swingx.autocomplete.ObjectToStringConverter; + + // Swingx auto complete (for account) : + AutoCompleteDecorator.decorate(accountComboBox, new ObjectToStringConverter() { + @Override + public String getPreferredStringForItem(Object item) { + if (item == null) { + return ""; + } + Account account = (Account) item; + return account.getAccountNumber() + " : " + account.getLabel(); + } + }); + + protected void addLettering() { + // never been implemented :( + }; + protected void removeLettering() { + // never been implemented :( + }; + ]]> </script> - <row weightx="1" weighty="0"> + <row> <cell> - <!-- account --> - <Table insets='0,0,0,0'> - <row weightx="0" weighty="0"> - <cell anchor='center' weightx="0" weighty="0"> - <!-- precedent --> - <JButton id="precedentButton" - preferredSize='{new Dimension(24,24)}' - verticalAlignment='0' - verticalTextPosition='0' - opaque='true' - borderPainted='false' - focusPainted='false' - enabled='true' - horizontalTextPosition='0' - onActionPerformed='precedentAccount()' - /> - </cell> - <cell anchor='center' weightx="0" weighty="0"> - <!-- next --> - <JButton id="nextButton" - preferredSize='{new Dimension(24,24)}' - verticalAlignment='0' - verticalTextPosition='0' - opaque='true' - borderPainted='false' - focusPainted='false' - enabled='true' - horizontalTextPosition='0' - onActionPerformed='nextAccount()' - /> - </cell> - </row> + <Table> <!-- account --> - <row fill="horizontal" weightx="1" weighty="0" anchor="center"> + <row fill="horizontal" weightx="1" anchor="center"> <cell anchor="east"> <JLabel text="lima.account"/> </cell> - <cell weightx="0" weighty="0"> - <JPanel id="accountPanel"/> + <cell> + <org.chorem.lima.widgets.JWideComboBox id="accountComboBox" + model="{new org.chorem.lima.ui.transaction.model.AccountComboBoxModel()}" /> </cell> </row> - <!-- since --> - <row fill="horizontal" weightx="1" weighty="0" anchor="center"> + <!-- from --> + <row fill="horizontal" weightx="1" anchor="center"> <cell anchor="east"> - <JLabel text="lima.since"/> + <JLabel text="lima.lettering.from"/> </cell> <cell> - <JPanel id="sincePanel"/> + <org.chorem.lima.widgets.JWideComboBox id="fromPeriodComoboBox" /> </cell> </row> <!-- to --> - <row fill="horizontal" weightx="1" weighty="0" anchor="center"> + <row fill="horizontal" weightx="1" anchor="center"> <cell anchor="east"> - <JLabel text="lima.to"/> + <JLabel text="lima.lettering.to"/> </cell> <cell> - <JPanel id="toPanel"/> + <org.chorem.lima.widgets.JWideComboBox id="toPeriodComoboBox" /> </cell> </row> </Table> </cell> <cell> <!-- entries --> - <Table insets='0,0,0,0' fill="both"> + <Table fill="both"> <row columns="3"> <cell> - <JLabel text="lima.entries"/> + <JLabel text="lima.lettering.entries"/> </cell> </row> <row> <cell> - <JRadioButton buttonGroup='entryButtons' text='lima.lettered' value='{_("lima.lettered")}' - selected='true'/> + <JRadioButton buttonGroup='entryButtons' text='lima.lettering.lettered' + value='{_("lima.lettering.lettered")}' selected='true'/> </cell> <cell> - <JRadioButton buttonGroup='entryButtons' text='lima.not.lettered' - value='{_("lima.not.lettered")}'/> + <JRadioButton buttonGroup='entryButtons' text='lima.lettering.notlettered' + value='{_("lima.lettering.notlettered")}'/> </cell> <cell> - <JRadioButton buttonGroup='entryButtons' text='lima.all' value='{_("lima.all")}'/> + <JRadioButton buttonGroup='entryButtons' text='lima.lettering.letteredall' + value='{_("lima.lettering.letteredall")}'/> </cell> </row> </Table> @@ -111,18 +102,21 @@ </row> <row columns="2" weightx="1" weighty="1" anchor="center" fill="both"> <cell> - <!-- table --> - <JScrollPane id="tablePanel"/> + <JScrollPane> + <org.jdesktop.swingx.JXTable id="letteringTable" /> + </JScrollPane> </cell> </row> <row> <cell> <!-- add lettering --> - <JButton id="addButton" text="lima.add.lettering" onActionPerformed="addLettering()"/> + <JButton id="addButton" text="lima.lettering.add" + onActionPerformed="addLettering()"/> </cell> <cell> <!-- remove lettering --> - <JButton id="removeButton" text="lima.remove.lettering" onActionPerformed="removeLettering()"/> + <JButton id="removeButton" text="lima.lettering.remove" + onActionPerformed="removeLettering()"/> </cell> </row> </Table> \ No newline at end of file Deleted: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringViewImpl.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringViewImpl.java 2010-04-09 16:10:45 UTC (rev 2840) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/LetteringViewImpl.java 2010-04-09 16:12:23 UTC (rev 2841) @@ -1,127 +0,0 @@ -/** - * *##% Lima Main - * Copyright (C) 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* - */ - -package org.chorem.lima.ui.transaction; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.chorem.lima.LimaContext; -import org.chorem.lima.combobox.JWideComboBox; -import org.chorem.lima.combobox.model.AccountComboBoxModel; -import org.chorem.lima.combobox.renderer.AccountComboBoxRenderer; -import org.chorem.lima.combobox.renderer.PeriodComboBoxRenderer; -import org.chorem.lima.dto.AccountDTO; -import org.chorem.lima.dto.PeriodDTO; -import org.chorem.lima.service.util.ServiceHelper; -import org.chorem.lima.util.AccountToStringConverter; -import org.nuiton.util.Resource; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; - -import javax.swing.*; -import java.awt.*; -import java.util.List; -import java.util.Vector; - -import jaxx.runtime.JAXXContext; - -/** - * @author ore - */ -public class LetteringViewImpl extends LetteringView { - - - - /** - * log - */ - private static final Log log = LogFactory.getLog(LetteringViewImpl.class); - private final JWideComboBox accountComboBox; - - /** - * @param parentContext - */ - public LetteringViewImpl(JAXXContext parentContext) { - super(parentContext); - - /** Calling services */ - List<AccountDTO> accounts = ServiceHelper.getAllFlatAccount( - LimaContext.getContext().getDataManager().getAccountModel().getData()); - /** Creating accounting model */ - Vector<AccountDTO> v1 = new Vector<AccountDTO>(accounts); - AccountComboBoxModel model = new AccountComboBoxModel(v1); - accountComboBox = new JWideComboBox(); - accountComboBox.setPreferredSize(new Dimension(200, 25)); - accountComboBox.setModel(model); - LimaContext.getContext().getDataManager().getAccountModel().addPropertyChangeListener(model); - accountComboBox.setRenderer(AccountComboBoxRenderer.getInstance()); - accountPanel.add(accountComboBox); - - /** AutoCompletion */ - AutoCompleteDecorator.decorate(accountComboBox, AccountToStringConverter.getInstance()); - - Icon forwardIcon = Resource.getIcon("toolbarButtonGraphics/navigation/Forward24.gif"); - Icon backIcon = Resource.getIcon("toolbarButtonGraphics/navigation/Back24.gif"); - nextButton.setIcon(forwardIcon); - precedentButton.setIcon(backIcon); - - /** Creating period model */ - List<PeriodDTO> periodes = LimaContext.getContext().getNeogiaFactory().getPeriodService().getAllPeriod( - LimaContext.getContext().getNeogiaFactory().getStatusService().getAllStatus() - ); - Vector<PeriodDTO> v2 = new Vector<PeriodDTO>(); - for (PeriodDTO period : periodes) { - v2.addElement(period); - v2.addAll(period.getChildren()); - } - JWideComboBox sinceComboBox = new JWideComboBox(v2); - sinceComboBox.setRenderer(PeriodComboBoxRenderer.getInstance()); - sinceComboBox.setPreferredSize(new Dimension(200, 25)); - sincePanel.add(sinceComboBox); - - JWideComboBox toComboBox = new JWideComboBox(v2); - toComboBox.setRenderer(PeriodComboBoxRenderer.getInstance()); - toComboBox.setPreferredSize(new Dimension(200, 25)); - toPanel.add(toComboBox); - - JXTable table = new JXTable(); - tablePanel.setViewportView(table); - } - - /** - * - */ - @Override - protected void nextAccount() { - if (!(accountComboBox.getSelectedIndex() == accountComboBox.getModel().getSize() - 1)) { - accountComboBox.setSelectedIndex(accountComboBox.getSelectedIndex() + 1); - } - - } - - /** - * - */ - @Override - protected void precedentAccount() { - if (!(accountComboBox.getSelectedIndex() == 0)) { - accountComboBox.setSelectedIndex(accountComboBox.getSelectedIndex() - 1); - } - } -} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/SearchTransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/SearchTransactionView.jaxx 2010-04-09 16:10:45 UTC (rev 2840) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/SearchTransactionView.jaxx 2010-04-09 16:12:23 UTC (rev 2841) @@ -28,7 +28,7 @@ <Table fill="horizontal" insets='5,5,5,5' anchor="north" weighty="1" weightx="1"> <row> <cell> - <JButton id="addButton" text="lima.add" width="100" onActionPerformed="addCriteriaWidget()"/> + <JButton id="addButton" text="lima.common.add" width="100" onActionPerformed="addCriteriaWidget()"/> </cell> <cell> <JLabel text="lima.search.items.where" width="200"/> @@ -49,10 +49,10 @@ </row> <row> <cell> - <JButton id="okButton" onActionPerformed="doSearch()" text="lima.ok"/> + <JButton id="okButton" onActionPerformed="doSearch()" text="lima.common.ok"/> </cell> <cell> - <JButton id="cancelButton" text="lima.cancel" onActionPerformed="windowClosing()"/> + <JButton id="cancelButton" text="lima.common.cancel" onActionPerformed="windowClosing()"/> </cell> </row> </Table> Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java 2010-04-09 16:12:23 UTC (rev 2841) @@ -0,0 +1,79 @@ +/* *##% Lima Main + * Copyright (C) 2008 - 2010 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* + */ + +package org.chorem.lima.ui.transaction; + +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.Transaction; + +/** + * TODO add comment here. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class TransactionHelper { + + /** + * Get total credit for a transaction. + * + * @param transaction transaction to get credit + * @return total credit + */ + public static double getCredit(Transaction transaction) { + double credit = 0; + for (Entry entry : transaction.getEntry()) { + // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) + if (!entry.getDebit()) { + credit += entry.getAmount(); + } + } + return credit; + } + + /** + * Get total debit for a transaction. + * + * @param transaction transaction to get debit + * @return total debit + */ + public static double getDebit(Transaction transaction) { + double debit = 0; + for (Entry entry : transaction.getEntry()) { + // TODO EC-20100407 voir si le modele correspond (amount, credit,debit) + if (entry.getDebit()) { + debit += entry.getAmount(); + } + } + return debit; + } + + /** + * Return true if transaction is balanced (credit == debit). + * + * @param transaction transaction to test + * @return {@code true} if transaction is balanced + */ + public static boolean isBalanced(Transaction transaction) { + boolean balanced = getDebit(transaction) == getCredit(transaction); + return balanced; + } +} Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx 2010-04-09 16:10:45 UTC (rev 2840) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionView.jaxx 2010-04-09 16:12:23 UTC (rev 2841) @@ -16,11 +16,15 @@ ##% --> <Table> + <TransactionViewHandler id="handler" javaBean="new TransactionViewHandler(this)" /> + <Boolean id="selectedRow" javaBean="false" /> + <script> <![CDATA[ ]]> </script> + <!-- <JPopupMenu id="MenuRightPanel"> <JMenuItem text="lima.add.transaction" onActionPerformed='addEmptyTransaction()'/> <JMenuItem text="lima.print"/> @@ -29,7 +33,7 @@ <JMenuItem text="lima.add" onActionPerformed='addEmptyTransaction()'/> <JMenuItem text="lima.print"/> </JPopupMenu> --> - <row fill="horizontal" weightx="0.75" weighty="0" anchor="center"> + <row fill="horizontal" weightx="1" weighty="0" anchor="center"> <cell> <JLabel id="entryBookLabel" text="lima.transaction.entrybook"/> </cell> @@ -46,26 +50,34 @@ </cell> </row> <row> - <cell fill="both" weightx="1" weighty="1" rows='3' columns='4'> + <cell fill="both" weightx="1" weighty="1" rows="3" columns="4"> <JScrollPane> + <org.chorem.lima.ui.transaction.table.TransactionTableModel + id="transactionTableModel" /> <org.chorem.lima.ui.transaction.table.TransactionTable - id="transactionsTable" sortable="false" rowHeight="22" + id="transactionTable" sortable="false" rowHeight="22" + constructorParams="getHandler()" model="{getTransactionTableModel()}" selectionMode="{ListSelectionModel.SINGLE_SELECTION}" - highlighters="{HighlighterFactory.createAlternateStriping(Color.WHITE,new Color(250,250,250))}" /> + highlighters="{org.jdesktop.swingx.decorator.HighlighterFactory.createAlternateStriping(Color.WHITE,new Color(250,250,250))}" /> + <javax.swing.ListSelectionModel javaBean="getTransactionTable().getSelectionModel()" + onValueChanged="setSelectedRow(transactionTable.getSelectedRow() != -1)"/> </JScrollPane> </cell> <cell> - <JButton id="addButton" text="lima.add.transaction" onActionPerformed="addEmptyTransaction()" width="150"/> + <JButton text="lima.add.transaction" + onActionPerformed="getHandler().addEmptyTransaction()"/> </cell> </row> <row> <cell> - <JButton id="removeButton" text="lima.remove.transaction" onActionPerformed="removeTransaction()" width="150"/> + <JButton text="lima.remove.transaction" + onActionPerformed="getHandler().removeTransaction()" + enabled="{isSelectedRow()}"/> </cell> </row> <row> <cell> - <JButton text="lima.add.entry" onActionPerformed="addEmptyEntry()" width="150"/> + <JButton text="lima.add.entry" onActionPerformed="getHandler().addEmptyEntry()"/> </cell> </row> </Table> \ No newline at end of file Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java 2010-04-09 16:12:23 UTC (rev 2841) @@ -0,0 +1,112 @@ +/* *##% Lima Swing + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * ##%*/ + +package org.chorem.lima.ui.transaction; + +import static org.nuiton.i18n.I18n._; + +import javax.swing.JOptionPane; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.lima.entity.Entry; +import org.chorem.lima.entity.Transaction; +import org.chorem.lima.table.model.TransactionTableModel; +import org.chorem.lima.ui.transaction.table.TransactionTable; + +/** + * Handler associated with account view. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class TransactionViewHandler { + + /** log. */ + private static final Log log = LogFactory.getLog(TransactionViewHandler.class); + + protected TransactionView view; + + protected TransactionViewHandler(TransactionView view) { + this.view = view; + } + + public void addEmptyTransaction() { + + } + + public void removeTransaction() { + + } + + public void addEmptyEntry() { + + } + + /** + * Delete selected row in table (could be transaction or entry). + * + * Called by model. + */ + public void deleteSelectedRow() { + + TransactionTable table = (TransactionTable)view.getTransactionTable(); + TransactionTableModel model = table.getModel(); + + int indexSelectedRow = table.getSelectedRow(); + if (indexSelectedRow != -1) { + + Object selectedValue = model.getElementAt(indexSelectedRow); + + String message = null; + if (selectedValue instanceof Transaction) { + message = _("lima.question.remove.transaction"); + } + else { + message = _("lima.question.remove.entry"); + } + + int response = JOptionPane.showConfirmDialog(view, message, + _("lima.transaction.confirmdelete"), JOptionPane.YES_NO_OPTION); + + if (response == JOptionPane.YES_OPTION) { + + if (selectedValue instanceof Transaction) { + // TODO EC-20100409 implements this + if (log.isWarnEnabled()) { + log.warn("TODO implement Transaction deletion"); + } + } + else if (selectedValue instanceof Entry) { + // TODO EC-20100409 implements this + if (log.isWarnEnabled()) { + log.warn("TODO implement Entry deletion"); + } + } + } + } + else { + if (log.isWarnEnabled()) { + log.warn("Call delete selected row without selection"); + } + } + } +} Property changes on: trunk/lima-swing/src/main/java/org/chorem/lima/ui/transaction/TransactionViewHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL