diff --git a/base/src/org/eevolution/model/QueryDB.java b/base/src/org/eevolution/model/QueryDB.java deleted file mode 100644 index 4e9ad2f4de..0000000000 --- a/base/src/org/eevolution/model/QueryDB.java +++ /dev/null @@ -1,173 +0,0 @@ -/****************************************************************************** - * 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-2007 e-Evolution,SC. All Rights Reserved. * - * Contributor(s): Victor Perez www.e-evolution.com * - *****************************************************************************/ - -package org.eevolution.model; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.logging.Level; - -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; - - -/** - * - * @author Victor Perez www.e-evolution.com - */ -public class QueryDB { - - private String classname; - private static CLogger log = CLogger.getCLogger (QueryDB.class); - /** Creates a new instance of POQuery */ - - public QueryDB(String classname) - { - this.classname = classname; - } - - - - public static Object newInstance(String classname, int id, String trxName ) - { - Object result = null; - Class args; - int begin = classname.indexOf("X_") + 2 ; - String table = classname.substring(begin); - Class[] intArgsClass = new Class[] {Properties.class , int.class, String.class}; - //Integer height = new Integer(12); - Integer ID = new Integer(id); - Object[] intArgs = new Object[] {Env.getCtx(), ID,table}; - Constructor intArgsConstructor; - - try - { - - args = Class.forName(classname); - intArgsConstructor = - args.getConstructor(intArgsClass); - result = createObject(intArgsConstructor, intArgs); - return result; - } - catch (ClassNotFoundException e) - { - System.out.println(e); - return result; - } - catch (NoSuchMethodException e) - { - System.out.println(e); - return result; - } - } - - public static Object createObject(Constructor constructor, - Object[] arguments) { - - log.fine("Constructor: " + constructor.toString()); - - Object object = null; - - try { - object = constructor.newInstance(arguments); - //System.out.println ("Object: " + object.toString()); - return object; - } catch (InstantiationException e) { - log.log(Level.SEVERE,"InstantiationException:" + e); - } catch (IllegalAccessException e) { - log.log(Level.SEVERE,"IllegalAccessException:" + e); - } catch (IllegalArgumentException e) { - log.log(Level.SEVERE,"IllegalArgumentExceptio:" + e); - } catch (InvocationTargetException e) { - log.log(Level.SEVERE,"InvocationTargetException:" + e); - } - return object; - } - - public List execute(String filter) { - log.fine((new Integer(classname.indexOf("X_"))).toString()); - - int begin = classname.indexOf("X_") + 2 ; - String table = classname.substring(begin); - StringBuffer sql = new StringBuffer("SELECT ").append(table).append("_ID FROM " + table); - if (filter.equals("")) - System.out.println("not exist filter"); - else - sql.append(" WHERE ").append(filter); - - log.fine("Query =" + sql.toString()); - - List results = new ArrayList(); - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - int id = rs.getInt(1); - Object element = newInstance(classname , id, table); - results.add(element); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE,"VCreateFrom.initIOS - Order\nSQL=" + sql.toString(), e); - } - - return results; - } - - - public List execute() { - - int begin = classname.indexOf("X_") + 2 ; - String table = classname.substring(begin); - StringBuffer sql = new StringBuffer("SELECT ").append(table).append("_ID FROM " + table); - - List results = new ArrayList(); - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - int id = rs.getInt(1); - Object element = newInstance(classname , id, table); - results.add(element); - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE,"VCreateFrom.initIOS - Order\nSQL=" + sql.toString(), e); - } - - return results; - } - -} \ No newline at end of file diff --git a/client/src/org/eevolution/form/bom/RadioButtonTreeCellRenderer.java b/client/src/org/eevolution/form/bom/RadioButtonTreeCellRenderer.java index d02e202688..f0275a15ca 100644 --- a/client/src/org/eevolution/form/bom/RadioButtonTreeCellRenderer.java +++ b/client/src/org/eevolution/form/bom/RadioButtonTreeCellRenderer.java @@ -33,7 +33,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; -import java.util.Iterator; +import java.util.List; import java.util.Vector; import javax.swing.JCheckBox; @@ -47,16 +47,17 @@ 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.model.MProduct; +import org.compiere.model.MUOM; +import org.compiere.model.Query; 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.X_PP_Product_BOM; -import org.eevolution.model.X_PP_Product_BOMLine; +import org.eevolution.model.MPPProductBOM; +import org.eevolution.model.MPPProductBOMLine; + public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { @@ -113,40 +114,40 @@ public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { /** * Action: Fill Tree with all nodes */ - public DefaultMutableTreeNode action_loadBOM(X_M_Product Product, boolean setRoot) + public DefaultMutableTreeNode action_loadBOM(MProduct Product, boolean setRoot) { int M_Product_ID = Product.get_ID(); - 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"); - 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)); + MProduct M_Product = MProduct.get(Env.getCtx(), M_Product_ID); + MUOM UOM = new MUOM(Env.getCtx() , M_Product.getC_UOM_ID(), 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") + ": " + UOM.getName(), M_Product, null, null)); if(setRoot) { this.root = root; } dataBOM.clear(); if (false) - { - QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine"); - String filter = "M_Product_ID=" + M_Product_ID; - java.util.List results = query.execute(filter); - Iterator select = results.iterator(); - while (select.hasNext()) - { - X_PP_Product_BOMLine bomline = (X_PP_Product_BOMLine) select.next(); - root.add(parent(bomline)); - } + { + String whereClause = "M_Product_ID=?"; + List bomlines = new Query(Env.getCtx(),MPPProductBOMLine.Table_Name,whereClause, null) + .setParameters(new Object[]{M_Product_ID}) + .list(); + for (MPPProductBOMLine bomline : bomlines) + { + root.add(parent(bomline)); + } } else - { - QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM"); - String filter = " IsActive='Y' AND M_Product_ID =" + M_Product_ID; - java.util.List results = query.execute(filter); - Iterator select = results.iterator(); - while (select.hasNext()) - { - X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next(); - DefaultMutableTreeNode child = parent(bom); - root.add(child); - } + { + String whereClause = "M_Product_ID=?"; + List boms = new Query(Env.getCtx(),MPPProductBOM.Table_Name,whereClause, null) + .setParameters(new Object[]{M_Product_ID}) + .setOnlyActiveRecords(true) + .list(); + for (MPPProductBOM bom : boms) + { + DefaultMutableTreeNode child = parent(bom); + root.add(child); + } + } log.fine("root.getChildCount: " + root.getChildCount()); if(root.getChildCount() > 0) { @@ -160,15 +161,15 @@ public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { } // action_fillTree - public DefaultMutableTreeNode parent(X_PP_Product_BOMLine bomline) + public DefaultMutableTreeNode parent(MPPProductBOMLine bomline) { log.fine("In parent with X_PP_Product_BOMLine"); - 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"); + MProduct M_Product = MProduct.get(Env.getCtx(), bomline.getM_Product_ID()); + MUOM UOM = new MUOM(Env.getCtx() , M_Product.getC_UOM_ID(),null); - X_PP_Product_BOM bomproduct = new X_PP_Product_BOM(Env.getCtx(),bomline.getPP_Product_BOM_ID(),"PP_Product_BOM"); - 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)); + MPPProductBOM bomproduct = new MPPProductBOM(Env.getCtx(),bomline.getPP_Product_BOM_ID(),null); + 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") + ": " + UOM.getName(), M_Product, bomproduct, bomline)); Vector> line = new Vector>(17); @@ -192,64 +193,62 @@ public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { line.add( (String) bomline.getBackflushGroup()); // 15 BackflushGroup line.add( (BigDecimal) bomline.getForecast()); // 16 Forecast dataBOM.add(line); - - QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM"); - String filter = "M_Product_ID = " + bomproduct.getM_Product_ID(); - java.util.List results = query.execute(filter); - Iterator select = results.iterator(); - while (select.hasNext()) - { - X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next(); - X_M_Product component = new X_M_Product(Env.getCtx(), bom.getM_Product_ID(),"M_Product"); - return component(component, bom, bomline); + + String whereClause = "M_Product_ID=?"; + List boms = new Query(Env.getCtx(),MPPProductBOM.Table_Name,whereClause, null) + .setParameters(new Object[]{bomproduct.getM_Product_ID()}) + .setOnlyActiveRecords(true) + .list(); + for (MPPProductBOM bom : boms) + { + MProduct component = MProduct.get(Env.getCtx(), bom.getM_Product_ID()); + return component(component, bom, bomline); } return parent; } - public DefaultMutableTreeNode parent(X_PP_Product_BOM bom) + public DefaultMutableTreeNode parent(MPPProductBOM bom) { log.fine("Parent:" + bom.getName()); - X_M_Product product = new X_M_Product(Env.getCtx(), bom.getM_Product_ID(),"M_Product"); + MProduct product = MProduct.get(Env.getCtx(), bom.getM_Product_ID()); //vparent.setValue(m_product_id); String data = Msg.translate(Env.getCtx(), "PP_Product_BOM_ID") + " " + Msg.translate(Env.getCtx(), "Value") + ":"+ bom.getValue()+ " " + Msg.translate(Env.getCtx(), "Name") + ": " + bom.getName(); DefaultMutableTreeNode parent = new DefaultMutableTreeNode(new nodeUserObject(data, product, bom, null)); - - QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOMLine"); - String filter = "PP_Product_BOM_ID=" + bom.getPP_Product_BOM_ID(); - java.util.List results = query.execute(filter); - Iterator select = results.iterator(); - while (select.hasNext()) - { - 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"); - //System.out.println("Componente :" + component.getValue() + "[" + component.getName() + "]"); - //component(component); - Vector> line = new Vector>(17); - line.add( new Boolean(false)); // 0 Select - line.add( new Boolean(true)); // 1 IsActive - line.add( new Integer(bomline.getLine())); // 2 Line - line.add( (Timestamp) bomline.getValidFrom()); // 3 ValidDrom - line.add( (Timestamp) bomline.getValidTo()); // 4 ValidTo - KeyNamePair pp = new KeyNamePair(component.getM_Product_ID(),component.getName()); - line.add(pp); // 5 M_Product_ID - KeyNamePair uom = new KeyNamePair(bomline.getC_UOM_ID(),""); - line.add(uom); // 6 C_UOM_ID - line.add(new Boolean(bomline.isQtyPercentage())); // 7 IsQtyPercentage - line.add((BigDecimal) bomline.getQtyBatch()); // 8 BatchPercent - line.add((BigDecimal) bomline.getQtyBOM()); // 9 QtyBom - line.add(new Boolean(bomline.isCritical())); // 10 IsCritical - line.add( (Integer) bomline.getLeadTimeOffset()); // 11 LTOffSet - line.add( (BigDecimal) bomline.getAssay()); // 12 Assay - line.add( (BigDecimal) (bomline.getScrap())); // 13 Scrap - line.add( (String) bomline.getIssueMethod()); // 14 IssueMethod - line.add( (String) bomline.getBackflushGroup()); // 15 BackflushGroup - line.add( (BigDecimal) bomline.getForecast()); // 16 Forecast - //line.add(this.); - dataBOM.add(line); - parent.add(component(component, bom, bomline)); - + + String whereClause = "PP_Product_BOM_ID=?"; + List bomlines = new Query(Env.getCtx(),MPPProductBOMLine.Table_Name,whereClause, null) + .setParameters(new Object[]{bom.getPP_Product_BOM_ID()}) + .list(); + for (MPPProductBOMLine bomline : bomlines) + { + MProduct component = MProduct.get(Env.getCtx(), bomline.getM_Product_ID()); + //System.out.println("Componente :" + component.getValue() + "[" + component.getName() + "]"); + //component(component); + Vector> line = new Vector>(17); + line.add( new Boolean(false)); // 0 Select + line.add( new Boolean(true)); // 1 IsActive + line.add( new Integer(bomline.getLine())); // 2 Line + line.add( (Timestamp) bomline.getValidFrom()); // 3 ValidDrom + line.add( (Timestamp) bomline.getValidTo()); // 4 ValidTo + KeyNamePair pp = new KeyNamePair(component.getM_Product_ID(),component.getName()); + line.add(pp); // 5 M_Product_ID + KeyNamePair uom = new KeyNamePair(bomline.getC_UOM_ID(),""); + line.add(uom); // 6 C_UOM_ID + line.add(new Boolean(bomline.isQtyPercentage())); // 7 IsQtyPercentage + line.add((BigDecimal) bomline.getQtyBatch()); // 8 BatchPercent + line.add((BigDecimal) bomline.getQtyBOM()); // 9 QtyBom + line.add(new Boolean(bomline.isCritical())); // 10 IsCritical + line.add( (Integer) bomline.getLeadTimeOffset()); // 11 LTOffSet + line.add( (BigDecimal) bomline.getAssay()); // 12 Assay + line.add( (BigDecimal) (bomline.getScrap())); // 13 Scrap + line.add( (String) bomline.getIssueMethod()); // 14 IssueMethod + line.add( (String) bomline.getBackflushGroup()); // 15 BackflushGroup + line.add( (BigDecimal) bomline.getForecast()); // 16 Forecast + //line.add(this.); + dataBOM.add(line); + parent.add(component(component, bom, bomline)); } return parent; } @@ -257,23 +256,20 @@ public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { - public DefaultMutableTreeNode component(X_M_Product M_Product, X_PP_Product_BOM bomPassed, X_PP_Product_BOMLine bomlinePassed) + public DefaultMutableTreeNode component(MProduct M_Product, MPPProductBOM bomPassed, MPPProductBOMLine bomlinePassed) { - - //System.out.print("--------------------------------------Componet Product:" + M_Product.getName()); - QueryDB query = new QueryDB("org.eevolution.model.X_PP_Product_BOM"); - String filter = "Value='" + M_Product.getValue() + "'"; - 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); - Iterator select = results.iterator(); - while (select.hasNext()) - { - X_PP_Product_BOM bom = (X_PP_Product_BOM) select.next(); - //System.out.print("--------------------------------------Componet BOM:" + bom.getName()); - return parent(bom); - } - - return new DefaultMutableTreeNode(new nodeUserObject(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, bomPassed, bomlinePassed)); + + MUOM UOM = new MUOM(Env.getCtx() , M_Product.getC_UOM_ID(),null); + String whereClause = "Value=?"; + List boms = new Query(Env.getCtx(),MPPProductBOM.Table_Name,whereClause, null) + .setParameters(new Object[]{M_Product.getValue()}) + .setOnlyActiveRecords(true) + .list(); + for (MPPProductBOM bom : boms) + { + return parent(bom); + } + return new DefaultMutableTreeNode(new nodeUserObject(Msg.translate(Env.getCtx(), "Value") + ": " + M_Product.getValue() + " " + Msg.translate(Env.getCtx(), "Name") + ": " +M_Product.getName() + " " + Msg.translate(Env.getCtx(), "C_UOM_ID") + ": " + UOM.getName(), M_Product, bomPassed, bomlinePassed)); } public boolean isOnHotspot(int x, int y) { @@ -418,7 +414,7 @@ public class RadioButtonTreeCellRenderer implements CheckboxTreeCellRenderer { log.fine("m_nodeUserObjectParent.bom.pp_product_bom_id: " + m_nodeUserObjectParent.bom.get_ID()); log.fine("m_nodeUserObject.M_Product.get_ID: " + m_nodeUserObject.M_Product.get_ID()); - if(getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(X_PP_Product_BOMLine.COMPONENTTYPE_Variant) || getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(X_PP_Product_BOMLine.COMPONENTTYPE_Component)) { + if(getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(MPPProductBOMLine.COMPONENTTYPE_Variant) || getComponentTypeUsingBOMParent(m_nodeUserObjectParent.bom.get_ID(), m_nodeUserObject.M_Product.get_ID()).equals(MPPProductBOMLine.COMPONENTTYPE_Component)) { log.fine("Type is checkbox"); if(!m_nodeUserObject.isCheckbox) { m_nodeUserObject.isCheckbox = true;