KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 public class WADGrid extends WADControl {
24
25   public WADGrid() {
26   }
27
28   public WADGrid(Properties prop) {
29     setInfo(prop);
30     initialize();
31   }
32
33   public void initialize() {
34     //addCSSImport("DataGrid", "");
35
//addImport("dojo", "../../../../../web/js/dojo/dojo.js");
36
generateJSCode();
37     setValidation("");
38   }
39
40   private void generateJSCode() {
41     addJSCode("DataGrid", "dojo.require(\"openbravo.widget.DataGrid\");");
42     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
43     {
44       text.append("function updateHeader(liveGrid, offset) {\n");
45       text.append(" dojo.byId('bookmark').innerHTML = (offset+1) + \" - \"");
46       text.append("+ (offset+liveGrid.visibleRows) + \" / \" + liveGrid.metaData.getTotalRows();\n");
47       text.append("}");
48       addJSCode("updateHeader", text.toString());
49     }
50     {
51       text = new StringBuffer JavaDoc();
52       text.append("function onRowDblClick(cell) {\n");
53       text.append(" var value = dojo.widget.byId('").append(getData("id")).append("').getSelectedRows();\n");
54       text.append(" if (value==null || value==\"\" || value.length>1) return false;\n");
55       text.append(" setInputValue('").append(getData("inpKeyName")).append("', value);\n");
56       text.append(" return submitCommandForm('EDIT', true, null, document.frmMain.action, '_self');\n");
57       text.append("}");
58       addJSCode("onRowDblClick", text.toString());
59     }
60     {
61       text = new StringBuffer JavaDoc();
62       text.append("function getSelectedValues() {\n");
63       text.append(" var value = dojo.widget.byId('").append(getData("id")).append("').getSelectedRows();\n");
64       text.append(" if (value==null || value.length==0) return \"\";\n");
65       text.append(" return value[0];\n");
66       text.append("}");
67       addJSCode("getSelectedValues", text.toString());
68     }
69     {
70       text = new StringBuffer JavaDoc();
71       text.append("function isMultipleSelected() {\n");
72       text.append(" var value = dojo.widget.byId('").append(getData("id")).append("').getSelectedRows();\n");
73       text.append(" if (value==null || value==\"\") return false;\n");
74       text.append(" return (value.length>1);\n");
75       text.append("}");
76       addJSCode("isMultipleSelected", text.toString());
77     }
78     {
79       text = new StringBuffer JavaDoc();
80       text.append("function onGridLoadDo() {\n");
81       text.append(" if (selectedRow==null) return true;\n");
82       text.append(" if (selectedRow<=0) dojo.widget.byId('").append(getData("id")).append("').goToFirstRow();\n");
83       text.append(" else dojo.widget.byId('").append(getData("id")).append("').goToRow(selectedRow);\n");
84       text.append(" if (orderByPositions!=null && orderByPositions.length>0) {\n");
85       text.append(" var total = orderByPositions.length;\n");
86       text.append(" for (var i=0;i<total;i++) {\n");
87       text.append(" dojo.widget.byId('").append(getData("id")).append("').setSortedColumns(orderByPositions[i], orderByDirections[i]);\n");
88       text.append(" }\n");
89       text.append(" }\n");
90       text.append(" dojo.widget.byId('").append(getData("id")).append("').setFocus();\n");
91       text.append(" return true;\n");
92       text.append("}");
93       addJSCode("onGridLoadDo", text.toString());
94     }
95     {
96       text = new StringBuffer JavaDoc();
97       text.append("function setGridFilters(newparams) {\n");
98       text.append(" var params = [];\n");
99       text.append(" params[\"newFilter\"] = \"1\";\n");
100       text.append(" if (newparams!=null && newparams.length>0) {\n");
101       text.append(" var total = newparams.length;\n");
102       text.append(" for (var i=0;i<total;i++) {\n");
103       text.append(" params[newparams[i][0]] = newparams[i][1];\n");
104       text.append(" }\n");
105       text.append(" }\n");
106       text.append(" dojo.widget.byId('").append(getData("id")).append("').setRequestParams(params);\n");
107       text.append(" return true;\n");
108       text.append("}");
109       addJSCode("setGridFilters", text.toString());
110     }
111     {
112       text = new StringBuffer JavaDoc();
113       text.append("function updateGridData() {\n");
114       text.append(" dojo.widget.byId('").append(getData("id")).append("').refreshGridData();\n");
115       text.append(" return true;\n");
116       text.append("}");
117       addJSCode("updateGridData", text.toString());
118     }
119     {
120       text = new StringBuffer JavaDoc();
121       text.append("function updateGridDataAfterFilter() {\n");
122       text.append(" dojo.widget.byId('").append(getData("id")).append("').refreshGridDataAfterFilter();\n");
123       text.append(" return true;\n");
124       text.append("}");
125       addJSCode("updateGridDataAfterFilter", text.toString());
126     }
127   }
128
129   public String JavaDoc toString() {
130     StringBuffer JavaDoc text = new StringBuffer JavaDoc();
131     text.append("<TABLE width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"Main_Client_TableRelation\"><TR><TD>");
132     text.append("<div id=\"").append(getData("id")).append("\" dojoType=\"openbravo:DataGrid\"\n");
133     text.append(" structureUrl=\"../utility/DataGrid.html?Command=STRUCTURE&inpadTabId=");
134     text.append(getData("AD_Tab_ID")).append("&inpadWindowId=");
135     text.append(getData("AD_Window_ID")).append("\" \n");
136     text.append(" dataUrl=\"../utility/DataGrid.html?Command=DATA&inpadTabId=");
137     text.append(getData("AD_Tab_ID")).append("&inpadWindowId=");
138     text.append(getData("AD_Window_ID")).append("\" \n");
139     text.append(" updatesUrl=\"../utility/DataGrid.html?Command=UPDATE&inpadTabId=");
140     text.append(getData("AD_Tab_ID")).append("&inpadWindowId=");
141     text.append(getData("AD_Window_ID")).append("\" \n");
142     text.append(" numRows=\"").append(getData("NumRows")).append("\" \n");
143     text.append(" editable=\"").append(getData("editable")).append("\" sortable=\"").append(getData("sortable")).append("\" \n");
144     text.append(" deleteable=\"").append(getData("deleteable")).append("\" \n");
145     text.append(" onInvalidValue=\"alert\" \n");
146     text.append(" onScroll=\"").append(getData("onScrollFunction")).append("\" \n");
147     text.append(" onGridLoad=\"").append(getData("onLoadFunction")).append("\"\n");
148     text.append(" bufferSize=\"3.0\"\n");
149     text.append(" showLineNumbers=\"").append(getData("ShowLineNumbers")).append("\" \n");
150     text.append(" maxWidth=\"").append(getData("width")).append("\" preventCache=\"true\" useCache=\"true\" cacheContent=\"false\">\n");
151     text.append(" </div>\n");
152     text.append("<script>djConfig.searchIds.push(\"").append(getData("id")).append("\");</script>");
153     text.append("</TD></TR></TABLE>");
154     return text.toString();
155   }
156
157   public String JavaDoc toXml() {
158     return "<PARAMETER id=\"" + getData("id") + "\" name=\"" + getData("id") + "\" attribute=\"numrows\"/>";
159   }
160
161   public String JavaDoc toJava() {
162     return "xmlDocument.setParameter(\"" + getData("id") + "\", Utility.getContext(this, vars, \"#RecordRange\", windowId));";
163   }
164 }
165
Popular Tags