This is an automated email from the git hooks/post-receive script. New commit to branch feature/1268-vat-statement-usable in repository lima. See http://git.chorem.org/lima.git commit 6b2e99c335e784dc608478520d978eccb282a809 Author: dcosse <cosse@codelutin.com> Date: Wed Jul 22 12:31:24 2015 +0200 refs #1268 utilisation de JXTreeTable à la place de VatChartTreeTable --- .../chorem/lima/ui/vatchart/VatChartTreeTable.java | 134 --------------------- .../lima/ui/vatchart/VatChartViewHandler.java | 62 ++++++++-- ...tTreeTableModel.java => VatChartViewModel.java} | 4 +- 3 files changed, 55 insertions(+), 145 deletions(-) diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java b/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java deleted file mode 100644 index ff1a31c..0000000 --- a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTable.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * #%L - * Lima :: Swing - * %% - * Copyright (C) 2008 - 2011 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% - */ -package org.chorem.lima.ui.vatchart; - -import org.chorem.lima.entity.VatStatement; -import org.jdesktop.swingx.JXTreeTable; -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.treetable.TreeTableModel; - -import javax.swing.tree.TreePath; -import java.awt.*; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - -public class VatChartTreeTable extends JXTreeTable - implements KeyListener, MouseListener { - - /** serialVersionUID. */ - private static final long serialVersionUID = 3960840343197845825L; - - protected VatChartViewHandler handler; - //protected Color colorSelectionFocus; - - private transient Highlighter colorLine; - - public VatChartTreeTable(VatChartViewHandler handler) { - this.handler = handler; - - addKeyListener(this); - addMouseListener(this); - - //highlight missing box name lines - addMissingBoxNameColor(); - } - - /** Highlights line when line is a leaf and is missing its BoxName parameter */ - private void addMissingBoxNameColor() { - if (colorLine != null) { - removeHighlighter(colorLine); - } - HighlightPredicate predicate = new HighlightPredicate() { - @Override - public boolean isHighlighted(Component renderer, - ComponentAdapter adapter) { - JXTreeTable vatTreeTable = handler.view.getVatTreeTable(); - TreeTableModel treeTableModel = vatTreeTable.getTreeTableModel(); - TreePath treePath = vatTreeTable.getPathForRow(adapter.row); - VatStatement vatStatement = - (VatStatement) treePath.getLastPathComponent(); - boolean highlighted = false; - if (vatStatement.getBoxName() != null) { - if (treeTableModel.isLeaf(vatStatement) && vatStatement.getBoxName().isEmpty()) { - highlighted = true; - } - } else { - highlighted = true; - } - return highlighted; - } - }; - colorLine = new ColorHighlighter(predicate, new Color(255, 198, 209), null); - addHighlighter(colorLine); - } - - @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) { - } - -} diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java b/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java index e6e3425..2c363b5 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewHandler.java @@ -22,6 +22,7 @@ package org.chorem.lima.ui.vatchart; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.chorem.lima.LimaSwingConfig; import org.chorem.lima.business.LimaServiceFactory; import org.chorem.lima.business.ServiceListener; @@ -34,12 +35,17 @@ import org.chorem.lima.enums.VatStatementsChartEnum; import org.chorem.lima.ui.importexport.ImportExport; import org.chorem.lima.util.ErrorHelper; import org.jdesktop.swingx.JXTreeTable; +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.treetable.DefaultMutableTreeTableNode; import org.jdesktop.swingx.treetable.DefaultTreeTableModel; import org.jdesktop.swingx.treetable.MutableTreeTableNode; import javax.swing.*; import javax.swing.tree.TreePath; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -52,6 +58,8 @@ import static org.nuiton.i18n.I18n.t; public class VatChartViewHandler implements ServiceListener { + private transient Highlighter colorLine; + protected VatStatementService vatStatementService; protected VatChartView view; @@ -70,6 +78,19 @@ public class VatChartViewHandler implements ServiceListener { public void init() { InputMap inputMap = view.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + + addShortCutEvent(inputMap); + + addDoubleClickEvent(); + + addErrorLineColor(); + + MutableTreeTableNode rootTreeTable = loadAllVatStatements(); + + setUpTreeTableModel(rootTreeTable); + } + + protected void addShortCutEvent(InputMap inputMap) { ActionMap actionMap = view.getActionMap(); // add action on Ctrl + N @@ -101,7 +122,9 @@ public class VatChartViewHandler implements ServiceListener { updateVatStatement(); } }); + } + protected void addDoubleClickEvent() { JXTreeTable table = view.getVatTreeTable(); table.addMouseListener(new MouseAdapter() { @Override @@ -112,9 +135,30 @@ public class VatChartViewHandler implements ServiceListener { } } }); + } - MutableTreeTableNode rootTreeTable = loadAllVatStatements(); - initVatChartTreeTableModel(rootTreeTable); + /** Highlights line when line is a leaf and is missing its BoxName parameter */ + protected void addErrorLineColor() { + if (colorLine != null) { + view.getVatTreeTable().removeHighlighter(colorLine); + } + HighlightPredicate predicate = new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, + ComponentAdapter adapter) { + JXTreeTable vatTreeTable = view.getVatTreeTable(); + TreePath treePath = vatTreeTable.getPathForRow(adapter.row); + MutableTreeTableNode vatStatementNode = (MutableTreeTableNode) treePath.getLastPathComponent(); + VatStatement vatStatement = (VatStatement) vatStatementNode.getUserObject(); + boolean highlighted = false; + if (!vatStatement.isHeader()) { + highlighted = StringUtils.isBlank(vatStatement.getBoxName()); + } + return highlighted; + } + }; + colorLine = new ColorHighlighter(predicate, new Color(255, 198, 209), null); + view.getVatTreeTable().addHighlighter(colorLine); } public void importVatStatementChart() { @@ -148,7 +192,7 @@ public class VatChartViewHandler implements ServiceListener { } MutableTreeTableNode root = loadAllVatStatements(); - initVatChartTreeTableModel(root); + setUpTreeTableModel(root); } @@ -185,7 +229,7 @@ public class VatChartViewHandler implements ServiceListener { public void createOrUpdateVatStatementMovement(VatChartMovementForm dialog) { JXTreeTable treeTable = view.getVatTreeTable(); - VatChartTreeTableModel treeTableModel = (VatChartTreeTableModel) treeTable.getTreeTableModel(); + VatChartViewModel treeTableModel = (VatChartViewModel) treeTable.getTreeTableModel(); VatStatement vatStatement = dialog.getVatStatement(); try { @@ -220,8 +264,8 @@ public class VatChartViewHandler implements ServiceListener { /** Ask for user to remove for selected account, and remove it if confirmed. */ public void removeVatStatement() { JXTreeTable treeTable = view.getVatTreeTable(); - VatChartTreeTableModel treeTableModel = - (VatChartTreeTableModel) treeTable.getTreeTableModel(); + VatChartViewModel treeTableModel = + (VatChartViewModel) treeTable.getTreeTableModel(); // Any row selected int selectedRow = treeTable.getSelectedRow(); @@ -304,9 +348,9 @@ public class VatChartViewHandler implements ServiceListener { return rootTreeTable; } - protected void initVatChartTreeTableModel(MutableTreeTableNode root) { + protected void setUpTreeTableModel(MutableTreeTableNode root) { // refreshing tree's model - DefaultTreeTableModel model = new VatChartTreeTableModel(root); + DefaultTreeTableModel model = new VatChartViewModel(root); model.setColumnIdentifiers(Arrays.asList(t("lima.table.label"), t("lima.table.account"), t("lima.table.boxName"))); JXTreeTable table = view.getVatTreeTable(); @@ -325,7 +369,7 @@ public class VatChartViewHandler implements ServiceListener { return masterVatStatement; } - protected VatStatement createOrUpdateVatStatement(VatChartTreeTableModel treeTableModel, VatStatement vatStatement) { + protected VatStatement createOrUpdateVatStatement(VatChartViewModel treeTableModel, VatStatement vatStatement) { VatStatement persistedVatStatement; if (vatStatement.isPersisted()) { diff --git a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java b/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewModel.java similarity index 98% rename from lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java rename to lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewModel.java index 3b067a2..b4200e3 100644 --- a/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartTreeTableModel.java +++ b/lima-swing/src/main/java/org/chorem/lima/ui/vatchart/VatChartViewModel.java @@ -40,7 +40,7 @@ import org.nuiton.util.beans.BinderFactory; import static org.nuiton.i18n.I18n.t; -public class VatChartTreeTableModel extends DefaultTreeTableModel { +public class VatChartViewModel extends DefaultTreeTableModel { /** log. */ private static final Log log = LogFactory.getLog(VatChartViewHandler.class); @@ -51,7 +51,7 @@ public class VatChartTreeTableModel extends DefaultTreeTableModel { protected ErrorHelper errorHelper; /** Model constructor. Initiate account service used here. */ - public VatChartTreeTableModel(TreeTableNode root) { + public VatChartViewModel(TreeTableNode root) { //create root for the tree super(root); // Gets factory service -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.