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 Query implements ActiveEditorDrop { 34 35 public static String QUERY_DEFAULT = "SELECT column_name(s) FROM table_name"; 37 SQLStmt stmt = null; 38 39 private String variable = ""; 40 private int scopeIndex = SQLStmt.SCOPE_DEFAULT; 41 private String dataSource = ""; 42 private String query = QUERY_DEFAULT; 43 44 private String displayName; 45 private String stmtLabel = ""; 46 private String stmtACSN = ""; 47 private String stmtACSD = ""; 48 49 public Query() { 50 51 try { 52 displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-Query"); } 54 catch (Exception e) {} 55 56 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.Bundle"); try { 58 stmtLabel = bundle.getString("LBL_Query_Stmt"); } 60 catch (Exception e) {} 61 try { 62 stmtACSN = bundle.getString("ACSN_Query_Stmt"); } 64 catch (Exception e) {} 65 try { 66 stmtACSD = bundle.getString("ACSD_Query_Stmt"); } 68 catch (Exception e) {} 69 70 stmt = new SQLStmt(variable, scopeIndex, dataSource, query, "QueryStmtCustomizer"); 72 } 73 74 public boolean handleTransfer(JTextComponent targetComponent) { 75 76 boolean accept = stmt.customize(targetComponent, displayName, stmtLabel, stmtACSN, stmtACSD); 77 if (accept) { 78 String body = createBody(); 79 try { 80 JSPPaletteUtilities.insert(body, targetComponent); 81 } catch (BadLocationException ble) { 82 accept = false; 83 } 84 } 85 86 return accept; 87 } 88 89 private String createBody() { 90 91 variable = stmt.getVariable(); 92 String strVariable = " var=\"\""; if (variable.length() > 0) 94 strVariable = " var=\"" + variable + "\""; 96 scopeIndex = stmt.getScopeIndex(); 97 String strScope = ""; 98 if (scopeIndex != SQLStmt.SCOPE_DEFAULT) 99 strScope = " scope=\"" + SQLStmt.scopes[scopeIndex] + "\""; 101 dataSource = stmt.getDataSource(); 102 String strDS = " dataSource=\"\""; if (strDS.length() > 0) 104 strDS = " dataSource=\"" + dataSource + "\""; 106 query = stmt.getStmt(); 107 String strQuery = query; 108 if (query.length() > 0) 109 strQuery += "\n"; 111 String queryBody = "<sql:query" + strVariable + strScope + strDS + ">\n" + strQuery + 113 "</sql:query>"; 115 return queryBody; 116 } 117 118 119 } 120 | Popular Tags |