KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > utility > VerticalMenu


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18 */

19 package org.openbravo.erpCommon.utility;
20
21 import org.openbravo.base.secureApp.*;
22 import org.openbravo.xmlEngine.XmlDocument;
23 import java.io.*;
24 import javax.servlet.*;
25 import javax.servlet.http.*;
26 import org.openbravo.utils.FormatUtilities;
27
28
29
30 public class VerticalMenu extends HttpSecureAppServlet {
31   
32
33   String JavaDoc target = "frameAplicacion";
34   
35   public void init (ServletConfig config) {
36     super.init(config);
37     boolHist = false;
38   }
39
40   public void doPost (HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
41     VariablesSecureApp vars = new VariablesSecureApp(request);
42
43     if (vars.commandIn("DEFAULT")) {
44       printPageDataSheet(response, vars, "0", false);
45     } else if (vars.commandIn("ALL")) {
46       printPageDataSheet(response, vars, "0", true);
47     } else if (vars.commandIn("ALERT")) {
48       printPageAlert(response, vars);
49     } else throw new ServletException();
50   }
51
52   void printPageAlert(HttpServletResponse response, VariablesSecureApp vars) throws IOException, ServletException {
53     
54     Integer JavaDoc alertCount = 0;
55     
56     VerticalMenuData[] data = VerticalMenuData.selectAlertRules(this, vars.getUser(), vars.getRole());
57     if (data!=null && data.length!=0) {
58       for (int i=0; i<data.length; i++) {
59         String JavaDoc strWhere = new UsedByLink().getWhereClause(vars,"",data[i].filterclause);
60         try {
61           Integer JavaDoc count = new Integer JavaDoc(VerticalMenuData.selectCountActiveAlerts(this, Utility.getContext(this, vars, "#User_Client", ""), Utility.getContext(this, vars, "#User_Org", ""),data[i].adAlertruleId,strWhere)).intValue();
62           alertCount += count;
63         } catch (Exception JavaDoc ex) {
64           log4j.error("Error in Alert Query, alertRule="+data[i].adAlertruleId+" error:"+ex.toString());
65         }
66       }
67     }
68   
69     response.setContentType("text/plain; charset=UTF-8");
70     PrintWriter out = response.getWriter();
71     out.println(alertCount.toString());
72     out.close();
73   }
74   
75   void printPageDataSheet(HttpServletResponse response, VariablesSecureApp vars, String JavaDoc strCliente, boolean open) throws IOException, ServletException {
76     if (log4j.isDebugEnabled()) log4j.debug("Output: Vertical Menu's screen");
77     String JavaDoc[] discard = new String JavaDoc[1];
78     if (open) discard[0] = new String JavaDoc("fieldDesplegar");
79     else discard[0] = new String JavaDoc("fieldContraer");
80     XmlDocument xmlDocument = xmlEngine.readXmlTemplate("org/openbravo/erpCommon/utility/VerticalMenu", discard).createXmlDocument();
81     
82     
83     MenuData[] data = MenuData.selectIdentificacion(this, strCliente);
84     MenuData[] dataMenu;
85     xmlDocument.setParameter("language", "LNG_POR_DEFECTO=\"" + vars.getLanguage() + "\";");
86     xmlDocument.setParameter("theme", vars.getTheme());
87     dataMenu = MenuData.select(this, vars.getLanguage(), vars.getRole(), data[0].parentId);
88     xmlDocument.setParameter("direction", "var baseDirection = \"" + strReplaceWith + "/\";\n");
89     StringBuffer JavaDoc menu = new StringBuffer JavaDoc();
90     menu.append(generarMenuVertical(dataMenu, strDireccion, "0", open));
91     menu.append("<tr>\n");
92     menu.append(" <td>\n");
93     menu.append(" <table cellspacing=\"0\" cellpadding=\"0\" onmouseover=\"window.status='");
94     menu.append(Utility.messageBD(this, "Information", vars.getLanguage()));
95     menu.append("';return true;\"");
96     menu.append(" onmouseout=\"window.status='';return true;\"");
97     menu.append(" id=\"folderInformation\">\n");
98     menu.append(" <tr class=\"Child");
99     if (open) menu.append(" Opened");
100     menu.append("\" id=\"childInformation\" onmouseover=\"setHover(this);return true;\" onmouseout=\"setMouseUp(this);this.className=this.className.replace(' Child_hover', (isOpened?' Opened':''));return true;\"");
101     menu.append(" onmousedown=\"setMouseDown(this);return true;\" onmouseup=\"setMouseUp(this);return true;\">\n");
102     menu.append(" <td width=\"5px\" id=\"folderCell1_Information\"><img SRC=\"").append(strReplaceWith).append("/images/blank.gif\" class=\"Menu_Client_Button_BigIcon Menu_Client_Button_BigIcon_folder");
103     menu.append((open?"Opened":""));
104     menu.append("\" id=\"folderImgInformation\"></td>\n");
105     menu.append(" <td nowrap=\"\" id=\"folderCell2_Information\">");
106     menu.append(Utility.messageBD(this, "Information", vars.getLanguage()));
107     menu.append(" </td>\n");
108     menu.append(" </tr>\n");
109     menu.append(" </table>\n");
110     menu.append(" </td>\n");
111     menu.append("</tr>\n");
112     menu.append("<tr>\n");
113     menu.append(" <td");
114     menu.append(" style=\"").append((!open?"display: none;":"")).append("\" id=\"parentInformation\">\n");
115     menu.append(" <table cellspacing=\"0\" cellpadding=\"0\">\n");
116     menu.append(generarMenuSearchs(vars, strDireccion, open));
117     menu.append(" </table>\n");
118     menu.append(" </td>\n");
119     menu.append("</tr>\n");
120     xmlDocument.setParameter("menu", menu.toString());
121     xmlDocument.setParameter("userName", MenuData.getUserName(this, vars.getUser()));
122
123     response.setContentType("text/html; charset=UTF-8");
124     PrintWriter out = response.getWriter();
125     out.println(xmlDocument.print());
126     out.close();
127   }
128
129   public String JavaDoc tipoVentana(String JavaDoc tipo) {
130     if (tipo.equals("W")) return "Windows";
131     else if (tipo.equals("X")) return "Forms";
132     else if (tipo.equals("P")) return "Processes";
133     else if (tipo.equals("T")) return "Tasks";
134     else if (tipo.equals("R")) return "Reports";
135     else if (tipo.equals("F")) return "WorkFlow";
136     else if (tipo.equals("B")) return "WorkBench";
137     else if (tipo.equals("L")) return "ExternalLink";
138     else return "";
139   }
140
141   public String JavaDoc tipoVentanaNico(String JavaDoc tipo) {
142     if (tipo.equals("W")) return "window";
143     else if (tipo.equals("X")) return "form";
144     else if (tipo.equals("P")) return "process";
145     else if (tipo.equals("T")) return "task";
146     else if (tipo.equals("R")) return "report";
147     else if (tipo.equals("F")) return "wf";
148     else if (tipo.equals("B")) return "wb";
149     else if (tipo.equals("L")) return "el";
150     else return "";
151   }
152
153   public String JavaDoc generarMenuVertical(MenuData[] menuData, String JavaDoc strDireccion, String JavaDoc indice, boolean open) {
154     if (menuData==null || menuData.length==0) return "";
155     if (indice == null) indice="0";
156     boolean hayDatos=false;
157     StringBuffer JavaDoc strText = new StringBuffer JavaDoc();
158     for (int i=0;i<menuData.length;i++) {
159       if (menuData[i].parentId.equals(indice)) {
160         hayDatos = true;
161         String JavaDoc strHijos = generarMenuVertical(menuData, strDireccion, menuData[i].nodeId, open);
162         String JavaDoc strID = "";
163         if (!strHijos.equals("") || menuData[i].issummary.equals("N")) {
164           strText.append("<tr>\n");
165           strText.append(" <td>\n");
166           strText.append(" <table cellspacing=\"0\" cellpadding=\"0\"");
167           if (menuData[i].issummary.equals("N")) {
168             strText.append(" id=\"").append(tipoVentanaNico(menuData[i].action)).append(menuData[i].nodeId).append("\"");
169             strID = tipoVentanaNico(menuData[i].action) + menuData[i].nodeId;
170           } else
171             strText.append(" id=\"folder").append(menuData[i].nodeId).append("\"");
172           strText.append(" onmouseover=\"window.status='");
173           strText.append(FormatUtilities.replaceJS(menuData[i].description));
174           strText.append("';return true;\"");
175           strText.append(" onmouseout=\"window.status='';return true;\">\n");
176           strText.append(" <tr");
177           strText.append(" class=\"Child");
178           if (open && menuData[i].issummary.equals("Y")) strText.append(" Opened");
179           strText.append("\"");
180           if (menuData[i].issummary.equals("N")) {
181             strText.append(" id=\"child").append(strID).append("\"");
182             strText.append(" onclick=\"checkSelected('child").append(strID).append("');openLink('");
183             if (menuData[i].action.equals("L")) strText.append(menuData[i].url);
184             else {
185               strText.append(getUrlString(strDireccion, menuData[i].name, menuData[i].action, menuData[i].classname, menuData[i].mappingname, menuData[i].adWorkflowId, menuData[i].adTaskId, menuData[i].adProcessId));
186             }
187             strText.append("', '");
188             if (menuData[i].action.equals("F") || menuData[i].action.equals("T") || (menuData[i].action.equals("P") && menuData[i].mappingname.equals(""))) strText.append("frameOculto");
189             else if (menuData[i].action.equals("L")) strText.append("_blank");
190             else strText.append(target);
191             strText.append("'");
192             if (menuData[i].action.equals("F")) strText.append(", 600, 600");
193             strText.append(");return false;\"");
194           } else {
195             strText.append(" id=\"child").append(menuData[i].nodeId).append("\"");
196           }
197           strText.append(" onmouseover=\"setHover(this);return true;\" onmouseout=\"setMouseUp(this);this.className=this.className.replace(' Child_hover', (isOpened?' Opened':''));return true;\"");
198           strText.append(" onmousedown=\"setMouseDown(this);return true;\" onmouseup=\"setMouseUp(this);return true;\">\n");
199           strText.append(" <td width=\"5px\"");
200           if (menuData[i].issummary.equals("Y")) strText.append(" id=\"folderCell1_").append(menuData[i].nodeId).append("\"");
201           strText.append(">");
202           strText.append("<img SRC=\"").append(strReplaceWith).append("/images/blank.gif\" class=\"Menu_Client_Button_").append((indice.equals("0")?"Big":"")).append("Icon");
203           if (menuData[i].issummary.equals("N")) {
204             if (menuData[i].action.equals("F")) strText.append(" Menu_Client_Button_Icon_childWorkFlow");
205             else if (menuData[i].action.equals("T")) strText.append(" Menu_Client_Button_Icon_childTasks");
206             else if (menuData[i].action.equals("B")) strText.append(" Menu_Client_Button_Icon_childWorkBench");
207             else if (menuData[i].action.equals("P")) strText.append(" Menu_Client_Button_Icon_childProcesses");
208             else if (menuData[i].action.equals("R")) strText.append(" Menu_Client_Button_Icon_childReports");
209             else if (menuData[i].action.equals("X")) strText.append(" Menu_Client_Button_Icon_childForms");
210             else if (menuData[i].action.equals("L")) strText.append(" Menu_Client_Button_Icon_childExternalLink");
211             else strText.append(" Menu_Client_Button_Icon_childWindows");
212           } else {
213             strText.append(" Menu_Client_Button_");
214             if (indice.equals("0")) strText.append("Big");
215             strText.append("Icon_folder");
216             strText.append((open?"Opened":""));
217           }
218           strText.append("\"");
219           if (menuData[i].issummary.equals("Y")) strText.append(" id=\"folderImg").append(menuData[i].nodeId).append("\"");
220           strText.append(">");
221           strText.append("</td>\n");
222           strText.append(" <td nowrap=\"\"");
223           if (menuData[i].issummary.equals("Y")) strText.append(" id=\"folderCell2_").append(menuData[i].nodeId).append("\"");
224           strText.append(">");
225           strText.append(menuData[i].name);
226           strText.append("</td>\n");
227           strText.append(" </tr>\n");
228           strText.append(" </table>\n");
229           strText.append(" </td>\n");
230           strText.append("</tr>\n");
231           strText.append("<tr>\n");
232           strText.append(" <td");
233           strText.append(" style=\"").append((!open?"display: none;":"")).append("\" id=\"parent").append(menuData[i].nodeId).append("\">\n");
234           strText.append(" <table cellspacing=\"0\" cellpadding=\"0\" class=\"Menu_Client_child_bg\">\n");
235           strText.append(strHijos);
236           strText.append(" </table>\n");
237           strText.append(" </td>\n");
238           strText.append("</tr>\n");
239         }
240       }
241     }
242     return (strText.toString());
243   }
244
245   public static String JavaDoc getUrlString(String JavaDoc strDireccionBase, String JavaDoc name, String JavaDoc action, String JavaDoc classname, String JavaDoc mappingname, String JavaDoc adWorkflowId, String JavaDoc adTaskId, String JavaDoc adProcessId) {
246     StringBuffer JavaDoc strResultado = new StringBuffer JavaDoc();
247     strResultado.append(strDireccionBase);
248     if (mappingname.equals("")) {
249       if (action.equals("F")) {
250         strResultado.append("/ad_workflow/WorkflowControl.html?inpadWorkflowId=").append(adWorkflowId);
251       } else if (action.equals("T")) {
252         strResultado.append("/utility/ExecuteTask.html?inpadTaskId=").append(adTaskId);
253       } else if (action.equals("P")) {
254         strResultado.append("/ad_actionButton/ActionButton_Responser.html?inpadProcessId=").append(adProcessId);
255       } else if (action.equals("X")) {
256         strResultado.append("/ad_forms/").append(FormatUtilities.replace(name)).append(".html");
257       } else if (action.equals("R")) {
258         strResultado.append("ad_reports/").append(FormatUtilities.replace(name)).append(".html");
259       }
260     } else {
261       strResultado.append(mappingname);
262     }
263     return strResultado.toString();
264   }
265
266   public String JavaDoc generarMenuSearchs(VariablesSecureApp vars, String JavaDoc direccion, boolean open) throws ServletException {
267     StringBuffer JavaDoc result = new StringBuffer JavaDoc();
268     MenuData[] data = MenuData.selectSearchs(this, vars.getLanguage());
269     if (data==null || data.length==0) return "";
270     for (int i=0;i<data.length;i++) {
271       result.append("<tr>\n");
272       result.append(" <td>\n");
273       result.append(" <table cellspacing=\"0\" cellpadding=\"0\" onmouseover=\"window.status='");
274       result.append(FormatUtilities.replaceJS(data[i].description));
275       result.append("';return true;\"");
276       result.append(" onmouseout=\"window.status='';return true;\"");
277       result.append(" id=\"info").append(FormatUtilities.replace(data[i].name)).append("\"");
278       result.append(">\n");
279       result.append(" <tr");
280       result.append(" class=\"Child\"");
281       result.append(" id=\"childinfo").append(FormatUtilities.replace(data[i].name)).append("\"");
282       result.append(" onclick=\"checkSelected('childinfo").append(FormatUtilities.replace(data[i].name)).append("');openSearch(null, null, '");
283       String JavaDoc javaClassName = data[i].classname.trim();
284       if (data[i].nodeId.equals("800011")) javaClassName = "/info/ProductComplete_FS.html";
285       else if (data[i].nodeId.equals("21")) javaClassName = "/info/Location_FS.html";
286       else if (data[i].nodeId.equals("25")) javaClassName = "/info/Account_FS.html";
287       else if (data[i].nodeId.equals("800013")) javaClassName = "/info/Locator_Detail_FS.html";
288       else if (data[i].nodeId.equals("31")) javaClassName = "/info/Locator_FS.html";
289       result.append(direccion).append(javaClassName);
290       result.append("', null, false);return false;\" onmouseover=\"setHover(this);return true;\" onmouseout=\"setMouseUp(this);this.className=this.className.replace(' Child_hover', (isOpened?' Opened':''));return true;\"");
291       result.append(" onmousedown=\"setMouseDown(this);return true;\" onmouseup=\"setMouseUp(this);return true;\">\n");
292       result.append(" <td width=\"5px\"><img SRC=\"").append(strReplaceWith).append("/images/blank.gif\" class=\"Menu_Client_Button_Icon Menu_Client_Button_Icon_childInfo\"></td>\n");
293       result.append(" <td nowrap=\"\">");
294       result.append(data[i].name);
295       result.append(" </td>\n");
296       result.append(" </tr>\n");
297       result.append(" </table>\n");
298       result.append(" </td>\n");
299       result.append("</tr>\n");
300     }
301     return result.toString();
302   }
303
304   public String JavaDoc getServletInfo() {
305     return "Servlet that presents application's vertical menu";
306   } // end of getServletInfo() method
307
}
308
Popular Tags