KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > palette > items > Report


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.palette.items;
21 import java.util.ResourceBundle JavaDoc;
22 import javax.swing.text.BadLocationException JavaDoc;
23 import javax.swing.text.JTextComponent JavaDoc;
24 import org.netbeans.modules.web.core.palette.JSPPaletteUtilities;
25 import org.openide.text.ActiveEditorDrop;
26 import org.openide.util.NbBundle;
27
28
29 /**
30  *
31  * @author Libor Kotouc
32  */

33 public class Report implements ActiveEditorDrop {
34
35     public static String JavaDoc QUERY_DEFAULT = "SELECT column_name(s) FROM table_name"; // NOI18N
36
private static final String JavaDoc VARIABLE_DEFAULT = "result"; // NOI18N
37

38     SQLStmt stmt = null;
39     
40     private String JavaDoc variable = VARIABLE_DEFAULT;
41     private int scopeIndex = SQLStmt.SCOPE_DEFAULT;
42     private String JavaDoc dataSource = "";
43     private String JavaDoc query = QUERY_DEFAULT;
44     
45     private String JavaDoc displayName;
46     private String JavaDoc stmtLabel = "";
47     private String JavaDoc stmtACSN = "";
48     private String JavaDoc stmtACSD = "";
49     
50     public Report() {
51         
52         try {
53             displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-Report"); // NOI18N
54
}
55         catch (Exception JavaDoc e) {}
56         
57         ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.Bundle"); // NOI18N
58
try {
59             stmtLabel = bundle.getString("LBL_Report_Stmt"); // NOI18N
60
}
61         catch (Exception JavaDoc e) {}
62         try {
63             stmtACSN = bundle.getString("ACSN_Report_Stmt"); // NOI18N
64
}
65         catch (Exception JavaDoc e) {}
66         try {
67             stmtACSD = bundle.getString("ACSD_Report_Stmt"); // NOI18N
68
}
69         catch (Exception JavaDoc e) {}
70         
71         stmt = new SQLStmt(variable, scopeIndex, dataSource, query, "ReportStmtCustomizer"); // NOI18N
72

73     }
74
75     public boolean handleTransfer(JTextComponent JavaDoc targetComponent) {
76         
77         boolean accept = stmt.customize(targetComponent, displayName, stmtLabel, stmtACSN, stmtACSD);
78         if (accept) {
79             String JavaDoc body = createBody();
80             try {
81                 JSPPaletteUtilities.insert(body, targetComponent);
82             } catch (BadLocationException JavaDoc ble) {
83                 accept = false;
84             }
85         }
86         
87         return accept;
88     }
89
90     private String JavaDoc createBody() {
91         
92         variable = stmt.getVariable();
93         String JavaDoc strVariable = " var=\"\""; // NOI18N
94
if (variable.length() > 0)
95             strVariable = " var=\"" + variable + "\""; // NOI18N
96

97         scopeIndex = stmt.getScopeIndex();
98         String JavaDoc strScope = "";
99         if (scopeIndex != SQLStmt.SCOPE_DEFAULT)
100             strScope = " scope=\"" + SQLStmt.scopes[scopeIndex] + "\""; // NOI18N
101

102         dataSource = stmt.getDataSource();
103         String JavaDoc strDS = " dataSource=\"\""; // NOI18N
104
if (strDS.length() > 0)
105             strDS = " dataSource=\"" + dataSource + "\""; // NOI18N
106

107         query = stmt.getStmt();
108         String JavaDoc strQuery = query;
109         if (query.length() > 0)
110             strQuery += "\n"; // NOI18N
111

112         String JavaDoc body = "<sql:query" + strVariable + strScope + strDS + ">\n" + // NOI18N
113
strQuery +
114                         "</sql:query>\n" + // NOI18N
115
"\n" + // NOI18N
116
"<table border=\"1\">\n" + // NOI18N
117
"<!-- column headers -->\n" + // NOI18N
118
"<tr>\n" + // NOI18N
119
"<c:forEach var=\"columnName\" items=\"${" + variable + ".columnNames}\">\n" + // NOI18N
120
"<th><c:out value=\"${columnName}\"/></th>\n" + // NOI18N
121
"</c:forEach>\n" + // NOI18N
122
"</tr>\n" + // NOI18N
123
"<!-- column data -->\n" + // NOI18N
124
"<c:forEach var=\"row\" items=\"${" + variable + ".rowsByIndex}\">\n" + // NOI18N
125
"<tr>\n" + // NOI18N
126
"<c:forEach var=\"column\" items=\"${row}\">\n" + // NOI18N
127
"<td><c:out value=\"${column}\"/></td>\n" + // NOI18N
128
"</c:forEach>\n" + // NOI18N
129
"</tr>\n" + // NOI18N
130
"</c:forEach>\n" + // NOI18N
131
"</table>";// NOI18N
132

133         return body;
134     }
135
136    
137 }
138
Popular Tags