KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > wad > controls > WADSearch


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.wad.controls;
20
21 import java.util.*;
22 import org.openbravo.data.Sqlc;
23 import org.openbravo.utils.FormatUtilities;
24 import org.openbravo.xmlEngine.XmlDocument;
25
26 public class WADSearch extends WADControl {
27   public WADControl button;
28   public String JavaDoc command = "";
29   public String JavaDoc hiddenFields = "";
30   public String JavaDoc imageName = "";
31   public String JavaDoc searchName = "";
32   public boolean isFieldEditable = true;
33
34   public WADSearch() {
35   }
36
37   public WADSearch(Properties prop) {
38     setInfo(prop);
39     initialize();
40   }
41
42   public void initialize() {
43     addImport("ValidationTextBox", "../../../../../web/js/default/ValidationTextBox.js");
44     addImport("searchs", "../../../../../web/js/searchs.js");
45     generateMessages();
46     generateJSCode();
47     this.button = new WADFieldButton(this.imageName, getData("ColumnName"), getData("ColumnNameInp"), this.searchName, this.command);
48     if (getData("AD_Reference_Value_ID").equals("21")) this.isFieldEditable = false;
49   }
50
51   private void generateJSCode() {
52     StringBuffer JavaDoc validation = new StringBuffer JavaDoc();
53     if (getData("IsMandatory").equals("Y")) {
54       validation.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==null || inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==\"\") {\n");
55       if (getData("IsDisplayed").equals("Y")) validation.append(" frm.inp").append(getData("ColumnNameInp")).append("_R.focus();\n");
56       validation.append(" mensaje(1);\n");
57       validation.append(" return false;\n");
58       validation.append(" }\n");
59     }
60     setValidation(validation.toString());
61     setCalloutJS();
62     {
63       StringBuffer JavaDoc text = new StringBuffer JavaDoc();
64       text.append("function debugSearch(key, text, keyField) {\n");
65       text.append(" return true;\n");
66       text.append("}");
67       addJSCode("debugSearch", text.toString());
68     }
69     if (!getData("IsReadOnly").equals("Y") && !getData("IsReadOnlyTab").equals("Y")) {
70       StringBuffer JavaDoc columnsScript = new StringBuffer JavaDoc();
71       StringBuffer JavaDoc commandScript = new StringBuffer JavaDoc();
72       StringBuffer JavaDoc hiddenScript = new StringBuffer JavaDoc();
73       StringBuffer JavaDoc text = new StringBuffer JavaDoc();
74       if (this.imageName==null || this.imageName.equals("")) this.imageName = FormatUtilities.replace(getData("searchName"));
75       if (this.searchName==null || this.searchName.equals("")) this.searchName = getData("Name");
76       String JavaDoc servletName = "/info/" + this.imageName + ".html";
77       try {
78         if (!getData("AD_Reference_Value_ID").equals("")) {
79           WADSearchData[] data = WADSearchData.select(getConnection(), getData("AD_Language"), getData("AD_Reference_Value_ID"));
80           if (data!=null && data.length>0) {
81             servletName = data[0].mappingname;
82             this.searchName = data[0].referenceNameTrl;
83             //this.imageName = FormatUtilities.replace(data[0].referenceName) + ".gif";
84
if (!servletName.startsWith("/")) servletName = "/" + servletName;
85             for (int i=0;i<data.length;i++) {
86               if (data[i].columntype.equals("I")) {
87                 columnsScript.append(", 'inp").append(data[i].name).append("'");
88                 columnsScript.append(", inputValue(document.frmMain.inp").append(Sqlc.TransformaNombreColumna(data[i].columnname)).append(")");
89               } else {
90                  hiddenScript.append("<input type=\"hidden\" name=\"inp").append(Sqlc.TransformaNombreColumna(data[i].name));
91                  hiddenScript.append(data[i].columnSuffix).append("\" value=\"\" ");
92                  hiddenScript.append("id=\"").append(data[i].columnname).append(data[i].columnSuffix).append("\"/>\n");
93               }
94             }
95           }
96         }
97       } catch (Exception JavaDoc ex) {
98         ex.printStackTrace();
99       }
100       commandScript.append("openSearch(null, null, '..").append(servletName).append("', ");
101       commandScript.append("null, false, 'frmMain', 'inp").append(getData("ColumnNameInp")).append("', ");
102       commandScript.append("'inp").append(getData("ColumnNameInp")).append("_R', ");
103       commandScript.append("inputValue(document.frmMain.inp").append(getData("ColumnNameInp")).append("_R), ");
104       commandScript.append("'inpIDValue', inputValue(document.frmMain.inp").append(getData("ColumnNameInp")).append("), ");
105       commandScript.append("'WindowID', inputValue(document.frmMain.inpwindowId)");
106       commandScript.append(columnsScript);
107       text.append(commandScript).append(", 'Command', 'KEY'");
108       commandScript.append(");");
109       text.append(");");
110       setOnLoad("arrTeclas[arrTeclas.length] = new Teclas(\"ENTER\", \"" + text.toString() + "\", \"inp" + getData("ColumnNameInp") + "_R\", \"null\");");
111       this.command = commandScript.toString();
112       this.hiddenFields = hiddenScript.toString();
113     }
114   }
115
116   public String JavaDoc getType() {
117     return "TextBox_btn";
118   }
119
120   public String JavaDoc editMode() {
121     String JavaDoc textButton = "";
122     String JavaDoc buttonClass = "";
123     if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N") && getData("IsUpdateable").equals("Y")) {
124       this.button.setReportEngine(getReportEngine());
125       textButton = this.button.toString();
126       buttonClass = this.button.getType();
127     }
128     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearch").createXmlDocument();
129
130     xmlDocument.setParameter("columnName", getData("ColumnName"));
131     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
132     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
133     xmlDocument.setParameter("maxlength", getData("FieldLength"));
134     xmlDocument.setParameter("hiddens", this.hiddenFields);
135     xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":""));
136     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
137     xmlDocument.setParameter("invalid", this.invalid);
138     xmlDocument.setParameter("missing", this.missing);
139     xmlDocument.setParameter("range", this.range);
140     xmlDocument.setParameter("button", textButton);
141     String JavaDoc className = "";
142     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N"));
143     if (isDisabled || !this.isFieldEditable) className += " readonly";
144     else if (getData("IsMandatory").equals("Y")) className += " required";
145     xmlDocument.setParameter("className", className);
146
147     if (isDisabled || !this.isFieldEditable) xmlDocument.setParameter("disabled", "Y");
148     else xmlDocument.setParameter("disabled", "N");
149     if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "true");
150     else xmlDocument.setParameter("required", "false");
151     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
152
153     xmlDocument.setParameter("callout", getOnChangeCode());
154     return replaceHTML(xmlDocument.print());
155   }
156
157   public String JavaDoc newMode() {
158     String JavaDoc textButton = "";
159     String JavaDoc buttonClass = "";
160     if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N")) {
161       this.button.setReportEngine(getReportEngine());
162       textButton = this.button.toString();
163       buttonClass = this.button.getType();
164     }
165     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearch").createXmlDocument();
166
167     xmlDocument.setParameter("columnName", getData("ColumnName"));
168     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
169     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
170     xmlDocument.setParameter("maxlength", getData("FieldLength"));
171     xmlDocument.setParameter("hiddens", this.hiddenFields);
172     xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":""));
173     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
174     xmlDocument.setParameter("invalid", this.invalid);
175     xmlDocument.setParameter("missing", this.missing);
176     xmlDocument.setParameter("range", this.range);
177     xmlDocument.setParameter("button", textButton);
178     String JavaDoc className = "";
179     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y"));
180     if (isDisabled || !this.isFieldEditable) className += " readonly";
181     else if (getData("IsMandatory").equals("Y")) className += " required";
182     xmlDocument.setParameter("className", className);
183
184     if (isDisabled || !this.isFieldEditable) xmlDocument.setParameter("disabled", "Y");
185     else xmlDocument.setParameter("disabled", "N");
186     if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "true");
187     else xmlDocument.setParameter("required", "false");
188     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
189
190     xmlDocument.setParameter("callout", getOnChangeCode());
191
192     return replaceHTML(xmlDocument.print());
193   }
194
195   public String JavaDoc toXml() {
196     String JavaDoc[] discard = {"xx_PARAM", "xx_PARAM_R"};
197     if (getData("IsParameter").equals("Y")) {
198       discard[0] = new String JavaDoc("xx");
199       discard[1] = new String JavaDoc("xx_R");
200     }
201     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADSearchXML", discard).createXmlDocument();
202
203     xmlDocument.setParameter("columnName", getData("ColumnName"));
204     return replaceHTML(xmlDocument.print());
205   }
206
207   public String JavaDoc toJava() {
208     return "";
209   }
210 }
211
Popular Tags