diff --git a/client/src/org/compiere/acct/AcctViewerData.java b/client/src/org/compiere/acct/AcctViewerData.java index a910fae6d9..dec16345e4 100644 --- a/client/src/org/compiere/acct/AcctViewerData.java +++ b/client/src/org/compiere/acct/AcctViewerData.java @@ -3,485 +3,485 @@ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * 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 * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.acct; - -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import javax.swing.*; - -import org.compiere.model.*; -import org.compiere.report.core.*; -import org.compiere.util.*; - - -/** - * Account Viewer State - maintaines State information for the Account Viewer - * - * @author Jorg Janke - * @version $Id: AcctViewerData.java,v 1.3 2006/08/10 01:00:27 jjanke Exp $ - */ -class AcctViewerData -{ - /** - * Constructor - * @param ctx context - * @param windowNo window no - * @param ad_Client_ID client - * @param ad_Table_ID table - */ - public AcctViewerData (Properties ctx, int windowNo, int ad_Client_ID, int ad_Table_ID) - { - WindowNo = windowNo; - AD_Client_ID = ad_Client_ID; - if (AD_Client_ID == 0) - AD_Client_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "AD_Client_ID"); - if (AD_Client_ID == 0) - AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "AD_Client_ID"); - AD_Table_ID = ad_Table_ID; - // - ASchemas = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID); - ASchema = ASchemas[0]; - } // AcctViewerData - - /** Window */ - public int WindowNo; - /** Client */ - public int AD_Client_ID; - /** All Acct Schema */ - public MAcctSchema[] ASchemas = null; - /** This Acct Schema */ - public MAcctSchema ASchema = null; - - // Selection Info - /** Document Query */ - public boolean documentQuery = false; - /** Acct Schema */ - public int C_AcctSchema_ID = 0; - /** Posting Type */ - public String PostingType = ""; - /** Organization */ - public int AD_Org_ID = 0; - /** Date From */ - public Timestamp DateFrom = null; - /** Date To */ - public Timestamp DateTo = null; - - // Dodument Table Selection Info - /** Table ID */ - public int AD_Table_ID; - /** Record */ - public int Record_ID; - - /** Containing Column and Query */ - public HashMap whereInfo = new HashMap(); - /** Containing TableName and AD_Table_ID */ - public HashMap tableInfo = new HashMap(); - - // Display Info - /** Display Qty */ - boolean displayQty = false; - /** Display Source Surrency */ - boolean displaySourceAmt = false; - /** Display Document info */ - boolean displayDocumentInfo = false; - // - String sortBy1 = ""; - String sortBy2 = ""; - String sortBy3 = ""; - String sortBy4 = ""; - // - boolean group1 = false; - boolean group2 = false; - boolean group3 = false; - boolean group4 = false; - - /** Leasing Columns */ - private int m_leadingColumns = 0; - /** UserElement1 Reference */ - private String m_ref1 = null; - /** UserElement2 Reference */ - private String m_ref2 = null; - /** Logger */ - private static CLogger log = CLogger.getCLogger(AcctViewerData.class); - - /** - * Dispose - */ - public void dispose() - { - ASchemas = null; - ASchema = null; - // - whereInfo.clear(); - whereInfo = null; - // - Env.clearWinContext(WindowNo); - } // dispose - - - /************************************************************************** - * Fill Accounting Schema - * @param cb JComboBox to be filled - */ - protected void fillAcctSchema (JComboBox cb) - { - for (int i = 0; i < ASchemas.length; i++) - cb.addItem(new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(), - ASchemas[i].getName())); - } // fillAcctSchema - - /** - * Fill Posting Type - * @param cb JComboBox to be filled - */ - protected void fillPostingType (JComboBox cb) - { - int AD_Reference_ID = 125; - ValueNamePair[] pt = MRefList.getList(AD_Reference_ID, true); - for (int i = 0; i < pt.length; i++) - cb.addItem(pt[i]); - } // fillPostingType - - /** - * Fill Table with - * ValueNamePair (TableName, translatedKeyColumnName) - * and tableInfo with (TableName, AD_Table_ID) - * and select the entry for AD_Table_ID - * - * @param cb JComboBox to be filled - */ - protected void fillTable (JComboBox cb) - { - ValueNamePair select = null; - // - String sql = "SELECT AD_Table_ID, TableName FROM AD_Table t " - + "WHERE EXISTS (SELECT * FROM AD_Column c" - + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" - + " AND IsView='N'"; - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - { - int id = rs.getInt(1); - String tableName = rs.getString(2); - String name = Msg.translate(Env.getCtx(), tableName+"_ID"); - // - ValueNamePair pp = new ValueNamePair(tableName, name); - cb.addItem(pp); - tableInfo.put (tableName, new Integer(id)); - if (id == AD_Table_ID) - select = pp; - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - if (select != null) - cb.setSelectedItem(select); - } // fillTable - - /** - * Fill Org - * - * @param cb JComboBox to be filled - */ - protected void fillOrg (JComboBox cb) - { - KeyNamePair pp = new KeyNamePair(0, ""); - cb.addItem(pp); - String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value"; - try - { - PreparedStatement pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, AD_Client_ID); - ResultSet rs = pstmt.executeQuery(); - while (rs.next()) - cb.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql, e); - } - } // fillOrg - - /** - * Get Button Text - * - * @param tableName table - * @param columnName column - * @param selectSQL sql - * @return Text on button - */ - protected String getButtonText (String tableName, String columnName, String selectSQL) - { - // SELECT () FROM tableName avd WHERE avd. - StringBuffer sql = new StringBuffer ("SELECT ("); - Language language = Env.getLanguage(Env.getCtx()); - sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")) - .append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL); - String retValue = "<" + selectSQL + ">"; - try - { - Statement stmt = DB.createStatement(); - ResultSet rs = stmt.executeQuery(sql.toString()); - if (rs.next()) - retValue = rs.getString(1); - rs.close(); - stmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - return retValue; - } // getButtonText - - /************************************************************************** - - /** - * Create Query and submit - * @return Report Model - */ - protected RModel query() - { - // Set Where Clause - StringBuffer whereClause = new StringBuffer(); - // Add Organization - if (C_AcctSchema_ID != 0) - whereClause.append(RModel.TABLE_ALIAS) - .append(".C_AcctSchema_ID=").append(C_AcctSchema_ID); - - // Posting Type Selected - if (PostingType != null && PostingType.length() > 0) - { - if (whereClause.length() > 0) - whereClause.append(" AND "); - whereClause.append(RModel.TABLE_ALIAS) - .append(".PostingType='").append(PostingType).append("'"); - } - - // - if (documentQuery) - { - if (whereClause.length() > 0) - whereClause.append(" AND "); - whereClause.append(RModel.TABLE_ALIAS).append(".AD_Table_ID=").append(AD_Table_ID) - .append(" AND ").append(RModel.TABLE_ALIAS).append(".Record_ID=").append(Record_ID); - } - else - { - // get values (Queries) - Iterator it = whereInfo.values().iterator(); - while (it.hasNext()) - { - String where = (String)it.next(); - if (where != null && where.length() > 0) // add only if not empty - { - if (whereClause.length() > 0) - whereClause.append(" AND "); - whereClause.append(RModel.TABLE_ALIAS).append(".").append(where); - } - } - if (DateFrom != null || DateTo != null) - { - if (whereClause.length() > 0) - whereClause.append(" AND "); - if (DateFrom != null && DateTo != null) - whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) BETWEEN ") - .append(DB.TO_DATE(DateFrom)).append(" AND ").append(DB.TO_DATE(DateTo)); - else if (DateFrom != null) - whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) >= ") - .append(DB.TO_DATE(DateFrom)); - else // DateTo != null - whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) <= ") - .append(DB.TO_DATE(DateTo)); - } - // Add Organization - if (AD_Org_ID != 0) - { - if (whereClause.length() > 0) - whereClause.append(" AND "); - whereClause.append(RModel.TABLE_ALIAS).append(".AD_Org_ID=").append(AD_Org_ID); - } - } - - // Set Order By Clause - StringBuffer orderClause = new StringBuffer(); - if (sortBy1.length() > 0) - orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy1); - if (sortBy2.length() > 0) - { - if (orderClause.length() > 0) - orderClause.append(","); - orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy2); - } - if (sortBy3.length() > 0) - { - if (orderClause.length() > 0) - orderClause.append(","); - orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy3); - } - if (sortBy4.length() > 0) - { - if (orderClause.length() > 0) - orderClause.append(","); - orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy4); - } - if (orderClause.length() == 0) - orderClause.append(RModel.TABLE_ALIAS).append(".Fact_Acct_ID"); - - RModel rm = getRModel(); - - // Groups - if (group1 && sortBy1.length() > 0) - rm.setGroup(sortBy1); - if (group2 && sortBy2.length() > 0) - rm.setGroup(sortBy2); - if (group3 && sortBy3.length() > 0) - rm.setGroup(sortBy3); - if (group4 && sortBy4.length() > 0) - rm.setGroup(sortBy4); - - // Totals - rm.setFunction("AmtAcctDr", RModel.FUNCTION_SUM); - rm.setFunction("AmtAcctCr", RModel.FUNCTION_SUM); - - rm.query (Env.getCtx(), whereClause.toString(), orderClause.toString()); - - return rm; - } // query - - /** - * Create Report Model (Columns) - * @return Report Model - */ - private RModel getRModel() - { - Properties ctx = Env.getCtx(); - RModel rm = new RModel("Fact_Acct"); - // Add Key (Lookups) - ArrayList keys = createKeyColumns(); - int max = m_leadingColumns; - if (max == 0) - max = keys.size(); - for (int i = 0; i < max; i++) - { - String column = (String)keys.get(i); - if (column != null && column.startsWith("Date")) - rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); - else if (column != null && column.endsWith("_ID")) - rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); - } - // Main Info - rm.addColumn(new RColumn(ctx, "AmtAcctDr", DisplayType.Amount)); - rm.addColumn(new RColumn(ctx, "AmtAcctCr", DisplayType.Amount)); - if (displaySourceAmt) - { - if (!keys.contains("DateTrx")) - rm.addColumn(new RColumn(ctx, "DateTrx", DisplayType.Date)); - rm.addColumn(new RColumn(ctx, "C_Currency_ID", DisplayType.TableDir)); - rm.addColumn(new RColumn(ctx, "AmtSourceDr", DisplayType.Amount)); - rm.addColumn(new RColumn(ctx, "AmtSourceCr", DisplayType.Amount)); - rm.addColumn(new RColumn(ctx, "Rate", DisplayType.Amount, - "CASE WHEN (AmtSourceDr + AmtSourceCr) = 0 THEN 0" - + " ELSE (AmtAcctDr + AmtAcctCr) / (AmtSourceDr + AmtSourceCr) END")); - } - // Remaining Keys - for (int i = max; i < keys.size(); i++) - { - String column = (String)keys.get(i); - if (column != null && column.startsWith("Date")) - rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); - else if (column.startsWith("UserElement")) - { - if (column.indexOf("1") != -1) - rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1)); - else - rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref2)); - } - else if (column != null && column.endsWith("_ID")) - rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); - } - // Info - if (!keys.contains("DateAcct")) - rm.addColumn(new RColumn(ctx, "DateAcct", DisplayType.Date)); - if (!keys.contains("C_Period_ID")) - rm.addColumn(new RColumn(ctx, "C_Period_ID", DisplayType.TableDir)); - if (displayQty) - { - rm.addColumn(new RColumn(ctx, "C_UOM_ID", DisplayType.TableDir)); - rm.addColumn(new RColumn(ctx, "Qty", DisplayType.Quantity)); - } - if (displayDocumentInfo) - { - rm.addColumn(new RColumn(ctx, "AD_Table_ID", DisplayType.TableDir)); - rm.addColumn(new RColumn(ctx, "Record_ID", DisplayType.ID)); + * 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 * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.acct; + +import java.sql.*; +import java.util.*; +import java.util.logging.*; +import javax.swing.*; + +import org.compiere.model.*; +import org.compiere.report.core.*; +import org.compiere.util.*; + + +/** + * Account Viewer State - maintaines State information for the Account Viewer + * + * @author Jorg Janke + * @version $Id: AcctViewerData.java,v 1.3 2006/08/10 01:00:27 jjanke Exp $ + */ +class AcctViewerData +{ + /** + * Constructor + * @param ctx context + * @param windowNo window no + * @param ad_Client_ID client + * @param ad_Table_ID table + */ + public AcctViewerData (Properties ctx, int windowNo, int ad_Client_ID, int ad_Table_ID) + { + WindowNo = windowNo; + AD_Client_ID = ad_Client_ID; + if (AD_Client_ID == 0) + AD_Client_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "AD_Client_ID"); + if (AD_Client_ID == 0) + AD_Client_ID = Env.getContextAsInt(Env.getCtx(), "AD_Client_ID"); + AD_Table_ID = ad_Table_ID; + // + ASchemas = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID); + ASchema = ASchemas[0]; + } // AcctViewerData + + /** Window */ + public int WindowNo; + /** Client */ + public int AD_Client_ID; + /** All Acct Schema */ + public MAcctSchema[] ASchemas = null; + /** This Acct Schema */ + public MAcctSchema ASchema = null; + + // Selection Info + /** Document Query */ + public boolean documentQuery = false; + /** Acct Schema */ + public int C_AcctSchema_ID = 0; + /** Posting Type */ + public String PostingType = ""; + /** Organization */ + public int AD_Org_ID = 0; + /** Date From */ + public Timestamp DateFrom = null; + /** Date To */ + public Timestamp DateTo = null; + + // Dodument Table Selection Info + /** Table ID */ + public int AD_Table_ID; + /** Record */ + public int Record_ID; + + /** Containing Column and Query */ + public HashMap whereInfo = new HashMap(); + /** Containing TableName and AD_Table_ID */ + public HashMap tableInfo = new HashMap(); + + // Display Info + /** Display Qty */ + boolean displayQty = false; + /** Display Source Surrency */ + boolean displaySourceAmt = false; + /** Display Document info */ + boolean displayDocumentInfo = false; + // + String sortBy1 = ""; + String sortBy2 = ""; + String sortBy3 = ""; + String sortBy4 = ""; + // + boolean group1 = false; + boolean group2 = false; + boolean group3 = false; + boolean group4 = false; + + /** Leasing Columns */ + private int m_leadingColumns = 0; + /** UserElement1 Reference */ + private String m_ref1 = null; + /** UserElement2 Reference */ + private String m_ref2 = null; + /** Logger */ + private static CLogger log = CLogger.getCLogger(AcctViewerData.class); + + /** + * Dispose + */ + public void dispose() + { + ASchemas = null; + ASchema = null; + // + whereInfo.clear(); + whereInfo = null; + // + Env.clearWinContext(WindowNo); + } // dispose + + + /************************************************************************** + * Fill Accounting Schema + * @param cb JComboBox to be filled + */ + protected void fillAcctSchema (JComboBox cb) + { + for (int i = 0; i < ASchemas.length; i++) + cb.addItem(new KeyNamePair(ASchemas[i].getC_AcctSchema_ID(), + ASchemas[i].getName())); + } // fillAcctSchema + + /** + * Fill Posting Type + * @param cb JComboBox to be filled + */ + protected void fillPostingType (JComboBox cb) + { + int AD_Reference_ID = 125; + ValueNamePair[] pt = MRefList.getList(AD_Reference_ID, true); + for (int i = 0; i < pt.length; i++) + cb.addItem(pt[i]); + } // fillPostingType + + /** + * Fill Table with + * ValueNamePair (TableName, translatedKeyColumnName) + * and tableInfo with (TableName, AD_Table_ID) + * and select the entry for AD_Table_ID + * + * @param cb JComboBox to be filled + */ + protected void fillTable (JComboBox cb) + { + ValueNamePair select = null; + // + String sql = "SELECT AD_Table_ID, TableName FROM AD_Table t " + + "WHERE EXISTS (SELECT * FROM AD_Column c" + + " WHERE t.AD_Table_ID=c.AD_Table_ID AND c.ColumnName='Posted')" + + " AND IsView='N'"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + { + int id = rs.getInt(1); + String tableName = rs.getString(2); + String name = Msg.translate(Env.getCtx(), tableName+"_ID"); + // + ValueNamePair pp = new ValueNamePair(tableName, name); + cb.addItem(pp); + tableInfo.put (tableName, new Integer(id)); + if (id == AD_Table_ID) + select = pp; + } + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + if (select != null) + cb.setSelectedItem(select); + } // fillTable + + /** + * Fill Org + * + * @param cb JComboBox to be filled + */ + protected void fillOrg (JComboBox cb) + { + KeyNamePair pp = new KeyNamePair(0, ""); + cb.addItem(pp); + String sql = "SELECT AD_Org_ID, Name FROM AD_Org WHERE AD_Client_ID=? ORDER BY Value"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql, null); + pstmt.setInt(1, AD_Client_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + cb.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2))); + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql, e); + } + } // fillOrg + + /** + * Get Button Text + * + * @param tableName table + * @param columnName column + * @param selectSQL sql + * @return Text on button + */ + protected String getButtonText (String tableName, String columnName, String selectSQL) + { + // SELECT () FROM tableName avd WHERE avd. + StringBuffer sql = new StringBuffer ("SELECT ("); + Language language = Env.getLanguage(Env.getCtx()); + sql.append(MLookupFactory.getLookup_TableDirEmbed(language, columnName, "avd")) + .append(") FROM ").append(tableName).append(" avd WHERE avd.").append(selectSQL); + String retValue = "<" + selectSQL + ">"; + try + { + Statement stmt = DB.createStatement(); + ResultSet rs = stmt.executeQuery(sql.toString()); + if (rs.next()) + retValue = rs.getString(1); + rs.close(); + stmt.close(); + } + catch (SQLException e) + { + log.log(Level.SEVERE, sql.toString(), e); + } + return retValue; + } // getButtonText + + /************************************************************************** + + /** + * Create Query and submit + * @return Report Model + */ + protected RModel query() + { + // Set Where Clause + StringBuffer whereClause = new StringBuffer(); + // Add Organization + if (C_AcctSchema_ID != 0) + whereClause.append(RModel.TABLE_ALIAS) + .append(".C_AcctSchema_ID=").append(C_AcctSchema_ID); + + // Posting Type Selected + if (PostingType != null && PostingType.length() > 0) + { + if (whereClause.length() > 0) + whereClause.append(" AND "); + whereClause.append(RModel.TABLE_ALIAS) + .append(".PostingType='").append(PostingType).append("'"); + } + + // + if (documentQuery) + { + if (whereClause.length() > 0) + whereClause.append(" AND "); + whereClause.append(RModel.TABLE_ALIAS).append(".AD_Table_ID=").append(AD_Table_ID) + .append(" AND ").append(RModel.TABLE_ALIAS).append(".Record_ID=").append(Record_ID); + } + else + { + // get values (Queries) + Iterator it = whereInfo.values().iterator(); + while (it.hasNext()) + { + String where = (String)it.next(); + if (where != null && where.length() > 0) // add only if not empty + { + if (whereClause.length() > 0) + whereClause.append(" AND "); + whereClause.append(RModel.TABLE_ALIAS).append(".").append(where); + } + } + if (DateFrom != null || DateTo != null) + { + if (whereClause.length() > 0) + whereClause.append(" AND "); + if (DateFrom != null && DateTo != null) + whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) BETWEEN ") + .append(DB.TO_DATE(DateFrom)).append(" AND ").append(DB.TO_DATE(DateTo)); + else if (DateFrom != null) + whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) >= ") + .append(DB.TO_DATE(DateFrom)); + else // DateTo != null + whereClause.append("TRUNC(").append(RModel.TABLE_ALIAS).append(".DateAcct) <= ") + .append(DB.TO_DATE(DateTo)); + } + // Add Organization + if (AD_Org_ID != 0) + { + if (whereClause.length() > 0) + whereClause.append(" AND "); + whereClause.append(RModel.TABLE_ALIAS).append(".AD_Org_ID=").append(AD_Org_ID); + } + } + + // Set Order By Clause + StringBuffer orderClause = new StringBuffer(); + if (sortBy1.length() > 0) + orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy1); + if (sortBy2.length() > 0) + { + if (orderClause.length() > 0) + orderClause.append(","); + orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy2); + } + if (sortBy3.length() > 0) + { + if (orderClause.length() > 0) + orderClause.append(","); + orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy3); + } + if (sortBy4.length() > 0) + { + if (orderClause.length() > 0) + orderClause.append(","); + orderClause.append(RModel.TABLE_ALIAS).append(".").append(sortBy4); + } + if (orderClause.length() == 0) + orderClause.append(RModel.TABLE_ALIAS).append(".Fact_Acct_ID"); + + RModel rm = getRModel(); + + // Groups + if (group1 && sortBy1.length() > 0) + rm.setGroup(sortBy1); + if (group2 && sortBy2.length() > 0) + rm.setGroup(sortBy2); + if (group3 && sortBy3.length() > 0) + rm.setGroup(sortBy3); + if (group4 && sortBy4.length() > 0) + rm.setGroup(sortBy4); + + // Totals + rm.setFunction("AmtAcctDr", RModel.FUNCTION_SUM); + rm.setFunction("AmtAcctCr", RModel.FUNCTION_SUM); + + rm.query (Env.getCtx(), whereClause.toString(), orderClause.toString()); + + return rm; + } // query + + /** + * Create Report Model (Columns) + * @return Report Model + */ + private RModel getRModel() + { + Properties ctx = Env.getCtx(); + RModel rm = new RModel("Fact_Acct"); + // Add Key (Lookups) + ArrayList keys = createKeyColumns(); + int max = m_leadingColumns; + if (max == 0) + max = keys.size(); + for (int i = 0; i < max; i++) + { + String column = (String)keys.get(i); + if (column != null && column.startsWith("Date")) + rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); + else if (column != null && column.endsWith("_ID")) + rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); + } + // Main Info + rm.addColumn(new RColumn(ctx, "AmtAcctDr", DisplayType.Amount)); + rm.addColumn(new RColumn(ctx, "AmtAcctCr", DisplayType.Amount)); + if (displaySourceAmt) + { + if (!keys.contains("DateTrx")) + rm.addColumn(new RColumn(ctx, "DateTrx", DisplayType.Date)); + rm.addColumn(new RColumn(ctx, "C_Currency_ID", DisplayType.TableDir)); + rm.addColumn(new RColumn(ctx, "AmtSourceDr", DisplayType.Amount)); + rm.addColumn(new RColumn(ctx, "AmtSourceCr", DisplayType.Amount)); + rm.addColumn(new RColumn(ctx, "Rate", DisplayType.Amount, + "CASE WHEN (AmtSourceDr + AmtSourceCr) = 0 THEN 0" + + " ELSE (AmtAcctDr + AmtAcctCr) / (AmtSourceDr + AmtSourceCr) END")); + } + // Remaining Keys + for (int i = max; i < keys.size(); i++) + { + String column = (String)keys.get(i); + if (column != null && column.startsWith("Date")) + rm.addColumn(new RColumn(ctx, column, DisplayType.Date)); + else if (column.startsWith("UserElement")) + { + if (column.indexOf("1") != -1) + rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref1)); + else + rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir, null, 0, m_ref2)); + } + else if (column != null && column.endsWith("_ID")) + rm.addColumn(new RColumn(ctx, column, DisplayType.TableDir)); + } + // Info + if (!keys.contains("DateAcct")) + rm.addColumn(new RColumn(ctx, "DateAcct", DisplayType.Date)); + if (!keys.contains("C_Period_ID")) + rm.addColumn(new RColumn(ctx, "C_Period_ID", DisplayType.TableDir)); + if (displayQty) + { + rm.addColumn(new RColumn(ctx, "C_UOM_ID", DisplayType.TableDir)); + rm.addColumn(new RColumn(ctx, "Qty", DisplayType.Quantity)); + } + if (displayDocumentInfo) + { + rm.addColumn(new RColumn(ctx, "AD_Table_ID", DisplayType.TableDir)); + rm.addColumn(new RColumn(ctx, "Record_ID", DisplayType.ID)); rm.addColumn(new RColumn(ctx, "Description", DisplayType.String)); } if (PostingType == null || PostingType.length() == 0) - rm.addColumn(new RColumn(ctx, RModel.TABLE_ALIAS+".PostingType", DisplayType.List, + rm.addColumn(new RColumn(ctx, "PostingType", DisplayType.List, MFactAcct.POSTINGTYPE_AD_Reference_ID)); return rm; } // createRModel - - /** - * Create the key columns in sequence - * @return List of Key Columns - */ - private ArrayList createKeyColumns() - { - ArrayList columns = new ArrayList(); - m_leadingColumns = 0; - // Sorting Fields - columns.add(sortBy1); // may add "" - if (!columns.contains(sortBy2)) - columns.add(sortBy2); - if (!columns.contains(sortBy3)) - columns.add(sortBy3); - if (!columns.contains(sortBy4)) - columns.add(sortBy4); - - // Add Account Segments - MAcctSchemaElement[] elements = ASchema.getAcctSchemaElements(); - for (int i = 0; i < elements.length; i++) - { - if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) - m_leadingColumns = columns.size(); - // - MAcctSchemaElement ase = elements[i]; - String columnName = ase.getColumnName(); - if (columnName.startsWith("UserElement")) - { - if (columnName.indexOf("1") != -1) - m_ref1 = ase.getDisplayColumnName(); - else - m_ref2 = ase.getDisplayColumnName(); - } - if (!columns.contains(columnName)) - columns.add(columnName); - } - if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) - m_leadingColumns = columns.size(); - return columns; - } // createKeyColumns - -} // AcctViewerData + + /** + * Create the key columns in sequence + * @return List of Key Columns + */ + private ArrayList createKeyColumns() + { + ArrayList columns = new ArrayList(); + m_leadingColumns = 0; + // Sorting Fields + columns.add(sortBy1); // may add "" + if (!columns.contains(sortBy2)) + columns.add(sortBy2); + if (!columns.contains(sortBy3)) + columns.add(sortBy3); + if (!columns.contains(sortBy4)) + columns.add(sortBy4); + + // Add Account Segments + MAcctSchemaElement[] elements = ASchema.getAcctSchemaElements(); + for (int i = 0; i < elements.length; i++) + { + if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) + m_leadingColumns = columns.size(); + // + MAcctSchemaElement ase = elements[i]; + String columnName = ase.getColumnName(); + if (columnName.startsWith("UserElement")) + { + if (columnName.indexOf("1") != -1) + m_ref1 = ase.getDisplayColumnName(); + else + m_ref2 = ase.getDisplayColumnName(); + } + if (!columns.contains(columnName)) + columns.add(columnName); + } + if (m_leadingColumns == 0 && columns.contains("AD_Org_ID") && columns.contains("Account_ID")) + m_leadingColumns = columns.size(); + return columns; + } // createKeyColumns + +} // AcctViewerData diff --git a/client/src/org/compiere/grid/tree/VTreePanel.java b/client/src/org/compiere/grid/tree/VTreePanel.java index c3fe05351f..56002d5b77 100644 --- a/client/src/org/compiere/grid/tree/VTreePanel.java +++ b/client/src/org/compiere/grid/tree/VTreePanel.java @@ -3,16 +3,16 @@ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * 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 * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * + * 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 * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * *****************************************************************************/ package org.compiere.grid.tree; @@ -35,192 +35,179 @@ import org.adempiere.plaf.AdempierePLAF; import org.compiere.apps.*; import org.compiere.model.*; import org.compiere.plaf.*; -import org.compiere.swing.*; -import org.compiere.util.*; - -/** - * Tree Panel displays trees. - *
- * When a node is selected, a propertyChange (NODE_SELECTION) event is fired - *
- *		PropertyChangeListener -
- *			treePanel.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this);
- *			calls: public void propertyChange(PropertyChangeEvent e)
- *  
- * To select a specific node call - * setSelectedNode(NodeID); - * - * @author Jorg Janke - * @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ - */ +import org.compiere.swing.*; +import org.compiere.util.*; + +/** + * Tree Panel displays trees. + *
+ * When a node is selected, a propertyChange (NODE_SELECTION) event is fired + *
+ *		PropertyChangeListener -
+ *			treePanel.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this);
+ *			calls: public void propertyChange(PropertyChangeEvent e)
+ *  
+ * To select a specific node call + * setSelectedNode(NodeID); + * + * @author Jorg Janke + * @version $Id: VTreePanel.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ + */ public final class VTreePanel extends CPanel implements ActionListener, DragGestureListener, DragSourceListener, DropTargetListener { - protected boolean m_lookAndFeelChanged = false; - /** * Tree Panel for browsing and editing of a tree. * Need to call initTree - * @param WindowNo WindowNo - * @param editable if true you can edit it - * @param hasBar has OutlookBar - */ - public VTreePanel(int WindowNo, boolean hasBar, boolean editable) - { - super(); - log.config("Bar=" + hasBar + ", Editable=" + editable); - m_WindowNo = WindowNo; - m_hasBar = hasBar; - m_editable = editable; - - // static init - jbInit(); - if (!hasBar) - { - bar.setPreferredSize(new Dimension(0,0)); - centerSplitPane.setDividerLocation(0); + * @param WindowNo WindowNo + * @param editable if true you can edit it + * @param hasBar has OutlookBar + */ + public VTreePanel(int WindowNo, boolean hasBar, boolean editable) + { + super(); + log.config("Bar=" + hasBar + ", Editable=" + editable); + m_WindowNo = WindowNo; + m_hasBar = hasBar; + m_editable = editable; + + // static init + jbInit(); + if (!hasBar) + { + bar.setPreferredSize(new Dimension(0,0)); + centerSplitPane.setDividerLocation(0); centerSplitPane.setDividerSize(0); popMenuTree.remove(mBarAdd); } - else { + else centerSplitPane.setDividerLocation(80); - UIManager.addPropertyChangeListener(new PropertyChangeListener() { - public void propertyChange(PropertyChangeEvent evt) { - if ("lookAndFeel".equals(evt.getPropertyName())) - m_lookAndFeelChanged = true; - } - - }); - } // base settings if (editable) tree.setDropTarget(dropTarget); - else - { - popMenuTree.remove(mFrom); - popMenuTree.remove(mTo); - } - } // VTreePanel - - /** - * Tree initialization. - * May be called several times - * @param AD_Tree_ID tree to load - * @return true if loaded ok - */ - public boolean initTree (int AD_Tree_ID) - { - log.config("AD_Tree_ID=" + AD_Tree_ID); - // - m_AD_Tree_ID = AD_Tree_ID; - - // Get Tree - MTree vTree = new MTree (Env.getCtx(), AD_Tree_ID, m_editable, true, null); - m_root = vTree.getRoot(); - log.config("root=" + m_root); - m_nodeTableName = vTree.getNodeTableName(); - treeModel = new DefaultTreeModel(m_root, true); - tree.setModel(treeModel); - + else + { + popMenuTree.remove(mFrom); + popMenuTree.remove(mTo); + } + } // VTreePanel + + /** + * Tree initialization. + * May be called several times + * @param AD_Tree_ID tree to load + * @return true if loaded ok + */ + public boolean initTree (int AD_Tree_ID) + { + log.config("AD_Tree_ID=" + AD_Tree_ID); + // + m_AD_Tree_ID = AD_Tree_ID; + + // Get Tree + MTree vTree = new MTree (Env.getCtx(), AD_Tree_ID, m_editable, true, null); + m_root = vTree.getRoot(); + log.config("root=" + m_root); + m_nodeTableName = vTree.getNodeTableName(); + treeModel = new DefaultTreeModel(m_root, true); + tree.setModel(treeModel); + // Shortcut Bar if (m_hasBar) { - toolbar.removeAll(); // remove all existing buttons + bar.removeAll(); // remove all existing buttons Enumeration en = m_root.preorderEnumeration(); while (en.hasMoreElements()) { - MTreeNode nd = (MTreeNode)en.nextElement(); - if (nd.isOnBar()) - addToBar(nd); - } - } - - return true; - } // initTree - - /** Logger */ - private static CLogger log = CLogger.getCLogger(VTreePanel.class); - - private BorderLayout mainLayout = new BorderLayout(); - private JTree tree = new JTree(); - private DefaultTreeModel treeModel; - private DefaultTreeSelectionModel treeSelect = new DefaultTreeSelectionModel(); - private CPanel southPanel = new CPanel(); - private CCheckBox treeExpand = new CCheckBox(); - private CTextField treeSearch = new CTextField(10); - private CLabel treeSearchLabel = new CLabel(); - private JPopupMenu popMenuTree = new JPopupMenu(); - private JPopupMenu popMenuBar = new JPopupMenu(); + MTreeNode nd = (MTreeNode)en.nextElement(); + if (nd.isOnBar()) + addToBar(nd); + } + } + + return true; + } // initTree + + /** Logger */ + private static CLogger log = CLogger.getCLogger(VTreePanel.class); + + private BorderLayout mainLayout = new BorderLayout(); + private JTree tree = new JTree(); + private DefaultTreeModel treeModel; + private DefaultTreeSelectionModel treeSelect = new DefaultTreeSelectionModel(); + private CPanel southPanel = new CPanel(); + private CCheckBox treeExpand = new CCheckBox(); + private CTextField treeSearch = new CTextField(10); + private CLabel treeSearchLabel = new CLabel(); + private JPopupMenu popMenuTree = new JPopupMenu(); + private JPopupMenu popMenuBar = new JPopupMenu(); private CMenuItem mFrom = new CMenuItem(); private CMenuItem mTo = new CMenuItem(); private CPanel bar = new CPanel(); - private JToolBar toolbar = new JToolBar(JToolBar.VERTICAL); private CMenuItem mBarAdd = new CMenuItem(); private CMenuItem mBarRemove = new CMenuItem(); private BorderLayout southLayout = new BorderLayout(); - private JSplitPane centerSplitPane = new JSplitPane(); - private JScrollPane treePane = new JScrollPane(); - private MouseListener mouseListener = new VTreePanel_mouseAdapter(this); - private KeyListener keyListener = new VTreePanel_keyAdapter(this); - - // - private int m_WindowNo; - /** Tree ID */ - private int m_AD_Tree_ID = 0; - /** Table Name for TreeNode */ - private String m_nodeTableName = null; - /** Tree is editable (can move nodes) - also not active shown */ - private boolean m_editable; - /** Tree has a shortcut Bar */ - private boolean m_hasBar; - /** The root node */ - private MTreeNode m_root = null; - - - private MTreeNode m_moveNode; // the node to move - private String m_search = ""; - private Enumeration m_nodeEn; - private MTreeNode m_selectedNode; // the selected model node - private CButton m_buttonSelected; - - /** Property Listener NodeSelected */ - public static final String NODE_SELECTION = "NodeSelected"; - - /** - * Static Component initialization. - *
-	 *  - centerSplitPane
-	 *      - treePane
-	 *          - tree
-	 *      - bar
-	 *  - southPanel
-	 *  
- */ - private void jbInit() - { - this.setLayout(mainLayout); - mainLayout.setVgap(5); - // - // only one node to be selected - treeSelect.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); - tree.setSelectionModel(treeSelect); - // - tree.setEditable(false); // allows to change the text - tree.addMouseListener(mouseListener); + private JSplitPane centerSplitPane = new JSplitPane(); + private JScrollPane treePane = new JScrollPane(); + private MouseListener mouseListener = new VTreePanel_mouseAdapter(this); + private KeyListener keyListener = new VTreePanel_keyAdapter(this); + + // + private int m_WindowNo; + /** Tree ID */ + private int m_AD_Tree_ID = 0; + /** Table Name for TreeNode */ + private String m_nodeTableName = null; + /** Tree is editable (can move nodes) - also not active shown */ + private boolean m_editable; + /** Tree has a shortcut Bar */ + private boolean m_hasBar; + /** The root node */ + private MTreeNode m_root = null; + + + private MTreeNode m_moveNode; // the node to move + private String m_search = ""; + private Enumeration m_nodeEn; + private MTreeNode m_selectedNode; // the selected model node + private CButton m_buttonSelected; + + /** Property Listener NodeSelected */ + public static final String NODE_SELECTION = "NodeSelected"; + + /** + * Static Component initialization. + *
+	 *  - centerSplitPane
+	 *      - treePane
+	 *          - tree
+	 *      - bar
+	 *  - southPanel
+	 *  
+ */ + private void jbInit() + { + this.setLayout(mainLayout); + mainLayout.setVgap(5); + // + // only one node to be selected + treeSelect.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); + tree.setSelectionModel(treeSelect); + // + tree.setEditable(false); // allows to change the text + tree.addMouseListener(mouseListener); tree.addKeyListener(keyListener); tree.setCellRenderer(new VTreeCellRenderer()); treePane.getViewport().add(tree, null); - treePane.setBorder(new ShadowBorder()); - tree.setBorder(BorderFactory.createEmptyBorder()); // treePane.setPreferredSize(new Dimension(50,200)); // tree.setPreferredSize(new Dimension(100,150)); // - treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree")); - treeExpand.setActionCommand("Expand"); - treeExpand.addMouseListener(mouseListener); - treeExpand.addActionListener(this); - // - treeSearchLabel.setText(Msg.getMsg(Env.getCtx(), "TreeSearch") + " "); + treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree")); + treeExpand.setActionCommand("Expand"); + treeExpand.addMouseListener(mouseListener); + treeExpand.addActionListener(this); + // + treeSearchLabel.setText(Msg.getMsg(Env.getCtx(), "TreeSearch") + " "); treeSearchLabel.setLabelFor(treeSearch); treeSearchLabel.setToolTipText(Msg.getMsg(Env.getCtx(), "TreeSearchText")); @@ -228,248 +215,226 @@ public final class VTreePanel extends CPanel treeSearch.addKeyListener(keyListener); southPanel.setLayout(southLayout); southPanel.add(treeExpand, BorderLayout.WEST); - southPanel.add(treeSearchLabel, BorderLayout.CENTER); + southPanel.add(treeSearchLabel, BorderLayout.CENTER); southPanel.add(treeSearch, BorderLayout.EAST); this.add(southPanel, BorderLayout.SOUTH); // - centerSplitPane.setOpaque(false); - toolbar.setOpaque(false); centerSplitPane.add(treePane, JSplitPane.RIGHT); centerSplitPane.add(bar, JSplitPane.LEFT); - centerSplitPane.setBorder(BorderFactory.createEmptyBorder()); - removeSplitPaneBorder(); - this.add(centerSplitPane, BorderLayout.CENTER); // mFrom.setText(Msg.getMsg(Env.getCtx(), "ItemMove")); - mFrom.setActionCommand("From"); - mFrom.addActionListener(this); - mTo.setEnabled(false); - mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert")); + mFrom.setActionCommand("From"); + mFrom.addActionListener(this); + mTo.setEnabled(false); + mTo.setText(Msg.getMsg(Env.getCtx(), "ItemInsert")); mTo.setActionCommand("To"); mTo.addActionListener(this); // + bar.setLayout(new BoxLayout(bar, BoxLayout.Y_AXIS)); bar.setMinimumSize(new Dimension (50,50)); - bar.setBorder(new ShadowBorder()); - bar.setLayout(new FlowLayout()); - ((FlowLayout)bar.getLayout()).setAlignment(FlowLayout.LEFT); - bar.add(toolbar); - toolbar.setLayout(new GridBagLayout()); - toolbar.setFloatable(false); - toolbar.setRollover(true); - toolbar.setBorder(BorderFactory.createEmptyBorder()); mBarAdd.setText(Msg.getMsg(Env.getCtx(), "BarAdd")); mBarAdd.setActionCommand("BarAdd"); - mBarAdd.addActionListener(this); - mBarRemove.setText(Msg.getMsg(Env.getCtx(), "BarRemove")); - mBarRemove.setActionCommand("BarRemove"); - mBarRemove.addActionListener(this); - // - popMenuTree.setLightWeightPopupEnabled(false); - popMenuTree.add(mBarAdd); - popMenuTree.addSeparator(); - popMenuTree.add(mFrom); - popMenuTree.add(mTo); - popMenuBar.setLightWeightPopupEnabled(false); - popMenuBar.add(mBarRemove); + mBarAdd.addActionListener(this); + mBarRemove.setText(Msg.getMsg(Env.getCtx(), "BarRemove")); + mBarRemove.setActionCommand("BarRemove"); + mBarRemove.addActionListener(this); + // + popMenuTree.setLightWeightPopupEnabled(false); + popMenuTree.add(mBarAdd); + popMenuTree.addSeparator(); + popMenuTree.add(mFrom); + popMenuTree.add(mTo); + popMenuBar.setLightWeightPopupEnabled(false); + popMenuBar.add(mBarRemove); } // jbInit - private void removeSplitPaneBorder() { - if (centerSplitPane != null) { - SplitPaneUI splitPaneUI = centerSplitPane.getUI(); - if (splitPaneUI instanceof BasicSplitPaneUI) { - BasicSplitPaneUI basicUI = (BasicSplitPaneUI) splitPaneUI; - basicUI.getDivider().setBorder(BorderFactory.createEmptyBorder()); - } - } - } - /** * Set Divider Location * @param location location (80 default) - */ - public void setDividerLocation(int location) - { - centerSplitPane.setDividerLocation(location); - } // setDividerLocation - - /** - * Get Divider Location - * @return divider location - */ - public int getDividerLocation() - { - return centerSplitPane.getDividerLocation(); - } // getDividerLocation - - - /************************************************************************* - * Drag & Drop - */ - protected DragSource dragSource - = DragSource.getDefaultDragSource(); - protected DropTarget dropTarget - = new DropTarget(tree, DnDConstants.ACTION_MOVE, this, true, null); - protected DragGestureRecognizer recognizer - = dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_MOVE, this); - - - /** - * Drag Gesture Interface ** Start ** - * @param e event - */ - public void dragGestureRecognized(DragGestureEvent e) - { - if (!m_editable) - return; - // - try - { - m_moveNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - } - catch (Exception ex) // nothing selected - { - return; - } - // start moving - StringSelection content = new StringSelection(m_moveNode.toString()); - e.startDrag(DragSource.DefaultMoveDrop, // cursor - content, // Transferable - this); - log.fine( "Drag: " + m_moveNode.toString()); - } // dragGestureRecognized - - - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dragDropEnd(DragSourceDropEvent e) {} - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dragEnter(DragSourceDragEvent e) {} - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dragExit(DragSourceEvent e) {} - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dragOver(DragSourceDragEvent e) {} - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dropActionChanged(DragSourceDragEvent e) {} - - /** - * DropTargetListener interface - * @param e event - */ - public void dragEnter(DropTargetDragEvent e) - { - e.acceptDrag(DnDConstants.ACTION_MOVE); - } - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dropActionChanged(DropTargetDragEvent e) {} - /** - * DragSourceListener interface - noop - * @param e event - */ - public void dragExit(DropTargetEvent e) {} - - - /** - * Drag over ** Between ** - * @param e event - */ - public void dragOver(DropTargetDragEvent e) - { - Point mouseLoc = e.getLocation(); // where are we? - TreePath path = tree.getClosestPathForLocation(mouseLoc.x, mouseLoc.y); - tree.setSelectionPath(path); // show it by selecting - MTreeNode toNode = (MTreeNode)path.getLastPathComponent(); - // - // log.fine( "Move: " + toNode); - if (m_moveNode == null // nothing to move - || toNode == null) // nothing to drop on - e.rejectDrag(); - else - e.acceptDrag(DnDConstants.ACTION_MOVE); - } // dragOver - - - /** - * Drop ** End ** - * @param e event - */ - public void drop(DropTargetDropEvent e) - { - Point mouseLoc = e.getLocation(); // where are we? - TreePath path = tree.getClosestPathForLocation(mouseLoc.x, mouseLoc.y); - tree.setSelectionPath(path); // show it by selecting - MTreeNode toNode = (MTreeNode)path.getLastPathComponent(); - // - log.fine( "Drop: " + toNode); - if (m_moveNode == null // nothing to move - || toNode == null) // nothing to drop on - { - e.rejectDrop(); - return; - } - // - e.acceptDrop(DnDConstants.ACTION_MOVE); - moveNode(m_moveNode, toNode); - - e.dropComplete(true); - m_moveNode = null; - } // drop - - - /** - * Move TreeNode - * @param movingNode The node to be moved - * @param toNode The target node - */ - private void moveNode(MTreeNode movingNode, MTreeNode toNode) - { - log.info(movingNode.toString() + " to " + toNode.toString()); - - if (movingNode == toNode) - return; - - // remove - MTreeNode oldParent = (MTreeNode)movingNode.getParent(); - movingNode.removeFromParent(); - treeModel.nodeStructureChanged(oldParent); - - // insert - MTreeNode newParent; - int index; - if (!toNode.isSummary()) // drop on a child node - { - newParent = (MTreeNode)toNode.getParent(); - index = newParent.getIndex(toNode) + 1; // the next node - } - else // drop on a summary node - { - newParent = toNode; - index = 0; // the first node - } - newParent.insert(movingNode, index); - treeModel.nodeStructureChanged(newParent); - - // *** Save changes to disk - setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + */ + public void setDividerLocation(int location) + { + centerSplitPane.setDividerLocation(location); + } // setDividerLocation + + /** + * Get Divider Location + * @return divider location + */ + public int getDividerLocation() + { + return centerSplitPane.getDividerLocation(); + } // getDividerLocation + + + /************************************************************************* + * Drag & Drop + */ + protected DragSource dragSource + = DragSource.getDefaultDragSource(); + protected DropTarget dropTarget + = new DropTarget(tree, DnDConstants.ACTION_MOVE, this, true, null); + protected DragGestureRecognizer recognizer + = dragSource.createDefaultDragGestureRecognizer(tree, DnDConstants.ACTION_MOVE, this); + + + /** + * Drag Gesture Interface ** Start ** + * @param e event + */ + public void dragGestureRecognized(DragGestureEvent e) + { + if (!m_editable) + return; + // + try + { + m_moveNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + } + catch (Exception ex) // nothing selected + { + return; + } + // start moving + StringSelection content = new StringSelection(m_moveNode.toString()); + e.startDrag(DragSource.DefaultMoveDrop, // cursor + content, // Transferable + this); + log.fine( "Drag: " + m_moveNode.toString()); + } // dragGestureRecognized + + + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dragDropEnd(DragSourceDropEvent e) {} + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dragEnter(DragSourceDragEvent e) {} + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dragExit(DragSourceEvent e) {} + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dragOver(DragSourceDragEvent e) {} + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dropActionChanged(DragSourceDragEvent e) {} + + /** + * DropTargetListener interface + * @param e event + */ + public void dragEnter(DropTargetDragEvent e) + { + e.acceptDrag(DnDConstants.ACTION_MOVE); + } + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dropActionChanged(DropTargetDragEvent e) {} + /** + * DragSourceListener interface - noop + * @param e event + */ + public void dragExit(DropTargetEvent e) {} + + + /** + * Drag over ** Between ** + * @param e event + */ + public void dragOver(DropTargetDragEvent e) + { + Point mouseLoc = e.getLocation(); // where are we? + TreePath path = tree.getClosestPathForLocation(mouseLoc.x, mouseLoc.y); + tree.setSelectionPath(path); // show it by selecting + MTreeNode toNode = (MTreeNode)path.getLastPathComponent(); + // + // log.fine( "Move: " + toNode); + if (m_moveNode == null // nothing to move + || toNode == null) // nothing to drop on + e.rejectDrag(); + else + e.acceptDrag(DnDConstants.ACTION_MOVE); + } // dragOver + + + /** + * Drop ** End ** + * @param e event + */ + public void drop(DropTargetDropEvent e) + { + Point mouseLoc = e.getLocation(); // where are we? + TreePath path = tree.getClosestPathForLocation(mouseLoc.x, mouseLoc.y); + tree.setSelectionPath(path); // show it by selecting + MTreeNode toNode = (MTreeNode)path.getLastPathComponent(); + // + log.fine( "Drop: " + toNode); + if (m_moveNode == null // nothing to move + || toNode == null) // nothing to drop on + { + e.rejectDrop(); + return; + } + // + e.acceptDrop(DnDConstants.ACTION_MOVE); + moveNode(m_moveNode, toNode); + + e.dropComplete(true); + m_moveNode = null; + } // drop + + + /** + * Move TreeNode + * @param movingNode The node to be moved + * @param toNode The target node + */ + private void moveNode(MTreeNode movingNode, MTreeNode toNode) + { + log.info(movingNode.toString() + " to " + toNode.toString()); + + if (movingNode == toNode) + return; + + // remove + MTreeNode oldParent = (MTreeNode)movingNode.getParent(); + movingNode.removeFromParent(); + treeModel.nodeStructureChanged(oldParent); + + // insert + MTreeNode newParent; + int index; + if (!toNode.isSummary()) // drop on a child node + { + newParent = (MTreeNode)toNode.getParent(); + index = newParent.getIndex(toNode) + 1; // the next node + } + else // drop on a summary node + { + newParent = toNode; + index = 0; // the first node + } + newParent.insert(movingNode, index); + treeModel.nodeStructureChanged(newParent); + + // *** Save changes to disk + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Trx trx = Trx.get ("VTreePanel", true); try { @@ -479,12 +444,12 @@ public final class VTreePanel extends CPanel // START TRANSACTION ************** for (int i = 0; i < oldParent.getChildCount(); i++) { - MTreeNode nd = (MTreeNode)oldParent.getChildAt(i); - StringBuffer sql = new StringBuffer("UPDATE "); - sql.append(m_nodeTableName) - .append(" SET Parent_ID=").append(oldParent.getNode_ID()) - .append(", SeqNo=").append(i) - .append(", Updated=SysDate") + MTreeNode nd = (MTreeNode)oldParent.getChildAt(i); + StringBuffer sql = new StringBuffer("UPDATE "); + sql.append(m_nodeTableName) + .append(" SET Parent_ID=").append(oldParent.getNode_ID()) + .append(", SeqNo=").append(i) + .append(", Updated=SysDate") .append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" AND Node_ID=").append(nd.getNode_ID()); log.fine(sql.toString()); @@ -495,13 +460,13 @@ public final class VTreePanel extends CPanel } if (oldParent != newParent) for (int i = 0; i < newParent.getChildCount(); i++) - { - MTreeNode nd = (MTreeNode)newParent.getChildAt(i); - StringBuffer sql = new StringBuffer("UPDATE "); - sql.append(m_nodeTableName) - .append(" SET Parent_ID=").append(newParent.getNode_ID()) - .append(", SeqNo=").append(i) - .append(", Updated=SysDate") + { + MTreeNode nd = (MTreeNode)newParent.getChildAt(i); + StringBuffer sql = new StringBuffer("UPDATE "); + sql.append(m_nodeTableName) + .append(" SET Parent_ID=").append(newParent.getNode_ID()) + .append(", SeqNo=").append(i) + .append(", Updated=SysDate") .append(" WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" AND Node_ID=").append(nd.getNode_ID()); log.fine(sql.toString()); @@ -523,410 +488,405 @@ public final class VTreePanel extends CPanel { trx.rollback(); log.log(Level.SEVERE, "move", e); - ADialog.error(m_WindowNo, this, "TreeUpdateError", e.getLocalizedMessage()); - } - trx.close(); - trx = null; - setCursor(Cursor.getDefaultCursor()); - log.config("complete"); - } // moveNode - - - /*************************************************************************/ - - /** - * Enter Key - * @param e event - */ - protected void keyPressed(KeyEvent e) - { - // *** Tree *** - if (e.getSource() instanceof JTree - || (e.getSource() == treeSearch && e.getModifiers() != 0)) // InputEvent.CTRL_MASK - { - TreePath tp = tree.getSelectionPath(); - if (tp == null) - ADialog.beep(); - else - { - MTreeNode tn = (MTreeNode)tp.getLastPathComponent(); - setSelectedNode(tn); - } - } - - // *** treeSearch *** - else if (e.getSource() == treeSearch) - { - String search = treeSearch.getText(); - boolean found = false; - - // at the end - try from top - if (m_nodeEn != null && !m_nodeEn.hasMoreElements()) - m_search = ""; - - // this is the first time - if (!search.equals(m_search)) - { - // get enumeration of all nodes - m_nodeEn = m_root.preorderEnumeration(); - m_search = search; - } - - // search the nodes - while(!found && m_nodeEn != null && m_nodeEn.hasMoreElements()) - { - MTreeNode nd = (MTreeNode)m_nodeEn.nextElement(); - // compare in upper case - if (nd.toString().toUpperCase().indexOf(search.toUpperCase()) != -1) - { - found = true; - TreePath treePath = new TreePath(nd.getPath()); - tree.setSelectionPath(treePath); - tree.makeVisible(treePath); // expand it - tree.scrollPathToVisible(treePath); - } - } - if (!found) - ADialog.beep(); - } // treeSearch - - } // keyPressed - - - /*************************************************************************/ - - /** - * Mouse clicked - * @param e event - */ - protected void mouseClicked(MouseEvent e) - { - // *** JTree *** - if (e.getSource() instanceof JTree) - { - // Left Double Click - if (SwingUtilities.isLeftMouseButton(e) - && e.getClickCount() > 0) - { - int selRow = tree.getRowForLocation(e.getX(), e.getY()); - if(selRow != -1) - { - MTreeNode tn = (MTreeNode)tree.getPathForLocation - (e.getX(), e.getY()).getLastPathComponent(); - setSelectedNode(tn); - } - } - - // Right Click for PopUp - else if ((m_editable || m_hasBar) - && SwingUtilities.isRightMouseButton(e) - && tree.getSelectionPath() != null) // need select first - { - MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - // if (nd.isLeaf()) // only leaves - { - Rectangle r = tree.getPathBounds(tree.getSelectionPath()); - popMenuTree.show(tree, (int)r.getMaxX(), (int)r.getY()); - } - } - } // JTree - - // *** JButton *** - else if (e.getSource() instanceof JButton) - { - if (SwingUtilities.isRightMouseButton(e)) - { - m_buttonSelected = (CButton)e.getSource(); - popMenuBar.show(m_buttonSelected, e.getX(), e.getY()); - } - } // JButton - - } // mouseClicked - - - /** - * Get currently selected node - * @return MTreeNode - */ - public MTreeNode getSelectedNode() - { - return m_selectedNode; - } // getSelectedNode - - /** - * Search Field - * @return Search Field - */ - public JComponent getSearchField() - { - return treeSearch; - } // getSearchField - - /** - * Set Selection to Node in Event - * @param nodeID Node ID - * @return true if selected - */ - public boolean setSelectedNode (int nodeID) - { - log.config("ID=" + nodeID); - if (nodeID != -1) // new is -1 - return selectID(nodeID, true); // show selection - return false; - } // setSelectedNode - - /** - * Select ID in Tree - * @param nodeID Node ID - * @param show scroll to node - * @return true if selected - */ - private boolean selectID (int nodeID, boolean show) - { - if (m_root == null) - return false; - log.config("NodeID=" + nodeID - + ", Show=" + show + ", root=" + m_root); - // try to find the node - MTreeNode node = m_root.findNode (nodeID); - if (node != null) - { - TreePath treePath = new TreePath(node.getPath()); - log.config("Node=" + node - + ", Path=" + treePath.toString()); - tree.setSelectionPath(treePath); - if (show) - { - tree.makeVisible(treePath); // expand it - tree.scrollPathToVisible(treePath); - } - return true; - } - log.info("Node not found; ID=" + nodeID); - return false; - } // selectID - - - /** - * Set the selected node & initiate all listeners - * @param nd node - */ - private void setSelectedNode (MTreeNode nd) - { - log.config("Node = " + nd); - m_selectedNode = nd; - // - firePropertyChange(NODE_SELECTION, null, nd); - } // setSelectedNode - - - /************************************************************************** - * Node Changed - synchromize Node - * - * @param save true the node was saved (changed/added), false if the row was deleted - * @param keyID the ID of the row changed - * @param name name - * @param description description - * @param isSummary summary node - * @param imageIndicator image indicator - */ - public void nodeChanged (boolean save, int keyID, - String name, String description, boolean isSummary, String imageIndicator) - { - log.config("Save=" + save + ", KeyID=" + keyID - + ", Name=" + name + ", Description=" + description - + ", IsSummary=" + isSummary + ", ImageInd=" + imageIndicator - + ", root=" + m_root); - // if ID==0=root - don't update it - if (keyID == 0) - return; - - // try to find the node - MTreeNode node = m_root.findNode(keyID); - - // Node not found and saved -> new - if (node == null && save) - { - node = new MTreeNode (keyID, 0, name, description, - m_root.getNode_ID(), isSummary, imageIndicator, false, null); - m_root.add (node); - } - - // Node found and saved -> change - else if (node != null && save) - { - node.setName (name); - node.setAllowsChildren(isSummary); - } - - // Node found and not saved -> delete - else if (node != null && !save) - { - MTreeNode parent = (MTreeNode)node.getParent(); - node.removeFromParent(); - node = parent; // select Parent - } - - // Error - else - { - log.log(Level.SEVERE, "Save=" + save + ", KeyID=" + keyID + ", Node=" + node); - node = null; - } - - // Nothing to display - if (node == null) - return; - - // (Re) Display Node - tree.updateUI(); - TreePath treePath = new TreePath(node.getPath()); - tree.setSelectionPath(treePath); - tree.makeVisible(treePath); // expand it - tree.scrollPathToVisible(treePath); - } // nodeChanged - - - /************************************************************************** - * ActionListener - * @param e event - */ - public void actionPerformed(ActionEvent e) - { - // bar button pressed - if (e.getSource() instanceof JButton) - { - // Find Node - don't show - selectID(Integer.parseInt(e.getActionCommand()), false); - // Select it - MTreeNode tn = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - setSelectedNode(tn); - } - - // popup menu commands - else if (e.getSource() instanceof JMenuItem) - { - if (e.getActionCommand().equals("From")) - moveFrom(); - else if (e.getActionCommand().equals("To")) - moveTo(); - else if (e.getActionCommand().equals("BarAdd")) - barAdd(); - else if (e.getActionCommand().equals("BarRemove")) - barRemove(); - } - - else if (e.getSource() instanceof JCheckBox) - { - if (e.getActionCommand().equals("Expand")) - expandTree(); - } - } // actionPerformed - - - /*************************************************************************/ - - /** - * Copy Node into buffer - */ - private void moveFrom() - { - m_moveNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - if (m_moveNode != null) - mTo.setEnabled(true); // enable menu - } // mFrom_actionPerformed - - /** - * Move Node - */ - private void moveTo() - { - mFrom.setEnabled(true); - mTo.setEnabled(false); - if (m_moveNode == null) - return; - - MTreeNode toNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - moveNode(m_moveNode, toNode); - // cleanup - m_moveNode = null; - } // mTo_actionPerformed - - /** - * Add selected TreeNode to Bar - */ - private void barAdd() - { - MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); - if (barDBupdate(true, nd.getNode_ID())) - addToBar(nd); - } // barAdd - - /** - * Add TreeNode to Bar - * @param nd node - */ - private void addToBar(MTreeNode nd) - { - // Only first word of Label - String label = nd.toString().trim(); - int space = label.indexOf(" "); + ADialog.error(m_WindowNo, this, "TreeUpdateError", e.getLocalizedMessage()); + } + trx.close(); + trx = null; + setCursor(Cursor.getDefaultCursor()); + log.config("complete"); + } // moveNode + + + /*************************************************************************/ + + /** + * Enter Key + * @param e event + */ + protected void keyPressed(KeyEvent e) + { + // *** Tree *** + if (e.getSource() instanceof JTree + || (e.getSource() == treeSearch && e.getModifiers() != 0)) // InputEvent.CTRL_MASK + { + TreePath tp = tree.getSelectionPath(); + if (tp == null) + ADialog.beep(); + else + { + MTreeNode tn = (MTreeNode)tp.getLastPathComponent(); + setSelectedNode(tn); + } + } + + // *** treeSearch *** + else if (e.getSource() == treeSearch) + { + String search = treeSearch.getText(); + boolean found = false; + + // at the end - try from top + if (m_nodeEn != null && !m_nodeEn.hasMoreElements()) + m_search = ""; + + // this is the first time + if (!search.equals(m_search)) + { + // get enumeration of all nodes + m_nodeEn = m_root.preorderEnumeration(); + m_search = search; + } + + // search the nodes + while(!found && m_nodeEn != null && m_nodeEn.hasMoreElements()) + { + MTreeNode nd = (MTreeNode)m_nodeEn.nextElement(); + // compare in upper case + if (nd.toString().toUpperCase().indexOf(search.toUpperCase()) != -1) + { + found = true; + TreePath treePath = new TreePath(nd.getPath()); + tree.setSelectionPath(treePath); + tree.makeVisible(treePath); // expand it + tree.scrollPathToVisible(treePath); + } + } + if (!found) + ADialog.beep(); + } // treeSearch + + } // keyPressed + + + /*************************************************************************/ + + /** + * Mouse clicked + * @param e event + */ + protected void mouseClicked(MouseEvent e) + { + // *** JTree *** + if (e.getSource() instanceof JTree) + { + // Left Double Click + if (SwingUtilities.isLeftMouseButton(e) + && e.getClickCount() > 0) + { + int selRow = tree.getRowForLocation(e.getX(), e.getY()); + if(selRow != -1) + { + MTreeNode tn = (MTreeNode)tree.getPathForLocation + (e.getX(), e.getY()).getLastPathComponent(); + setSelectedNode(tn); + } + } + + // Right Click for PopUp + else if ((m_editable || m_hasBar) + && SwingUtilities.isRightMouseButton(e) + && tree.getSelectionPath() != null) // need select first + { + MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + // if (nd.isLeaf()) // only leaves + { + Rectangle r = tree.getPathBounds(tree.getSelectionPath()); + popMenuTree.show(tree, (int)r.getMaxX(), (int)r.getY()); + } + } + } // JTree + + // *** JButton *** + else if (e.getSource() instanceof JButton) + { + if (SwingUtilities.isRightMouseButton(e)) + { + m_buttonSelected = (CButton)e.getSource(); + popMenuBar.show(m_buttonSelected, e.getX(), e.getY()); + } + } // JButton + + } // mouseClicked + + + /** + * Get currently selected node + * @return MTreeNode + */ + public MTreeNode getSelectedNode() + { + return m_selectedNode; + } // getSelectedNode + + /** + * Search Field + * @return Search Field + */ + public JComponent getSearchField() + { + return treeSearch; + } // getSearchField + + /** + * Set Selection to Node in Event + * @param nodeID Node ID + * @return true if selected + */ + public boolean setSelectedNode (int nodeID) + { + log.config("ID=" + nodeID); + if (nodeID != -1) // new is -1 + return selectID(nodeID, true); // show selection + return false; + } // setSelectedNode + + /** + * Select ID in Tree + * @param nodeID Node ID + * @param show scroll to node + * @return true if selected + */ + private boolean selectID (int nodeID, boolean show) + { + if (m_root == null) + return false; + log.config("NodeID=" + nodeID + + ", Show=" + show + ", root=" + m_root); + // try to find the node + MTreeNode node = m_root.findNode (nodeID); + if (node != null) + { + TreePath treePath = new TreePath(node.getPath()); + log.config("Node=" + node + + ", Path=" + treePath.toString()); + tree.setSelectionPath(treePath); + if (show) + { + tree.makeVisible(treePath); // expand it + tree.scrollPathToVisible(treePath); + } + return true; + } + log.info("Node not found; ID=" + nodeID); + return false; + } // selectID + + + /** + * Set the selected node & initiate all listeners + * @param nd node + */ + private void setSelectedNode (MTreeNode nd) + { + log.config("Node = " + nd); + m_selectedNode = nd; + // + firePropertyChange(NODE_SELECTION, null, nd); + } // setSelectedNode + + + /************************************************************************** + * Node Changed - synchromize Node + * + * @param save true the node was saved (changed/added), false if the row was deleted + * @param keyID the ID of the row changed + * @param name name + * @param description description + * @param isSummary summary node + * @param imageIndicator image indicator + */ + public void nodeChanged (boolean save, int keyID, + String name, String description, boolean isSummary, String imageIndicator) + { + log.config("Save=" + save + ", KeyID=" + keyID + + ", Name=" + name + ", Description=" + description + + ", IsSummary=" + isSummary + ", ImageInd=" + imageIndicator + + ", root=" + m_root); + // if ID==0=root - don't update it + if (keyID == 0) + return; + + // try to find the node + MTreeNode node = m_root.findNode(keyID); + + // Node not found and saved -> new + if (node == null && save) + { + node = new MTreeNode (keyID, 0, name, description, + m_root.getNode_ID(), isSummary, imageIndicator, false, null); + m_root.add (node); + } + + // Node found and saved -> change + else if (node != null && save) + { + node.setName (name); + node.setAllowsChildren(isSummary); + } + + // Node found and not saved -> delete + else if (node != null && !save) + { + MTreeNode parent = (MTreeNode)node.getParent(); + node.removeFromParent(); + node = parent; // select Parent + } + + // Error + else + { + log.log(Level.SEVERE, "Save=" + save + ", KeyID=" + keyID + ", Node=" + node); + node = null; + } + + // Nothing to display + if (node == null) + return; + + // (Re) Display Node + tree.updateUI(); + TreePath treePath = new TreePath(node.getPath()); + tree.setSelectionPath(treePath); + tree.makeVisible(treePath); // expand it + tree.scrollPathToVisible(treePath); + } // nodeChanged + + + /************************************************************************** + * ActionListener + * @param e event + */ + public void actionPerformed(ActionEvent e) + { + // bar button pressed + if (e.getSource() instanceof JButton) + { + // Find Node - don't show + selectID(Integer.parseInt(e.getActionCommand()), false); + // Select it + MTreeNode tn = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + setSelectedNode(tn); + } + + // popup menu commands + else if (e.getSource() instanceof JMenuItem) + { + if (e.getActionCommand().equals("From")) + moveFrom(); + else if (e.getActionCommand().equals("To")) + moveTo(); + else if (e.getActionCommand().equals("BarAdd")) + barAdd(); + else if (e.getActionCommand().equals("BarRemove")) + barRemove(); + } + + else if (e.getSource() instanceof JCheckBox) + { + if (e.getActionCommand().equals("Expand")) + expandTree(); + } + } // actionPerformed + + + /*************************************************************************/ + + /** + * Copy Node into buffer + */ + private void moveFrom() + { + m_moveNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + if (m_moveNode != null) + mTo.setEnabled(true); // enable menu + } // mFrom_actionPerformed + + /** + * Move Node + */ + private void moveTo() + { + mFrom.setEnabled(true); + mTo.setEnabled(false); + if (m_moveNode == null) + return; + + MTreeNode toNode = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + moveNode(m_moveNode, toNode); + // cleanup + m_moveNode = null; + } // mTo_actionPerformed + + /** + * Add selected TreeNode to Bar + */ + private void barAdd() + { + MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent(); + if (barDBupdate(true, nd.getNode_ID())) + addToBar(nd); + } // barAdd + + /** + * Add TreeNode to Bar + * @param nd node + */ + private void addToBar(MTreeNode nd) + { + // Only first word of Label + String label = nd.toString().trim(); + int space = label.indexOf(" "); // if (space != -1) // label = label.substring(0, space); - CButton button = new CButton(label); - button.setOpaque(false); - button.setHorizontalAlignment(JButton.LEFT); + CButton button = new CButton(label); // Create the button button.setToolTipText(nd.getDescription()); button.setActionCommand(String.valueOf(nd.getNode_ID())); // button.setMargin(new Insets(0, 0, 0, 0)); button.setIcon(nd.getIcon()); - //button.setBorderPainted(false); + button.setBorderPainted(false); + // button.setFocusPainted(false); button.setRequestFocusEnabled(false); // button.addActionListener(this); button.addMouseListener(mouseListener); // - toolbar.add(button, - new GridBagConstraints(0, GridBagConstraints.RELATIVE, - 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, - GridBagConstraints.HORIZONTAL, new Insets(1,0,1,0), 4,2)); + bar.add(button); bar.validate(); - if (centerSplitPane.getDividerLocation() == -1) centerSplitPane.setDividerLocation(button.getPreferredSize().width); bar.repaint(); - } // addToBar - - /** - * Remove from Bar + } // addToBar + + /** + * Remove from Bar */ private void barRemove() { - toolbar.remove(m_buttonSelected); + bar.remove(m_buttonSelected); bar.validate(); bar.repaint(); barDBupdate(false, Integer.parseInt(m_buttonSelected.getActionCommand())); - } // barRemove - - /** - * Make Bar add/remove persistent - * @param add true if add - otherwise remove - * @param Node_ID Node ID - * @return true if updated - */ - private boolean barDBupdate (boolean add, int Node_ID) - { - int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); - int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Org_ID"); - int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"); - StringBuffer sql = new StringBuffer(); - if (add) - sql.append("INSERT INTO AD_TreeBar " - + "(AD_Tree_ID,AD_User_ID,Node_ID, " - + "AD_Client_ID,AD_Org_ID, " - + "IsActive,Created,CreatedBy,Updated,UpdatedBy)VALUES (") + } // barRemove + + /** + * Make Bar add/remove persistent + * @param add true if add - otherwise remove + * @param Node_ID Node ID + * @return true if updated + */ + private boolean barDBupdate (boolean add, int Node_ID) + { + int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx()); + int AD_Org_ID = Env.getContextAsInt(Env.getCtx(), "#AD_Org_ID"); + int AD_User_ID = Env.getContextAsInt(Env.getCtx(), "#AD_User_ID"); + StringBuffer sql = new StringBuffer(); + if (add) + sql.append("INSERT INTO AD_TreeBar " + + "(AD_Tree_ID,AD_User_ID,Node_ID, " + + "AD_Client_ID,AD_Org_ID, " + + "IsActive,Created,CreatedBy,Updated,UpdatedBy)VALUES (") .append(m_AD_Tree_ID).append(",").append(AD_User_ID).append(",").append(Node_ID).append(",") .append(AD_Client_ID).append(",").append(AD_Org_ID).append(",") .append("'Y',SysDate,").append(AD_User_ID).append(",SysDate,").append(AD_User_ID).append(")"); @@ -934,90 +894,81 @@ public final class VTreePanel extends CPanel else sql.append("DELETE AD_TreeBar WHERE AD_Tree_ID=").append(m_AD_Tree_ID) .append(" AND AD_User_ID=").append(AD_User_ID) - .append(" AND Node_ID=").append(Node_ID); - int no = DB.executeUpdate(sql.toString(), true, null); - return no == 1; - } // barDBupdate - - - /** - * Clicked on Expand All - */ - private void expandTree() - { - if (treeExpand.isSelected()) - { - for (int row = 0; row < tree.getRowCount(); row++) - tree.expandRow(row); - } - else - { - for (int row = 0; row < tree.getRowCount(); row++) - tree.collapseRow(row); + .append(" AND Node_ID=").append(Node_ID); + int no = DB.executeUpdate(sql.toString(), true, null); + return no == 1; + } // barDBupdate + + + /** + * Clicked on Expand All + */ + private void expandTree() + { + if (treeExpand.isSelected()) + { + for (int row = 0; row < tree.getRowCount(); row++) + tree.expandRow(row); + } + else + { + for (int row = 0; row < tree.getRowCount(); row++) + tree.collapseRow(row); } } // expandTree - @Override - public void paint(Graphics g) { - if (m_lookAndFeelChanged) { - m_lookAndFeelChanged = false; - if (m_hasBar) removeSplitPaneBorder(); - } - super.paint(g); - } - } // VTreePanel -/****************************************************************************** - * Mouse Clicked - */ -class VTreePanel_mouseAdapter extends java.awt.event.MouseAdapter -{ - VTreePanel m_adaptee; - - /** - * VTreePanel_mouseAdapter - * @param adaptee - */ - VTreePanel_mouseAdapter(VTreePanel adaptee) - { - m_adaptee = adaptee; - } - - /** - * Mouse Clicked - * @param e - */ - public void mouseClicked(MouseEvent e) - { - m_adaptee.mouseClicked(e); - } -} // VTreePanel_mouseAdapter - -/** - * Key Pressed - */ -class VTreePanel_keyAdapter extends java.awt.event.KeyAdapter -{ - VTreePanel m_adaptee; - - /** - * VTreePanel_keyAdapter - * @param adaptee - */ - VTreePanel_keyAdapter(VTreePanel adaptee) - { - m_adaptee = adaptee; - } - - /** - * Key Pressed - * @param e - */ - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_ENTER) - m_adaptee.keyPressed(e); - } -} // VTreePanel_keyAdapter +/****************************************************************************** + * Mouse Clicked + */ +class VTreePanel_mouseAdapter extends java.awt.event.MouseAdapter +{ + VTreePanel m_adaptee; + + /** + * VTreePanel_mouseAdapter + * @param adaptee + */ + VTreePanel_mouseAdapter(VTreePanel adaptee) + { + m_adaptee = adaptee; + } + + /** + * Mouse Clicked + * @param e + */ + public void mouseClicked(MouseEvent e) + { + m_adaptee.mouseClicked(e); + } +} // VTreePanel_mouseAdapter + +/** + * Key Pressed + */ +class VTreePanel_keyAdapter extends java.awt.event.KeyAdapter +{ + VTreePanel m_adaptee; + + /** + * VTreePanel_keyAdapter + * @param adaptee + */ + VTreePanel_keyAdapter(VTreePanel adaptee) + { + m_adaptee = adaptee; + } + + /** + * Key Pressed + * @param e + */ + public void keyPressed(KeyEvent e) + { + if (e.getKeyCode() == KeyEvent.VK_ENTER) + m_adaptee.keyPressed(e); + } +} // VTreePanel_keyAdapter diff --git a/client/src/org/compiere/minigrid/MiniTable.java b/client/src/org/compiere/minigrid/MiniTable.java index 379d81457b..c098972959 100644 --- a/client/src/org/compiere/minigrid/MiniTable.java +++ b/client/src/org/compiere/minigrid/MiniTable.java @@ -3,620 +3,618 @@ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * * 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 * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.compiere.minigrid; - -import java.awt.*; -import java.math.*; -import java.sql.*; -import java.util.*; -import java.util.logging.*; -import javax.swing.*; -import javax.swing.table.*; -import org.compiere.grid.ed.*; -import org.compiere.model.*; -import org.compiere.swing.*; -import org.compiere.util.*; - -/** - * Mini Table. - * Default Read Only Table for Boolean, String, Number, Timestamp values - *

- * After initializing the Table Model, you need to call setColumnClass, - * add columns via addColumn or in one go prepare the table. - * - * MiniTable mt = new MiniTable(); - * String sql = mt.prepareTable(..); // table defined - * // add where to the sql statement - * ResultSet rs = .. - * mt.loadTable(rs); - * rs.close(); - * - * @author Jorg Janke - * @version $Id: MiniTable.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ - */ -public class MiniTable extends CTable -{ - /** - * Default Constructor - */ - public MiniTable() - { - super(); - // log.config( "MiniTable"); - setCellSelectionEnabled(false); - setRowSelectionAllowed(false); - // Default Editor - this.setCellEditor(new ROCellEditor()); - } // MiniTable - - /** List of R/W columns */ - private ArrayList m_readWriteColumn = new ArrayList(); - /** List of Column Width */ - private ArrayList m_minWidth = new ArrayList(); - - /** Color Column Index of Model */ - private int m_colorColumnIndex = -1; - /** Color Column compare data */ - private Object m_colorDataCompare = Env.ZERO; - - /** Multi Selection mode (default false) */ - private boolean m_multiSelection = false; - - /** Lauout set in prepareTable and used in loadTable */ - private ColumnInfo[] m_layout = null; - /** Logger */ - private static CLogger log = CLogger.getCLogger(MiniTable.class); - - /** - * Size Columns. - * Uses Mimimum Column Size - */ - public void autoSize() - { - long start = System.currentTimeMillis(); - // - final int SLACK = 8; // making sure it fits in a column - final int MAXSIZE = 300; // max size of a column - // - TableModel model = this.getModel(); - int size = model.getColumnCount(); - // for all columns - for (int col = 0; col < size; col++) - { - // Column & minimum width - TableColumn tc = this.getColumnModel().getColumn(col); - int width = 0; - if (m_minWidth.size() > col) - width = ((Integer)m_minWidth.get(col)).intValue(); - // log.config( "Column=" + col + " " + column.getHeaderValue()); - - // Header - TableCellRenderer renderer = tc.getHeaderRenderer(); - if (renderer == null) - renderer = new DefaultTableCellRenderer(); - Component comp = renderer.getTableCellRendererComponent - (this, tc.getHeaderValue(), false, false, 0, 0); - // log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth()); - width = Math.max(width, comp.getPreferredSize().width + SLACK); - - // Cells - int maxRow = Math.min(30, getRowCount()); // first 30 rows - for (int row = 0; row < maxRow; row++) - { - renderer = getCellRenderer(row, col); - comp = renderer.getTableCellRendererComponent - (this, getValueAt(row, col), false, false, row, col); - int rowWidth = comp.getPreferredSize().width + SLACK; - width = Math.max(width, rowWidth); - } - // Width not greater .. - width = Math.min(MAXSIZE, width); - tc.setPreferredWidth(width); - // log.fine( "width=" + width); - } // for all columns - log.finer("Cols=" + size + " - " + (System.currentTimeMillis()-start) + "ms"); - } // autoSize - - - /** - * Is Cell Editable - * @param row row - * @param column column - * @return true if editable - */ - public boolean isCellEditable(int row, int column) - { - // if the first column is a boolean and it is false, it is not editable - if (column != 0 - && getValueAt(row, 0) instanceof Boolean - && !((Boolean)getValueAt(row, 0)).booleanValue()) - return false; - - // is the column RW? - if (m_readWriteColumn.contains(new Integer(column))) - return true; - return false; - } // isCellEditable - - /** - * Set Column to ReadOnly - * @param column column - * @param readOnly read only - */ - public void setColumnReadOnly (int column, boolean readOnly) - { - // Column is ReadWrite - if (m_readWriteColumn.contains(new Integer(column))) - { - // Remove from list - if (readOnly) - { - int size = m_readWriteColumn.size(); - for (int i = 0; i < size; i++) - { - if (((Integer)m_readWriteColumn.get(i)).intValue() == column) - { - m_readWriteColumn.remove(i); - break; - } - } - } // ReadOnly - } - // current column is R/O - ReadWrite - add to list - else if (!readOnly) - m_readWriteColumn.add(new Integer(column)); - } // setColumnReadOnly - - - /************************************************************************** - * Prepare Table and return SQL - * - * @param layout array of column info - * @param from SQL FROM content - * @param where SQL WHERE content - * @param multiSelection multiple selections - * @param tableName table name - * @return SQL - */ - public String prepareTable(ColumnInfo[] layout, - String from, String where, boolean multiSelection, String tableName) - { - m_layout = layout; - m_multiSelection = multiSelection; - // - StringBuffer sql = new StringBuffer ("SELECT "); - // add columns & sql - for (int i = 0; i < layout.length; i++) - { - // create sql - if (i > 0) - sql.append(", "); - sql.append(layout[i].getColSQL()); - // adding ID column - if (layout[i].isKeyPairCol()) - sql.append(",").append(layout[i].getKeyPairColSQL()); - - // add to model - addColumn(layout[i].getColHeader()); - if (layout[i].isColorColumn()) - setColorColumn(i); - if (layout[i].getColClass() == IDColumn.class) - p_keyColumnIndex = i; - } - // set editors (two steps) - for (int i = 0; i < layout.length; i++) - setColumnClass(i, layout[i].getColClass(), layout[i].isReadOnly(), layout[i].getColHeader()); - - sql.append( " FROM ").append(from); - sql.append(" WHERE ").append(where); - - // Table Selection - setRowSelectionAllowed(true); - - // org.compiere.apps.form.VMatch.dynInit calls routine for initial init only - if (from.length() == 0) - return sql.toString(); - // - String finalSQL = MRole.getDefault().addAccessSQL(sql.toString(), - tableName, MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); - log.finest(finalSQL); - return finalSQL; - } // prepareTable - - /** - * Add Table Column. - * after adding a column, you need to set the column classes again - * (DefaultTableModel fires TableStructureChanged, which calls - * JTable.tableChanged .. createDefaultColumnsFromModel - * @param header header + * 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 * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.minigrid; + +import java.awt.*; +import java.math.*; +import java.sql.*; +import java.util.*; +import java.util.logging.*; +import javax.swing.*; +import javax.swing.table.*; +import org.compiere.grid.ed.*; +import org.compiere.model.*; +import org.compiere.swing.*; +import org.compiere.util.*; + +/** + * Mini Table. + * Default Read Only Table for Boolean, String, Number, Timestamp values + *

+ * After initializing the Table Model, you need to call setColumnClass, + * add columns via addColumn or in one go prepare the table. + * + * MiniTable mt = new MiniTable(); + * String sql = mt.prepareTable(..); // table defined + * // add where to the sql statement + * ResultSet rs = .. + * mt.loadTable(rs); + * rs.close(); + * + * @author Jorg Janke + * @version $Id: MiniTable.java,v 1.3 2006/07/30 00:51:28 jjanke Exp $ + */ +public class MiniTable extends CTable +{ + /** + * Default Constructor + */ + public MiniTable() + { + super(); + // log.config( "MiniTable"); + setCellSelectionEnabled(false); + setRowSelectionAllowed(false); + // Default Editor + this.setCellEditor(new ROCellEditor()); + } // MiniTable + + /** List of R/W columns */ + private ArrayList m_readWriteColumn = new ArrayList(); + /** List of Column Width */ + private ArrayList m_minWidth = new ArrayList(); + + /** Color Column Index of Model */ + private int m_colorColumnIndex = -1; + /** Color Column compare data */ + private Object m_colorDataCompare = Env.ZERO; + + /** Multi Selection mode (default false) */ + private boolean m_multiSelection = false; + + /** Lauout set in prepareTable and used in loadTable */ + private ColumnInfo[] m_layout = null; + /** Logger */ + private static CLogger log = CLogger.getCLogger(MiniTable.class); + + /** + * Size Columns. + * Uses Mimimum Column Size + */ + public void autoSize() + { + long start = System.currentTimeMillis(); + // + final int SLACK = 8; // making sure it fits in a column + final int MAXSIZE = 300; // max size of a column + // + TableModel model = this.getModel(); + int size = model.getColumnCount(); + // for all columns + for (int col = 0; col < size; col++) + { + // Column & minimum width + TableColumn tc = this.getColumnModel().getColumn(col); + int width = 0; + if (m_minWidth.size() > col) + width = ((Integer)m_minWidth.get(col)).intValue(); + // log.config( "Column=" + col + " " + column.getHeaderValue()); + + // Header + TableCellRenderer renderer = tc.getHeaderRenderer(); + if (renderer == null) + renderer = new DefaultTableCellRenderer(); + Component comp = renderer.getTableCellRendererComponent + (this, tc.getHeaderValue(), false, false, 0, 0); + // log.fine( "Hdr - preferred=" + comp.getPreferredSize().width + ", width=" + comp.getWidth()); + width = Math.max(width, comp.getPreferredSize().width + SLACK); + + // Cells + int maxRow = Math.min(30, getRowCount()); // first 30 rows + for (int row = 0; row < maxRow; row++) + { + renderer = getCellRenderer(row, col); + comp = renderer.getTableCellRendererComponent + (this, getValueAt(row, col), false, false, row, col); + int rowWidth = comp.getPreferredSize().width + SLACK; + width = Math.max(width, rowWidth); + } + // Width not greater .. + width = Math.min(MAXSIZE, width); + tc.setPreferredWidth(width); + // log.fine( "width=" + width); + } // for all columns + log.finer("Cols=" + size + " - " + (System.currentTimeMillis()-start) + "ms"); + } // autoSize + + + /** + * Is Cell Editable + * @param row row + * @param column column + * @return true if editable + */ + public boolean isCellEditable(int row, int column) + { + // if the first column is a boolean and it is false, it is not editable + if (column != 0 + && getValueAt(row, 0) instanceof Boolean + && !((Boolean)getValueAt(row, 0)).booleanValue()) + return false; + + // is the column RW? + if (m_readWriteColumn.contains(new Integer(column))) + return true; + return false; + } // isCellEditable + + /** + * Set Column to ReadOnly + * @param column column + * @param readOnly read only + */ + public void setColumnReadOnly (int column, boolean readOnly) + { + // Column is ReadWrite + if (m_readWriteColumn.contains(new Integer(column))) + { + // Remove from list + if (readOnly) + { + int size = m_readWriteColumn.size(); + for (int i = 0; i < size; i++) + { + if (((Integer)m_readWriteColumn.get(i)).intValue() == column) + { + m_readWriteColumn.remove(i); + break; + } + } + } // ReadOnly + } + // current column is R/O - ReadWrite - add to list + else if (!readOnly) + m_readWriteColumn.add(new Integer(column)); + } // setColumnReadOnly + + + /************************************************************************** + * Prepare Table and return SQL + * + * @param layout array of column info + * @param from SQL FROM content + * @param where SQL WHERE content + * @param multiSelection multiple selections + * @param tableName table name + * @return SQL + */ + public String prepareTable(ColumnInfo[] layout, + String from, String where, boolean multiSelection, String tableName) + { + m_layout = layout; + m_multiSelection = multiSelection; + // + StringBuffer sql = new StringBuffer ("SELECT "); + // add columns & sql + for (int i = 0; i < layout.length; i++) + { + // create sql + if (i > 0) + sql.append(", "); + sql.append(layout[i].getColSQL()); + // adding ID column + if (layout[i].isKeyPairCol()) + sql.append(",").append(layout[i].getKeyPairColSQL()); + + // add to model + addColumn(layout[i].getColHeader()); + if (layout[i].isColorColumn()) + setColorColumn(i); + if (layout[i].getColClass() == IDColumn.class) + p_keyColumnIndex = i; + } + // set editors (two steps) + for (int i = 0; i < layout.length; i++) + setColumnClass(i, layout[i].getColClass(), layout[i].isReadOnly(), layout[i].getColHeader()); + + sql.append( " FROM ").append(from); + sql.append(" WHERE ").append(where); + + // Table Selection + setRowSelectionAllowed(true); + + // org.compiere.apps.form.VMatch.dynInit calls routine for initial init only + if (from.length() == 0) + return sql.toString(); + // + String finalSQL = MRole.getDefault().addAccessSQL(sql.toString(), + tableName, MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); + log.finest(finalSQL); + return finalSQL; + } // prepareTable + + /** + * Add Table Column. + * after adding a column, you need to set the column classes again + * (DefaultTableModel fires TableStructureChanged, which calls + * JTable.tableChanged .. createDefaultColumnsFromModel + * @param header header */ public void addColumn (String header) { - // log.config( "MiniTable.addColumn", header); - int index = getColumnCount(); if (getModel() instanceof DefaultTableModel) { DefaultTableModel model = (DefaultTableModel)getModel(); - model.addColumn(Util.cleanAmp(header)); - } - else - throw new IllegalArgumentException("Model must be instance of DefaultTableModel"); - } // addColumn - - /** - * Set Column Editor & Renderer to Class. - * (after all columns were added) - * @param index column index - * @param c class of column - determines renderere - * @param readOnly read only flag - */ - public void setColumnClass (int index, Class c, boolean readOnly) - { - setColumnClass(index, c, readOnly, null); - } // setColumnClass - - /** - * Set Column Editor & Renderer to Class - * (after all columns were added) - * Lauout of IDColumn depemds on multiSelection - * @param index column index - * @param c class of column - determines renderere/editors supported: - * IDColumn, Boolean, Double (Quantity), BigDecimal (Amount), Integer, Timestamp, String (default) - * @param readOnly read only flag - * @param header optional header value - */ - public void setColumnClass (int index, Class c, boolean readOnly, String header) - { - // log.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly); - TableColumn tc = getColumnModel().getColumn(index); - if (tc == null) - return; - // Set R/O - setColumnReadOnly(index, readOnly); - - // Header - if (header != null && header.length() > 0) - tc.setHeaderValue(Util.cleanAmp(header)); - - // ID Column & Selection - if (c == IDColumn.class) - { - tc.setCellRenderer(new IDColumnRenderer(m_multiSelection)); - if (m_multiSelection) - tc.setCellEditor(new IDColumnEditor()); - else - tc.setCellEditor(new ROCellEditor()); - m_minWidth.add(new Integer(10)); - tc.setMaxWidth(20); - tc.setPreferredWidth(20); - tc.setResizable(false); - } - // Boolean - else if (c == Boolean.class) - { - tc.setCellRenderer(new CheckRenderer()); - if (readOnly) - tc.setCellEditor(new ROCellEditor()); - else + model.addColumn(Util.cleanAmp(header)); + } + else + throw new IllegalArgumentException("Model must be instance of DefaultTableModel"); + } // addColumn + + /** + * Set Column Editor & Renderer to Class. + * (after all columns were added) + * @param index column index + * @param c class of column - determines renderere + * @param readOnly read only flag + */ + public void setColumnClass (int index, Class c, boolean readOnly) + { + setColumnClass(index, c, readOnly, null); + } // setColumnClass + + /** + * Set Column Editor & Renderer to Class + * (after all columns were added) + * Lauout of IDColumn depemds on multiSelection + * @param index column index + * @param c class of column - determines renderere/editors supported: + * IDColumn, Boolean, Double (Quantity), BigDecimal (Amount), Integer, Timestamp, String (default) + * @param readOnly read only flag + * @param header optional header value + */ + public void setColumnClass (int index, Class c, boolean readOnly, String header) + { + // log.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly); + TableColumn tc = getColumnModel().getColumn(index); + if (tc == null) + return; + // Set R/O + setColumnReadOnly(index, readOnly); + + // Header + if (header != null && header.length() > 0) + tc.setHeaderValue(Util.cleanAmp(header)); + + // ID Column & Selection + if (c == IDColumn.class) + { + tc.setCellRenderer(new IDColumnRenderer(m_multiSelection)); + if (m_multiSelection) + tc.setCellEditor(new IDColumnEditor()); + else + tc.setCellEditor(new ROCellEditor()); + m_minWidth.add(new Integer(10)); + tc.setMaxWidth(20); + tc.setPreferredWidth(20); + tc.setResizable(false); + } + // Boolean + else if (c == Boolean.class) + { + tc.setCellRenderer(new CheckRenderer()); + if (readOnly) + tc.setCellEditor(new ROCellEditor()); + else { CCheckBox check = new CCheckBox(); check.setMargin(new Insets(0,0,0,0)); - check.setHorizontalAlignment(JLabel.CENTER); + check.setHorizontalAlignment(SwingConstants.CENTER); tc.setCellEditor(new DefaultCellEditor(check)); } m_minWidth.add(new Integer(30)); - } - // Date - else if (c == Timestamp.class) - { - tc.setCellRenderer(new VCellRenderer(DisplayType.Date)); - if (readOnly) - tc.setCellEditor(new ROCellEditor()); - else - tc.setCellEditor(new MiniCellEditor(c)); - m_minWidth.add(new Integer(30)); - } - // Amount - else if (c == BigDecimal.class) - { - tc.setCellRenderer(new VCellRenderer(DisplayType.Amount)); - if (readOnly) - { - tc.setCellEditor(new ROCellEditor()); - m_minWidth.add(new Integer(70)); - } - else - { - tc.setCellEditor(new MiniCellEditor(c)); - m_minWidth.add(new Integer(80)); - } - } - // Number - else if (c == Double.class) - { - tc.setCellRenderer(new VCellRenderer(DisplayType.Number)); - if (readOnly) - { - tc.setCellEditor(new ROCellEditor()); - m_minWidth.add(new Integer(70)); - } - else - { - tc.setCellEditor(new MiniCellEditor(c)); - m_minWidth.add(new Integer(80)); - } - } - // Integer - else if (c == Integer.class) - { - tc.setCellRenderer(new VCellRenderer(DisplayType.Integer)); - if (readOnly) - tc.setCellEditor(new ROCellEditor()); - else - tc.setCellEditor(new MiniCellEditor(c)); - m_minWidth.add(new Integer(30)); - } - // String - else - { - tc.setCellRenderer(new VCellRenderer(DisplayType.String)); - if (readOnly) - tc.setCellEditor(new ROCellEditor()); - else - tc.setCellEditor(new MiniCellEditor(String.class)); - m_minWidth.add(new Integer(30)); - } - // log.fine( "Renderer=" + tc.getCellRenderer().toString() + ", Editor=" + tc.getCellEditor().toString()); - } // setColumnClass - - /** - * Clear Table Content - * @param no number of rows - */ - public void setRowCount (int no) - { - if (getModel() instanceof DefaultTableModel) - { - DefaultTableModel model = (DefaultTableModel)getModel(); - model.setRowCount(no); - // log.config( "MiniTable.setRowCount", "rows=" + getRowCount() + ", cols=" + getColumnCount()); - } - else - throw new IllegalArgumentException("Model must be instance of DefaultTableModel"); - } // setRowCount - - - /************************************************************************** - * Load Table from ResultSet - The ResultSet is not closed - * - * @param rs ResultSet with the column layout defined in prepareTable - */ - public void loadTable(ResultSet rs) - { - if (m_layout == null) - throw new UnsupportedOperationException("Layout not defined"); - - // Clear Table - setRowCount(0); - // - try - { - while (rs.next()) - { - int row = getRowCount(); - setRowCount(row+1); - int colOffset = 1; // columns start with 1 - for (int col = 0; col < m_layout.length; col++) - { - Object data = null; - Class c = m_layout[col].getColClass(); - int colIndex = col + colOffset; - if (c == IDColumn.class) - data = new IDColumn(rs.getInt(colIndex)); - else if (c == Boolean.class) - data = new Boolean(rs.getString(colIndex).equals("Y")); - else if (c == Timestamp.class) - data = rs.getTimestamp(colIndex); - else if (c == BigDecimal.class) - data = rs.getBigDecimal(colIndex); - else if (c == Double.class) - data = new Double(rs.getDouble(colIndex)); - else if (c == Integer.class) - data = new Integer(rs.getInt(colIndex)); - else if (c == KeyNamePair.class) - { - String display = rs.getString(colIndex); - int key = rs.getInt(colIndex+1); - data = new KeyNamePair(key, display); - colOffset++; - } - else - { - String s = rs.getString(colIndex); - if (s != null) - data = s.trim(); // problems with NCHAR - } - // store - setValueAt(data, row, col); - // log.fine( "r=" + row + ", c=" + col + " " + m_layout[col].getColHeader(), - // "data=" + data.toString() + " " + data.getClass().getName() + " * " + m_table.getCellRenderer(row, col)); - } - } - } - catch (SQLException e) - { - log.log(Level.SEVERE, "", e); - } - autoSize(); - log.config("Row(rs)=" + getRowCount()); - } // loadTable - - /** - * Load Table from Object Array - * @param pos array of POs - */ - public void loadTable(PO[] pos) - { - if (m_layout == null) - throw new UnsupportedOperationException("Layout not defined"); - - // Clear Table - setRowCount(0); - // - for (int i = 0; i < pos.length; i++) - { - PO myPO = pos[i]; - int row = getRowCount(); - setRowCount(row+1); - - for (int col = 0; col < m_layout.length; col++) - { - String columnName = m_layout[col].getColSQL(); - Object data = myPO.get_Value(columnName); - if (data != null) - { - Class c = m_layout[col].getColClass(); - if (c == IDColumn.class) - data = new IDColumn(((Integer)data).intValue()); - else if (c == Double.class) - data = new Double(((BigDecimal)data).doubleValue()); - } - // store - setValueAt(data, row, col); - } - } - autoSize(); - log.config("Row(array)=" + getRowCount()); - } // loadTable - - - /** - * Get the key of currently selected row based on layout defined in prepareTable - * @return ID if key - */ - public Integer getSelectedRowKey() - { - if (m_layout == null) - throw new UnsupportedOperationException("Layout not defined"); - - int row = getSelectedRow(); - if (row != -1 && p_keyColumnIndex != -1) - { - Object data = getModel().getValueAt(row, p_keyColumnIndex); - if (data instanceof IDColumn) - data = ((IDColumn)data).getRecord_ID(); - if (data instanceof Integer) - return (Integer)data; - } - return null; - } // getSelectedRowKey - - - /************************************************************************** - * Get Layout - * @return Array of ColumnInfo - */ - public ColumnInfo[] getLayoutInfo() - { - return m_layout; - } // getLayout - - /** - * Set Single Selection - * @param multiSelection multiple selections - */ - public void setMultiSelection (boolean multiSelection) - { - m_multiSelection = multiSelection; - } // setMultiSelection - - /** - * Single Selection Table - * @return true if multiple rows can be selected - */ - public boolean isMultiSelection() - { - return m_multiSelection; - } // isMultiSelection - - /** - * Set the Column to determine the color of the row (based on model index) - * @param modelIndex model index - */ - public void setColorColumn (int modelIndex) - { - m_colorColumnIndex = modelIndex; - } // setColorColumn - - /** - * Set ColorColumn comparison criteria - * @param dataCompare data - */ - public void setColorCompare (Object dataCompare) - { - m_colorDataCompare = dataCompare; - } // - - /** - * Get ColorCode for Row. - *

-	 *	If numerical value in compare column is
-	 *		negative = -1,
-	 *      positive = 1,
-	 *      otherwise = 0
-	 *  If Timestamp
-	 *  
- * @param row row - * @return color code - */ - public int getColorCode (int row) - { - if (m_colorColumnIndex == -1) - return 0; - - Object data = getModel().getValueAt(row, m_colorColumnIndex); - int cmp = 0; - - // We need to have a Number - if (data == null) - return 0; - try - { - if (data instanceof Timestamp) - { - if (m_colorDataCompare == null || !(m_colorDataCompare instanceof Timestamp)) - m_colorDataCompare = new Timestamp(System.currentTimeMillis()); - cmp = ((Timestamp)m_colorDataCompare).compareTo((Timestamp)data); - } - else - { - if (m_colorDataCompare == null || !(m_colorDataCompare instanceof BigDecimal)) - m_colorDataCompare = Env.ZERO; - if (!(data instanceof BigDecimal)) - data = new BigDecimal(data.toString()); - cmp = ((BigDecimal)m_colorDataCompare).compareTo((BigDecimal)data); - } - } - catch (Exception e) - { - return 0; - } - if (cmp > 0) - return -1; - if (cmp < 0) - return 1; - return 0; - } // getColorCode - -} // MiniTable + } + // Date + else if (c == Timestamp.class) + { + tc.setCellRenderer(new VCellRenderer(DisplayType.Date)); + if (readOnly) + tc.setCellEditor(new ROCellEditor()); + else + tc.setCellEditor(new MiniCellEditor(c)); + m_minWidth.add(new Integer(30)); + } + // Amount + else if (c == BigDecimal.class) + { + tc.setCellRenderer(new VCellRenderer(DisplayType.Amount)); + if (readOnly) + { + tc.setCellEditor(new ROCellEditor()); + m_minWidth.add(new Integer(70)); + } + else + { + tc.setCellEditor(new MiniCellEditor(c)); + m_minWidth.add(new Integer(80)); + } + } + // Number + else if (c == Double.class) + { + tc.setCellRenderer(new VCellRenderer(DisplayType.Number)); + if (readOnly) + { + tc.setCellEditor(new ROCellEditor()); + m_minWidth.add(new Integer(70)); + } + else + { + tc.setCellEditor(new MiniCellEditor(c)); + m_minWidth.add(new Integer(80)); + } + } + // Integer + else if (c == Integer.class) + { + tc.setCellRenderer(new VCellRenderer(DisplayType.Integer)); + if (readOnly) + tc.setCellEditor(new ROCellEditor()); + else + tc.setCellEditor(new MiniCellEditor(c)); + m_minWidth.add(new Integer(30)); + } + // String + else + { + tc.setCellRenderer(new VCellRenderer(DisplayType.String)); + if (readOnly) + tc.setCellEditor(new ROCellEditor()); + else + tc.setCellEditor(new MiniCellEditor(String.class)); + m_minWidth.add(new Integer(30)); + } + // log.fine( "Renderer=" + tc.getCellRenderer().toString() + ", Editor=" + tc.getCellEditor().toString()); + } // setColumnClass + + /** + * Clear Table Content + * @param no number of rows + */ + public void setRowCount (int no) + { + if (getModel() instanceof DefaultTableModel) + { + DefaultTableModel model = (DefaultTableModel)getModel(); + model.setRowCount(no); + // log.config( "MiniTable.setRowCount", "rows=" + getRowCount() + ", cols=" + getColumnCount()); + } + else + throw new IllegalArgumentException("Model must be instance of DefaultTableModel"); + } // setRowCount + + + /************************************************************************** + * Load Table from ResultSet - The ResultSet is not closed + * + * @param rs ResultSet with the column layout defined in prepareTable + */ + public void loadTable(ResultSet rs) + { + if (m_layout == null) + throw new UnsupportedOperationException("Layout not defined"); + + // Clear Table + setRowCount(0); + // + try + { + while (rs.next()) + { + int row = getRowCount(); + setRowCount(row+1); + int colOffset = 1; // columns start with 1 + for (int col = 0; col < m_layout.length; col++) + { + Object data = null; + Class c = m_layout[col].getColClass(); + int colIndex = col + colOffset; + if (c == IDColumn.class) + data = new IDColumn(rs.getInt(colIndex)); + else if (c == Boolean.class) + data = new Boolean(rs.getString(colIndex).equals("Y")); + else if (c == Timestamp.class) + data = rs.getTimestamp(colIndex); + else if (c == BigDecimal.class) + data = rs.getBigDecimal(colIndex); + else if (c == Double.class) + data = new Double(rs.getDouble(colIndex)); + else if (c == Integer.class) + data = new Integer(rs.getInt(colIndex)); + else if (c == KeyNamePair.class) + { + String display = rs.getString(colIndex); + int key = rs.getInt(colIndex+1); + data = new KeyNamePair(key, display); + colOffset++; + } + else + { + String s = rs.getString(colIndex); + if (s != null) + data = s.trim(); // problems with NCHAR + } + // store + setValueAt(data, row, col); + // log.fine( "r=" + row + ", c=" + col + " " + m_layout[col].getColHeader(), + // "data=" + data.toString() + " " + data.getClass().getName() + " * " + m_table.getCellRenderer(row, col)); + } + } + } + catch (SQLException e) + { + log.log(Level.SEVERE, "", e); + } + autoSize(); + log.config("Row(rs)=" + getRowCount()); + } // loadTable + + /** + * Load Table from Object Array + * @param pos array of POs + */ + public void loadTable(PO[] pos) + { + if (m_layout == null) + throw new UnsupportedOperationException("Layout not defined"); + + // Clear Table + setRowCount(0); + // + for (int i = 0; i < pos.length; i++) + { + PO myPO = pos[i]; + int row = getRowCount(); + setRowCount(row+1); + + for (int col = 0; col < m_layout.length; col++) + { + String columnName = m_layout[col].getColSQL(); + Object data = myPO.get_Value(columnName); + if (data != null) + { + Class c = m_layout[col].getColClass(); + if (c == IDColumn.class) + data = new IDColumn(((Integer)data).intValue()); + else if (c == Double.class) + data = new Double(((BigDecimal)data).doubleValue()); + } + // store + setValueAt(data, row, col); + } + } + autoSize(); + log.config("Row(array)=" + getRowCount()); + } // loadTable + + + /** + * Get the key of currently selected row based on layout defined in prepareTable + * @return ID if key + */ + public Integer getSelectedRowKey() + { + if (m_layout == null) + throw new UnsupportedOperationException("Layout not defined"); + + int row = getSelectedRow(); + if (row != -1 && p_keyColumnIndex != -1) + { + Object data = getModel().getValueAt(row, p_keyColumnIndex); + if (data instanceof IDColumn) + data = ((IDColumn)data).getRecord_ID(); + if (data instanceof Integer) + return (Integer)data; + } + return null; + } // getSelectedRowKey + + + /************************************************************************** + * Get Layout + * @return Array of ColumnInfo + */ + public ColumnInfo[] getLayoutInfo() + { + return m_layout; + } // getLayout + + /** + * Set Single Selection + * @param multiSelection multiple selections + */ + public void setMultiSelection (boolean multiSelection) + { + m_multiSelection = multiSelection; + } // setMultiSelection + + /** + * Single Selection Table + * @return true if multiple rows can be selected + */ + public boolean isMultiSelection() + { + return m_multiSelection; + } // isMultiSelection + + /** + * Set the Column to determine the color of the row (based on model index) + * @param modelIndex model index + */ + public void setColorColumn (int modelIndex) + { + m_colorColumnIndex = modelIndex; + } // setColorColumn + + /** + * Set ColorColumn comparison criteria + * @param dataCompare data + */ + public void setColorCompare (Object dataCompare) + { + m_colorDataCompare = dataCompare; + } // + + /** + * Get ColorCode for Row. + *
+	 *	If numerical value in compare column is
+	 *		negative = -1,
+	 *      positive = 1,
+	 *      otherwise = 0
+	 *  If Timestamp
+	 *  
+ * @param row row + * @return color code + */ + public int getColorCode (int row) + { + if (m_colorColumnIndex == -1) + return 0; + + Object data = getModel().getValueAt(row, m_colorColumnIndex); + int cmp = 0; + + // We need to have a Number + if (data == null) + return 0; + try + { + if (data instanceof Timestamp) + { + if (m_colorDataCompare == null || !(m_colorDataCompare instanceof Timestamp)) + m_colorDataCompare = new Timestamp(System.currentTimeMillis()); + cmp = ((Timestamp)m_colorDataCompare).compareTo((Timestamp)data); + } + else + { + if (m_colorDataCompare == null || !(m_colorDataCompare instanceof BigDecimal)) + m_colorDataCompare = Env.ZERO; + if (!(data instanceof BigDecimal)) + data = new BigDecimal(data.toString()); + cmp = ((BigDecimal)m_colorDataCompare).compareTo((BigDecimal)data); + } + } + catch (Exception e) + { + return 0; + } + if (cmp > 0) + return -1; + if (cmp < 0) + return 1; + return 0; + } // getColorCode + +} // MiniTable diff --git a/webCM/src/main/servlet/org/compiere/cm/request/Request.java b/webCM/src/main/servlet/org/compiere/cm/request/Request.java index 2627c9a2bc..eff45f9e63 100644 --- a/webCM/src/main/servlet/org/compiere/cm/request/Request.java +++ b/webCM/src/main/servlet/org/compiere/cm/request/Request.java @@ -3,10 +3,10 @@ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * 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. + * 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. @@ -15,405 +15,405 @@ *****************************************************************************/ package org.compiere.cm.request; -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Enumeration; -import java.util.Properties; - -import javax.servlet.http.HttpServletRequest; - -import org.compiere.model.MColumn; -import org.compiere.model.MRequest; -import org.compiere.model.MTable; -import org.compiere.model.PO; -import org.compiere.model.X_AD_Reference; -import org.compiere.util.DB; - -/** - * Request Class to create or update Requests. - * - * @author Kai Viiksaar - * @version $Id: Request.java,v 1.3 2006/10/16 11:34:47 comdivision Exp $ - */ -public class Request { - - //Integer values - private final static int i_integer = 11; - private final static int i_id = 13; - private final static int i_table = 18; - private final static int i_tableDirect = 19; - private final static int i_rowID = 26; - private final static int i_searchField = 30; - - //BigDecimal values - private final static int bd_amount = 12; - private final static int bd_floatNumber = 22; - private final static int bd_quantity = 29; - private final static int bd_costsAndPrice = 37; - - //Date values - private final static int d_date = 15; - private final static int d_dateTime = 16; - private final static int d_time = 24; - - //String values - private final static int s_string = 10; - private final static int s_text = 14; - private final static int s_textLong = 36; - private final static int s_list = 17; - private final static int s_location = 21; - private final static int s_binary = 23; - private final static int s_account = 25; - private final static int s_color = 27; - private final static int s_button = 28; - private final static int s_warehousLocator = 31; - private final static int simage = 32; - private final static int s_assignment = 33; - private final static int s_memo = 34; - private final static int s_productAttribute = 35; - - //Boolean values - private final static int b_bool = 20; - - - /** - * Creates a new Request. - * - * @param request - * @param ctx - * @return new Request ID - */ - public static String createRequest(HttpServletRequest request, Properties ctx) { - String l_szTrxName = null; - String l_szReturn = null; - - boolean l_bSuccess = true; - - BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); - - int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); - //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); - int l_nRoleID = getParameterAsInt(request, "AD_Role_ID"); - int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); - int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); - int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); - int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); - int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); - int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); - - int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); - int l_nUserID = getParameterAsInt(request, "AD_User_ID"); - int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); - int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); - int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); - int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); - int l_nProductID = getParameterAsInt(request, "M_Product_ID"); - int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); - int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); - int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); - int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); +import java.math.BigDecimal; +import java.sql.Timestamp; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Enumeration; +import java.util.Properties; + +import javax.servlet.http.HttpServletRequest; + +import org.compiere.model.MColumn; +import org.compiere.model.MRequest; +import org.compiere.model.MTable; +import org.compiere.model.PO; +import org.compiere.model.X_AD_Reference; +import org.compiere.util.DB; + +/** + * Request Class to create or update Requests. + * + * @author Kai Viiksaar + * @version $Id: Request.java,v 1.3 2006/10/16 11:34:47 comdivision Exp $ + */ +public class Request { + + //Integer values + private final static int i_integer = 11; + private final static int i_id = 13; + private final static int i_table = 18; + private final static int i_tableDirect = 19; + private final static int i_rowID = 26; + private final static int i_searchField = 30; + + //BigDecimal values + private final static int bd_amount = 12; + private final static int bd_floatNumber = 22; + private final static int bd_quantity = 29; + private final static int bd_costsAndPrice = 37; + + //Date values + private final static int d_date = 15; + private final static int d_dateTime = 16; + private final static int d_time = 24; + + //String values + private final static int s_string = 10; + private final static int s_text = 14; + private final static int s_textLong = 36; + private final static int s_list = 17; + private final static int s_location = 21; + private final static int s_binary = 23; + private final static int s_account = 25; + private final static int s_color = 27; + private final static int s_button = 28; + private final static int s_warehousLocator = 31; + private final static int simage = 32; + private final static int s_assignment = 33; + private final static int s_memo = 34; + private final static int s_productAttribute = 35; + + //Boolean values + private final static int b_bool = 20; + + + /** + * Creates a new Request. + * + * @param request + * @param ctx + * @return new Request ID + */ + public static String createRequest(HttpServletRequest request, Properties ctx) { + String l_szTrxName = null; + String l_szReturn = null; + + boolean l_bSuccess = true; + + BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); + + int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); + //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); + int l_nRoleID = getParameterAsInt(request, "AD_Role_ID"); + int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); + int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); + int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); + int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); + int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); + int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); + + int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); + int l_nUserID = getParameterAsInt(request, "AD_User_ID"); + int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); + int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); + int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); + int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); + int l_nProductID = getParameterAsInt(request, "M_Product_ID"); + int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); + int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); + int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); + int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); /* - * Durchlauf der Parameter Werte. Dabei werden alle �bergebenen Parameter + * Durchlauf der Parameter Werte. Dabei werden alle übergebenen Parameter * als Columns in der MColumn gesucht und bei einem Treffer diese Werte - * dann �ber set_ValueOfColumn gesetzt + * dann über set_ValueOfColumn gesetzt */ /* MRequest l_newRequest = new MRequest(ctx, 0, l_szTrxName); Enumeration l_eParameterNames = request.getParameterNames(); - MColumn curColumn = null; - - int l_nColumnID = 0; - int l_nRefID = 0; - - while (l_eParameterNames.hasMoreElements()) { - String name = l_eParameterNames.nextElement().toString(); - - l_nColumnID = l_newRequest.get_ColumnIndex(name); - if (l_nColumnID > -1) { - curColumn = new MColumn(ctx, l_nColumnID, l_szTrxName); - l_nRefID = curColumn.getAD_Reference_ID(); - - if (l_nRefID == b_bool) { - l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBool(request, name)); - } else if (l_nRefID == bd_amount || l_nRefID == bd_costsAndPrice || l_nRefID == bd_floatNumber || l_nRefID == bd_quantity) { - l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBD(request, name)); - } else if (l_nRefID == d_date || l_nRefID == d_dateTime || l_nRefID == d_time) { - l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsDate(request, name)); - } else if (l_nRefID == i_id || l_nRefID == i_integer || l_nRefID == i_rowID || l_nRefID == i_searchField || l_nRefID == i_table || l_nRefID == i_table) { - l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsInt(request, name)); - } else { - l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsString(request, name)); - } - } - } - l_bSuccess &= l_newRequest.save(); -*/ - - MRequest newRequest = new MRequest(ctx, 0, l_szTrxName); - - // values for values no fieldgroup - newRequest.setAD_Org_ID(l_nOrgID); - newRequest.setDueType(getParameterAsString(request, "DueType")); - newRequest.setR_RequestType_ID(l_nRReqTypeID); - newRequest.setR_Group_ID(l_nRGroupID); - newRequest.setR_Category_ID(l_nRCategoryID); - newRequest.setR_RequestRelated_ID(l_nRReqRelID); - newRequest.setR_Status_ID(l_nRStatusID); - newRequest.setR_Resolution_ID(l_nRResolID); - newRequest.setPriority(getParameterAsString(request, "Priority")); - newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); - newRequest.setSummary(getParameterAsString(request, "Summary")); - newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); - newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); - - // Mandatory values for fieldgroup Action - newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); - newRequest.setAD_Role_ID(l_nRoleID); - //newRequest.setSalesRep_ID(l_nSalesRepID); - - // values for fieldgroup Reference - newRequest.setC_BPartner_ID(l_nBPartnerID); - newRequest.setAD_User_ID(l_nUserID); - newRequest.setC_Project_ID(l_nProjectID); - newRequest.setA_Asset_ID(l_nAssetID); - newRequest.setC_Order_ID(l_nOrderID); - newRequest.setC_Invoice_ID(l_nInvoiceID); - newRequest.setM_Product_ID(l_nProductID); - newRequest.setC_Payment_ID(l_nPaymentID); - newRequest.setM_InOut_ID(l_nInOutID); - newRequest.setM_RMA_ID(l_nRMAID); - newRequest.setRequestAmt(l_bdAmt); - newRequest.setC_Campaign_ID(l_nCampaignID); - - l_bSuccess &= newRequest.save(); - - if (l_bSuccess) { - try { - DB.commit(true, l_szTrxName); - l_szReturn = "" + newRequest.get_ID(); - } catch (Exception e) { - l_szReturn = e.getMessage(); - } - } - return l_szReturn; - } - - /** - * Updates a Request. - * - * @param request - * @param ctx - * @return - */ - public static String changeRequest(HttpServletRequest request, Properties ctx) { - String l_szTrxName = null; - String l_szReturn = null; - - boolean l_bSuccess = true; - - BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); - - int l_nReqID = getParameterAsInt(request, "R_Request_ID"); - int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); - //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); - int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); - int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); - int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); - int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); - int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); - int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); - - int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); - int l_nUserID = getParameterAsInt(request, "AD_User_ID"); - int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); - int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); - int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); - int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); - int l_nProductID = getParameterAsInt(request, "M_Product_ID"); - int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); - int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); - int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); - int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); - - int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID"); - int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID"); - int l_nActivityID = getParameterAsInt(request, "C_Activity_ID"); - int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID"); - - BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent"); - BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced"); - BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan"); - - Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction"); - Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan"); - Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan"); - Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate"); - Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate"); - - MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName); - - // values for values no fieldgroup - newRequest.setAD_Org_ID(l_nOrgID); - newRequest.setDueType(getParameterAsString(request, "DueType")); - newRequest.setR_RequestType_ID(l_nRReqTypeID); - newRequest.setR_Group_ID(l_nRGroupID); - newRequest.setR_Category_ID(l_nRCategoryID); - newRequest.setR_RequestRelated_ID(l_nRReqRelID); - newRequest.setR_Status_ID(l_nRStatusID); - newRequest.setR_Resolution_ID(l_nRResolID); - newRequest.setPriority(getParameterAsString(request, "Priority")); - newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); - newRequest.setSummary(getParameterAsString(request, "Summary")); - newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); - newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); - - // values for fieldgroup Action - newRequest.setDateNextAction(l_tsDateNextAction); - newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); - newRequest.setR_StandardResponse_ID(l_nResponseID); - newRequest.setR_MailText_ID(l_nMailTextID); - newRequest.setResult(getParameterAsString(request, "Result")); - newRequest.setC_Activity_ID(l_nActivityID); - newRequest.setQtyPlan(l_QtyPlan); - newRequest.setQtySpent(l_QtySpent); - newRequest.setM_ProductSpent_ID(l_nProdSpentID); - newRequest.setQtyInvoiced(l_QtyInvoiced); - newRequest.setDateStartPlan(l_tsDateStartPlan); - newRequest.setDateCompletePlan(l_tsDateCompletePlan); - newRequest.setStartDate(l_tsStartDate); - newRequest.setCloseDate(l_tsCloseDate); - - // values for fieldgroup Reference - newRequest.setC_BPartner_ID(l_nBPartnerID); - newRequest.setAD_User_ID(l_nUserID); - newRequest.setC_Project_ID(l_nProjectID); - newRequest.setA_Asset_ID(l_nAssetID); - newRequest.setC_Order_ID(l_nOrderID); - newRequest.setC_Invoice_ID(l_nInvoiceID); - newRequest.setM_Product_ID(l_nProductID); - newRequest.setC_Payment_ID(l_nPaymentID); - newRequest.setM_InOut_ID(l_nInOutID); - newRequest.setM_RMA_ID(l_nRMAID); - newRequest.setRequestAmt(l_bdAmt); - newRequest.setC_Campaign_ID(l_nCampaignID); - - l_bSuccess &= newRequest.save(); - - if (l_bSuccess) { - try { - DB.commit(true, l_szTrxName); - l_szReturn = "" + newRequest.get_ID(); - } catch (Exception e) { - l_szReturn = e.getMessage(); - } - } - return l_szReturn; - } - - /** - * Returns a Request Parameter as String. - * Removes format characters. - * - * @param request - * @param parameterName - * @return - */ - private static String getParameterAsString(HttpServletRequest request, String parameterName) { - String l_szReturn = new String(""); - - if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { - l_szReturn = request.getParameter(parameterName).toString(); - l_szReturn = l_szReturn.replace("\r",""); - l_szReturn = l_szReturn.replace("\n",""); - } - return l_szReturn; - } - - /** - * Returns a Request Parameter as Integer. - * - * @param request - * @param parameterName - * @return value, 0 if no parameter or parse error - */ - private static int getParameterAsInt(HttpServletRequest request, String parameterName) { - int l_nID = 0; - - if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { - try { - l_nID = Integer.parseInt(request.getParameter(parameterName)); - } catch (Exception e) { - l_nID = 0; - } - } - return l_nID; - } - - /** - * Returns a Request Parameter as BigDecimal. - * - * @param request - * @param parameterName - * @return value, 0 if no parameter or parse error - */ - private static BigDecimal getParameterAsBD(HttpServletRequest request, String parameterName) { - BigDecimal l_bdValue = new BigDecimal(0); - - if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { - try { - String l_szValue = request.getParameter(parameterName); - l_szValue = l_szValue.replace(",", "."); - l_bdValue = new BigDecimal(Float.parseFloat(l_szValue)); - } catch (Exception e) { - l_bdValue = new BigDecimal(0); - } - } - l_bdValue = l_bdValue.setScale(2, BigDecimal.ROUND_CEILING); - return l_bdValue; - } - - /** - * Returns a Parameter as boolean. - * - * @param request - * @param parameterName - * @return true if parameter != null - */ - private static boolean getParameterAsBool(HttpServletRequest request, String parameterName) { - boolean l_bIs = false; - - if (request.getParameter(parameterName) != null) { - l_bIs = true; - } - return l_bIs; - } - - /** - * Returns a Parameter as Timestamp. - * - * @param request - * @param parameterName - * @return Timestamp or null - */ - private static Timestamp getParameterAsDate(HttpServletRequest request, String parameterName) { - Date myDate = new Date(); - SimpleDateFormat ger = new SimpleDateFormat("dd.MM.yyyy"); - long time = 0; - - if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { - try { - myDate = ger.parse(request.getParameter(parameterName).toString()); - time = myDate.getTime(); - } catch (ParseException e) { - return null; - } - return new Timestamp(time); - } - return null; - } -} + MColumn curColumn = null; + + int l_nColumnID = 0; + int l_nRefID = 0; + + while (l_eParameterNames.hasMoreElements()) { + String name = l_eParameterNames.nextElement().toString(); + + l_nColumnID = l_newRequest.get_ColumnIndex(name); + if (l_nColumnID > -1) { + curColumn = new MColumn(ctx, l_nColumnID, l_szTrxName); + l_nRefID = curColumn.getAD_Reference_ID(); + + if (l_nRefID == b_bool) { + l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBool(request, name)); + } else if (l_nRefID == bd_amount || l_nRefID == bd_costsAndPrice || l_nRefID == bd_floatNumber || l_nRefID == bd_quantity) { + l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsBD(request, name)); + } else if (l_nRefID == d_date || l_nRefID == d_dateTime || l_nRefID == d_time) { + l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsDate(request, name)); + } else if (l_nRefID == i_id || l_nRefID == i_integer || l_nRefID == i_rowID || l_nRefID == i_searchField || l_nRefID == i_table || l_nRefID == i_table) { + l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsInt(request, name)); + } else { + l_newRequest.set_ValueOfColumn(l_nColumnID, getParameterAsString(request, name)); + } + } + } + l_bSuccess &= l_newRequest.save(); +*/ + + MRequest newRequest = new MRequest(ctx, 0, l_szTrxName); + + // values for values no fieldgroup + newRequest.setAD_Org_ID(l_nOrgID); + newRequest.setDueType(getParameterAsString(request, "DueType")); + newRequest.setR_RequestType_ID(l_nRReqTypeID); + newRequest.setR_Group_ID(l_nRGroupID); + newRequest.setR_Category_ID(l_nRCategoryID); + newRequest.setR_RequestRelated_ID(l_nRReqRelID); + newRequest.setR_Status_ID(l_nRStatusID); + newRequest.setR_Resolution_ID(l_nRResolID); + newRequest.setPriority(getParameterAsString(request, "Priority")); + newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); + newRequest.setSummary(getParameterAsString(request, "Summary")); + newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); + newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); + + // Mandatory values for fieldgroup Action + newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); + newRequest.setAD_Role_ID(l_nRoleID); + //newRequest.setSalesRep_ID(l_nSalesRepID); + + // values for fieldgroup Reference + newRequest.setC_BPartner_ID(l_nBPartnerID); + newRequest.setAD_User_ID(l_nUserID); + newRequest.setC_Project_ID(l_nProjectID); + newRequest.setA_Asset_ID(l_nAssetID); + newRequest.setC_Order_ID(l_nOrderID); + newRequest.setC_Invoice_ID(l_nInvoiceID); + newRequest.setM_Product_ID(l_nProductID); + newRequest.setC_Payment_ID(l_nPaymentID); + newRequest.setM_InOut_ID(l_nInOutID); + newRequest.setM_RMA_ID(l_nRMAID); + newRequest.setRequestAmt(l_bdAmt); + newRequest.setC_Campaign_ID(l_nCampaignID); + + l_bSuccess &= newRequest.save(); + + if (l_bSuccess) { + try { + DB.commit(true, l_szTrxName); + l_szReturn = "" + newRequest.get_ID(); + } catch (Exception e) { + l_szReturn = e.getMessage(); + } + } + return l_szReturn; + } + + /** + * Updates a Request. + * + * @param request + * @param ctx + * @return + */ + public static String changeRequest(HttpServletRequest request, Properties ctx) { + String l_szTrxName = null; + String l_szReturn = null; + + boolean l_bSuccess = true; + + BigDecimal l_bdAmt = getParameterAsBD(request, "RequestAmt"); + + int l_nReqID = getParameterAsInt(request, "R_Request_ID"); + int l_nOrgID = getParameterAsInt(request, "AD_Org_ID"); + //int l_nSalesRepID = getParameterAsInt(request, "SalesRep_ID"); + int l_nRReqTypeID = getParameterAsInt(request, "R_RequestType_ID"); + int l_nRGroupID = getParameterAsInt(request, "R_Group_ID"); + int l_nRCategoryID = getParameterAsInt(request, "R_Category_ID"); + int l_nRReqRelID = getParameterAsInt(request, "R_RequestRelated_ID"); + int l_nRStatusID = getParameterAsInt(request, "R_Status_ID"); + int l_nRResolID = getParameterAsInt(request, "R_Resolution_ID"); + + int l_nBPartnerID = getParameterAsInt(request, "C_BPartner_ID"); + int l_nUserID = getParameterAsInt(request, "AD_User_ID"); + int l_nProjectID = getParameterAsInt(request, "C_Project_ID"); + int l_nAssetID = getParameterAsInt(request, "A_Asset_ID"); + int l_nOrderID = getParameterAsInt(request, "C_Order_ID"); + int l_nInvoiceID = getParameterAsInt(request, "C_Invoice_ID"); + int l_nProductID = getParameterAsInt(request, "M_Product_ID"); + int l_nPaymentID = getParameterAsInt(request, "C_Payment_ID"); + int l_nInOutID = getParameterAsInt(request, "M_InOut_ID"); + int l_nRMAID = getParameterAsInt(request, "M_RMA_ID"); + int l_nCampaignID = getParameterAsInt(request, "C_Campaign_ID"); + + int l_nResponseID = getParameterAsInt(request, "R_StandardResponse_ID"); + int l_nMailTextID = getParameterAsInt(request, "R_MailText_ID"); + int l_nActivityID = getParameterAsInt(request, "C_Activity_ID"); + int l_nProdSpentID = getParameterAsInt(request, "M_ProductSpent_ID"); + + BigDecimal l_QtySpent = getParameterAsBD(request, "QtySpent"); + BigDecimal l_QtyInvoiced = getParameterAsBD(request, "QtyInvoiced"); + BigDecimal l_QtyPlan = getParameterAsBD(request, "QtyPlan"); + + Timestamp l_tsDateNextAction = getParameterAsDate(request, "DateNextAction"); + Timestamp l_tsDateStartPlan = getParameterAsDate(request, "DateStartPlan"); + Timestamp l_tsDateCompletePlan = getParameterAsDate(request, "DateCompletePlan"); + Timestamp l_tsStartDate = getParameterAsDate(request, "StartDate"); + Timestamp l_tsCloseDate = getParameterAsDate(request, "CloseDate"); + + MRequest newRequest = new MRequest(ctx, l_nReqID, l_szTrxName); + + // values for values no fieldgroup + newRequest.setAD_Org_ID(l_nOrgID); + newRequest.setDueType(getParameterAsString(request, "DueType")); + newRequest.setR_RequestType_ID(l_nRReqTypeID); + newRequest.setR_Group_ID(l_nRGroupID); + newRequest.setR_Category_ID(l_nRCategoryID); + newRequest.setR_RequestRelated_ID(l_nRReqRelID); + newRequest.setR_Status_ID(l_nRStatusID); + newRequest.setR_Resolution_ID(l_nRResolID); + newRequest.setPriority(getParameterAsString(request, "Priority")); + newRequest.setPriorityUser(getParameterAsString(request, "PriorityUser")); + newRequest.setSummary(getParameterAsString(request, "Summary")); + newRequest.setConfidentialType(getParameterAsString(request, "ConfidentialType")); + newRequest.setIsInvoiced(getParameterAsBool(request, "IsInvoiced")); + + // values for fieldgroup Action + newRequest.setDateNextAction(l_tsDateNextAction); + newRequest.setConfidentialTypeEntry(getParameterAsString(request, "ConfidentialTypeEntry")); + newRequest.setR_StandardResponse_ID(l_nResponseID); + newRequest.setR_MailText_ID(l_nMailTextID); + newRequest.setResult(getParameterAsString(request, "Result")); + newRequest.setC_Activity_ID(l_nActivityID); + newRequest.setQtyPlan(l_QtyPlan); + newRequest.setQtySpent(l_QtySpent); + newRequest.setM_ProductSpent_ID(l_nProdSpentID); + newRequest.setQtyInvoiced(l_QtyInvoiced); + newRequest.setDateStartPlan(l_tsDateStartPlan); + newRequest.setDateCompletePlan(l_tsDateCompletePlan); + newRequest.setStartDate(l_tsStartDate); + newRequest.setCloseDate(l_tsCloseDate); + + // values for fieldgroup Reference + newRequest.setC_BPartner_ID(l_nBPartnerID); + newRequest.setAD_User_ID(l_nUserID); + newRequest.setC_Project_ID(l_nProjectID); + newRequest.setA_Asset_ID(l_nAssetID); + newRequest.setC_Order_ID(l_nOrderID); + newRequest.setC_Invoice_ID(l_nInvoiceID); + newRequest.setM_Product_ID(l_nProductID); + newRequest.setC_Payment_ID(l_nPaymentID); + newRequest.setM_InOut_ID(l_nInOutID); + newRequest.setM_RMA_ID(l_nRMAID); + newRequest.setRequestAmt(l_bdAmt); + newRequest.setC_Campaign_ID(l_nCampaignID); + + l_bSuccess &= newRequest.save(); + + if (l_bSuccess) { + try { + DB.commit(true, l_szTrxName); + l_szReturn = "" + newRequest.get_ID(); + } catch (Exception e) { + l_szReturn = e.getMessage(); + } + } + return l_szReturn; + } + + /** + * Returns a Request Parameter as String. + * Removes format characters. + * + * @param request + * @param parameterName + * @return + */ + private static String getParameterAsString(HttpServletRequest request, String parameterName) { + String l_szReturn = new String(""); + + if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { + l_szReturn = request.getParameter(parameterName).toString(); + l_szReturn = l_szReturn.replace("\r",""); + l_szReturn = l_szReturn.replace("\n",""); + } + return l_szReturn; + } + + /** + * Returns a Request Parameter as Integer. + * + * @param request + * @param parameterName + * @return value, 0 if no parameter or parse error + */ + private static int getParameterAsInt(HttpServletRequest request, String parameterName) { + int l_nID = 0; + + if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { + try { + l_nID = Integer.parseInt(request.getParameter(parameterName)); + } catch (Exception e) { + l_nID = 0; + } + } + return l_nID; + } + + /** + * Returns a Request Parameter as BigDecimal. + * + * @param request + * @param parameterName + * @return value, 0 if no parameter or parse error + */ + private static BigDecimal getParameterAsBD(HttpServletRequest request, String parameterName) { + BigDecimal l_bdValue = new BigDecimal(0); + + if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { + try { + String l_szValue = request.getParameter(parameterName); + l_szValue = l_szValue.replace(",", "."); + l_bdValue = new BigDecimal(Float.parseFloat(l_szValue)); + } catch (Exception e) { + l_bdValue = new BigDecimal(0); + } + } + l_bdValue = l_bdValue.setScale(2, BigDecimal.ROUND_CEILING); + return l_bdValue; + } + + /** + * Returns a Parameter as boolean. + * + * @param request + * @param parameterName + * @return true if parameter != null + */ + private static boolean getParameterAsBool(HttpServletRequest request, String parameterName) { + boolean l_bIs = false; + + if (request.getParameter(parameterName) != null) { + l_bIs = true; + } + return l_bIs; + } + + /** + * Returns a Parameter as Timestamp. + * + * @param request + * @param parameterName + * @return Timestamp or null + */ + private static Timestamp getParameterAsDate(HttpServletRequest request, String parameterName) { + Date myDate = new Date(); + SimpleDateFormat ger = new SimpleDateFormat("dd.MM.yyyy"); + long time = 0; + + if (request.getParameter(parameterName) != null && request.getParameter(parameterName) != "") { + try { + myDate = ger.parse(request.getParameter(parameterName).toString()); + time = myDate.getTime(); + } catch (ParseException e) { + return null; + } + return new Timestamp(time); + } + return null; + } +} \ No newline at end of file