KickJava   Java API By Example, From Geeks To Geeks.

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


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 WADLink extends WADControl {
25   private WADControl button;
26
27   public WADLink() {
28   }
29
30   public WADLink(Properties prop) {
31     setInfo(prop);
32     initialize();
33   }
34
35   public void initialize() {
36     generateJSCode();
37     this.button = new WADFieldButton("Link", getData("ColumnName"), getData("ColumnNameInp"), getData("Name"), "window.open(document.getElementById('" + getData("ColumnName") + "').value);");
38   }
39
40   private void generateJSCode() {
41     addImport("UrlTextBox", "../../../../../web/js/default/UrlTextBox.js");
42     generateMessages();
43     if (getData("IsMandatory").equals("Y")) {
44       XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADLinkJSValidation").createXmlDocument();
45       xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
46       setValidation(replaceHTML(xmlDocument.print()));
47     }
48     setCalloutJS();
49   }
50
51   public String JavaDoc getType() {
52     return "TextBox_btn";
53   }
54
55   public String JavaDoc editMode() {
56     String JavaDoc textButton = "";
57     String JavaDoc buttonClass = "";
58     this.button.setReportEngine(getReportEngine());
59     textButton = this.button.toString();
60     buttonClass = this.button.getType();
61     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADLink").createXmlDocument();
62
63     xmlDocument.setParameter("columnName", getData("ColumnName"));
64     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
65     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
66     xmlDocument.setParameter("maxlength", getData("FieldLength"));
67     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
68     xmlDocument.setParameter("invalid", this.invalid);
69     xmlDocument.setParameter("missing", this.missing);
70     xmlDocument.setParameter("range", this.range);
71     xmlDocument.setParameter("button", textButton);
72
73     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y") || getData("IsUpdateable").equals("N"));
74     xmlDocument.setParameter("disabled", (isDisabled?"Y":"N"));
75     if (!isDisabled && getData("IsMandatory").equals("Y")) {
76       xmlDocument.setParameter("required", "true");
77       xmlDocument.setParameter("requiredClass", " required");
78     } else {
79       xmlDocument.setParameter("required", "false");
80       xmlDocument.setParameter("requiredClass", (isDisabled?" readonly":""));
81     }
82     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
83
84     xmlDocument.setParameter("callout", getOnChangeCode());
85
86     return replaceHTML(xmlDocument.print());
87   }
88
89   public String JavaDoc newMode() {
90     String JavaDoc textButton = "";
91     String JavaDoc buttonClass = "";
92     this.button.setReportEngine(getReportEngine());
93     textButton = this.button.toString();
94     buttonClass = this.button.getType();
95     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADLink").createXmlDocument();
96
97     xmlDocument.setParameter("columnName", getData("ColumnName"));
98     xmlDocument.setParameter("columnNameInp", getData("ColumnNameInp"));
99     xmlDocument.setParameter("size", (textButton.equals("")?"":"btn_") + getData("CssSize"));
100     xmlDocument.setParameter("maxlength", getData("FieldLength"));
101     xmlDocument.setParameter("buttonClass", buttonClass + "_ContentCell");
102     xmlDocument.setParameter("invalid", this.invalid);
103     xmlDocument.setParameter("missing", this.missing);
104     xmlDocument.setParameter("range", this.range);
105     xmlDocument.setParameter("button", textButton);
106
107     boolean isDisabled = (getData("IsReadOnly").equals("Y") || getData("IsReadOnlyTab").equals("Y"));
108     xmlDocument.setParameter("disabled", (isDisabled?"Y":"N"));
109     if (!isDisabled && getData("IsMandatory").equals("Y")) {
110       xmlDocument.setParameter("required", "true");
111       xmlDocument.setParameter("requiredClass", " required");
112     } else {
113       xmlDocument.setParameter("required", "false");
114       xmlDocument.setParameter("requiredClass", (isDisabled?" readonly":""));
115     }
116     xmlDocument.setParameter("textBoxCSS", (isDisabled?"_ReadOnly":""));
117
118     xmlDocument.setParameter("callout", getOnChangeCode());
119
120     return replaceHTML(xmlDocument.print());
121   }
122
123   public String JavaDoc toXml() {
124     String JavaDoc[] discard = {"xx_PARAM"};
125     if (getData("IsParameter").equals("Y")) discard[0] = new String JavaDoc("xx");
126     XmlDocument xmlDocument = getReportEngine().readXmlTemplate("org/openbravo/wad/controls/WADLinkXML", discard).createXmlDocument();
127
128     xmlDocument.setParameter("columnName", getData("ColumnName"));
129     return replaceHTML(xmlDocument.print());
130   }
131
132   public String JavaDoc toJava() {
133     return "";
134   }
135 }
136
Popular Tags