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 Delete implements ActiveEditorDrop { 34 35 public static String STMT_DEFAULT = "DELETE FROM table_name\nWHERE column_name = some_value"; 36 37 SQLStmt stmt = null; 38 39 private String variable = ""; 40 private int scopeIndex = SQLStmt.SCOPE_DEFAULT; 41 private String dataSource = ""; 42 private String update = STMT_DEFAULT; 43 44 private String displayName; 45 private String stmtLabel = ""; 46 private String stmtACSN = ""; 47 private String stmtACSD = ""; 48 49 public Delete() { 50 51 try { 52 displayName = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.resources.Bundle").getString("NAME_jsp-Delete"); } 54 catch (Exception e) {} 55 56 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.web.core.palette.items.Bundle"); try { 58 stmtLabel = bundle.getString("LBL_Delete_Stmt"); } 60 catch (Exception e) {} 61 try { 62 stmtACSN = bundle.getString("ACSN_Delete_Stmt"); } 64 catch (Exception e) {} 65 try { 66 stmtACSD = bundle.getString("ACSD_Delete_Stmt"); } 68 catch (Exception e) {} 69 70 stmt = new SQLStmt(variable, scopeIndex, dataSource, update, "DeleteStmtCustomizer"); 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=\"\""; 93 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 update = stmt.getStmt(); 107 String strUpdate = update; 108 if (update.length() > 0) 109 strUpdate += "\n"; 110 111 String queryBody = "<sql:update" + strVariable + strScope + strDS + ">\n" + strUpdate + 113 "</sql:update>"; 115 return queryBody; 116 } 117 118 119 } 120 | Popular Tags |