Copyright Notice, correct Indentation for readability, parameterizing, logger outputs
VICTOR PLEASE REVIEW
This commit is contained in:
parent
e18e3c3c7c
commit
8541d6a704
|
@ -1,34 +1,65 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. 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. *
|
||||||
|
* For the text or an alternative of this public license, you may reach us *
|
||||||
|
* Copyright (C) 2003-2008 e-Evolution,SC. All Rights Reserved. *
|
||||||
|
* Contributor(s): Victor Perez www.e-evolution.com *
|
||||||
|
*****************************************************************************/
|
||||||
//RadioButtonTreeCellRenderer.java
|
//RadioButtonTreeCellRenderer.java
|
||||||
package org.eevolution.form.bom;
|
package org.eevolution.form.bom;
|
||||||
|
|
||||||
import java.util.*;
|
import it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTree;
|
||||||
|
import it.cnr.imaa.essi.lablib.gui.checkboxtree.CheckboxTreeCellRenderer;
|
||||||
|
import it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingEvent;
|
||||||
import org.compiere.model.*;
|
import it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingListener;
|
||||||
import org.compiere.util.*;
|
import it.cnr.imaa.essi.lablib.gui.checkboxtree.TreeCheckingModel;
|
||||||
import java.sql.*;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import java.awt.*;
|
|
||||||
import javax.swing.tree.*;
|
|
||||||
|
|
||||||
import org.eevolution.model.X_PP_Product_BOM;
|
|
||||||
import org.eevolution.model.X_PP_Product_BOMLine;
|
|
||||||
import org.compiere.model.X_M_Product;
|
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JRadioButton;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.TreeModel;
|
||||||
|
import javax.swing.tree.TreeNode;
|
||||||
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
|
import org.compiere.model.X_C_UOM;
|
||||||
|
import org.compiere.model.X_M_Product;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.KeyNamePair;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
import org.eevolution.model.QueryDB;
|
import org.eevolution.model.QueryDB;
|
||||||
import java.math.BigDecimal;
|
import org.eevolution.model.X_PP_Product_BOM;
|
||||||
|
import org.eevolution.model.X_PP_Product_BOMLine;
|
||||||
import it.cnr.imaa.essi.lablib.gui.checkboxtree.*;
|
|
||||||
|
|
||||||
|
|
||||||
import org.adempiere.pipo.*;
|
public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer {
|
||||||
|
|
||||||
|
|
||||||
public class RadioButtonTreeCellRenderer implements
|
|
||||||
CheckboxTreeCellRenderer {
|
|
||||||
|
|
||||||
JRadioButton button = new JRadioButton();
|
JRadioButton button = new JRadioButton();
|
||||||
JCheckBox checkBox = new JCheckBox();
|
JCheckBox checkBox = new JCheckBox();
|
||||||
|
@ -36,7 +67,7 @@ import org.adempiere.pipo.*;
|
||||||
JLabel label = new JLabel();
|
JLabel label = new JLabel();
|
||||||
//ButtonGroup group = new ButtonGroup();
|
//ButtonGroup group = new ButtonGroup();
|
||||||
boolean toggle = false;
|
boolean toggle = false;
|
||||||
private Vector dataBOM = new Vector();
|
private Vector<Vector<Comparable<?>>> dataBOM = new Vector<Vector<Comparable<?>>>();
|
||||||
public DefaultMutableTreeNode root = null;
|
public DefaultMutableTreeNode root = null;
|
||||||
|
|
||||||
public HashSet<TreePath> checkedPathsSet = new HashSet<TreePath>();
|
public HashSet<TreePath> checkedPathsSet = new HashSet<TreePath>();
|
||||||
|
@ -53,7 +84,7 @@ import org.adempiere.pipo.*;
|
||||||
log.fine("In getTreeNodeForNodeUserObject");
|
log.fine("In getTreeNodeForNodeUserObject");
|
||||||
DefaultMutableTreeNode foundChild = null;
|
DefaultMutableTreeNode foundChild = null;
|
||||||
|
|
||||||
Enumeration children = this.root.breadthFirstEnumeration();
|
Enumeration<?> children = this.root.breadthFirstEnumeration();
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
while (children.hasMoreElements()) {
|
while (children.hasMoreElements()) {
|
||||||
|
|
||||||
|
@ -64,14 +95,13 @@ import org.adempiere.pipo.*;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundChild;
|
return foundChild;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void printDescendents(TreeNode root) {
|
public static void printDescendents(TreeNode root) {
|
||||||
log.fine(root.toString());
|
log.fine(root.toString());
|
||||||
Enumeration children = root.children();
|
Enumeration<?> children = root.children();
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
while (children.hasMoreElements()) {
|
while (children.hasMoreElements()) {
|
||||||
printDescendents((TreeNode) children.nextElement());
|
printDescendents((TreeNode) children.nextElement());
|
||||||
|
@ -85,27 +115,20 @@ import org.adempiere.pipo.*;
|
||||||
*/
|
*/
|
||||||
public DefaultMutableTreeNode action_loadBOM(X_M_Product Product, boolean setRoot)
|
public DefaultMutableTreeNode action_loadBOM(X_M_Product Product, boolean setRoot)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
int M_Product_ID = Product.get_ID();
|
int M_Product_ID = Product.get_ID();
|
||||||
|
|
||||||
|
|
||||||
X_M_Product M_Product = new X_M_Product(Env.getCtx(), M_Product_ID,"M_Product");
|
X_M_Product M_Product = new X_M_Product(Env.getCtx(), M_Product_ID,"M_Product");
|
||||||
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(), "C_UOM");
|
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(), "C_UOM");
|
||||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "M_Product_ID") + Msg.translate(Env.getCtx(), "Value") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " +M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + C_UOM.getName(), M_Product, null, null));
|
DefaultMutableTreeNode root = new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "M_Product_ID") + Msg.translate(Env.getCtx(), "Value") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " +M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + C_UOM.getName(), M_Product, null, null));
|
||||||
if(setRoot) {
|
if(setRoot) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
dataBOM.clear();
|
dataBOM.clear();
|
||||||
|
|
||||||
if (false)
|
if (false)
|
||||||
{
|
{
|
||||||
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine");
|
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine");
|
||||||
String filter = "M_Product_ID=" + M_Product_ID;
|
String filter = "M_Product_ID=" + M_Product_ID;
|
||||||
java.util.List results = query.execute(filter);
|
java.util.List<Object> results = query.execute(filter);
|
||||||
Iterator select = results.iterator();
|
Iterator<Object> select = results.iterator();
|
||||||
while (select.hasNext())
|
while (select.hasNext())
|
||||||
{
|
{
|
||||||
X_PP_Product_BOMLine bomline = (X_PP_Product_BOMLine) select.next();
|
X_PP_Product_BOMLine bomline = (X_PP_Product_BOMLine) select.next();
|
||||||
|
@ -116,21 +139,18 @@ import org.adempiere.pipo.*;
|
||||||
{
|
{
|
||||||
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
||||||
String filter = " IsActive='Y' AND M_Product_ID =" + M_Product_ID;
|
String filter = " IsActive='Y' AND M_Product_ID =" + M_Product_ID;
|
||||||
java.util.List results = query.execute(filter);
|
java.util.List<Object> results = query.execute(filter);
|
||||||
Iterator select = results.iterator();
|
Iterator<Object> select = results.iterator();
|
||||||
while (select.hasNext())
|
while (select.hasNext())
|
||||||
{
|
{
|
||||||
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
||||||
DefaultMutableTreeNode child = parent(bom);
|
DefaultMutableTreeNode child = parent(bom);
|
||||||
root.add(child);
|
root.add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log.fine("root.getChildCount: " + root.getChildCount());
|
log.fine("root.getChildCount: " + root.getChildCount());
|
||||||
if(root.getChildCount() > 0) {
|
if(root.getChildCount() > 0) {
|
||||||
root = (DefaultMutableTreeNode)root.getFirstChild();
|
root = (DefaultMutableTreeNode)root.getFirstChild();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(setRoot)
|
if(setRoot)
|
||||||
|
@ -144,7 +164,6 @@ import org.adempiere.pipo.*;
|
||||||
{
|
{
|
||||||
log.fine("In parent with X_PP_Product_BOMLine");
|
log.fine("In parent with X_PP_Product_BOMLine");
|
||||||
|
|
||||||
//System.out.println("-------------------------Padre:" + bom.getName());
|
|
||||||
X_M_Product M_Product = new X_M_Product(Env.getCtx(), bomline.getM_Product_ID(),"M_Product");
|
X_M_Product M_Product = new X_M_Product(Env.getCtx(), bomline.getM_Product_ID(),"M_Product");
|
||||||
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(),"C_UOM");
|
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(),"C_UOM");
|
||||||
|
|
||||||
|
@ -152,7 +171,7 @@ import org.adempiere.pipo.*;
|
||||||
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "M_Product_ID") + Msg.translate(Env.getCtx(), "key") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " +M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + C_UOM.getName(), M_Product, bomproduct, bomline));
|
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "M_Product_ID") + Msg.translate(Env.getCtx(), "key") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " +M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + C_UOM.getName(), M_Product, bomproduct, bomline));
|
||||||
|
|
||||||
|
|
||||||
Vector line = new Vector(17);
|
Vector<Comparable<?>> line = new Vector<Comparable<?>>(17);
|
||||||
line.add( new Boolean(false)); // 0 Select
|
line.add( new Boolean(false)); // 0 Select
|
||||||
line.add( new Boolean(true)); // 1 IsActive
|
line.add( new Boolean(true)); // 1 IsActive
|
||||||
line.add( new Integer(bomline.getLine())); // 2 Line
|
line.add( new Integer(bomline.getLine())); // 2 Line
|
||||||
|
@ -176,8 +195,8 @@ import org.adempiere.pipo.*;
|
||||||
|
|
||||||
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
||||||
String filter = "M_Product_ID = " + bomproduct.getM_Product_ID();
|
String filter = "M_Product_ID = " + bomproduct.getM_Product_ID();
|
||||||
java.util.List results = query.execute(filter);
|
java.util.List<Object> results = query.execute(filter);
|
||||||
Iterator select = results.iterator();
|
Iterator<Object> select = results.iterator();
|
||||||
while (select.hasNext())
|
while (select.hasNext())
|
||||||
{
|
{
|
||||||
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
||||||
|
@ -190,7 +209,7 @@ import org.adempiere.pipo.*;
|
||||||
public DefaultMutableTreeNode parent(X_PP_Product_BOM bom)
|
public DefaultMutableTreeNode parent(X_PP_Product_BOM bom)
|
||||||
{
|
{
|
||||||
|
|
||||||
//System.out.println("Padre:" + bom.getName());
|
log.fine("Parent:" + bom.getName());
|
||||||
X_M_Product product = new X_M_Product(Env.getCtx(), bom.getM_Product_ID(),"M_Product");
|
X_M_Product product = new X_M_Product(Env.getCtx(), bom.getM_Product_ID(),"M_Product");
|
||||||
|
|
||||||
//vparent.setValue(m_product_id);
|
//vparent.setValue(m_product_id);
|
||||||
|
@ -199,15 +218,15 @@ import org.adempiere.pipo.*;
|
||||||
|
|
||||||
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine");
|
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine");
|
||||||
String filter = "PP_Product_BOM_ID=" + bom.getPP_Product_BOM_ID();
|
String filter = "PP_Product_BOM_ID=" + bom.getPP_Product_BOM_ID();
|
||||||
java.util.List results = query.execute(filter);
|
java.util.List<Object> results = query.execute(filter);
|
||||||
Iterator select = results.iterator();
|
Iterator<Object> select = results.iterator();
|
||||||
while (select.hasNext())
|
while (select.hasNext())
|
||||||
{
|
{
|
||||||
X_PP_Product_BOMLine bomline = (X_PP_Product_BOMLine) select.next();
|
X_PP_Product_BOMLine bomline = (X_PP_Product_BOMLine) select.next();
|
||||||
X_M_Product component = new X_M_Product(Env.getCtx(), bomline.getM_Product_ID(),"M_Product");
|
X_M_Product component = new X_M_Product(Env.getCtx(), bomline.getM_Product_ID(),"M_Product");
|
||||||
//System.out.println("Componente :" + component.getValue() + "[" + component.getName() + "]");
|
//System.out.println("Componente :" + component.getValue() + "[" + component.getName() + "]");
|
||||||
//component(component);
|
//component(component);
|
||||||
Vector line = new Vector(17);
|
Vector<Comparable<?>> line = new Vector<Comparable<?>>(17);
|
||||||
line.add( new Boolean(false)); // 0 Select
|
line.add( new Boolean(false)); // 0 Select
|
||||||
line.add( new Boolean(true)); // 1 IsActive
|
line.add( new Boolean(true)); // 1 IsActive
|
||||||
line.add( new Integer(bomline.getLine())); // 2 Line
|
line.add( new Integer(bomline.getLine())); // 2 Line
|
||||||
|
@ -245,8 +264,8 @@ import org.adempiere.pipo.*;
|
||||||
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM");
|
||||||
String filter = "Value='" + M_Product.getValue() + "'";
|
String filter = "Value='" + M_Product.getValue() + "'";
|
||||||
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(),"C_UOM");
|
X_C_UOM C_UOM = new X_C_UOM(Env.getCtx() , M_Product.getC_UOM_ID(),"C_UOM");
|
||||||
java.util.List results = query.execute(filter);
|
java.util.List<Object> results = query.execute(filter);
|
||||||
Iterator select = results.iterator();
|
Iterator<Object> select = results.iterator();
|
||||||
while (select.hasNext())
|
while (select.hasNext())
|
||||||
{
|
{
|
||||||
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next();
|
||||||
|
@ -273,7 +292,7 @@ import org.adempiere.pipo.*;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreePath getPath(TreeNode node) {
|
public TreePath getPath(TreeNode node) {
|
||||||
java.util.List list = new ArrayList();
|
java.util.List<TreeNode> list = new ArrayList<TreeNode>();
|
||||||
|
|
||||||
// Add all nodes to list
|
// Add all nodes to list
|
||||||
while (node != null) {
|
while (node != null) {
|
||||||
|
@ -345,11 +364,11 @@ import org.adempiere.pipo.*;
|
||||||
TreePath path = tree.getPathForRow(row);
|
TreePath path = tree.getPathForRow(row);
|
||||||
boolean enabled = checkingModel.isPathEnabled(path);
|
boolean enabled = checkingModel.isPathEnabled(path);
|
||||||
boolean checked = checkingModel.isPathChecked(path);
|
boolean checked = checkingModel.isPathChecked(path);
|
||||||
boolean checkBoxed = checkingModel.isPathCheckBox(path);
|
// boolean checkBoxed = checkingModel.isPathCheckBox(path);
|
||||||
|
|
||||||
checked = checkingModel.isPathChecked(path);
|
checked = checkingModel.isPathChecked(path);
|
||||||
|
|
||||||
boolean grayed = checkingModel.isPathGreyed(path);
|
// boolean grayed = checkingModel.isPathGreyed(path);
|
||||||
button.setEnabled(true);
|
button.setEnabled(true);
|
||||||
|
|
||||||
button.setSelected(checked);
|
button.setSelected(checked);
|
||||||
|
@ -465,9 +484,9 @@ import org.adempiere.pipo.*;
|
||||||
tree.addTreeCheckingListener(new TreeCheckingListener() {
|
tree.addTreeCheckingListener(new TreeCheckingListener() {
|
||||||
public void valueChanged(TreeCheckingEvent e) {
|
public void valueChanged(TreeCheckingEvent e) {
|
||||||
log.fine("Checked paths changed: user clicked on " + (e.getLeadingPath().getLastPathComponent()));
|
log.fine("Checked paths changed: user clicked on " + (e.getLeadingPath().getLastPathComponent()));
|
||||||
TreeModel tm = tree.getModel();
|
// TreeModel tm = tree.getModel();
|
||||||
TreePath selected = tree.getSelectionPath();
|
// TreePath selected = tree.getSelectionPath();
|
||||||
TreeCheckingModel checkingModel = ((CheckboxTree)tree).getCheckingModel();
|
// TreeCheckingModel checkingModel = ((CheckboxTree)tree).getCheckingModel();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -478,4 +497,4 @@ import org.adempiere.pipo.*;
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue