From 88dd91f29db846a7c52d6ce290526529d507514d Mon Sep 17 00:00:00 2001 From: vinhpt Date: Wed, 13 May 2009 07:20:24 +0000 Subject: [PATCH] Start point upgrade HTML UI with Adempiere 3.5.3a --- .../org/compiere/www/DisplayTable.java | 28 +- .../main/servlet/org/compiere/www/Test.java | 55 +- .../main/servlet/org/compiere/www/Test2.java | 50 +- .../servlet/org/compiere/www/WAccount.java | 146 +-- .../servlet/org/compiere/www/WAttachment.java | 125 ++- .../main/servlet/org/compiere/www/WChat.java | 23 +- .../main/servlet/org/compiere/www/WError.java | 21 +- .../org/compiere/www/WFieldUpdate.java | 33 +- .../servlet/org/compiere/www/WFilter.java | 72 +- .../main/servlet/org/compiere/www/WForm.java | 39 +- .../main/servlet/org/compiere/www/WHelp.java | 44 +- .../servlet/org/compiere/www/WLocation.java | 126 ++- .../main/servlet/org/compiere/www/WLogin.java | 55 +- .../servlet/org/compiere/www/WLookup.java | 469 +++++----- .../main/servlet/org/compiere/www/WMenu.java | 76 +- .../servlet/org/compiere/www/WProcess.java | 197 ++-- .../servlet/org/compiere/www/WProcessCtl.java | 50 +- .../servlet/org/compiere/www/WReport.java | 6 +- .../main/servlet/org/compiere/www/WStart.java | 22 +- .../servlet/org/compiere/www/WStatus.java | 23 +- .../main/servlet/org/compiere/www/WTask.java | 35 +- .../main/servlet/org/compiere/www/WTest.java | 23 +- .../org/compiere/www/WValuePreference.java | 6 +- .../servlet/org/compiere/www/WWindow.java | 265 ++++-- .../org/compiere/www/WWindowStatus.java | 113 ++- .../servlet/org/compiere/www/WWorkflow.java | 877 +++++++++++++++++- .../main/servlet/org/compiere/www/WZoom.java | 30 +- .../servlet/org/compiere/www/WebField.java | 73 +- 28 files changed, 1777 insertions(+), 1305 deletions(-) diff --git a/serverApps/src/main/servlet/org/compiere/www/DisplayTable.java b/serverApps/src/main/servlet/org/compiere/www/DisplayTable.java index a723c103fd..41ae857e68 100644 --- a/serverApps/src/main/servlet/org/compiere/www/DisplayTable.java +++ b/serverApps/src/main/servlet/org/compiere/www/DisplayTable.java @@ -15,39 +15,21 @@ * or via info@compiere.org or http://www.compiere.org/license.html * *****************************************************************************/ package org.compiere.www; - - -/** - * Display Table Information - * - * @author Jorg Janke - * @version $Id: DisplayTable.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class DisplayTable { - /** - * DisplayTable - */ public DisplayTable (String tableName, String columnName) { - } // DisplayTable - + } public String[] getQueryLabels() { return null; - } // getQueryNames - + } public String[] getQueryFields() { return null; - } // getQueryFields - + } public String[] getResultLabels() { return null; - } // getResultLabels - - - - -} // DisplayTable + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/Test.java b/serverApps/src/main/servlet/org/compiere/www/Test.java index d0992505d4..df53905a6b 100644 --- a/serverApps/src/main/servlet/org/compiere/www/Test.java +++ b/serverApps/src/main/servlet/org/compiere/www/Test.java @@ -16,64 +16,29 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; - -/** - * Test Servlet - * - * @author Jorg Janke - * @version $Id: Test.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; public class Test extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -8474219907861637179L; - - - /** - * Initialize global variables - */ public void init(ServletConfig config) throws ServletException { super.init(config); if (!WebEnv.initWeb(config)) throw new ServletException("Test.init"); - } // init - - /** - * Process the HTTP Get request - */ + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("Get Request Test"); - // - WebUtil.createResponse(request, response, this, null, doc, false); - } // doGet - - - /** - * Process the HTTP Post request - */ + WebUtil.createResponse(request, response, this, null, doc, true); + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("Post Request Test"); - // - WebUtil.createResponse(request, response, this, null, doc, false); - } // doPost - -} // Test + WebUtil.createResponse(request, response, this, null, doc, true); + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/Test2.java b/serverApps/src/main/servlet/org/compiere/www/Test2.java index 3036131215..a77523d715 100644 --- a/serverApps/src/main/servlet/org/compiere/www/Test2.java +++ b/serverApps/src/main/servlet/org/compiere/www/Test2.java @@ -16,60 +16,28 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; - -/** - * Test Servlet 2 - * - * @author Jorg Janke - * @version $Id: Test2.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class Test2 extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -6839830507472511719L; - - - /** - * Initialize global variables - */ public void init(ServletConfig config) throws ServletException { super.init(config); WebEnv.initWeb(config); - } // init - - /** - * Process the HTTP Get request - */ + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { RequestDispatcher dispatcher = request.getRequestDispatcher("/Test"); dispatcher.forward(request, response); - } // doGet - - - /** - * Process the HTTP Post request - */ + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("Get Request Test2"); // - WebUtil.createResponse(request, response, this, null, doc, false); - } // doPost + WebUtil.createResponse(request, response, this, null, doc, true); + } -} // Test2 +} diff --git a/serverApps/src/main/servlet/org/compiere/www/WAccount.java b/serverApps/src/main/servlet/org/compiere/www/WAccount.java index 8122df7e51..78dca5dfff 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WAccount.java +++ b/serverApps/src/main/servlet/org/compiere/www/WAccount.java @@ -34,6 +34,7 @@ import org.apache.ecs.xhtml.th; import org.apache.ecs.xhtml.tr; import org.compiere.model.GridField; import org.compiere.model.Lookup; +import org.compiere.model.MField; import org.compiere.util.CLogger; import org.compiere.util.KeyNamePair; import org.compiere.util.Msg; @@ -42,166 +43,86 @@ import org.compiere.util.WebEnv; import org.compiere.util.WebSessionCtx; import org.compiere.util.WebUtil; -/** - * WAccount Servlet. - *

- * The servlet is invoked by a parent window via - * - * WAccount?FormName=formName%ColumnName=columnName - * - * and assumes that in the opening window/form there are two fields - * - * opener.document.formName.columnName - The (hidden) field for the ID - * opener.document.formName.columnName_D - The display field for the value - * - * When selecting an entry, the window is closed and the value of the two fields set. - * - * @author Jorg Janke - * @version $Id: WAccount.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class WAccount extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 7932467581955114222L; + private static final String FIELD_NAME = "FieldName"; + private static final String FIELD_VALUE = "FieldValue"; + private static final String P_Command = "PCommand"; + private static final String P_FORM_NAME = "PForm"; - /** - * Initialize global variables - * - * @param config - * @throws ServletException - */ public void init(ServletConfig config) throws ServletException { super.init(config); if (!WebEnv.initWeb(config)) throw new ServletException("WAccount.init"); - } // init - - /** Logger */ + } private static CLogger log = CLogger.getCLogger(WAccount.class); - - /** - * Process the HTTP Get request - initial Start - * Needs to have parameters FormName and ColumnName - * - * @param request - * @param response - * @throws ServletException - * @throws IOException - */ public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - log.config("WAccount.doGet"); - WebSessionCtx wsc = WebSessionCtx.get(request); + log.config( "WAccount.doGet"); + WebSessionCtx wsc = WebSessionCtx.get(request); WWindowStatus ws = WWindowStatus.get(request); if (wsc == null || ws == null) { WebUtil.createTimeoutPage(request, response, this, null); return; } - // Get Mandatory Parameters - String formName = WebUtil.getParameter (request, "FormName"); String columnName = WebUtil.getParameter (request, "ColumnName"); - // GridField mField = ws.curTab.getField(columnName); - //Modified by Rob Klein 4/29/07 - log.config("FormName=" + formName + ", ColumnName=" + columnName + ", MField=" + mField.toString()); - if (mField == null || columnName == null || columnName.equals("")) + log.config(" ColumnName=" + columnName + ", MField=" + mField.toString()); + if (mField == null || columnName == null || columnName.equals("")) { - WebUtil.createTimeoutPage(request, response, this, + WebUtil.createTimeoutPage(request, response, this, Msg.getMsg(wsc.ctx, "ParameterMissing")); return; } - // Object value = ws.curTab.getValue(columnName); - String target = "opener.document." + formName + "." + columnName; - String targetBase = "'" + columnName; - //Modifeid by Rob Klein 4/229/07 - // Create Document - WebDoc doc = WebDoc.createPopup (mField.getHeader()); + String target = "opener.document.WForm." + columnName; + + WebDoc doc = WebDoc.create (mField.getHeader()); body body = doc.getBody(); body.setOnBlur("self.focus();"); - body.addElement(fillTable(ws, mField, targetBase)); - //Modified by Rob Klein 4/29/07 - // Reset, Cancel + body.addElement(fillTable(ws, mField, target)); + button reset = new button(); - reset.addElement("Reset"); // translate - reset.setOnClick(targetBase + "F.value='';" + targetBase + "D.value='';self.close();"); + reset.addElement("Reset"); + reset.setOnClick(target + "D.value='';" + target + "F.value='';window.close();"); button cancel = new button(); - cancel.addElement("Cancel"); // translate - cancel.setOnClick("self.close();return false;"); + cancel.addElement("Cancel"); + cancel.setOnClick("window.close();"); body.addElement(new p(AlignType.RIGHT) .addElement(reset) .addElement(" ") .addElement(cancel)); - // - // log.fine( doc.toString()); - WebUtil.createResponse (request, response, this, null, doc, false); - } // doGet - - - /** - * Process the HTTP Post request - perform doGet - * @param request - * @param response - * @throws ServletException - * @throws IOException - */ + WebUtil.createResponse (request, response, this, null, doc, true); + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.config( "WAccount.doPost"); doGet(request, response); - } // doPost - - - /*************************************************************************/ - - /** - * Fill Table (Generic) - * - * @param ws WindowStatus - * @param mField the Field - * @param target target field string - * @return Table with selection - */ + } private table fillTable (WWindowStatus ws, GridField mField, String target) { table table = new table("1"); - //Modified by Rob klein 4/29/07 - table.setClass("table-autosort table-autostripe table-stripeclass:alternate"); - table.addElement(""); tr line = new tr(); - line.addElement(new th(" ")).addElement(new th(Msg.translate(ws.ctx, "Name")).setClass("table-sortable:default")); + line.addElement(new th(" ")).addElement(new th(Msg.translate(ws.ctx, "Name"))); table.addElement(line); - table.addElement(""); - table.addElement(""); - - // Fill & list options + Lookup lookup = mField.getLookup(); - lookup.fillComboBox(mField.isMandatory(false), true, true, true); // no context check + lookup.fillComboBox(mField.isMandatory(false), true, true, true); int size = lookup.getSize(); for (int i = 0; i < size; i++) { Object lValue = lookup.getElementAt(i); if (!(lValue != null && lValue instanceof KeyNamePair)) continue; - // - // log.fine( lValue.toString()); KeyNamePair np = (KeyNamePair)lValue; button button = new button(); button.addElement(">"); - //Modified by Rob Klein 4/29/07 - StringBuffer script = new StringBuffer(); - script - //.append("';closePopup();") - .append("startUpdate(").append(target).append("F',") - .append(target).append("D','").append(np.getKey()).append("',") - .append(target).append("F','").append(np.getName()) - .append("');return false;"); - button.setOnClick(script.toString()); - // + StringBuffer script = new StringBuffer(target); + script.append("D.value='").append(np.getKey()).append("';") + .append(target).append("F.value='").append(np.getName()).append("';window.close();"); + button.setOnClick(script.toString()); line = new tr(); line.addElement(new td(button)); String name = np.getName(); @@ -210,10 +131,7 @@ public class WAccount extends HttpServlet line.addElement(new td(name)); table.addElement(line); } - // Restore lookup.fillComboBox(true); - table.addElement(""); return table; - } // fillTable - -} // WAccount + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WAttachment.java b/serverApps/src/main/servlet/org/compiere/www/WAttachment.java index a9eb8ecb51..06902ef8ac 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WAttachment.java +++ b/serverApps/src/main/servlet/org/compiere/www/WAttachment.java @@ -16,49 +16,24 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.util.Properties; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.ecs.AlignType; -import org.apache.ecs.xhtml.a; -import org.apache.ecs.xhtml.br; -import org.apache.ecs.xhtml.form; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.label; -import org.apache.ecs.xhtml.p; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.textarea; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.MAttachment; -import org.compiere.model.MAttachmentEntry; -import org.compiere.util.CLogger; -import org.compiere.util.FileUpload; -import org.compiere.util.Msg; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; +import java.io.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.ecs.*; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.util.*; /** * HTML UI Attachment * * @author Jorg Janke - * @version $Id: WAttachment.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WAttachment.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WAttachment extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -4241116889907930155L; /** Logger */ private static CLogger log = CLogger.getCLogger(WAttachment.class); @@ -77,6 +52,7 @@ public class WAttachment extends HttpServlet public static final String P_ATTACHMENT_INDEX = "AttachmentIndex"; public static final String P_TEXTMSG = "TextMsg"; + private String m_error; /** * Process the HTTP Get request. @@ -99,20 +75,26 @@ public class WAttachment extends HttpServlet } else { - String error = null; + m_error = null; int AD_Attachment_ID = WebUtil.getParameterAsInt(request, P_Attachment_ID); if (AD_Attachment_ID != 0) { int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX); if (attachmentIndex != 0) { - error = streamAttachment (AD_Attachment_ID, attachmentIndex, response, ws); - if (error == null) + m_error = streamAttachment (AD_Attachment_ID, attachmentIndex, response, ws); + if (m_error == null) return; } } - doc = createPage (ws.ctx, ws.curTab.getAD_AttachmentID(), - ws.curTab.getAD_Table_ID(), ws.curTab.getRecord_ID(), error); + + MAttachment attachment = null; + if (AD_Attachment_ID != 0) + attachment = new MAttachment(ws.ctx, ws.curTab.getAD_AttachmentID(), null); + else + attachment = new MAttachment (ws.ctx, ws.curTab.getAD_Table_ID(), ws.curTab.getRecord_ID(), null); + + doc = createPage (ws.ctx, attachment, m_error); } // WebUtil.createResponse(request, response, this, null, doc, false); @@ -137,9 +119,8 @@ public class WAttachment extends HttpServlet doc = WebDoc.create ("Help - No Context"); else { - String error = processPost (request, response, ws); - doc = createPage (ws.ctx, ws.curTab.getAD_AttachmentID(), - ws.curTab.getAD_Table_ID(), ws.curTab.getRecord_ID(), error); + MAttachment attachment = processPost (request, response, ws); + doc = createPage (ws.ctx, attachment, m_error); } // WebUtil.createResponse(request, response, this, null, doc, false); @@ -151,11 +132,10 @@ public class WAttachment extends HttpServlet * @param AD_Attachment_ID id for existing attachment * @param AD_Table_ID table for new attachment * @param Record_ID record for new attachment - * @param error optional error message + * @param m_error optional m_error message * @return WebDoc */ - private WebDoc createPage (Properties ctx, int AD_Attachment_ID, - int AD_Table_ID, int Record_ID, String error) + private WebDoc createPage (Properties ctx, MAttachment attachment, String error) { WebDoc doc = WebDoc.createPopup (Msg.translate(ctx, "AD_Attachment_ID")); table table = doc.getTable(); @@ -168,11 +148,6 @@ public class WAttachment extends HttpServlet new p(error, AlignType.LEFT).setClass("Cerror")))); // window.css } - MAttachment attachment = null; - if (AD_Attachment_ID != 0) - attachment = new MAttachment(ctx, AD_Attachment_ID, null); - else - attachment = new MAttachment (ctx, AD_Table_ID, Record_ID, null); // tr tr = new tr(); td left = new td("popupCenter", AlignType.LEFT, AlignType.TOP, false, @@ -182,9 +157,9 @@ public class WAttachment extends HttpServlet // Text Message Update form textMsg = new form("WAttachment"); - textMsg.addElement(new input (input.TYPE_HIDDEN, P_Attachment_ID, AD_Attachment_ID)); - textMsg.addElement(new input (input.TYPE_HIDDEN, "AD_Table_ID", AD_Table_ID)); - textMsg.addElement(new input (input.TYPE_HIDDEN, "Record_ID", Record_ID)); + textMsg.addElement(new input (input.TYPE_HIDDEN, P_Attachment_ID, attachment.getAD_Attachment_ID())); + textMsg.addElement(new input (input.TYPE_HIDDEN, "AD_Table_ID", attachment.getAD_Table_ID())); + textMsg.addElement(new input (input.TYPE_HIDDEN, "Record_ID", attachment.getRecord_ID())); textarea msg = new textarea(P_TEXTMSG, 5, 40); msg.addElement(attachment.getTextMsg()); textMsg.addElement(msg); @@ -211,7 +186,7 @@ public class WAttachment extends HttpServlet MAttachmentEntry entry = entries[i]; if (i > 0) p.addElement(" - "); - String url = "WAttachment?" + P_Attachment_ID + "=" + AD_Attachment_ID + String url = "WAttachment?" + P_Attachment_ID + "=" + attachment.getAD_Attachment_ID() + "&" + P_ATTACHMENT_INDEX + "=" + entry.getIndex(); p.addElement(new a(url, null, a.TARGET_BLANK, entry.getName())); } @@ -219,9 +194,9 @@ public class WAttachment extends HttpServlet // Upload form upload = FileUpload.createForm("WAttachment"); - upload.addElement(new input (input.TYPE_HIDDEN, P_Attachment_ID, AD_Attachment_ID)); - upload.addElement(new input (input.TYPE_HIDDEN, "AD_Table_ID", AD_Table_ID)); - upload.addElement(new input (input.TYPE_HIDDEN, "Record_ID", Record_ID)); + upload.addElement(new input (input.TYPE_HIDDEN, P_Attachment_ID, attachment.getAD_Attachment_ID())); + upload.addElement(new input (input.TYPE_HIDDEN, "AD_Table_ID", attachment.getAD_Table_ID())); + upload.addElement(new input (input.TYPE_HIDDEN, "Record_ID", attachment.getRecord_ID())); right.addElement(upload); // tr.addElement(left); @@ -242,7 +217,7 @@ public class WAttachment extends HttpServlet * @param attachmentIndex index * @param response response * @param ws status - * @return error message + * @return m_error message */ private String streamAttachment (int AD_Attachment_ID, int attachmentIndex, HttpServletResponse response, WWindowStatus ws) @@ -274,9 +249,9 @@ public class WAttachment extends HttpServlet * Upload Attachment Entry * @param request request * @param response response - * @return error message + * @return m_error message */ - private String processPost (HttpServletRequest request, + private MAttachment processPost (HttpServletRequest request, HttpServletResponse response, WWindowStatus ws) { int AD_Attachment_ID = 0; @@ -296,11 +271,11 @@ public class WAttachment extends HttpServlet else { upload = new FileUpload(request); - String error = upload.getError(); - if (error != null) + m_error = upload.getError(); + if (m_error != null) { - log.warning("pocessPost - " + error); - return error; + log.warning("pocessPost - " + m_error); + return null; } AD_Attachment_ID = upload.getParameterAsInt(P_Attachment_ID); AD_Table_ID = upload.getParameterAsInt("AD_Table_ID"); @@ -312,11 +287,15 @@ public class WAttachment extends HttpServlet + " - Upload=" + upload); // Check if you own the attachment - if (ws.curTab.getAD_AttachmentID() != AD_Attachment_ID) - return "Your Attachment not found"; + if (ws.curTab.getAD_AttachmentID() != AD_Attachment_ID) { + m_error = "Your Attachment not found"; + return null; + } // Check if we can save - if (AD_Attachment_ID != 0 && Record_ID == 0) - return "Need to save record first"; + if (AD_Attachment_ID != 0 && Record_ID == 0) { + m_error = "Need to save record first"; + return null; + } MAttachment attachment = null; if (AD_Attachment_ID == 0) @@ -335,11 +314,13 @@ public class WAttachment extends HttpServlet // Save and update if (attachment.save()) ws.curTab.loadAttachments(); // update Tab - else - return "Attachment not saved"; + else { + m_error = "Attachment not saved"; + return null; + } + + return attachment; - // OK - return null; } // processPost diff --git a/serverApps/src/main/servlet/org/compiere/www/WChat.java b/serverApps/src/main/servlet/org/compiere/www/WChat.java index b495e057b5..8b41f52abc 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WChat.java +++ b/serverApps/src/main/servlet/org/compiere/www/WChat.java @@ -16,13 +16,10 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; +import java.io.*; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.*; +import javax.servlet.http.*; import org.apache.ecs.AlignType; import org.apache.ecs.Element; @@ -35,27 +32,17 @@ import org.apache.ecs.xhtml.tr; import org.compiere.model.GridField; import org.compiere.model.MChat; import org.compiere.model.MChatEntry; -import org.compiere.util.CLogger; -import org.compiere.util.Msg; -import org.compiere.util.Util; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import org.compiere.util.*; /** * Web (window) Chat * * @author Jorg Janke - * @version $Id: WChat.java $ + * @version $Id: WChat.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WChat extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 6826855534161342772L; /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); private MChat m_chat; diff --git a/serverApps/src/main/servlet/org/compiere/www/WError.java b/serverApps/src/main/servlet/org/compiere/www/WError.java index 6dafa47205..cee94e2571 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WError.java +++ b/serverApps/src/main/servlet/org/compiere/www/WError.java @@ -16,30 +16,19 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.io.PrintWriter; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.*; +import javax.servlet.http.*; +import java.io.*; public class WError extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 7940367932646085428L; static final private String CONTENT_TYPE = "text/html"; static final private String DOC_TYPE = ""; - /**Initialize global variables*/ public void init(ServletConfig config) throws ServletException { super.init(config); } - /**Process the HTTP Get request*/ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); @@ -52,7 +41,6 @@ public class WError extends HttpServlet out.println("

