KickJava   Java API By Example, From Geeks To Geeks.

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


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 Update implements ActiveEditorDrop {
34
35     public static String JavaDoc STMT_DEFAULT = "UPDATE table_name\nSET column_name = new_value\nWHERE column_name = some_value"; // NOI18N
36

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

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

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

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

106         update = stmt.getStmt();
107         String JavaDoc strUpdate = update;
108         if (update.length() > 0)
109             strUpdate += "\n"; // NOI18N
110

111         String JavaDoc queryBody = "<sql:update" + strVariable + strScope + strDS + ">\n" + // NOI18N
112
strUpdate +
113                             "</sql:update>";// NOI18N
114

115         return queryBody;
116     }
117
118    
119 }
120
Popular Tags