r3728 - in trunk/lima-swing/src/main: java/org/chorem/lima/ui/common java/org/chorem/lima/ui/financialperiod java/org/chorem/lima/ui/fiscalperiod resources/i18n resources/icons
Author: sbavencoff Date: 2014-01-02 11:35:55 +0100 (Thu, 02 Jan 2014) New Revision: 3728 Url: http://chorem.org/projects/lima/repository/revisions/3728 Log: refactor financial period Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodRenderer.java trunk/lima-swing/src/main/resources/icons/action-financialPeriod-close.png Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTable.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/common/AbstractLimaTableModel.java 2014-01-02 10:35:55 UTC (rev 3728) @@ -50,6 +50,11 @@ sort(); fireTableDataChanged(); } + + public void setValue(int row, E value) { + values.set(row, value); + fireTableRowsUpdated(row, row); + } public void addValue(E value) { int row = values.size(); Added: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodRenderer.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodRenderer.java (rev 0) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodRenderer.java 2014-01-02 10:35:55 UTC (rev 3728) @@ -0,0 +1,29 @@ +package org.chorem.lima.ui.financialperiod; + +import org.chorem.lima.entity.ClosedPeriodicEntryBook; +import org.chorem.lima.ui.common.LineRenderer; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Sylvain Bavencoff <bavencoff@codelutin.com> + */ +public class FinancialPeriodRenderer extends LineRenderer { + + @Override + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + + Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + + if (table.getModel() instanceof FinancialPeriodTableModel) { + FinancialPeriodTableModel model = (FinancialPeriodTableModel) table.getModel(); + ClosedPeriodicEntryBook closedPeriodicEntryBook = model.get(row); + if (!isSelected && closedPeriodicEntryBook.getLocked()) { + component.setForeground(new Color(222, 0, 0)); + } + } + return component; + } + +} Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTable.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTable.java 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTable.java 2014-01-02 10:35:55 UTC (rev 3728) @@ -25,21 +25,8 @@ package org.chorem.lima.ui.financialperiod; -import java.awt.Color; -import java.awt.Component; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import org.chorem.lima.ui.common.AbstractLimaTable; -import org.chorem.lima.entity.ClosedPeriodicEntryBook; -import org.jdesktop.swingx.JXTable; -import org.jdesktop.swingx.decorator.ColorHighlighter; -import org.jdesktop.swingx.decorator.ComponentAdapter; -import org.jdesktop.swingx.decorator.HighlightPredicate; -import org.jdesktop.swingx.decorator.Highlighter; -import org.jdesktop.swingx.decorator.HighlighterFactory; - /** * Financial period table adding color hidhlighter and key management. * @@ -49,101 +36,21 @@ * Last update : $Date$ * By : $Author$ */ -public class FinancialPeriodTable extends JXTable implements KeyListener, MouseListener { +public class FinancialPeriodTable extends AbstractLimaTable<FinancialPeriodViewHandler> { /** serialVersionUID. */ private static final long serialVersionUID = -1960326844433064178L; - protected FinancialPeriodViewHandler handler; - - protected FinancialPeriodTableModel model; - /** * Constructor, install highlighter. * * @param handler */ public FinancialPeriodTable(FinancialPeriodViewHandler handler) { - this.handler = handler; - model = handler.view.getFinancialPeriodTableModel(); + super(handler); - addKeyListener(this); - addMouseListener(this); + lineRenderer = new FinancialPeriodRenderer(); - //highlight financial financial transactions - addStripingColor(); - addBlockColor(); } - /** - * Color the background row in grey if the month number is even (pair in french) - */ - protected void addStripingColor() { - Highlighter colorTransaction = HighlighterFactory.createSimpleStriping(new Color(233,233,233)); - addHighlighter(colorTransaction); - } - - /** - * Color the font in red if period are closed - */ - protected void addBlockColor() { - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - ClosedPeriodicEntryBook closedPeriodicEntryBook = - (ClosedPeriodicEntryBook) model.getElementAt(adapter.row); - return closedPeriodicEntryBook.getLocked(); - } - }; - Highlighter colorTransaction = - new ColorHighlighter(predicate, null, new Color(222, 0, 0)); - addHighlighter(colorTransaction); - } - - @Override - public void mouseClicked(MouseEvent e) { - } - - @Override - public void mousePressed(MouseEvent e) { - if (rowAtPoint(e.getPoint()) == -1) { - clearSelection(); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - } - - @Override - public void mouseEntered(MouseEvent e) { - } - - @Override - public void mouseExited(MouseEvent e) { - } - - @Override - public void keyTyped(KeyEvent e) { - } - - /** - * for each action combination key are think - * for extend keyboard and laptop keyboard - */ - @Override - public void keyPressed(KeyEvent e) { - // clear row selection with the key: escape - if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - if (!isEditing()) { - clearSelection(); - } - } - } - - @Override - public void keyReleased(KeyEvent e) { - } - } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodTableModel.java 2014-01-02 10:35:55 UTC (rev 3728) @@ -25,18 +25,16 @@ package org.chorem.lima.ui.financialperiod; -import static org.nuiton.i18n.I18n._; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.List; - -import javax.swing.table.AbstractTableModel; - import org.chorem.lima.entity.ClosedPeriodicEntryBook; import org.chorem.lima.entity.EntryBook; import org.chorem.lima.entity.FinancialPeriod; +import org.chorem.lima.ui.common.AbstractColumn; +import org.chorem.lima.ui.common.AbstractLimaTableModel; +import java.util.Date; + +import static org.nuiton.i18n.I18n._; + /** * Financial period table model. * @@ -46,110 +44,53 @@ * Last update : $Date$ * By : $Author$ */ -public class FinancialPeriodTableModel extends AbstractTableModel { +public class FinancialPeriodTableModel extends AbstractLimaTableModel<ClosedPeriodicEntryBook> { /** serialVersionUID. */ private static final long serialVersionUID = 77027335135838258L; - /** Datas cache */ - protected List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks; - - public FinancialPeriodTableModel() { - - } - - /** - * Update model data list. - * - * @param closedPeriodicEntryBooks new data - */ - public void setClosedPeriodicEntryBooks(List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks) { - this.closedPeriodicEntryBooks = closedPeriodicEntryBooks; - fireTableDataChanged(); - } - @Override - public int getRowCount() { - int result = 0; - if (closedPeriodicEntryBooks != null) { - result = closedPeriodicEntryBooks.size(); - } - return result; - } + protected void initColumn() { - @Override - public int getColumnCount() { - return 3; - } + addColumn(new AbstractColumn<FinancialPeriodTableModel>(Date.class, _("lima.ui.financialperiod.begin"), false) { + @Override + public Object getValueAt(int row) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = tableModel.get(row); + FinancialPeriod financialPeriod = closedPeriodicEntryBook.getFinancialPeriod(); + return financialPeriod.getBeginDate(); + } + }); - @Override - public String getColumnName(int columnIndex) { + addColumn(new AbstractColumn<FinancialPeriodTableModel>(Date.class, _("lima.ui.financialperiod.end"), false) { + @Override + public Object getValueAt(int row) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = tableModel.get(row); + FinancialPeriod financialPeriod = closedPeriodicEntryBook.getFinancialPeriod(); + return financialPeriod.getEndDate(); + } + }); - String result = "n/a"; + addColumn(new AbstractColumn<FinancialPeriodTableModel>(EntryBook.class, _("lima.ui.financialperiod.entrybook"), false) { + @Override + public Object getValueAt(int row) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = tableModel.get(row); + return closedPeriodicEntryBook.getEntryBook(); + } + }); - switch (columnIndex) { - case 0: - result = _("lima.ui.financialperiod.period"); - break; - case 1: - result = _("lima.ui.financialperiod.entrybook"); - break; - case 2: - result = _("lima.ui.financialperiod.closure"); - break; - } - - return result; - } - - @Override - public Class<?> getColumnClass(int columnIndex) { - // both String - return String.class; - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - return false; - } - - public ClosedPeriodicEntryBook getElementAt(int row) { - ClosedPeriodicEntryBook currentRow = closedPeriodicEntryBooks.get(row); - return currentRow; - } - - public void setElementAt(int row, ClosedPeriodicEntryBook closedPeriodicEntryBook) { - closedPeriodicEntryBooks.set(row, closedPeriodicEntryBook); - fireTableRowsUpdated(row, row); - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - Object result = null; - - ClosedPeriodicEntryBook closedPeriodicEntryBook = getElementAt(rowIndex); - - switch (columnIndex) { - case 0: - // FIXME echatellier 20120413 remove hardcoded french date format - DateFormat df = new SimpleDateFormat("dd MMM yyyy"); - FinancialPeriod financialPeriod = closedPeriodicEntryBook.getFinancialPeriod(); - result = df.format(financialPeriod.getBeginDate()) - + " - " + df.format(financialPeriod.getEndDate()); - break; - case 1: - EntryBook entryBook = closedPeriodicEntryBook.getEntryBook(); - result = entryBook.getCode() + " - " + entryBook.getLabel(); - break; - case 2: + addColumn(new AbstractColumn<FinancialPeriodTableModel>(String.class, _("lima.ui.financialperiod.status"), false) { + @Override + public Object getValueAt(int row) { + ClosedPeriodicEntryBook closedPeriodicEntryBook = tableModel.get(row); + String status = _("lima.common.open"); if (closedPeriodicEntryBook.getLocked()) { - result = _("lima.common.closed"); - } else { - result = _("lima.common.open"); + status = _("lima.common.closed"); } - break; - } + return status; + } + }); - return result; + } + } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodView.jaxx 2014-01-02 10:35:55 UTC (rev 3728) @@ -30,6 +30,7 @@ org.chorem.lima.entity.FinancialPeriod org.chorem.lima.ui.financialperiod.FinancialPeriodTable org.chorem.lima.ui.financialperiod.FinancialPeriodTableModel + static org.nuiton.i18n.I18n._ </import> <FinancialPeriodViewHandler id="handler" constructorParams="this"/> @@ -42,11 +43,27 @@ ]]></script> <row> + <cell fill="horizontal"> + <JToolBar floatable="false"> + + <JButton id="blockButton" + toolTipText="{ _("lima.ui.financialperiod.block") + " (Ctrl+C)"}" + actionIcon='financialPeriod-close' + onActionPerformed="handler.blockFinancialPeriod()" + enabled="{isSelectedPeriod()}"/> + + </JToolBar> + </cell> + </row> + + <row> <cell fill="both" weightx="1" weighty="1"> <JScrollPane> <FinancialPeriodTableModel id="financialPeriodTableModel"/> <FinancialPeriodTable - id="financialPeriodTable" sortable="false" rowHeight="24" + id="financialPeriodTable" + sortable="false" + rowHeight="24" constructorParams="getHandler()" model="{financialPeriodTableModel}" selectionMode="{ListSelectionModel.SINGLE_INTERVAL_SELECTION}" @@ -56,16 +73,5 @@ onValueChanged="setSelectedPeriod(financialPeriodTable.getSelectedRow() != -1)"/> </JScrollPane> </cell> - <cell fill="horizontal" weighty="1" anchor="north"> - <Table> - <row> - <cell> - <JButton text="lima.ui.financialperiod.block" - enabled="{isSelectedPeriod()}" - onActionPerformed="getHandler().blockFinancialPeriod();"/> - </cell> - </row> - </Table> - </cell> </row> </Table> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialperiod/FinancialPeriodViewHandler.java 2014-01-02 10:35:55 UTC (rev 3728) @@ -25,13 +25,6 @@ package org.chorem.lima.ui.financialperiod; -import static org.nuiton.i18n.I18n._; - -import java.util.Collections; -import java.util.List; - -import javax.swing.JOptionPane; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.ServiceListener; @@ -43,6 +36,14 @@ import org.chorem.lima.service.LimaServiceFactory; import org.jdesktop.swingx.JXTable; +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; +import java.util.Collections; +import java.util.List; + +import static org.nuiton.i18n.I18n._; + /** * Handler for FinancialPeriodView. * @@ -73,6 +74,20 @@ */ public void init() { + InputMap inputMap = view.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + ActionMap actionMap = view.getActionMap(); + + // add action on Ctrl + B + String binding = "close-FinancialPeriod"; + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_DOWN_MASK), binding); + actionMap.put(binding, new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + blockFinancialPeriod(); + } + }); + + // get data from service List<ClosedPeriodicEntryBook> closedPeriodicEntryBooks = financialPeriodService. getAllClosedPeriodicEntryBooksFromUnblockedFiscalPeriod(); @@ -82,7 +97,7 @@ } // notify ui - view.getFinancialPeriodTableModel().setClosedPeriodicEntryBooks(closedPeriodicEntryBooks); + view.getFinancialPeriodTableModel().setValues(closedPeriodicEntryBooks); } /** @@ -94,14 +109,14 @@ FinancialPeriodTableModel model = (FinancialPeriodTableModel) view.getFinancialPeriodTable().getModel(); // blocked it - ClosedPeriodicEntryBook closedPeriodicEntryBook = model.getElementAt(selectedRow); + ClosedPeriodicEntryBook closedPeriodicEntryBook = model.get(selectedRow); int response = JOptionPane.showConfirmDialog(view, _("lima.ui.financialperiod.blockmessage"), _("lima.ui.financialperiod.blocktitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { closedPeriodicEntryBook = financialPeriodService.blockClosedPeriodicEntryBook(closedPeriodicEntryBook); - model.setElementAt(selectedRow, closedPeriodicEntryBook); + model.setValue(selectedRow, closedPeriodicEntryBook); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/fiscalperiod/FiscalPeriodView.jaxx 2014-01-02 10:35:55 UTC (rev 3728) @@ -52,7 +52,7 @@ onActionPerformed="handler.addFiscalPeriod()"/> <JButton id="blockButton" - toolTipText="{ _("lima.charts.fiscalperiod.block") + " (Ctrl+C)"}" + toolTipText="{ _("lima.charts.fiscalperiod.block") + " (Ctrl+B)"}" actionIcon='fiscalPeriod-close' onActionPerformed="handler.blockFiscalPeriod()" enabled="{isBlockEnabled()}"/> 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 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_en_GB.properties 2014-01-02 10:35:55 UTC (rev 3728) @@ -289,12 +289,15 @@ lima.ui.entrybook.label= lima.ui.entrybook.remove= lima.ui.entrybook.update= +lima.ui.financialperiod.begin= lima.ui.financialperiod.block= lima.ui.financialperiod.blockmessage= lima.ui.financialperiod.blocktitle= lima.ui.financialperiod.closure= +lima.ui.financialperiod.end= lima.ui.financialperiod.entrybook= lima.ui.financialperiod.period= +lima.ui.financialperiod.status= lima.ui.financialtransaction.account= lima.ui.financialtransaction.balance= lima.ui.financialtransaction.buttonback= 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 2014-01-02 09:41:08 UTC (rev 3727) +++ trunk/lima-swing/src/main/resources/i18n/lima-swing_fr_FR.properties 2014-01-02 10:35:55 UTC (rev 3728) @@ -279,12 +279,15 @@ lima.ui.entrybook.label=Libellé lima.ui.entrybook.remove=Supprimer lima.ui.entrybook.update=Modifier +lima.ui.financialperiod.begin=Début lima.ui.financialperiod.block=Cloturer une période lima.ui.financialperiod.blockmessage=Êtes vous sûre de vouloir clôturer cette période ? Cette action est irréversible \! lima.ui.financialperiod.blocktitle=Clôture lima.ui.financialperiod.closure=Clôture +lima.ui.financialperiod.end=Fin lima.ui.financialperiod.entrybook=Journal lima.ui.financialperiod.period=Période +lima.ui.financialperiod.status=Statut lima.ui.financialtransaction.account=Compte lima.ui.financialtransaction.balance=Balance lima.ui.financialtransaction.buttonback=← Copied: trunk/lima-swing/src/main/resources/icons/action-financialPeriod-close.png (from rev 3727, trunk/lima-swing/src/main/resources/icons/action-fiscalPeriod-close.png) =================================================================== (Binary files differ)
participants (1)
-
sbavencoff@users.chorem.org