The servlet has received a GET. This is the reply.

"); out.println(""); } - /**Process the HTTP Post request*/ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); @@ -65,8 +53,7 @@ public class WError extends HttpServlet out.println("

The servlet has received a POST. This is the reply.

"); out.println(""); } - /**Clean up resources*/ public void destroy() { } -} +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WFieldUpdate.java b/serverApps/src/main/servlet/org/compiere/www/WFieldUpdate.java index b16eaa0ccc..894bee6580 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WFieldUpdate.java +++ b/serverApps/src/main/servlet/org/compiere/www/WFieldUpdate.java @@ -16,41 +16,22 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.util.Properties; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.ecs.xhtml.body; -import org.apache.ecs.xhtml.form; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.p; -import org.apache.ecs.xhtml.script; -import org.compiere.util.CLogger; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Login; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import java.io.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.ecs.xhtml.*; +import org.compiere.util.*; /** * Dynamic Field Updates. * * * @author Jorg Janke - * @version $Id: WFieldUpdate.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WFieldUpdate.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WFieldUpdate extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -1576213475379404148L; /** Static Logger */ private static CLogger log = CLogger.getCLogger (WFieldUpdate.class); diff --git a/serverApps/src/main/servlet/org/compiere/www/WFilter.java b/serverApps/src/main/servlet/org/compiere/www/WFilter.java index 56a803effd..951bdb7fcc 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WFilter.java +++ b/serverApps/src/main/servlet/org/compiere/www/WFilter.java @@ -1,50 +1,32 @@ -/********************************************************************** - * This file is part of Adempiere ERP Bazaar * - * http://www.adempiere.org * - * * - * Copyright (C) 1999 - 2006 Compiere Inc. * - * Copyright (C) Contributors * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the Free Software * - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * - * MA 02110-1301, USA. * - * * - * Contributors: * - * - Bahman Movaqar (bmovaqar@users.sf.net) * - **********************************************************************/ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * 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.www; -import java.io.IOException; -import java.util.Enumeration; -import java.util.logging.Level; - -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; - -import org.compiere.util.CLogger; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; +import java.io.*; +import java.util.*; +import java.util.logging.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; /** * HTML UI Filter to do timing and list parameters * @author Jorg Janke - * @version $Id: WFilter.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WFilter.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public final class WFilter implements javax.servlet.Filter @@ -139,12 +121,10 @@ public final class WFilter implements javax.servlet.Filter // Get URI String uri = ""; - String urilow = ""; if (request instanceof HttpServletRequest) { HttpServletRequest req = (HttpServletRequest)request; uri = req.getRequestURI(); - urilow = uri.toLowerCase(); } @@ -173,9 +153,9 @@ public final class WFilter implements javax.servlet.Filter else pass = false; else if (!uri.startsWith(WebEnv.DIR_BASE) // not requesting /adempiere/... - || urilow.endsWith(".gif") || urilow.endsWith(".jpg") || urilow.endsWith(".png") - || urilow.endsWith(".html") || urilow.endsWith(".css") - || urilow.endsWith(".js")) + || uri.endsWith(".gif") || uri.endsWith(".jpg") || uri.endsWith(".png") + || uri.endsWith(".html") || uri.endsWith(".css") + || uri.endsWith(".js")) check = false; else ; diff --git a/serverApps/src/main/servlet/org/compiere/www/WForm.java b/serverApps/src/main/servlet/org/compiere/www/WForm.java index d1cf7bb1ae..2d525d1f04 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WForm.java +++ b/serverApps/src/main/servlet/org/compiere/www/WForm.java @@ -28,52 +28,25 @@ import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; import org.compiere.util.WebUtil; -/** - * Form - * - * @author Jorg Janke - * @version $Id: WForm.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class WForm extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -3168260837305771442L; - - - /** - * Initialize global variables - */ public void init(ServletConfig config) throws ServletException { super.init(config); if (!WebEnv.initWeb(config)) throw new ServletException("WForm.init"); - } // init - - /** - * Process the HTTP Get request - */ + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - WebDoc doc = WebDoc.create ("Not Implemented Yet"); - // + WebDoc doc = WebDoc.create ("WForm - Get - Not Implemented Yet"); WebUtil.createResponse(request, response, this, null, doc, false); - } // doGet - - - /** - * Process the HTTP Post request - */ + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - WebDoc doc = WebDoc.create ("Not Implemented Yet"); - // + WebDoc doc = WebDoc.create ("WForm - Post - Not Implemented Yet"); WebUtil.createResponse(request, response, this, null, doc, false); - } // doPost - -} // WForm + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WHelp.java b/serverApps/src/main/servlet/org/compiere/www/WHelp.java index ff99aee942..38acb2b294 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WHelp.java +++ b/serverApps/src/main/servlet/org/compiere/www/WHelp.java @@ -25,69 +25,39 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.compiere.util.CLogger; -import org.compiere.util.Env; import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; import org.compiere.util.WebUtil; -/** - * Web (window) Help - * - * @author Jorg Janke - * @version $Id: WHelp.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class WHelp extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 2586562865823315494L; - /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); - /** - * Initialize global variables - */ public void init(ServletConfig config) throws ServletException { super.init(config); if (!WebEnv.initWeb(config)) throw new ServletException("WHelp.init"); - } // init - - /** - * Process the HTTP Get request - */ + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.fine("doGet"); WWindowStatus ws = WWindowStatus.get(request); - // WebDoc doc = null; - if (ws == null) - { + if (ws == null) { doc = WebDoc.createPopup("No Context"); - //Modified by Rob Klein 4/29/07 - doc.addPopupClose(Env.getCtx()); - } - else + doc.addPopupClose(ws.ctx); + } else doc = ws.mWindow.getHelpDoc(false); - // WebUtil.createResponse(request, response, this, null, doc, false); - } // doGet - - - /** - * Process the HTTP Post request - */ + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("Help - Post - Not Implemented"); WebUtil.createResponse(request, response, this, null, doc, false); - } // doPost - -} // WHelp + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WLocation.java b/serverApps/src/main/servlet/org/compiere/www/WLocation.java index acbdb23c8f..ba38d9de20 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WLocation.java +++ b/serverApps/src/main/servlet/org/compiere/www/WLocation.java @@ -44,7 +44,6 @@ import org.compiere.model.MRegion; import org.compiere.util.CLogger; import org.compiere.util.Env; import org.compiere.util.Msg; -import org.compiere.util.Util; import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; import org.compiere.util.WebUtil; @@ -64,17 +63,13 @@ import org.compiere.util.WebUtil; * When selecting an entry, the window is closed and the value of the two fields set. * * @author Jorg Janke - * @version $Id: WLocation.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WLocation.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WLocation extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 285780594700749274L; /** Logger */ protected static CLogger log = CLogger.getCLogger(WLocation.class); - + /** * Initialize global variables * @@ -93,6 +88,8 @@ public class WLocation extends HttpServlet private static final String P_C_LOCATION_ID = "C_LOCATION_ID"; private static final String P_ADDRESS1 = "ADDRESS1"; private static final String P_ADDRESS2 = "ADDRESS2"; + private static final String P_ADDRESS3= "ADDRESS3"; + private static final String P_ADDRESS4= "ADDRESS4"; private static final String P_CITY = "CITY"; private static final String P_POSTAL = "POSTAL"; private static final String P_C_COUNTRY_ID = "C_COUNTRY_ID"; @@ -122,35 +119,35 @@ public class WLocation extends HttpServlet log.info ("ColumnName=" + columnName + " - " + ws.toString()); // GridField mField = ws.curTab.getField(columnName); - log.config("ColumnName=" + columnName + log.config("ColumnName=" + columnName + ", MField=" + mField); - if (mField == null || columnName == null + if (mField == null || columnName == null || columnName.equals("")) { - WebUtil.createErrorPage(request, response, this, + WebUtil.createErrorPage(request, response, this, Msg.getMsg(ws.ctx, "ParameterMissing")); return; } - MLocation location = null; - Object value = mField.getValue(); + MLocation location = null; + Object value = mField.getValue(); if (value != null && value instanceof Integer) - location = new MLocation(ws.ctx, ((Integer)value).intValue(), null); + location = new MLocation(ws.ctx, ((Integer)value).intValue(),null); else - location = new MLocation(ws.ctx, 0, null); - - String targetBase = "parent.WWindow." + WWindow.FORM_NAME + "." + columnName; - String action = request.getRequestURI(); + location = new MLocation(ws.ctx, 0,null); + + //String targetBase = "parent.WWindow." + WWindow.FORM_NAME + "." + columnName; + String targetBase = "opener.WWindow." + WWindow.FORM_NAME + "." + columnName; + String action = request.getRequestURI(); // Create Document WebDoc doc = WebDoc.createPopup (mField.getHeader()); - //Modified by Rob klein 4/29/07 doc.addPopupClose(ws.ctx); boolean hasDependents = ws.curTab.hasDependants(columnName); boolean hasCallout = mField.getCallout().length() > 0; - + // Reset button reset = new button(); reset.addElement("Reset"); // translate - String script = targetBase + "F.value='';" + targetBase + "D.value='';closePopup();"; + String script = targetBase + "D.value='';" + targetBase + "F.value='';closePopup();"; if (hasDependents || hasCallout) script += "startUpdate(" + targetBase + "F);"; reset.setOnClick(script); @@ -158,10 +155,10 @@ public class WLocation extends HttpServlet doc.getTable().addElement(new tr() .addElement(fillForm(ws, action, location, targetBase, hasDependents || hasCallout)) .addElement(reset)); - //Modified by Rob Klein 4/29/07 + // doc.addPopupClose(ws.ctx); // log.trace(log.l6_Database, doc.toString()); - WebUtil.createResponse (request, response, this, null, doc, false); + WebUtil.createResponse (request, response, this, null, doc, true); } // doGet @@ -173,7 +170,7 @@ public class WLocation extends HttpServlet * @throws ServletException * @throws IOException */ - public void doPost(HttpServletRequest request, HttpServletResponse response) + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { log.fine(""); @@ -185,22 +182,23 @@ public class WLocation extends HttpServlet return; } int C_Location_ID = WebUtil.getParameterAsInt(request, P_C_LOCATION_ID); - String targetBase = "parent.WWindow." + WWindow.FORM_NAME + ".C_Location_ID"; + String targetBase = "opener.WWindow." + WWindow.FORM_NAME + ".C_Location_ID"; // Create Location - MLocation location = new MLocation(ws.ctx, C_Location_ID, null); + MLocation location = new MLocation(ws.ctx, C_Location_ID,null); log.fine("doPost updating C_Location_ID=" + C_Location_ID + " - " + targetBase); location.setAddress1 (WebUtil.getParameter(request, P_ADDRESS1)); location.setAddress2 (WebUtil.getParameter(request, P_ADDRESS2)); + location.setAddress3(WebUtil.getParameter(request, P_ADDRESS3)); + location.setAddress4(WebUtil.getParameter(request, P_ADDRESS4)); location.setCity (WebUtil.getParameter(request, P_CITY)); location.setPostal (WebUtil.getParameter(request, P_POSTAL)); location.setC_Country_ID (WebUtil.getParameterAsInt(request, P_C_COUNTRY_ID)); - location.setC_Region_ID (WebUtil.getParameterAsInt(request, P_C_REGION_ID)); - + location.setC_Region_ID (WebUtil.getParameterAsInt(request, P_C_REGION_ID)); + System.out.println("location =========== "+location); // Document WebDoc doc = WebDoc.createPopup ("WLocation"); - //Modified by Rob Klein 4/29/07 doc.addPopupClose(ws.ctx); // Save Location @@ -211,7 +209,7 @@ public class WLocation extends HttpServlet if (C_Location_ID == 0) center.addElement(new p(new b("ERROR - Location=0"))); center.addElement(new p().addElement(location.toString())); - + // Update Target script script = new script(new StringBuffer() .append(targetBase).append("D.value='").append(C_Location_ID).append("';") @@ -220,7 +218,25 @@ public class WLocation extends HttpServlet doc.getBody().addElement(script); log.fine("script=" + script.toString()); // - WebUtil.createResponse(request, response, this, null, doc, false); + form myForm = null; + myForm = new form (); + table table = new table(); + table.setID("WLocation"); + button button = new button(); + button.addElement("ok"); + StringBuffer script2 = new StringBuffer(); + String targetBase2 = "opener.document.WForm.C_Location_ID"; + script2.append(targetBase2).append("D.value='").append(C_Location_ID).append("';") + //script.append(targetBase).append("D.value='").append("';") + .append(targetBase2).append("F.value='").append(location.toString()) + //.append(targetBase).append("F.value='") + .append("';submit();window.close();"); + button.setOnClick(script2.toString()); + table.addElement(button); + myForm.addElement(table); + doc.getTable().addElement(myForm); + + WebUtil.createResponse(request, response, this, null, doc, true); } // doPost /** @@ -231,7 +247,7 @@ public class WLocation extends HttpServlet * @param addStart add startUpdate * @return Table with selection */ - private form fillForm (WWindowStatus ws, String action, MLocation location, + private form fillForm (WWindowStatus ws, String action, MLocation location, String targetBase, boolean addStart) { form myForm = null; @@ -256,6 +272,23 @@ public class WLocation extends HttpServlet myInput.setMaxlength(50).setSize(50); line.addElement(new td(myInput).setAlign(AlignType.LEFT).setColSpan(5)); table.addElement(line); + + //-- add by Dan + line = new tr(); + line.addElement(new td(Msg.getMsg(ws.ctx, "Address")+ " 3").setAlign(AlignType.RIGHT)); + myInput = new input (input.TYPE_TEXT, P_ADDRESS3, location.getAddress3()); + myInput.setMaxlength(50).setSize(50); + line.addElement(new td(myInput).setAlign(AlignType.LEFT).setColSpan(5)); + table.addElement(line); + +// -- add by Dan + line = new tr(); + line.addElement(new td(Msg.getMsg(ws.ctx, "Address")+ " 4").setAlign(AlignType.RIGHT)); + myInput = new input (input.TYPE_TEXT, P_ADDRESS4, location.getAddress4()); + myInput.setMaxlength(50).setSize(50); + line.addElement(new td(myInput).setAlign(AlignType.LEFT).setColSpan(5)); + table.addElement(line); + // -- Line 3 line = new tr(); line.addElement(new td(Msg.getMsg(ws.ctx, "City")).setAlign(AlignType.RIGHT)); // 1 @@ -282,27 +315,38 @@ public class WLocation extends HttpServlet line.addElement(new td(Msg.getMsg(ws.ctx, "Country")).setAlign(AlignType.RIGHT)); line.addElement(new td(this.getCountry(location, ws)).setAlign(AlignType.LEFT).setColSpan(5)); table.addElement(line); - + // -- Line 5 line = new tr(); // Submit + StringBuffer script = new StringBuffer(); + script.append(targetBase).append("D.value='").append("temp").append("';") + //script.append(targetBase).append("D.value='").append("';") + .append(targetBase).append("F.value='").append("temp") + //.append(targetBase).append("F.value='") + .append("';submit();closePopup();"); + + line.addElement(new td(" ")); input submit = new input(input.TYPE_SUBMIT, "Submit", "Submit"); // translate - line.addElement(new td(submit).setAlign(AlignType.RIGHT).setColSpan(5)); + submit.setOnClick(script.toString()); + line.addElement(new td(submit).setAlign(AlignType.RIGHT).setColSpan(5)); table.addElement(line); - /** - button button = new button(); + + /*button button = new button(); button.addElement(">"); StringBuffer script = new StringBuffer(); - script.append(targetBase).append("D.value='").append(np.getKey()).append("';") - .append(targetBase).append("F.value='").append(np.getName()) - .append("';closePopup();"); + script.append(targetBase).append("D.value='").append("temp").append("';") + //script.append(targetBase).append("D.value='").append("';") + .append(targetBase).append("F.value='").append("temp") + //.append(targetBase).append("F.value='") + .append("';closePopup();"); if (addStart) script.append("startUpdate(").append(targetBase).append("F);"); button.setOnClick(script.toString()); - **/ + table.addElement(button);*/ myForm.addElement(table); // return myForm; @@ -326,7 +370,7 @@ public class WLocation extends HttpServlet for (int i = 0; i < countries.length; i++) { options[i] = new option (String.valueOf(countries[i].getC_Country_ID())); - options[i].addElement(Util.maskHTML(countries[i].getName())); + options[i].addElement(countries[i].getName()); if (comp == countries[i].getC_Country_ID()) options[i].setSelected(true); } @@ -352,7 +396,7 @@ public class WLocation extends HttpServlet for (int i = 0; i < regions.length; i++) { options[i] = new option (String.valueOf(regions[i].getC_Region_ID())); - options[i].addElement(Util.maskHTML(regions[i].getName())); + options[i].addElement(regions[i].getName()); if (comp == regions[i].getC_Region_ID()) options[i].setSelected(true); } diff --git a/serverApps/src/main/servlet/org/compiere/www/WLogin.java b/serverApps/src/main/servlet/org/compiere/www/WLogin.java index a31802625e..ceff687c53 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WLogin.java +++ b/serverApps/src/main/servlet/org/compiere/www/WLogin.java @@ -16,46 +16,15 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.security.Principal; -import java.util.Properties; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import org.apache.ecs.AlignType; -import org.apache.ecs.HtmlColor; -import org.apache.ecs.xhtml.b; -import org.apache.ecs.xhtml.font; -import org.apache.ecs.xhtml.form; -import org.apache.ecs.xhtml.img; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.label; -import org.apache.ecs.xhtml.option; -import org.apache.ecs.xhtml.p; -import org.apache.ecs.xhtml.script; -import org.apache.ecs.xhtml.select; -import org.apache.ecs.xhtml.strong; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.MSession; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Language; -import org.compiere.util.Login; -import org.compiere.util.Msg; -import org.compiere.util.Util; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import java.io.*; +import java.security.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.ecs.*; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.util.*; /** * Web Login Page. @@ -75,14 +44,10 @@ import org.compiere.util.WebUtil; * * * @author Jorg Janke - * @version $Id: WLogin.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WLogin.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WLogin extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -407753489095758837L; /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); diff --git a/serverApps/src/main/servlet/org/compiere/www/WLookup.java b/serverApps/src/main/servlet/org/compiere/www/WLookup.java index 1cec3ba236..c9d53fb786 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WLookup.java +++ b/serverApps/src/main/servlet/org/compiere/www/WLookup.java @@ -16,37 +16,19 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; +import java.io.*; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.logging.Level; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import javax.servlet.*; +import javax.servlet.http.*; -import org.apache.ecs.xhtml.button; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.th; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.GridField; -import org.compiere.model.MProcess; -import org.compiere.model.MProcessPara; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Msg; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.util.*; /** * WLookup Servlet. @@ -57,30 +39,27 @@ import org.compiere.util.WebUtil; * * and assumes that in the opening window/form there are two fields * - * opener.document.formName.columnName - The (hidden) field for the ID + * opener.document.formName.columnName - The (hidden) field for thcoe ID * opener.document.formName.columnName_D - The display field for the value * * When selecting an entry, the window is closed and the value of the two fields set. * * @author Jorg Janke - * @version $Id: WLookup.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WLookup.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WLookup extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -1564370055815050553L; - /** Logger */ protected static CLogger log = CLogger.getCLogger(WLookup.class); /** The Data List */ protected volatile ArrayList p_data = new ArrayList(); - private static final int MAX_LINES = 5; + private static final int MAX_LINES = 99999; + private int m_recordCount; + private int m_colCount; - private StringBuffer HeaderSelect = null; + private StringBuffer m_HeaderSelect = null; /** * Initialize global variables @@ -160,46 +139,75 @@ public class WLookup extends HttpServlet // Create Document WebDoc doc = WebDoc.createPopup (para.getColumnName()); + div panel=new div(); + panel.setStyle("height: 330px;overflow: scroll;overflow: auto;"); + panel.addElement(fillTable(wsc, para.getColumnName(), para.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase,false, page)); + + //tr tr = new tr().addElement(panel); + // Reset String text = "Reset"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Reset"); + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Reset"); - input button = new input("button", text, " "+text); - button.setID(text); - button.setClass("resetbtn"); + input resetbtn = new input("button", text, " "+text); + resetbtn.setID(text); + resetbtn.setClass("resetbtn"); String script = targetBase + "F.value='';" + targetBase + "D.value='';closePopup();"; - button.setOnClick(script); + resetbtn.setOnClick(script); // -// Next Page - String textbtn = "Next Page"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Next Page"); - input nextpgbtn = new input(input.TYPE_BUTTON, textbtn, " "+text); - int nextpage = (page+1); - nextpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+nextpage+");return false;"); - nextpgbtn.setID(text); - nextpgbtn.setClass("nextpgbtn"); +// + //First Page + text = "First"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Next Page"); + input firstpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + + firstpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", 1);return false;"); + firstpgbtn.setID(text); + firstpgbtn.setClass("firstpgbtn"); //Previous Page - textbtn = "Prior Page"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Prior Page"); - input prevpgbtn = new input(input.TYPE_BUTTON, textbtn, " "+text); + text = "Prior"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Prior Page"); + input prevpgbtn = new input(input.TYPE_BUTTON, text, " "+text); int prevpage = (page == 1) ? 1 : page-1; prevpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+prevpage+");return false;"); prevpgbtn.setID(text); prevpgbtn.setClass("prevpgbtn"); - doc.getTable().addElement(new tr() - .addElement(fillTable(wsc, para.getColumnName(), para.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase,false, page)) - .addElement(nextpgbtn) - .addElement(prevpgbtn) - .addElement(button)); + //Next Page + text = "Next"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Next Page"); + input nextpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + int nextpage = (page+1); + nextpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+nextpage+");return false;"); + nextpgbtn.setID(text); + nextpgbtn.setClass("nextpgbtn"); + //Last Page + text = "Next"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Next Page"); + input lastpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + int lastpage = m_recordCount/MAX_LINES + 1; + lastpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+lastpage+");return false;"); + lastpgbtn.setID(text); + lastpgbtn.setClass("lastpgbtn"); + int index1=(page-1)*MAX_LINES+1; + int index2=(page)*MAX_LINES 0; + div panel=new div(); + panel.setStyle("height: 330px;overflow: scroll;overflow: auto;"); + panel.addElement(fillTable(wsc, mField.getColumnName(), mField.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase, hasDependents || hasCallout, page)); + + //tr tr = new tr().addElement(panel); + // Reset String text = "Reset"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Reset"); - input restbtn = new input(input.TYPE_RESET, text, " "+text); - restbtn.setID(text); - restbtn.setClass("resetbtn"); + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Reset"); + input resetbtn = new input(input.TYPE_RESET, text, " "+text); + resetbtn.setID(text); + resetbtn.setClass("resetbtn"); String script = targetBase + "F.value='';" + targetBase + "D.value='';self.close();"; if (hasDependents || hasCallout) script += "startUpdate(" + targetBase + "F);"; - restbtn.setOnClick(script); + resetbtn.setOnClick(script); - //Next Page - String textbtn = "Next Page"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Next Page"); - input nextpgbtn = new input(input.TYPE_BUTTON, textbtn, " "+text); - int nextpage = (page+1); - nextpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+nextpage+");return false;"); - nextpgbtn.setID(text); - nextpgbtn.setClass("nextpgbtn"); + //First Page + text = "First"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "First"); + input firstpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + firstpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", 1);return false;"); + firstpgbtn.setID(text); + firstpgbtn.setClass("firstpgbtn"); //Previous Page - textbtn = "Prior Page"; - if (wsc.ctx != null) - text = Msg.getMsg (wsc.ctx, "Prior Page"); - input prevpgbtn = new input(input.TYPE_BUTTON, textbtn, " "+text); + text = "Prior"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Prior"); + input prevpgbtn = new input(input.TYPE_BUTTON, text, " "+text); int prevpage = (page == 1) ? 1 : page-1; prevpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+prevpage+");return false;"); prevpgbtn.setID(text); prevpgbtn.setClass("prevpgbtn"); + //Next Page + text = "Next"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Next"); + input nextpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + int nextpage = (page+1); + nextpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+nextpage+");return false;"); + nextpgbtn.setID(text); + nextpgbtn.setClass("nextpgbtn"); - doc.getTable().addElement(new tr() - .addElement(fillTable(wsc, mField.getColumnName(), mField.getAD_Reference_Value_ID(), request.getRequestURI(),targetBase, hasDependents || hasCallout, page)) - .addElement(nextpgbtn) - .addElement(prevpgbtn)); - //.addElement(restbtn)); + //Last Page + text = "Last"; + //if (wsc.ctx != null) + // text = Msg.getMsg (wsc.ctx, "Last"); + input lastpgbtn = new input(input.TYPE_BUTTON, text, " "+text); + int lastpage=m_recordCount/MAX_LINES + 1; + lastpgbtn.setOnClick("startLookup('" + columnName + "', "+AD_Process_ID+", "+ lastpage +");return false;"); + lastpgbtn.setID(text); + lastpgbtn.setClass("lastpgbtn"); + + int index1=(page-1)*MAX_LINES+1; + int index2=(page)*MAX_LINES"); table.addElement(""); @@ -354,116 +391,66 @@ public class WLookup extends HttpServlet table table1, String targetBase, boolean mandatory, boolean onlyValidated, boolean onlyActive, boolean temporary, int page) { - ArrayList list = new ArrayList(); StringBuffer sqlSelect = null; - StringBuffer sqlSelectDetail = null; - - int size = 0; - int colCount = 0; - - if (!mandatory) - list.add(new KeyNamePair (-1, "")); - - StringBuffer sql = null; + StringBuffer sqlCount = null; + String sql=null; + String colKey=null; + String colDisplay=null; if (fieldRefId > 0){ - sql = new StringBuffer ("SELECT AD_Display, AD_Key, AD_Table_ID, WhereClause, OrderByClause " - + "FROM AD_Ref_Table WHERE AD_Reference_ID = "+fieldRefId); + sql = "SELECT AD_Table_ID, AD_Key, AD_Display, WhereClause, OrderByClause FROM AD_Ref_Table WHERE AD_Reference_ID = " + fieldRefId; - int nameID = 0; - int keyID = 0; int tableID = 0; + String whereClause = null; - String orderBy = null; + String orderBy = null; + try { PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); ResultSet rs = pstmt.executeQuery(); - size=2; - while (rs.next()){ - nameID = rs.getInt(1); - keyID = rs.getInt(2); - tableID = rs.getInt(3); + if (rs.next()){ + tableID = rs.getInt(1); + whereClause = rs.getString(4); orderBy = rs.getString(5); + sql="Select ColumnName FROM AD_Column Where AD_Column_ID = ? AND AD_Table_ID = ?"; + colKey = DB.getSQLValueString(null, sql, rs.getInt(2), tableID); + colDisplay = DB.getSQLValueString(null, sql, rs.getInt(3), tableID); } - - String sql1 = "Select ColumnName FROM AD_Column Where AD_Column_ID = ? AND AD_Table_ID = "+tableID; - sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID); - colCount = DB.getSQLValue(null, sql.toString()); - - String name = DB.getSQLValueString(null, sql1 , nameID); - String key = DB.getSQLValueString(null, sql1 , keyID); - sqlSelect = new StringBuffer ("SELECT "+key+", "+name); - rs.close(); pstmt.close(); } catch (SQLException e) { - log.log(Level.SEVERE, sqlSelect.toString(), e); + log.log(Level.SEVERE, sql.toString(), e); } - String sql1 = "Select TableName FROM AD_Table Where AD_Table_ID = ?"; - String tableName = DB.getSQLValueString(null, sql1 , tableID); - sqlSelect.append(" FROM " + tableName + " WHERE AD_Client_ID=?"); - sqlSelectDetail = HeaderSelect.append(" FROM " + tableName + " WHERE "+columnName+" = ?"); - + sql = "Select TableName FROM AD_Table Where AD_Table_ID = ?"; + String tableName = DB.getSQLValueString(null, sql , tableID); + sqlSelect=new StringBuffer ( "SELECT " + m_HeaderSelect + " FROM " + tableName + " WHERE AD_Client_ID=?"); + sqlCount=new StringBuffer ( "SELECT count(*) FROM " + tableName + " WHERE AD_Client_ID=?"); + if (whereClause != null){ sqlSelect.append(" AND " + whereClause); - sqlSelectDetail.append(" AND " + whereClause); + sqlCount.append(" AND " + whereClause); } - - if (orderBy != null){ + if (orderBy != null) sqlSelect.append(" ORDER BY " + orderBy); - sqlSelectDetail.append(" ORDER BY " + orderBy); - } + } else{ - - //direct select as indicated below - sql = new StringBuffer ("SELECT AD_Table_ID " - + "FROM AD_Table WHERE TableName = '"+columnName.replace("_ID", "")+"'"); - int tableID = DB.getSQLValue(null, sql.toString()); - - sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID); - colCount = DB.getSQLValue(null, sql.toString()); - - sql = new StringBuffer ("SELECT ColumnName " - + "FROM AD_Column WHERE IsIdentifier = 'Y' AND " - + "AD_Table_ID= "+tableID - + " ORDER BY SeqNo"); - - sqlSelect = new StringBuffer ("SELECT "+columnName+", "); - size=1; - - try - { - PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null); - ResultSet rs = pstmt.executeQuery(); - - while (rs.next()){ - if (size>1) - sqlSelect.append(", "); - sqlSelect.append(rs.getObject(1)); - size++; - } - rs.close(); - pstmt.close(); - } - catch (SQLException e) - { - log.log(Level.SEVERE, sqlSelect.toString(), e); - } - - sqlSelect.append(" FROM " + columnName.replace("_ID", "") + " WHERE AD_Client_ID=?"); - sqlSelectDetail = HeaderSelect.append(" FROM " + columnName.replace("_ID", "") + " WHERE "+columnName+" = ?"); - - } + sqlSelect=new StringBuffer("SELECT " + m_HeaderSelect + " FROM " + columnName.replace("_ID", "") + " WHERE AD_Client_ID=?"); + sqlCount=new StringBuffer("SELECT count(*) FROM " + columnName.replace("_ID", "") + " WHERE AD_Client_ID=?"); + colKey=columnName; + if (m_HeaderSelect.toString().contains("Name")) + colDisplay="Name"; + else + colDisplay="Description"; + } try { - PreparedStatement pstmt = DB.prepareStatement(sqlSelect.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY, null); @@ -471,57 +458,38 @@ public class WLookup extends HttpServlet ResultSet rs = pstmt.executeQuery(); log.info("This is the page number "+page); log.info("This is the MAX_LINES "+MAX_LINES); - rs.absolute(((page-1)*MAX_LINES)+1); - - for (int j= 1; j<= MAX_LINES; j++){ - if(rs.next()){ - StringBuffer name = new StringBuffer (""); - for (int i = 2; i <= size; i++) - { - if (i>2) - name.append("_"); - name.append(rs.getObject(i)); - } - button button = new button(); - button.addElement(">"); - StringBuffer script = new StringBuffer(); - script - .append("startLookUpdate(").append(targetBase).append("F',") - .append(targetBase).append("D','").append(rs.getObject(1).toString()).append("',") - .append(targetBase).append("F','").append(name.toString()) - .append("');startUpdate(").append(targetBase).append("');return false;"); - button.setOnClick(script.toString()); + //rs.absolute(((page-1)*MAX_LINES)+1); + + //for (int j= 1; j<= MAX_LINES; j++){ + while(rs.next()){ + button button = new button(); + button.addElement(">"); + StringBuffer script = new StringBuffer(); + script + .append("startLookUpdate(").append(targetBase).append("F',") + .append(targetBase).append("D','").append(rs.getString(colKey)).append("',") + .append(targetBase).append("F','").append(rs.getString(colDisplay)) + .append("');startUpdate(").append(targetBase).append("');return false;"); + button.setOnClick(script.toString()); // - tr line = new tr(); - line.addElement(new td(button)); - line.addElement(new td(name.toString())); - try - { - PreparedStatement pstmt1 = DB.prepareStatement(sqlSelectDetail.toString(), null); - pstmt1.setInt(1, rs.getInt(1)); - ResultSet rs1 = pstmt1.executeQuery(); - while (rs1.next()){ - for (int i = 1; i <= colCount; i++) - { - Object fieldRS = rs1.getObject(i); - if (fieldRS == null) - line.addElement(new td(" ")); - else - line.addElement(new td(rs1.getObject(i).toString())); - } + tr line = new tr(); + line.addElement(new td(button)); + //line.addElement(new td(rs.getString(i))); + + for (int i = 1; i <=m_colCount; i++) + { + line.addElement(new td(rs.getString(i))); } - rs1.close(); - pstmt1.close(); - - } + + table1.addElement(line); + } + //} + + + //count + m_recordCount = DB.getSQLValue(null, sqlCount.toString(),Env.getAD_Client_ID(wsc.ctx)); - catch (SQLException e) - { - log.log(Level.SEVERE, sql.toString(), e); - } - table1.addElement(line); - } - } + rs.close(); pstmt.close(); @@ -546,66 +514,57 @@ public class WLookup extends HttpServlet boolean temporary, boolean firstHeaderLine) { - StringBuffer sqlSelect = null; - int size = 0; - StringBuffer sql = null; - int colCount = 0; - if (fieldRefId > 0){ - - sql = new StringBuffer ("SELECT AD_Table_ID " - + "FROM AD_Ref_Table WHERE AD_Reference_ID = "+fieldRefId); - int tableID = DB.getSQLValue(null, sql.toString()); - - sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID); - colCount = DB.getSQLValue(null, sql.toString()); - sqlSelect = new StringBuffer ("SELECT ColumnName, Name FROM AD_Column WHERE AD_Table_ID="+tableID+" ORDER BY AD_Column_ID"); - - } - else{ - //direct select as indicated below - - sql = new StringBuffer ("SELECT AD_Table_ID " - + "FROM AD_Table WHERE TableName = '"+columnName.replace("_ID", "")+"'"); - int tableID = DB.getSQLValue(null, sql.toString()); - sql = new StringBuffer ("SELECT count(Name) FROM AD_Column WHERE AD_TABLE_ID="+tableID); - colCount = DB.getSQLValue(null, sql.toString()); - sqlSelect = new StringBuffer ("SELECT ColumnName, Name FROM AD_Column WHERE AD_TABLE_ID="+tableID+" ORDER BY AD_Column_ID"); - - } + String sqlSelect = null; + input filter = null; + if (fieldRefId > 0) + sqlSelect = "SELECT ColumnName, Name FROM AD_Column WHERE AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Ref_Table WHERE AD_Reference_ID = " + fieldRefId + ") ORDER BY SEQNO"; + else + sqlSelect = "SELECT ColumnName, Name FROM AD_Column WHERE AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE TableName = '" + columnName.replace("_ID", "") + "') ORDER BY SEQNO"; - if(firstHeaderLine) - HeaderSelect = new StringBuffer ("Select "); + + + if(firstHeaderLine) { + line.addElement(new th()); + m_HeaderSelect = new StringBuffer(columnName); + line.addElement(new th(columnName).setClass("table-filterable table-filtered table-sortable:default")); + m_colCount=1; + } else { + line.addElement(new th("Find")); + filter = new input (input.TYPE_TEXT, columnName+"filter", ""); + filter.setOnKeyUp("Table.filter(this,this)"); + line.addElement(new th().addElement(filter)); + } try { PreparedStatement pstmt = DB.prepareStatement(sqlSelect.toString(), null); ResultSet rs = pstmt.executeQuery(); - - input filter = null; + + + String col; while (rs.next()){ + col=rs.getString(1); + if(col.equals("Value")||col.equals("DocumentNo")||col.equals("Name")||col.equals("Description")){ if(firstHeaderLine){ line.addElement(new th(rs.getString(2)).setClass("table-filterable table-filtered table-sortable:default")); - HeaderSelect.append(rs.getString(1)+","); + m_HeaderSelect.append(",").append(col); + m_colCount++; } else{ - th th = new th(); filter = new input (input.TYPE_TEXT, rs.getString(2)+"filter", ""); - filter.setOnKeyUp("Table.filter(this,this)"); - th.addElement(filter); - line.addElement(th); + filter.setOnKeyUp("Table.filter(this,this)"); + line.addElement(new th().addElement(filter)); } + } } - if(firstHeaderLine) - HeaderSelect.setLength(HeaderSelect.length()-1); - rs.close(); pstmt.close(); } catch (SQLException e) { - log.log(Level.SEVERE, sql.toString(), e); + log.log(Level.SEVERE, sqlSelect.toString(), e); } return line; diff --git a/serverApps/src/main/servlet/org/compiere/www/WMenu.java b/serverApps/src/main/servlet/org/compiere/www/WMenu.java index bf8a767085..d03c14edd4 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WMenu.java +++ b/serverApps/src/main/servlet/org/compiere/www/WMenu.java @@ -16,60 +16,26 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Enumeration; -import java.util.Properties; -import java.util.logging.Level; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.ecs.Element; -import org.apache.ecs.xhtml.a; -import org.apache.ecs.xhtml.base; -import org.apache.ecs.xhtml.body; -import org.apache.ecs.xhtml.cite; -import org.apache.ecs.xhtml.head; -import org.apache.ecs.xhtml.link; -import org.apache.ecs.xhtml.script; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.MForm; -import org.compiere.model.MTree; -import org.compiere.model.MTreeNode; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Login; -import org.compiere.util.Msg; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import java.io.*; +import java.sql.*; +import java.util.*; +import java.util.logging.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.ecs.*; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.util.*; /** * Web Menu * * @author Jorg Janke - * @version $Id: WMenu.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WMenu.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WMenu extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -6357775290362135602L; /** Logger */ protected CLogger log = CLogger.getCLogger (getClass ()); @@ -373,7 +339,7 @@ public class WMenu extends HttpServlet // Document //Modified by Rob Klein 4/29/07 //String windowTitle = Msg.getMsg(wsc.ctx, "Menu"); - String windowTitle = ""; + String windowTitle = "Menu"; WebDoc doc = WebDoc.create (windowTitle); head head = doc.getHead(); // Target @@ -381,6 +347,7 @@ public class WMenu extends HttpServlet // Specific Menu Script/Stylesheet head.addElement(new link(WebEnv.getBaseDirectory("/css/menu.css"), link.REL_STYLESHEET, link.TYPE_CSS)); head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/menu.js"))); + head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/window.js"))); //Modified by Rob Klein 4/29/07 //head.addElement(new script((Element)null, WebEnv.getBaseDirectory("/js/mktree.js"))); //head.addElement(new link(WebEnv.getBaseDirectory("/css/mktree.css"), link.REL_STYLESHEET, link.TYPE_CSS)); @@ -391,6 +358,7 @@ public class WMenu extends HttpServlet //Rob 12-16-2006 head.addElement(new script(scriptTxt)); // Body + body body = doc.getBody(); body.setTitle(statusMessage); // Clear Window Frame @@ -398,9 +366,13 @@ public class WMenu extends HttpServlet // Header table table = doc.getTable(); + doc.setClasses ("menuTable", "menuHeader"); //Rob 12-16-2006 doc.getTopLeft().addElement(new cite(wsc.loginInfo)); - doc.getTopLeft().addElement(new cite("")); + input txtSearch = new input(input.TYPE_TEXT, "txtSearch", ""); + txtSearch.setOnKeyDown("searchMenu('main',this.value,event,'" + WebEnv.TARGET_WINDOW + "')"); + doc.getTopLeft().addElement("Find: "); + doc.getTopLeft().addElement(txtSearch); // Load Menu Structure ---------------------- int AD_Tree_ID = DB.getSQLValue(null, @@ -415,7 +387,7 @@ public class WMenu extends HttpServlet // Trim tree MTreeNode root = tree.getRoot(); Enumeration en = root.preorderEnumeration(); - while (en.hasMoreElements()) + /*while (en.hasMoreElements()) { MTreeNode nd = (MTreeNode)en.nextElement(); if (nd.isTask() @@ -427,7 +399,7 @@ public class WMenu extends HttpServlet MTreeNode parent = (MTreeNode)nd.getParent(); parent.remove(nd); } - } + }*/ tree.trimTree(); // Print tree @@ -587,15 +559,15 @@ public class WMenu extends HttpServlet .append(node.getNode_ID()); } // remaining a tag - sb.append("\" onMouseOver=\"status='" + description - + "';\" onClick=\"showLoadingWindow('" + WebEnv.getBaseDirectory("") + "')\">") + sb.append("\" title=\"" + description + + "\" onClick=\"showLoadingWindow('" + WebEnv.getBaseDirectory("") + "')\">") .append(name) // language set in MTree.getNodeDetails based on ctx .append("\n"); } else { /** - *
  • MenuEntry + *
  • MenuEntry *
      * .... *
  • diff --git a/serverApps/src/main/servlet/org/compiere/www/WProcess.java b/serverApps/src/main/servlet/org/compiere/www/WProcess.java index 18a681e265..83caf65505 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WProcess.java +++ b/serverApps/src/main/servlet/org/compiere/www/WProcess.java @@ -16,62 +16,20 @@ *****************************************************************************/ package org.compiere.www; -import java.io.File; -import java.io.IOException; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; +import java.io.*; +import java.math.*; +import java.sql.*; import java.util.ArrayList; -import java.util.logging.Level; +import java.util.logging.*; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.ecs.AlignType; -import org.apache.ecs.Element; -import org.apache.ecs.xhtml.form; -import org.apache.ecs.xhtml.i; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.option; -import org.apache.ecs.xhtml.p; -import org.apache.ecs.xhtml.select; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.GridTab; -import org.compiere.model.MAllocationHdr; -import org.compiere.model.MBankStatement; -import org.compiere.model.MInOut; -import org.compiere.model.MInventory; -import org.compiere.model.MInvoice; -import org.compiere.model.MJournal; -import org.compiere.model.MJournalBatch; -import org.compiere.model.MMovement; -import org.compiere.model.MOrder; -import org.compiere.model.MPInstance; -import org.compiere.model.MPInstancePara; -import org.compiere.model.MPayment; -import org.compiere.model.MProcess; -import org.compiere.model.MProcessPara; -import org.compiere.print.ReportEngine; -import org.compiere.process.DocumentEngine; -import org.compiere.process.ProcessInfo; -import org.compiere.util.ASyncProcess; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.Trx; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import javax.servlet.*; +import javax.servlet.http.*; +import org.apache.ecs.*; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.print.*; +import org.compiere.process.*; +import org.compiere.util.*; import org.compiere.wf.MWFActivity; @@ -79,14 +37,10 @@ import org.compiere.wf.MWFActivity; * HTML Process and Report UI * * @author Jorg Janke - * @version $Id: WProcess.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WProcess.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WProcess extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 3937980012432969521L; /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); //Modified by Rob Klein 4/29/07 @@ -269,7 +223,9 @@ public class WProcess extends HttpServlet center.addElement(new p(process.getHelp(), AlignType.LEFT)); form myForm = new form ("WProcess") .setName("process" + process.getAD_Process_ID()); - myForm.setOnSubmit("this.Submit.disabled=true;return true;"); + + myForm.setTarget("WPopup"); + //myForm.setOnSubmit("this.Submit.disabled=true;return true;"); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID())); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID)); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID)); @@ -321,7 +277,8 @@ public class WProcess extends HttpServlet // form myForm = new form ("WProcess") .setName("process" + process.getAD_Process_ID()); - myForm.setOnSubmit("this.Submit.disabled=true;return true;"); + myForm.setTarget("WPopup"); + //myForm.setOnSubmit("this.Submit.disabled=true;return true;"); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Process_ID", process.getAD_Process_ID())); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Window_ID", windowID)); myForm.addElement(new input(input.TYPE_HIDDEN, "AD_Table_ID", tableID)); @@ -377,8 +334,8 @@ public class WProcess extends HttpServlet text = Msg.getMsg (wsc.ctx, "Submit"); input submitbtn = new input(input.TYPE_SUBMIT, text, " "+text); submitbtn.setID(text); - submitbtn.setClass("submitbtn"); - + submitbtn.setClass("submitbtn"); + submitbtn.setOnClick("popUp('WProcess','WPopup')"); myTable.addElement(new tr() .addElement(new td(null, AlignType.RIGHT, AlignType.MIDDLE, false, @@ -478,8 +435,13 @@ public class WProcess extends HttpServlet center.addElement(pi.getLogInfo(true)); } + String jasper=process.getJasperReport(); if (process.isJavaProcess()) { + if (jasper!=null) { + pi.setPrintPreview (false); + pi.setIsBatch(true); + } Trx trx = Trx.get(Trx.createTrxName("WebPrc"), true); try { @@ -497,62 +459,77 @@ public class WProcess extends HttpServlet center.addElement(new p("Error:" + pi.getSummary(), AlignType.LEFT).setClass("Cerror")); processOK = false; + } else { + if(jasper!=null) { + String error = WebUtil.streamFile(response, pi.getPDFReport()); + //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file); + if (error == null) + return; + doc = WebDoc.create(error); + wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok"); + } else { + center.addElement(new p().addElement(pi.getSummary())); + center.addElement(pi.getLogInfo(true)); + } } - center.addElement(new p().addElement(pi.getSummary())); - center.addElement(pi.getLogInfo(true)); } // Report if (process.isReport()) //if (processOK && process.isReport()) { - doc = null; - log.info(response.toString()); - ReportEngine re = ReportEngine.get(wsc.ctx, pi); - if (re == null) - { - center.addElement(new p("Could not start ReportEngine", - AlignType.LEFT).setClass("Cerror")); - } - else - { - try + //doc = null; + + + + if(jasper==null) { + log.info(response.toString()); + ReportEngine re = ReportEngine.get(wsc.ctx, pi); + if (re == null) { - File file = File.createTempFile("WProcess", ".pdf"); - boolean ok = re.createPDF(file); - if (ok) - { - String error = WebUtil.streamFile(response, file); - //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file); - if (error == null) - return; - doc = WebDoc.create(error); - - //Modified by Rob Klein 6/1/07 - /** - String url = "WProcess?AD_PInstance_ID=" - + pInstance.getAD_PInstance_ID() - + "&File=" - + URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING); - a link = new a (url, null, a.TARGET_BLANK, process.getName()); - center - .addElement(new p() - .addElement("Report created: ") - .addElement(link)); - // Marker that Process is OK - * */ - wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok"); - - } - else - center.addElement(new p("Could not create Report", - AlignType.LEFT).setClass("Cerror")); - } - catch (Exception e) - { - center.addElement(new p("Could not create Report:", + center.addElement(new p("Could not start ReportEngine", AlignType.LEFT).setClass("Cerror")); - center.addElement(e.toString()); + } + else + { + try + { + File file = File.createTempFile("WProcess", ".pdf"); + boolean ok = re.createPDF(file); + if (ok) + { + String error = WebUtil.streamFile(response, file); + //String error = streamResult (request, response, pInstance.getAD_PInstance_ID(), file); + if (error == null) + return; + doc = WebDoc.create(error); + + //Modified by Rob Klein 6/1/07 + /** + String url = "WProcess?AD_PInstance_ID=" + + pInstance.getAD_PInstance_ID() + + "&File=" + + URLEncoder.encode(file.getAbsolutePath(), WebEnv.ENCODING); + a link = new a (url, null, a.TARGET_BLANK, process.getName()); + center + .addElement(new p() + .addElement("Report created: ") + .addElement(link)); + // Marker that Process is OK + * */ + wsc.ctx.put("AD_PInstance_ID=" + pInstance.getAD_PInstance_ID(), "ok"); + + } + else + center.addElement(new p("Could not create Report", + AlignType.LEFT).setClass("Cerror")); + } + catch (Exception e) + { + center.addElement(new p("Could not create Report:", + AlignType.LEFT).setClass("Cerror")); + center.addElement(e.toString()); + } } } } diff --git a/serverApps/src/main/servlet/org/compiere/www/WProcessCtl.java b/serverApps/src/main/servlet/org/compiere/www/WProcessCtl.java index a244653215..a92fd7a98d 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WProcessCtl.java +++ b/serverApps/src/main/servlet/org/compiere/www/WProcessCtl.java @@ -16,40 +16,28 @@ *****************************************************************************/ package org.compiere.www; -import java.io.InvalidClassException; -import java.lang.reflect.UndeclaredThrowableException; -import java.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.io.*; +import java.lang.reflect.*; +import java.sql.*; import java.util.Properties; -import java.util.logging.Level; +import java.util.logging.*; import javax.servlet.http.HttpServletRequest; import org.compiere.apps.Waiting; -import org.compiere.db.CConnection; -import org.compiere.interfaces.Server; -import org.compiere.model.MPInstance; -import org.compiere.print.ReportCtl; -import org.compiere.process.ProcessCall; -import org.compiere.process.ProcessInfo; -import org.compiere.process.ProcessInfoUtil; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.Env; -import org.compiere.util.Ini; -import org.compiere.util.Msg; -import org.compiere.util.Trx; -import org.compiere.util.WebSessionCtx; -import org.compiere.wf.MWFProcess; -import org.compiere.wf.MWorkflow; +import org.compiere.db.*; +import org.compiere.interfaces.*; +import org.compiere.model.*; +import org.compiere.print.*; +import org.compiere.process.*; +import org.compiere.util.*; +import org.compiere.wf.*; /** * Process Interface Controller. * * @author Jorg Janke - * @version $Id: ProcessCtl.java,v 1.2 2006/07/30 00:51:27 jjanke Exp $ + * @version $Id: WProcessCtl.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WProcessCtl extends Thread { @@ -382,7 +370,7 @@ public class WProcessCtl extends Thread if (server != null) { // See ServerBean log.info("running on the server"); - m_pi = server.workflow (Env.getRemoteCallCtx(m_wscctx), m_pi, AD_Workflow_ID); + m_pi = server.workflow (m_wscctx, m_pi, AD_Workflow_ID); log.finest("server => " + m_pi); started = true; } @@ -428,7 +416,7 @@ public class WProcessCtl extends Thread { if (server != null) { // See ServerBean - m_pi = server.process (Env.getRemoteCallCtx(m_wscctx), m_pi); + m_pi = server.process (m_wscctx, m_pi); log.finest("server => " + m_pi); started = true; } @@ -450,6 +438,14 @@ public class WProcessCtl extends Thread + m_pi, ex); started = false; } + catch (Exception ex) + { + Throwable cause = ex.getCause(); + if (cause == null) + cause = ex; + log.log(Level.SEVERE, "AppsServer error - " + m_pi, cause); + started = false; + } } // Run locally if (!started && !m_IsServerProcess) @@ -496,7 +492,7 @@ public class WProcessCtl extends Thread String sql = "{call " + ProcedureName + "(?)}"; try { - CallableStatement cstmt = DB.prepareCall(sql); // ro?? + CallableStatement cstmt = DB.prepareCall(sql, ResultSet.CONCUR_UPDATABLE,null); // ro?? cstmt.setInt(1, m_pi.getAD_PInstance_ID()); cstmt.executeUpdate(); cstmt.close(); diff --git a/serverApps/src/main/servlet/org/compiere/www/WReport.java b/serverApps/src/main/servlet/org/compiere/www/WReport.java index 3d485f301b..29ef36cc58 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WReport.java +++ b/serverApps/src/main/servlet/org/compiere/www/WReport.java @@ -53,14 +53,10 @@ import org.compiere.util.WebUtil; * Web (window) Report * * @author Jorg Janke -* @version $Id: WReport.java $ +* @version $Id: WReport.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WReport extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -6281182537210181407L; /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); /** Current MTab */ diff --git a/serverApps/src/main/servlet/org/compiere/www/WStart.java b/serverApps/src/main/servlet/org/compiere/www/WStart.java index a6fc9853b5..f0976af5d4 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WStart.java +++ b/serverApps/src/main/servlet/org/compiere/www/WStart.java @@ -16,16 +16,10 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; /** * Application Start Page @@ -44,16 +38,10 @@ import org.compiere.util.WebUtil; * +- WWindow * see webapps/adempiere/index.html * @author Jorg Janke - * @version $Id: WStart.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WStart.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WStart extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -3520310916249390852L; - - /** * Set UI directory to Servlet init param */ diff --git a/serverApps/src/main/servlet/org/compiere/www/WStatus.java b/serverApps/src/main/servlet/org/compiere/www/WStatus.java index f5ad62a767..56db86caac 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WStatus.java +++ b/serverApps/src/main/servlet/org/compiere/www/WStatus.java @@ -16,32 +16,19 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; /** * Status Servlet * * @author Jorg Janke - * @version $Id: WStatus.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WStatus.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WStatus extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -6029799149174591507L; - - /** * Initialize global variables * This servlet is also loaded on startup to initialize the system diff --git a/serverApps/src/main/servlet/org/compiere/www/WTask.java b/serverApps/src/main/servlet/org/compiere/www/WTask.java index f79a071a17..978169fa20 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WTask.java +++ b/serverApps/src/main/servlet/org/compiere/www/WTask.java @@ -28,52 +28,25 @@ import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; import org.compiere.util.WebUtil; -/** - * - * - * @author Jorg Janke - * @version $Id: WTask.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ - */ public class WTask extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 4088461230847084532L; - - - /** - * Initialize global variables - */ public void init(ServletConfig config) throws ServletException { super.init(config); if (!WebEnv.initWeb(config)) throw new ServletException("WTask.init"); - } // init - - /** - * Process the HTTP Get request - */ + } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("WTask - Get - Not Implemented Yet"); - // WebUtil.createResponse(request, response, this, null, doc, false); - } // doGet - - - /** - * Process the HTTP Post request - */ + } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebDoc doc = WebDoc.create ("WTask - Post - Not Implemented Yet"); - // WebUtil.createResponse(request, response, this, null, doc, false); - } // doPost - -} // WTask + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WTest.java b/serverApps/src/main/servlet/org/compiere/www/WTest.java index 441e37643c..cdaa47dda1 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WTest.java +++ b/serverApps/src/main/servlet/org/compiere/www/WTest.java @@ -16,32 +16,19 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.compiere.util.CLogger; -import org.compiere.util.Env; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebUtil; +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.compiere.util.*; /** * Web (window) Help * * @author Jorg Janke - * @version $Id: WHelp.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WTest.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WTest extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = -669477433080711028L; /** Logger */ protected CLogger log = CLogger.getCLogger(WTest.class); diff --git a/serverApps/src/main/servlet/org/compiere/www/WValuePreference.java b/serverApps/src/main/servlet/org/compiere/www/WValuePreference.java index 59b14ad3a7..08a57303e9 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WValuePreference.java +++ b/serverApps/src/main/servlet/org/compiere/www/WValuePreference.java @@ -52,14 +52,10 @@ import org.compiere.util.WebUtil; * HTML Process and Report UI * * @author Jorg Janke - * @version $Id: WProcess.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WValuePreference.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WValuePreference extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 6283213348834944668L; /** Logger */ protected CLogger log = CLogger.getCLogger(getClass()); //Modified by Rob Klein 4/29/07 diff --git a/serverApps/src/main/servlet/org/compiere/www/WWindow.java b/serverApps/src/main/servlet/org/compiere/www/WWindow.java index f4c810d54d..df36003fd6 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WWindow.java +++ b/serverApps/src/main/servlet/org/compiere/www/WWindow.java @@ -16,65 +16,29 @@ *****************************************************************************/ package org.compiere.www; -import java.io.IOException; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Enumeration; -import java.util.logging.Level; +import java.io.*; +import java.math.*; +import java.sql.*; +import java.util.*; +import java.util.logging.*; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import javax.servlet.*; +import javax.servlet.http.*; -import org.apache.ecs.AlignType; -import org.apache.ecs.xhtml.a; -import org.apache.ecs.xhtml.button; -import org.apache.ecs.xhtml.form; -import org.apache.ecs.xhtml.hr; -import org.apache.ecs.xhtml.img; -import org.apache.ecs.xhtml.input; -import org.apache.ecs.xhtml.script; -import org.apache.ecs.xhtml.small; -import org.apache.ecs.xhtml.span; -import org.apache.ecs.xhtml.table; -import org.apache.ecs.xhtml.td; -import org.apache.ecs.xhtml.th; -import org.apache.ecs.xhtml.thead; -import org.apache.ecs.xhtml.tr; -import org.compiere.model.GridField; -import org.compiere.model.GridTab; -import org.compiere.model.GridWindowVO; -import org.compiere.model.MQuery; -import org.compiere.model.MRole; -import org.compiere.model.MSession; -import org.compiere.util.CLogger; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.Msg; -import org.compiere.util.WebDoc; -import org.compiere.util.WebEnv; -import org.compiere.util.WebSessionCtx; -import org.compiere.util.WebUtil; +import org.adempiere.exceptions.DBException; +import org.apache.ecs.*; +import org.apache.ecs.xhtml.*; +import org.compiere.model.*; +import org.compiere.util.*; /** * Web Window Servlet * * @author Jorg Janke - * @version $Id: WWindow.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ + * @version $Id: WWindow.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WWindow extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 8801734074649997374L; /** Logger */ protected static CLogger log = CLogger.getCLogger(WWindow.class); @@ -128,13 +92,16 @@ public class WWindow extends HttpServlet /** Multi Row Lines per Screen */ // Modified by Rob Klein 4/29/2007 //private static final int MAX_LINES = 12; - private static final int MAX_LINES = 1000; + private static final int MAX_LINES = 100; /** Indicator for last line */ - private static final int LAST_LINE = 999999; + private static final int LAST_LINE = 999999999; /** Error Indicator */ private static final String ERROR = " ERROR! "; + private String m_searchField; + private String m_targetWindow; + /** * Process the HTTP Get request - Initial Call. *
    @@ -167,7 +134,7 @@ public class WWindow extends HttpServlet int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID"); // Get Parameter: Menu_ID int AD_Menu_ID = WebUtil.getParameterAsInt(request, "AD_Menu_ID"); - // + log.info("AD_Window_ID=" + AD_Window_ID + "; AD_Menu_ID=" + AD_Menu_ID); @@ -225,7 +192,8 @@ public class WWindow extends HttpServlet ws.mWindow.dispose(); Env.clearWinContext(wsc.ctx, WindowNo); } - + + /** * New Window data */ @@ -247,8 +215,7 @@ public class WWindow extends HttpServlet ws.mWindow.initTab(ws.curTab.getTabNo()); ws.curTab.setQuery(MQuery.getEqualQuery(TableName + "_ID", AD_Record_ID)); ws.curTab.query(false); - } - else{ + } else { ws.mWindow.initTab(ws.curTab.getTabNo()); ws.curTab.query(ws.mWindow.isTransaction()); ws.curTab.navigate(0); @@ -294,6 +261,7 @@ public class WWindow extends HttpServlet doGet(request, response); return; } + // Get Parameter: Command String p_cmd = WebUtil.getParameter (request, P_Command); String column = WebUtil.getParameter (request, P_ChangedColumn); @@ -316,7 +284,6 @@ public class WWindow extends HttpServlet } executeCommand(request, p_cmd, wsc, ws); } - /************************************************** * Build Page @@ -435,7 +402,7 @@ public class WWindow extends HttpServlet } else if (p_cmd.equals("Last")) { - ws.curTab.navigateRelative(999999); + ws.curTab.navigateRelative(LAST_LINE); } /** * Find @@ -563,6 +530,43 @@ public class WWindow extends HttpServlet { executeSave (request, wsc, ws); } + + else if (p_cmd.equals("Find")) + { + String strSearch=WebUtil.getParameter(request, "txtSearch"); + if (strSearch!=null) { + MQuery query=new MQuery(); + if (strSearch.length()!=0) + query.addRestriction(m_searchField, MQuery.LIKE, strSearch); + ws.curTab.setQuery(query); + ws.curTab.query(false); + ws.curTab.navigate(0); + } + } + + else if (p_cmd.equals("FindAdv")) + { + String strSQL=WebUtil.getParameter(request, "txtSQL"); + if (strSQL!=null) { + MQuery query=new MQuery(); + if (strSQL.equals("FIND")) { + String value=WebUtil.getParameter(request, "txtValue"); + String docno=WebUtil.getParameter(request, "txtDocumentNo"); + String name=WebUtil.getParameter(request, "txtName"); + String desc=WebUtil.getParameter(request, "txtDescription"); + + if (value!=null && value.length()!=0) query.addRestriction("Value", MQuery.LIKE, value); + if (docno!=null && docno.length()!=0) query.addRestriction("DocumentNo", MQuery.LIKE, docno); + if (name!=null && name.length()!=0) query.addRestriction("Name", MQuery.LIKE, name); + if (desc!=null && desc.length()!=0) query.addRestriction("Description", MQuery.LIKE, desc); + } else { + query.addRestriction(strSQL); + } + ws.curTab.setQuery(query); + ws.curTab.query(false); + ws.curTab.navigate(0); + } + } } // executeCommand /** @@ -644,7 +648,15 @@ public class WWindow extends HttpServlet // we found a writable field if (mField != null && mField.isEditable(true)) { - String value = WebUtil.getParameter(request, key); + String oldValue = WebUtil.getParameter(request, key); + String newValue = WebUtil.getParameter(request, key + "F"); + String value=null; + if (newValue!=null) { + Object val=lookupValue(newValue, mField.getLookup()); + if (val!=null) value=val.toString(); + } + if (value==null)value=oldValue; + Object dbValue = mField.getValue(); boolean fieldError = false; String columnName = mField.getColumnName(); @@ -675,7 +687,7 @@ public class WWindow extends HttpServlet } // for all parameteres // Re-Do Changed Column to overwrite - String columnName = WebUtil.getParameter (request, P_ChangedColumn); + /*String columnName = WebUtil.getParameter (request, P_ChangedColumn); if (columnName != null && columnName.length() > 0) { GridField mField = ws.curTab.getField(columnName); @@ -692,7 +704,7 @@ public class WWindow extends HttpServlet ws.curTab.setValue(mField, newValue); } } - } + }*/ return error; } // updateFields @@ -856,6 +868,7 @@ public class WWindow extends HttpServlet // tr line = new tr(); //Modified by Rob Klein 4/29/07 + m_searchField=null; boolean isTabRO = ws.curTab.isReadOnly(); if (ws.curTab.isDisplayed()) { @@ -898,6 +911,16 @@ public class WWindow extends HttpServlet .append(".").append(columnName) .append(".displayLogic='").append(dispLogic).append("';\n"); } + + if (m_searchField==null) + if (columnName.equals("Description")) + m_searchField=columnName; + else if (columnName.equals("Name")) + m_searchField=columnName; + else if (columnName.equals("DocumentNo")) + m_searchField=columnName; + else if (columnName.equals("Value")) + m_searchField=columnName; } } // for all fields } // displayed @@ -906,9 +929,9 @@ public class WWindow extends HttpServlet // Status Line int rowNo = ws.curTab.getCurrentRow(); - String statusDB = String.valueOf(rowNo+1) + " # " + ws.curTab.getRowCount(); + String statusDB = String.valueOf(rowNo+1) + " / " + ws.curTab.getRowCount(); // - return createLayout (action, table, wsc, ws, "", statusDB); + return createLayout (action, table, wsc, ws, ws.curTab.getDescription(), statusDB); } // getSR_Form @@ -936,17 +959,19 @@ public class WWindow extends HttpServlet table.setCellSpacing(1); tr line = new tr(); // First Column - //Modified by Rob Klein 4/29/07 + //Modified by Rob Klein 4/29/07 + m_searchField=null; line.addElement(new th().addElement(" ")); // Tab not displayed if (!ws.curTab.isDisplayed()) - return createLayout (action, table, wsc, ws, "", "-"); + return createLayout (action, table, wsc, ws, "The table is not displayed", "-"); int noFields = ws.curTab.getFieldCount(); // for all (header) columns for (int colNo = 0; colNo < noFields; colNo++) { GridField field = ws.curTab.getField(colNo); + String columnName = field.getColumnName(); if (field.isDisplayed(false)) { th th = new th(); @@ -954,32 +979,43 @@ public class WWindow extends HttpServlet th.addElement(field.getHeader()).setClass("table-filterable table-filtered table-sortable:default"); //th.addElement(field.getHeader()); th.setAbbr(field.getDescription()); - line.addElement(th); + line.addElement(th); + + if (m_searchField==null) + if (columnName.equals("Description")) + m_searchField=columnName; + else if (columnName.equals("Name")) + m_searchField=columnName; + else if (columnName.equals("DocumentNo")) + m_searchField=columnName; + else if (columnName.equals("Value")) + m_searchField=columnName; + } } // for all columns // Modified by Rob Klein Client Side Filter Manual Filter 6/1/07 - tr line2 = new tr(); - th th = new th(); + //tr line2 = new tr(); + //th th = new th(); //input filter = new input (input.TYPE_TEXT, " filter", ""); //filter.setOnKeyUp("Table.filter(this,this)"); - th.addElement(" "); - line2.addElement(th); - input filter = null; - for (int colNo = 0; colNo < noFields; colNo++) - { - GridField field = ws.curTab.getField(colNo); - if (field.isDisplayed(false)) - { - th = new th(); - filter = new input (input.TYPE_TEXT, field.getHeader()+"filter", ""); - filter.setOnKeyUp("Table.filter(this,this)"); - th.addElement(filter); - line2.addElement(th); + //th.addElement(" "); + //line2.addElement(th); + //input filter = null; + //for (int colNo = 0; colNo < noFields; colNo++) + //{ + // GridField field = ws.curTab.getField(colNo); + // if (field.isDisplayed(false)) + // { + // th = new th(); + // filter = new input (input.TYPE_TEXT, field.getHeader()+"filter", ""); + // filter.setOnKeyUp("Table.filter(this,this)"); + // th.addElement(filter); + // line2.addElement(th); //line.addElement(th); - } - } // for all columns + // } + //} // for all columns //Modified by Rob Klein 4/29/07 - table.addElement(new thead().addElement(line).addElement(line2)); + table.addElement(new thead().addElement(line)); //Modified by Rob Klein 4/29/07 table.addElement(""); @@ -1070,9 +1106,9 @@ public class WWindow extends HttpServlet //Modified by Rob Klein 4/29/07 table.addElement(""); // Status Line - String statusDB = String.valueOf(initRowNo+1) + "-" + String.valueOf(lastRow) + " # " + ws.curTab.getRowCount(); + String statusDB = String.valueOf(initRowNo+1) + "-" + String.valueOf(lastRow) + " / " + ws.curTab.getRowCount(); - return createLayout (action, table, wsc, ws, "", statusDB); + return createLayout (action, table, wsc, ws, ws.curTab.getDescription(), statusDB); } // getMR_Form /** @@ -1087,11 +1123,11 @@ public class WWindow extends HttpServlet */ private WebDoc createLayout (String action, table contentTable, WebSessionCtx wsc, WWindowStatus ws, String statusInfo, String statusDB) - { + { form myForm = null; myForm = new form(action); - myForm.setTarget(WebEnv.TARGET_WINDOW); - myForm.setID("WWindow" + ws.mWindow.getAD_Window_ID()); + myForm.setID("WForm"); + myForm.setOnSubmit("this.target=window.name"); String AD_Language = Env.getAD_Language(ws.ctx); // Window @@ -1099,6 +1135,7 @@ public class WWindow extends HttpServlet myForm.addElement(new input("hidden", P_Command, "")); // button commands myForm.addElement(new input("hidden", P_MR_RowNo, "")); // RowNo myForm.addElement(new input("hidden", P_ChangedColumn, "")); // + // Set Title of main window String title = ws.mWindow.getName() + " - " + wsc.loginInfo; myForm.addElement(new script("top.document.title='" + title + "';")); @@ -1122,11 +1159,20 @@ public class WWindow extends HttpServlet toolbar.addElement(createImageLink (AD_Language, "Chat","startPopup('WChat')", true, false)); toolbar.addElement(createImageLink (AD_Language, "Refresh")); toolbar.addElement(createImageLink (AD_Language, "Attachment", - "startPopup('WAttachment')", ws.curTab.canHaveAttachment(), ws.curTab.hasAttachment())); + "startPopup('WAttachment')", ws.curTab.canHaveAttachment(), ws.curTab.hasAttachment())); toolbar.addElement(createImageLink (AD_Language, "Multi", null, true, !ws.curTab.isSingleRow())); + toolbar.addElement(createImageLink (AD_Language, "FindAdv","startPopup('WFindAdv')", true, false)); + + if (m_searchField!=null) { + input txtSearch = new input(input.TYPE_TEXT, "txtSearch", "[" + m_searchField + "]"); + txtSearch.setOnChange("SubmitForm('Find', 'Submit','toolbar');return false;"); + toolbar.addElement(txtSearch); + } + toolbar.addElement(" "); - toolbar.addElement(createImageLink (AD_Language, "History", - null, ws.mWindow.isTransaction()&&ws.curTab.getTabNo()==0, !ws.curTab.isOnlyCurrentRows())); + toolbar.addElement(createImageLink (AD_Language, "History","startPopup('WHistory')", true, false)); + //toolbar.addElement(createImageLink (AD_Language, "History", + // null, ws.mWindow.isTransaction()&&ws.curTab.getTabNo()==0, !ws.curTab.isOnlyCurrentRows())); toolbar.addElement(" "); boolean isFirst = ws.curTab.getCurrentRow() < 1; toolbar.addElement(createImageLink (AD_Language, "First", null, !isFirst, false)); @@ -1161,7 +1207,10 @@ public class WWindow extends HttpServlet if (tab.getDescription().length() > 0) big.setOnMouseOver("status='" + tab.getDescription() + "';return true;"); - tabbar.addElement(big); + if (tab.isReadOnly()) + tabbar.addElement(new i().addElement(big)); + else + tabbar.addElement(big); } // Top Table @@ -1173,16 +1222,24 @@ public class WWindow extends HttpServlet myForm.addElement(topTable); // Fields - myForm.addElement(contentTable); + + div panel=new div(); + panel.setStyle("overflow: scroll;overflow: auto;"); + panel.addElement(contentTable); + + myForm.addElement(panel); // Status Line table statusTable = new table ("0", "0", "0", "100%", null); topTable.setID("WWindow.statusLine"); tr statusLine = new tr(); statusLine.addElement(new td().setWidth("85%").setAlign(AlignType.LEFT) - .addElement(statusInfo)); + .addElement(" # " + statusInfo)); + a db =new a("#"); + db.setOnClick("alert('" + ws.curTab.getKeyColumnName() + " = " + ws.curTab.getRecord_ID() + "')"); + db.addElement(statusDB); statusLine.addElement(new td().setWidth("10%").setAlign(AlignType.RIGHT) - .addElement(new small(statusDB))); + .addElement(db)); statusLine.addElement(new td().setWidth("5%").setAlign(AlignType.RIGHT) //Modified by Rob Klein 4/29/07 .addElement(createImageLink (AD_Language, "Save"))); @@ -1298,8 +1355,12 @@ public class WWindow extends HttpServlet // if (js_command == null) js_command = "'Submit'"; - if (js_command.length() > 0 && enabled) - img.setOnClick( "SubmitForm('" + name + "', " + js_command + ",'toolbar');return false;"); + if (js_command.length() > 0 && enabled){ + if(js_command.startsWith("startPopup")) + img.setOnClick(js_command); + else + img.setOnClick( "SubmitForm('" + name + "', " + js_command + ",'toolbar');return false;"); + } img.setClass("ToolbarButton"); img.setOnMouseOver("window.status='"+name+"';return true;"); img.setOnMouseOut("window.status='';return true;"); @@ -1327,7 +1388,7 @@ public class WWindow extends HttpServlet * @param oData original data * @param hasDependents has Callout function(s) */ - private void addField (WebSessionCtx wsc, tr line, GridField field, + public static void addField (WebSessionCtx wsc, tr line, GridField field, Object oData, boolean hasDependents, int recordID, int tableID, boolean tabRO, int fieldNumber, GridTab mTab, MRole role) { @@ -1385,6 +1446,12 @@ public class WWindow extends HttpServlet .addElement(wField.getLabel()) .addElement(wField.getField(field.getLookup(), oData)); } // addField - + + private Object lookupValue(String key, Lookup lookup) { + if (lookup.containsKey(key)) + return lookup.get(key); + + return DB.getSQLValueString(null, "SELECT " + lookup.getColumnName() + " FROM " + lookup.getZoomQuery().getTableName() + " WHERE " + lookup.getZoomQuery().getWhereClause() + " AND Value LIKE ?", key); + } } // WWindow diff --git a/serverApps/src/main/servlet/org/compiere/www/WWindowStatus.java b/serverApps/src/main/servlet/org/compiere/www/WWindowStatus.java index 92779fa6ea..1ecc2bda61 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WWindowStatus.java +++ b/serverApps/src/main/servlet/org/compiere/www/WWindowStatus.java @@ -21,67 +21,96 @@ import java.util.Properties; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.compiere.model.GridTab; -import org.compiere.model.GridWindow; -import org.compiere.model.GridWindowVO; +import org.compiere.model.*; +import org.compiere.util.WebUtil; -/** - * WWindow Status Information (Value Object) - * - * @author Jorg Janke - * @version $Id: WWindowStatus.java,v 1.3 2006/07/30 00:53:21 jjanke Exp $ - */ public class WWindowStatus { - /** - * Get Web Window Status. - WWindowStatus ws = WWindowStatus.get(ctx); - * @param request request - * @return ctx or null - */ public static WWindowStatus get (HttpServletRequest request) { - HttpSession session = request.getSession(false); - if (session == null) + HttpSession sess = request.getSession(false); + if (sess == null) return null; - return (WWindowStatus)session.getAttribute(NAME); - } // get - - /************************************************************************** - * Constructor - First Tab - First Row - Single Row. - *
    - * Initialize Formats - * @param mWindowVO window VO - */ + String wsName=WebUtil.getParameter(request,"wsName"); + System.out.println("main window wsName = "+wsName); + String newWindow=WebUtil.getParameter(request,"blankWindow"); + WWindowStatus clientWS=(WWindowStatus)sess.getAttribute(NAME); + if((wsName==null&&WStatusArrayList.get(request)==null)||clientWS.getStatusName().equals(wsName)) + { + System.out.println("Run wsName==null 1"); + System.out.println("clientWS = "+clientWS); + return clientWS; + } + String AD_Menu_ID=WebUtil.getParameter(request,"AD_Menu_ID"); + if(wsName==null&&WStatusArrayList.get(request)!=null&&newWindow==null&&AD_Menu_ID!=null) + { System.out.println("Run if(wsName == null) 2"); + WWindowStatus ws=(WWindowStatus)WStatusArrayList.get(request).getWSFromStatusArray("1"); + sess.setAttribute(WWindowStatus.NAME, ws); + return ws; + } + if(wsName!=null) + { + System.out.println("if(wsName!=null)"); + WStatusArrayList wsl=WStatusArrayList.get(request); + + if(wsl==null) + {System.out.println("wsName!=null && wsl == null"); + return null; + } + + WWindowStatus serverWS=wsl.getWSFromStatusArray(wsName); + + if(serverWS==null) + { System.out.println("wsName!=null && serverWS == null"); + return null; + } + + sess.setAttribute(WWindowStatus.NAME, serverWS); + System.out.println("serverWS"); + return serverWS; + + } + return clientWS; + } public WWindowStatus (GridWindowVO mWindowVO) { - mWindow = new GridWindow(mWindowVO); + mWindow = new GridWindow(mWindowVO); curTab = mWindow.getTab(0); curTab.setSingleRow(true); // ctx = mWindowVO.ctx; + statusName=""; } // WWindowStatus - - /** Session Attribute Name */ +/* public WWindowStatus (GridWindowVO mWindowVO) + { + mWindow = new GridWindow(mWindowVO); + curTab = mWindow.getTab(0); + curTab.setSingleRow(true); + ctx = mWindowVO.ctx; + statusName=""; + } */ public static final String NAME = "WWindowStatus"; - - /** The MWindow */ protected GridWindow mWindow; - /** The current MTab */ protected GridTab curTab; - - /** Window Context */ + private String statusName; + public Properties ctx = null; - - /** - * String representation - * @return String representation - */ + public String getStatusName() + { + return statusName; + } + public void setStatusName(String name) + { + statusName=name; + } + public int getWindowNo() + { + return mWindow.getWindowNo(); + } public String toString() { return "WWindowStatus[" + mWindow + " - " + curTab + "]"; - } // toString - -} // WWindowStatus + } +} \ No newline at end of file diff --git a/serverApps/src/main/servlet/org/compiere/www/WWorkflow.java b/serverApps/src/main/servlet/org/compiere/www/WWorkflow.java index bf2c5f2d7d..91eaae7b27 100644 --- a/serverApps/src/main/servlet/org/compiere/www/WWorkflow.java +++ b/serverApps/src/main/servlet/org/compiere/www/WWorkflow.java @@ -17,34 +17,91 @@ package org.compiere.www; import java.io.IOException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Properties; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import org.apache.ecs.xhtml.body; +import org.apache.ecs.xhtml.br; +import org.apache.ecs.xhtml.form; +import org.apache.ecs.xhtml.h2; +import org.apache.ecs.xhtml.h6; +import org.apache.ecs.xhtml.head; +import org.apache.ecs.xhtml.hr; +import org.apache.ecs.xhtml.img; +import org.apache.ecs.xhtml.input; +import org.apache.ecs.xhtml.link; +import org.apache.ecs.xhtml.script; +import org.apache.ecs.xhtml.table; +import org.apache.ecs.xhtml.td; +import org.apache.ecs.xhtml.tr; +import org.compiere.util.DB; +import org.compiere.util.Env; +import org.compiere.util.Msg; import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; +import org.compiere.util.WebSessionCtx; import org.compiere.util.WebUtil; +import org.compiere.wf.MWFNode; +import org.compiere.wf.MWorkflow; + + + /** * * - * @author Jorg Janke - * @version $Id: WWorkflow.java,v 1.2 2006/07/30 00:53:21 jjanke Exp $ + * @author Jack Lam + * @version $Id: WWorkflow.java,v 1.1 2009/04/15 11:27:15 vinhpt Exp $ */ public class WWorkflow extends HttpServlet { - /** - * - */ - private static final long serialVersionUID = 7535552109735485229L; - /** * Initialize global variables */ + +public static final int SIZE = 3; +public static final int SPACE = 0; +public static final int ARROW_FORWARD = -1; +public static final int ARROW_BACKWARD = -3; +public static final int ARROW_DOWN = -2; + +public static final String WORKFLOW = "Workflow"; +public static final String NODES = "Nodes"; +public static final String NODES_ID = "Nodes_ID"; +public static final String IMAGE_MAP= "Image_Map"; +public static final String ACTIVE_NODE= "Active_Node"; + +public static final String M_Command = "MCommand"; // move command +public static final String J_Command = "JCommand"; // jump command + +public static final String FIRST = "Start"; +public static final String NEXT = "Next"; +public static final String BACK= "Back"; +public static final String LAST= "End"; + +private static final String FORM_NAME = "MForm"; +private static final String TARGET_WINDOW = "WWindow"; +private static final String FORM_ACTION = "/adempiere/WWorkflow"; + + +private static String AD_Language = null; +Properties ctx = null; + +/** Window Number Counter */ +private static int s_WindowNo = 1; + + public void init(ServletConfig config) throws ServletException { @@ -54,26 +111,820 @@ public class WWorkflow extends HttpServlet } // init /** - * Process the HTTP Get request + * Process the HTTP Get request - Initial Call. + *
    + * http://localhost/adempiere/WWorkflow?AD_Menu_ID=123 + *
    + * + * Find the AD_Workflow_ID + * Load workflow and initial session atribute + * Create output + * + * @param request + * @param response + * @throws ServletException + * @throws IOException */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - WebDoc doc = WebDoc.create ("WWorkflow - Get - Not Implemented Yet"); - // + //Log.trace(Log.l1_User, "WWorkflow.doGet"); +//WUtil.debug(new String("In do get"),""); + + + // Get Session attributes + HttpSession sess = request.getSession(); + WebSessionCtx wsc = WebSessionCtx.get(request); + ctx = wsc.ctx; + //String loginInfo = (String)sess.getAttribute(WebEnv.SA_LOGININFO); + if (ctx == null) + { + WebUtil.createTimeoutPage(request, response, this, null); + return; + } + + + + // Get Parameter: Menu_ID + int AD_Menu_ID = WebUtil.getParameterAsInt(request, "AD_Menu_ID"); + + // Get Parameter: Menu_ID + int AD_Window_ID = WebUtil.getParameterAsInt(request, "AD_Window_ID"); + + + //set language + AD_Language = Env.getAD_Language(ctx); + + //load AD_Workflow_ID + int AD_Workflow_ID = getAD_Workflow_ID(AD_Menu_ID); + + //load workflow + loadWorkflow(ctx, AD_Workflow_ID,sess); + + //get session attributes + MWorkflow wf = (MWorkflow)sess.getAttribute(WORKFLOW); + MWFNode [] nodes = (MWFNode []) sess.getAttribute( NODES); + ArrayList nodes_ID = (ArrayList) sess.getAttribute( NODES_ID); + int [][] imageMap = (int [][] )sess.getAttribute( IMAGE_MAP); + int activeNode = ((Integer) sess.getAttribute( ACTIVE_NODE)).intValue(); + + //create output + WebDoc doc = preparePage("loginInfo"); + doc = createLayout( doc,wf,activeNode,nodes,nodes_ID,imageMap); WebUtil.createResponse(request, response, this, null, doc, false); } // doGet /** - * Process the HTTP Post request + * Process the HTTP Post request - Initial Call. + * + * Execute the received command + * Update session attributes + * Create output + * + * @param request + * @param response + * @throws ServletException + * @throws IOException */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - WebDoc doc = WebDoc.create ("WWorkflow - Post - Not Implemented Yet"); - // + //WUtil.debug(new String("In do Post"),""); + HttpSession sess = request.getSession(); + + WebSessionCtx wsc = WebSessionCtx.get(request); + Properties ctx = wsc.ctx; + if (ctx == null){ + WebUtil.createTimeoutPage(request, response, this, null); + + return; + } + //String loginInfo = (String)sess.getAttribute(WEnv.SA_LOGININFO); + + + + + //get session attributes + MWorkflow wf = (MWorkflow)sess.getAttribute(WORKFLOW); + MWFNode [] nodes = (MWFNode []) sess.getAttribute( NODES); + ArrayList nodes_ID = (ArrayList) sess.getAttribute( NODES_ID); + int [][] imageMap = (int [][] )sess.getAttribute( IMAGE_MAP); + int activeNode = ((Integer) sess.getAttribute( ACTIVE_NODE)).intValue(); + + + + //execute commnad + String m_command = request.getParameter(M_Command); + int j_command = WebUtil.getParameterAsInt(request, J_Command); + //WUtil.debug(m_command,"m_command"); + //WUtil.debug(""+j_command,"j_command"); + + + executeCommand(m_command,j_command ,wf,activeNode,nodes,nodes_ID,sess); + + +//get updated session attributes + wf = (MWorkflow)sess.getAttribute(WORKFLOW); + nodes = (MWFNode []) sess.getAttribute( NODES); + nodes_ID = (ArrayList) sess.getAttribute( NODES_ID); + imageMap = (int [][] )sess.getAttribute( IMAGE_MAP); + activeNode = ((Integer) sess.getAttribute( ACTIVE_NODE)).intValue(); + + + //create layout + WebDoc doc = preparePage ("loginInfo"); + doc = createLayout(doc,wf,activeNode,nodes,nodes_ID,imageMap); WebUtil.createResponse(request, response, this, null, doc, false); } // doPost + +/**********************************************************************************************/ + +/** + * Generate image map array. + * - Generate the orientation of workflow automatically + * + * @param nodes + * @return int [][] + */ +private int [][] generateImageMap(ArrayList nodes_ID){ + +// number of nodes +int numOfNode = nodes_ID.size(); + +int rowNode_count = (int) Math.ceil( (float)numOfNode/SIZE ) ; + +int rowTotal_count = 2*rowNode_count -1 ; + +int ROW = rowTotal_count; +int COL = 2*SIZE-1; + + +int [][] imageMap = new int [ROW][COL]; +// +boolean isEmptyRow_Right = true; +boolean isForwardRow = true; +int row_Last = ROW - 1; +//indexs +int index_Row =0; +int index_Node =0; +int i,j; + + +//operate on every row +for (index_Row=0;index_Row < ROW ;index_Row++) +{ +//odd row +if ( (index_Row % 2) != 0) +{ +if(isEmptyRow_Right){ + imageMap[index_Row][COL-1] = ARROW_DOWN; +isEmptyRow_Right = false; +} +else { + imageMap[index_Row][0]= ARROW_DOWN; +isEmptyRow_Right = true; +} +}//odd row + + +//even row +if ( (index_Row % 2) == 0) +{ +if (isForwardRow) +{ +isForwardRow = false; + +// Last row +if (index_Row == row_Last) +{ +j=0; +for (i=index_Node;i"+nodes[getIndex(imageMap[i][j],nodes_ID)].getName()+""); +}//active node + +else { +//Create image +AD_Window_ID = nodes[getIndex(imageMap[i][j],nodes_ID)].getAD_Window_ID(); + // url = "'WWindow?AD_Window_ID="+AD_Window_ID+"&Target_Window=win_"+AD_Window_ID+"'"; + url = "'WWindow?AD_Window_ID="+AD_Window_ID; + +//url=WebEnv.getBaseDirectory("WWindow")+"?AD_Window_ID="+AD_Window_ID+"&Target_Window=win_"+AD_Window_ID+"'"; + Target_Window = "'WWindow"+AD_Window_ID+"'"; + + System.out.println("WorkFlow else======"+url); + parameters = url+ "',"+Target_Window; + js_command = "popUp("+parameters+");submit()"; + normalNodeImage = createWorkflowImage("mWorkFlow_", imageMap[i][j],js_command, false); + +grid.addElement(normalNodeImage); +grid.addElement(new br()); +grid.addElement(""+imageMap[i][j]); +grid.addElement(new br()); +grid.addElement(nodes[getIndex(imageMap[i][j],nodes_ID)].getName()); +}//inactive node +} +aRow.addElement(grid); +}//process every gird + +imageTable.addElement(aRow); +}//every row + + + +return imageTable; +}//printWorkflow + + + +/** + * Print the description for a workflow or a node. + * + * + * @param activeNode + * @param wf + * @param nodes + * @param nodes_ID + * + * @return table + */ +private table printDescription(int activeNode, MWorkflow wf, MWFNode [] nodes, ArrayList nodes_ID){ +//create new table +table desTable = new table(); + +String WFName=""; +String WFDescription =""; + +//not started yet +if(activeNode < 0 ){ +WFName =wf.getName(); +WFDescription=wf.getHelp(); +} + +//started +else{ +WFName =nodes[getIndex(activeNode,nodes_ID)].getName(); +WFDescription=nodes[getIndex(activeNode,nodes_ID)].getHelp(); +} + +//add info to the desciption table +tr aRow = new tr(); +td aGrid = new td(); +aGrid.addElement (new h6(WFName)); +aGrid.addElement (new br()); +aGrid.addElement (WFDescription); +desTable.addElement(aRow.addElement(aGrid)); + +return desTable; +}// printDescription + + + +/** + * Find the index at which the WFNode ID is positioned. + * + * + * @param node_ID + * @param nodes_ID + * + * @return int + */ +private int getIndex(int node_ID, ArrayList nodes_ID){ + +int index = 0; + +for(int i =0;i=0 ? getIndex(activeNode,nodes_ID)-1 : 0 ; +//WUtil.debug(""+index,"index"); +Back_Window_ID= nodes[index].getAD_Window_ID(); +} +if(!isLast){ +index = activeNode >=0 ? getIndex(activeNode,nodes_ID)+1 : 0 ; +Next_Window_ID= nodes[index].getAD_Window_ID(); +} +boolean enableFirst = true; +boolean enableBack = true; +boolean enableNext = true; +boolean enableLast = true; + +if(isFirst) { + enableBack = false; + enableFirst = false; +} +if(isLast) { +enableNext = false; +enableLast = false; +} + +td firstImage = new td(); +td backImage = new td(); +td nextImage = new td(); +td lastImage = new td(); + +//first + String url = "'WWindow?AD_Window_ID="+First_Window_ID +"'"; + //String url=WebEnv.getBaseDirectory("WWindow")+"?AD_Window_ID="+First_Window_ID+"&Target_Window=win_"+First_Window_ID+"'"; + String Target_Window = "'WWindow"+First_Window_ID+"'"; + String parameters = url+ ","+Target_Window; + String js_command = "popUp("+parameters+");submit()"; + firstImage.addElement(createControlButtonImage("Start", js_command, enableFirst)); +//back + url = "'WWindow?AD_Window_ID="+Back_Window_ID + "'"; + // url=WebEnv.getBaseDirectory("WWindow")+"?AD_Window_ID="+Back_Window_ID+"&Target_Window=win_"+Back_Window_ID+"'"; + Target_Window = "'WWindow"+Back_Window_ID+"'"; + parameters = url+ ","+Target_Window; + js_command = "popUp("+parameters+");submit()"; + backImage.addElement(createControlButtonImage("Back", js_command, enableBack)); + +//next + url = "'WWindow?AD_Window_ID="+Next_Window_ID+"'"; + //url=WebEnv.getBaseDirectory("WWindow")+"?AD_Window_ID="+Next_Window_ID+"&Target_Window=win_"+Next_Window_ID+"'"; + Target_Window = "'WWindow"+Next_Window_ID+"'"; + parameters = url+ ","+Target_Window; + js_command = "popUp("+parameters+");submit()"; + nextImage.addElement(createControlButtonImage("Next", js_command, enableNext)); + +//last + url = "'WWindow?AD_Window_ID="+Last_Window_ID+"'"; +// url=WebEnv.getBaseDirectory("WWindow")+"?AD_Window_ID="+Last_Window_ID+"&Target_Window=win_"+Last_Window_ID+"'"; + Target_Window = "'WWindow"+Last_Window_ID+"'"; + parameters = url+ ","+Target_Window; + js_command = "popUp("+parameters+");submit()"; + lastImage.addElement(createControlButtonImage("End", js_command, enableLast)); + + +tr aRow = new tr(); +aRow.addElement(firstImage); +aRow.addElement(backImage); +aRow.addElement(nextImage); +aRow.addElement(lastImage); + +//add the table to the form +myForm.addElement(new table().addElement(aRow)); + +return myForm; +}//printControlPanel + + +/** + * Create Image with name, id of button_name and set M_Command onClick + * + * + * @param name Name of the Image used also for Name24.gif + * @param js_command Java script command, null results in 'submit();', an empty string disables OnClick + * @param enabled Enable the immage button, if not uses the "D" image + + * @return Image + */ + private static img createControlButtonImage (String name, String js_command, boolean enabled) + { + StringBuffer imgName = new StringBuffer("wf" + name); + + if (!enabled) + imgName.append("D"); + + imgName.append("24.gif"); + // + img img = new img (WebEnv.getImageDirectory(imgName.toString()), name); + if (enabled) + img.setAlt(Msg.getMsg(AD_Language, name)); // Translate ToolTip + + img.setID("imgButton"); // css + + //append js command only to enabled image + if ( js_command != null && js_command.length() > 0 && enabled){ + img.setOnClick("document." + FORM_NAME + "." + M_Command + ".value='" + name + "';" + js_command); + } + // + return img; + } // createImage + +/** + * Create Image with name, id of button_name and set M_Command onClick + * + * + * @param name Name of the Image used also for Name24.gif + * @param js_command Java script command, null results in 'submit();', an empty string disables OnClick + * @param enabled Enable the immage button, if not uses the "D" image + + * @return Image + */ + private static img createWorkflowImage (String name, int activeNode , String js_command, boolean pressed) + { + StringBuffer imgName = new StringBuffer(name); + imgName.append("WF"); + + imgName.append(".gif"); + // + img img = new img (WebEnv.getImageDirectory(imgName.toString()), name); + + + +if ( !(imgName.toString()).startsWith("Spacer") && !(imgName.toString()).startsWith("Arrow")){ + if(!pressed) + img.setID("imgButton"); // css + else + img.setID("imgButtonPressed"); + } + + //append js command only to enabled image + if ( js_command != null && js_command.length() > 0 && activeNode != 0){ +String js_command_front = "document." + FORM_NAME + "." + J_Command + ".value='" + activeNode + "'; " ; +js_command_front= js_command_front + "document." + FORM_NAME + ".submit();"; + img.setOnClick(js_command_front + js_command ); + } + // + return img; + } // createImage + + +/** + * Print the entire layout . + * + * + * @param activeNode + * @param wf + * @param nodes + * @param nodes_ID + * @param imageMap + * + * @return WReportEngine + */ +private WebDoc createLayout(WebDoc doc , MWorkflow wf,int activeNode,MWFNode [] nodes, ArrayList nodes_ID, int [][] imageMap){ +body b= doc.getBody(); + +b.addElement(printWorkflow(activeNode, wf, nodes, nodes_ID, imageMap)); +b.addElement(new hr()); +b.addElement(printDescription(activeNode, wf, nodes, nodes_ID)); +b.addElement(new br()); +b.addElement(printControlPanel(activeNode, wf, nodes, nodes_ID)); + +return doc; +}//createLayout + +/** + * Load workflw and initialize the session attributes. + * + * + * @param ctx + * @param AD_Workflow_ID + * @param sess + * + */ +private void loadWorkflow(Properties ctx, int AD_Workflow_ID, HttpSession sess) { + + + MWorkflow wf = new MWorkflow (ctx, AD_Workflow_ID,null); + //get the MWFNode in order + MWFNode[] nodes = wf.getNodes(true,Env.getContextAsInt(ctx, "#AD_Client_ID")); + MWFNode wfn=null; + ArrayList nodes_ID = new ArrayList(); + for (int i = 0; i < nodes.length; i++) + { + wfn= nodes[i]; + nodes_ID.add (new Integer(wfn.getAD_WF_Node_ID())); + }//for + int imageMap [][] = generateImageMap(nodes_ID); + //printMap(imageMap); +//set session attribtes +sess.setAttribute( WORKFLOW,wf); +sess.setAttribute( NODES,nodes); +sess.setAttribute( NODES_ID,nodes_ID); +sess.setAttribute( IMAGE_MAP,imageMap); +sess.setAttribute( ACTIVE_NODE,new Integer(-999)); + +}//loadWorkflow + +/** + * Execute the M_Command and update the . + * + * + * @param m_command + * @param wf + * @param activeNode + * @param nodes + * @param nodes_ID + * @param sess + * + */ +private void executeCommand(String m_command, int j_command , MWorkflow wf,int activeNode, MWFNode [] nodes,ArrayList nodes_ID, HttpSession sess){ +if (j_command != 0 ) +{ +sess.setAttribute(ACTIVE_NODE, new Integer(j_command)); +return; +} + +debug(m_command,"m_command in executeCommand"); +//check first or last node +boolean isFirst = wf.isFirst(activeNode,Env.getContextAsInt(ctx, "#AD_Client_ID")); +boolean isLast = wf.isLast(activeNode,Env.getContextAsInt(ctx, "#AD_Client_ID")); + +boolean notReady = false; +int updatedActiveNode = activeNode; + +if (activeNode < 0 ) notReady = true; + +if (notReady){ +updatedActiveNode = ((Integer) nodes_ID.get(0)).intValue(); + +} + +else{ +if(m_command.equals(NEXT)){ +if(notReady) + updatedActiveNode = ((Integer) nodes_ID.get(0)).intValue(); + else + updatedActiveNode= wf.getNext(activeNode,Env.getContextAsInt(ctx, "#AD_Client_ID")); + +}//next +if(m_command.equals(BACK)) { + if(notReady) + updatedActiveNode = ((Integer) nodes_ID.get(0)).intValue(); + else + updatedActiveNode= wf.getPrevious(activeNode,Env.getContextAsInt(ctx, "#AD_Client_ID")); +}//back +if(m_command.equals(FIRST)) + updatedActiveNode= ((Integer) nodes_ID.get(0)).intValue(); + +if(m_command.equals(LAST)) updatedActiveNode= wf.getLast(0,Env.getContextAsInt(ctx, "#AD_Client_ID")); +}//ready + +//update +sess.setAttribute(ACTIVE_NODE,new Integer(updatedActiveNode)); +}//executeCommand + + +/** + * Retrieve the AD_Workflow_ID from database using AD_Menu_ID. + * + * + * @param AD_Menu_ID + * + * @return int + */ +private int getAD_Workflow_ID(int AD_Menu_ID){ + + int AD_Workflow_ID=0; + String sql = "SELECT AD_Workflow_ID FROM AD_Menu " + + "WHERE AD_Menu_ID=? AND Action='F'"; + try + { + PreparedStatement pstmt = DB.prepareStatement(sql); + pstmt.setInt(1, AD_Menu_ID); + ResultSet rs = pstmt.executeQuery(); + while (rs.next()) + AD_Workflow_ID= rs.getInt(1); + rs.close(); + pstmt.close(); + } + catch (SQLException e) + { + + e.printStackTrace(); + } +return AD_Workflow_ID; +}//getAD_Workflow_ID + + +/** + * Prepare Page. + * - Set Header + * + * @param loginInfo + * + * @return WReportEngine page + */ + private WebDoc preparePage(String loginInfo) + { + WebDoc doc = WebDoc.create ("Workflow"); + head header = doc.getHead(); + body b=doc.getBody(); + // add window.js & .css + header.addElement(new script("", WebEnv.getBaseDirectory("/js/window.js"))); + header.addElement(new link().setRel("stylesheet").setHref(WebEnv.getBaseDirectory("/css/window.css"))); + // + // + String title ="Workflow"+" - " + loginInfo; + b.addElement(new script("top.document.title='" + title + "';")); + return doc; + } // preparePage + +/** + * Debugger. + * - Display the name and value set + * + * @param variable + * @param name + * + * @return WReportEngine page + */ +private void debug(Object variable , String name){ +if (variable!=null) +{ +System.out.println("*************"+name+"="+variable); +} +else +System.out.println("*************"+name+" is null"); +}//debug +private void printMap(int [][] map){ +final int ROW = map.length; +final int COL = map[0].length; + + for(int row=0;row