1 19 20 package org.netbeans.modules.web.core.palette.items; 21 import java.util.ResourceBundle ; 22 import javax.swing.text.BadLocationException ; 23 import javax.swing.text.JTextComponent ; 24 import org.netbeans.modules.web.core.palette.JSPPaletteUtilities; 25 import org.openide.text.ActiveEditorDrop; 26 import org.openide.util.NbBundle; 27 28 29 33 public class Report implements ActiveEditorDrop { 34 35 public static String QUERY_DEFAULT = "SELECT column_name(s) FROM table_name"; private static final String VARIABLE_DEFAULT = "result"; 38 SQLStmt stmt = null; 39 40 private String variable = VARIABLE_DEFAULT; 41 private int scopeIndex = SQLStmt.SCOPE_DEFAULT; 42 private String dataSource = ""; 43 private String query = QUERY_DEFAULT; 44 45 private String displayName; 46 private String stmtLabel = ""; 47 private String stmtACSN = ""; 48 private String 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"); } 55 catch (Exception e) {} 56 57 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.Bundle"); try { 59 stmtLabel = bundle.getString("LBL_Report_Stmt"); } 61 catch (Exception e) {} 62 try { 63 stmtACSN = bundle.getString("ACSN_Report_Stmt"); } 65 catch (Exception e) {} 66 try { 67 stmtACSD = bundle.getString("ACSD_Report_Stmt"); } 69 catch (Exception e) {} 70 71 stmt = new SQLStmt(variable, scopeIndex, dataSource, query, "ReportStmtCustomizer"); 73 } 74 75 public boolean handleTransfer(JTextComponent targetComponent) { 76 77 boolean accept = stmt.customize(targetComponent, displayName, stmtLabel, stmtACSN, stmtACSD); 78 if (accept) { 79 String body = createBody(); 80 try { 81 JSPPaletteUtilities.insert(body, targetComponent); 82 } catch (BadLocationException ble) { 83 accept = false; 84 } 85 } 86 87 return accept; 88 } 89 90 private String createBody() { 91 92 variable = stmt.getVariable(); 93 String strVariable = " var=\"\""; if (variable.length() > 0) 95 strVariable = " var=\"" + variable + "\""; 97 scopeIndex = stmt.getScopeIndex(); 98 String strScope = ""; 99 if (scopeIndex != SQLStmt.SCOPE_DEFAULT) 100 strScope = " scope=\"" + SQLStmt.scopes[scopeIndex] + "\""; 102 dataSource = stmt.getDataSource(); 103 String strDS = " dataSource=\"\""; if (strDS.length() > 0) 105 strDS = " dataSource=\"" + dataSource + "\""; 107 query = stmt.getStmt(); 108 String strQuery = query; 109 if (query.length() > 0) 110 strQuery += "\n"; 112 String body = "<sql:query" + strVariable + strScope + strDS + ">\n" + strQuery + 114 "</sql:query>\n" + "\n" + "<table border=\"1\">\n" + "<!-- column headers -->\n" + "<tr>\n" + "<c:forEach var=\"columnName\" items=\"${" + variable + ".columnNames}\">\n" + "<th><c:out value=\"${columnName}\"/></th>\n" + "</c:forEach>\n" + "</tr>\n" + "<!-- column data -->\n" + "<c:forEach var=\"row\" items=\"${" + variable + ".rowsByIndex}\">\n" + "<tr>\n" + "<c:forEach var=\"column\" items=\"${row}\">\n" + "<td><c:out value=\"${column}\"/></td>\n" + "</c:forEach>\n" + "</tr>\n" + "</c:forEach>\n" + "</table>"; 133 return body; 134 } 135 136 137 } 138 | Popular Tags |