KickJava   Java API By Example, From Geeks To Geeks.

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


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.xmlEngine.XmlDocument;
23
24 public class WADList extends WADControl {
25
26   public WADList() {
27   }
28
29   public WADList(Properties prop) {
30     setInfo(prop);
31     initialize();
32   }
33
34   public void initialize() {
35     addImport("String", "../../../../../web/js/String.js");
36     addImport("TypeAheadCombo", "../../../../../web/js/TypeAheadCombo.js");
37     generateJSCode();
38   }
39
40   private void generateJSCode() {
41     if (getData("IsMandatory").equals("Y")) {
42       StringBuffer JavaDoc text = new StringBuffer JavaDoc();
43       text.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp"));
44       text.append(")==null || inputValue(frm.inp");
45       text.append(getData("ColumnNameInp"));
46       text.append(")==\"\") {\n");
47       text.append(" setFocus(frm.inp").append(getData("ColumnNameInp")).append(");\n");
48       text.append(" mensaje(1);\n");
49       text.append(" return false;\n");
50       text.append(" }");
51       setValidation(replaceHTML(text.toString()));
52     }
53     setOnLoad("new TypeAheadCombo(\"report" + getData("ColumnName") + "_S\");\nif (inputValue(key)==\"\") updateOnChange(frm.inp" + getData("ColumnNameInp") + ");");
54     setCalloutJS();
55   }
56
57   public String JavaDoc getType() {
58     return "Combo";
59   }
60
61   public String JavaDoc editMode() {
62     String JavaDoc[] discard = {""};
63     if (getData("IsMandatory").equals("Y")) discard[0] = "fieldBlankSection";
64     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADList", discard).createXmlDocument();
65
66     xmlDocument.setParameter("columnName", getData("ColumnName"));
67     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
68     String JavaDoc length = getData("DisplayLength");
69     if (!length.endsWith("%")) length += "px";
70     xmlDocument.setParameter("size", getData("CssSize"));
71     
72     String JavaDoc auxClassName = "";
73     if (getData("IsMandatory").equals("Y")) auxClassName += "Key";
74     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) auxClassName += "ReadOnly";
75     else if (getData("IsUpdateable").equals("N")) auxClassName += "NoUpdatable";
76     xmlDocument.setParameter("myClass", auxClassName);
77
78     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) xmlDocument.setParameter("disabled", "Y");
79     else xmlDocument.setParameter("disabled", "N");
80     //if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "Y");
81
//else xmlDocument.setParameter("required", "N");
82

83     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
84     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) text.append("selectCombo(this, 'xx');");
85     text.append(getOnChangeCode());
86     xmlDocument.setParameter("callout", text.toString());
87
88     return replaceHTML(xmlDocument.print());
89   }
90
91   public String JavaDoc newMode() {
92     String JavaDoc[] discard = {""};
93     if (getData("IsMandatory").equals("Y")) discard[0] = "fieldBlankSection";
94     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADList", discard).createXmlDocument();
95
96     xmlDocument.setParameter("columnName", getData("ColumnName"));
97     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
98     String JavaDoc length = getData("DisplayLength");
99     if (!length.endsWith("%")) length += "px";
100     xmlDocument.setParameter("size", getData("CssSize"));
101     
102     String JavaDoc auxClassName = "";
103     if (getData("IsMandatory").equals("Y")) auxClassName += "Key";
104     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) auxClassName += "ReadOnly";
105     xmlDocument.setParameter("myClass", auxClassName);
106
107     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) xmlDocument.setParameter("disabled", "Y");
108     else xmlDocument.setParameter("disabled", "N");
109     //if (getData("IsMandatory").equals("Y")) xmlDocument.setParameter("required", "Y");
110
//else xmlDocument.setParameter("required", "N");
111

112     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
113     if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y")) text.append("selectCombo(this, 'xx');");
114     text.append(getOnChangeCode());
115     xmlDocument.setParameter("callout", text.toString());
116
117     return replaceHTML(xmlDocument.print());
118   }
119
120   public String JavaDoc toXml() {
121     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
122     if (getData("IsParameter").equals("Y")) {
123       text.append("<PARAMETER id=\"").append(getData("ColumnName"));
124       text.append("\" name=\"").append(getData("ColumnName")).append("\" attribute=\"value\"/>");
125       if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) {
126         text.append("\n<PARAMETER id=\"report").append(getData("ColumnName"));
127         text.append("_S\" name=\"report").append(getData("ColumnName")).append("_S\" attribute=\"onchange\" replace=\"xx\"/>");
128       }
129     } else {
130       text.append("<FIELD id=\"").append(getData("ColumnName"));
131       text.append("\" attribute=\"value\">");
132       text.append(getData("ColumnName")).append("</FIELD>");
133       if (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N")) {
134         text.append("\n<FIELD id=\"report").append(getData("ColumnName"));
135         text.append("_S\" attribute=\"onchange\" replace=\"xx\">");
136         text.append(getData("ColumnName")).append("</FIELD>");
137       }
138     }
139     if (getData("IsDisplayed").equals("Y")) {
140       text.append("\n<SUBREPORT id=\"report").append(getData("ColumnName"));
141       text.append("\" name=\"report").append(getData("ColumnName"));
142       text.append("\" report=\"org/openbravo/erpCommon/reference/List\">\n");
143       text.append(" <ARGUMENT name=\"parameterListSelected\" withId=\"").append(getData("ColumnName")).append("\"/>\n");
144       text.append("</SUBREPORT>");
145     }
146     return text.toString();
147   }
148
149   public String JavaDoc toJava() {
150     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
151     if (getData("IsDisplayed").equals("Y")) {
152       text.append("comboTableData = new ComboTableData(vars, this, \"").append(getData("AD_Reference_ID")).append("\", ");
153       text.append("\"").append(getData("ColumnName")).append("\", \"");
154       text.append(getData("AD_Reference_Value_ID")).append("\", ");
155       text.append("\"").append(getData("AD_Val_Rule_ID")).append("\", ");
156       text.append("Utility.getContext(this, vars, \"#User_Org\", windowId), ");
157       text.append("Utility.getContext(this, vars, \"#User_Client\", windowId), 0);\n");
158       text.append("Utility.fillSQLParameters(this, vars, (dataField==null?data[0]:dataField), comboTableData, windowId, (dataField==null?data[0].getField(\"");
159       text.append(getData("ColumnNameInp")).append("\"):dataField.getField(\"");
160       text.append(getData("ColumnNameInp")).append("\")));\n");
161       text.append("xmlDocument.setData(\"report").append(getData("ColumnName")).append("\",\"liststructure\", ");
162       text.append("comboTableData.select(!strCommand.equals(\"NEW\")));\n");
163       text.append("comboTableData = null;");
164     }
165     return text.toString();
166   }
167 }
168
Popular Tags