KickJava   Java API By Example, From Geeks To Geeks.

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


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 WADTime extends WADControl {
25
26   public WADTime() {
27   }
28
29   public WADTime(Properties prop) {
30     setInfo(prop);
31     initialize();
32   }
33
34   public void initialize() {
35     generateJSCode();
36   }
37
38   private void generateJSCode() {
39     addImport("TimeTextBox", "../../../../../web/js/default/TimeTextBox.js");
40     //addImport("time", "../../../../../web/js/time.js");
41
generateMessages();
42     StringBuffer JavaDoc validation = new StringBuffer JavaDoc();
43     if (getData("IsMandatory").equals("Y")) {
44       validation.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==null || inputValue(frm.inp").append(getData("ColumnNameInp")).append(")==\"\") {\n");
45       if (getData("IsDisplayed").equals("Y")) validation.append(" frm.inp").append(getData("ColumnNameInp")).append(".focus();\n");
46       validation.append(" mensaje(1);\n");
47       validation.append(" return false;\n");
48       validation.append(" }\n");
49     }
50     if (!getData("ValueMin").equals("") || !getData("ValueMax").equals("")) {
51       validation.append(" if (inputValue(frm.inp").append(getData("ColumnNameInp")).append(")!=null && ");
52       validation.append("inputValue(frm.inp").append(getData("ColumnNameInp")).append(")!=\"\" && (");
53       boolean valmin=false;
54       if (!getData("ValueMin").equals("")) {
55         validation.append("timecmp(frm.inp").append(getData("ColumnNameInp")).append(".value, '").append(getData("ValueMin")).append("')<0");
56         valmin = true;
57       }
58       if (!getData("ValueMax").equals("")) {
59         if (valmin) validation.append(" || ");
60         validation.append("timecmp(frm.inp").append(getData("ColumnNameInp")).append(".value, '").append(getData("ValueMax")).append("')>0");
61       }
62       validation.append(")) {\n");
63       if (getData("IsDisplayed").equals("Y")) validation.append(" frm.inp").append(getData("ColumnNameInp")).append(".focus();\n");
64       validation.append(" mensaje(9);\n");
65       validation.append(" return false;\n");
66       validation.append(" }\n");
67     }
68     setValidation(validation.toString());
69     setCalloutJS();
70   }
71
72   public String JavaDoc getType() {
73     return "TextBox";
74   }
75
76   public String JavaDoc editMode() {
77     String JavaDoc textButton = "";
78     String JavaDoc buttonClass = "";
79     /*if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N") && getData("IsUpdateable").equals("Y")) {
80       this.button.setReportEngine(getReportEngine());
81       textButton = this.button.toString();
82       buttonClass = this.button.getType();
83     }*/

84     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADTime").createXmlDocument();
85
86     xmlDocument.setParameter("columnName", getData("ColumnName"));
87     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
88     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
89     xmlDocument.setParameter("maxlength", getData("FieldLength"));
90     xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":""));
91     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
92     xmlDocument.setParameter("invalid", this.invalid);
93     xmlDocument.setParameter("missing", this.missing);
94     xmlDocument.setParameter("range", this.range);
95     xmlDocument.setParameter("button", textButton);
96
97     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N"));
98     xmlDocument.setParameter("disabled", (isDisabled?"Y":"N"));
99     if (!isDisabled && getData("IsMandatory").equals("Y")) {
100       xmlDocument.setParameter("required", "true");
101       xmlDocument.setParameter("requiredClass", " required");
102     } else {
103       xmlDocument.setParameter("required", "false");
104       xmlDocument.setParameter("requiredClass", (isDisabled?" readonly":""));
105     }
106     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
107
108     xmlDocument.setParameter("callout", getOnChangeCode());
109
110     return replaceHTML(xmlDocument.print());
111   }
112
113   public String JavaDoc newMode() {
114     String JavaDoc textButton = "";
115     String JavaDoc buttonClass = "";
116     /*if (getData("IsReadOnly").equals("N") && getData("IsReadOnlyTab").equals("N")) {
117       this.button.setReportEngine(getReportEngine());
118       textButton = this.button.toString();
119       buttonClass = this.button.getType();
120     }*/

121     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADTime").createXmlDocument();
122
123     xmlDocument.setParameter("columnName", getData("ColumnName"));
124     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
125     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
126     xmlDocument.setParameter("maxlength", getData("FieldLength"));
127     xmlDocument.setParameter("hasButton", (textButton.equals("")?"TextButton_ContentCell":""));
128     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
129     xmlDocument.setParameter("invalid", this.invalid);
130     xmlDocument.setParameter("missing", this.missing);
131     xmlDocument.setParameter("range", this.range);
132     xmlDocument.setParameter("button", textButton);
133
134     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y"));
135     xmlDocument.setParameter("disabled", (isDisabled?"Y":"N"));
136     if (!isDisabled && getData("IsMandatory").equals("Y")) {
137       xmlDocument.setParameter("required", "true");
138       xmlDocument.setParameter("requiredClass", " required");
139     } else {
140       xmlDocument.setParameter("required", "false");
141       xmlDocument.setParameter("requiredClass", (isDisabled?" readonly":""));
142     }
143     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
144
145     xmlDocument.setParameter("callout", getOnChangeCode());
146
147     return replaceHTML(xmlDocument.print());
148   }
149
150   public String JavaDoc toXml() {
151     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
152     if (getData("IsParameter").equals("Y")) {
153       text.append("<PARAMETER id=\"").append(getData("ColumnName")).append("\" name=\"").append(getData("ColumnName")).append("\" attribute=\"value\"/>");
154     } else {
155       text.append("<FIELD id=\"").append(getData("ColumnName")).append("\" attribute=\"value\">");
156       text.append(getData("ColumnName")).append("</FIELD>");
157     }
158     return text.toString();
159   }
160
161   public String JavaDoc toJava() {
162     return "";
163   }
164 }
165
Popular Tags