1 19 20 package org.netbeans.modules.web.core.palette.items; 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import javax.swing.DefaultComboBoxModel ; 25 import javax.swing.text.JTextComponent ; 26 import org.openide.DialogDescriptor; 27 import org.openide.DialogDisplayer; 28 import org.openide.util.NbBundle; 29 30 31 32 33 34 35 39 public class SQLStmtCustomizer extends javax.swing.JPanel { 40 41 private Dialog dialog = null; 42 private DialogDescriptor descriptor = null; 43 private boolean dialogOK = false; 44 45 SQLStmt stmt; 46 JTextComponent target; 47 48 private String displayName; 49 private String stmtLabel; 50 private String stmtACSN; 51 private String stmtACSD; 52 private String helpID; 53 54 public SQLStmtCustomizer(SQLStmt stmt, JTextComponent target, 55 String displayName, String stmtLabel, String stmtACSN, String stmtACSD, 56 String helpID) 57 { 58 this.stmt = stmt; 59 this.target = target; 60 61 this.displayName = displayName; 62 this.stmtLabel = stmtLabel; 63 this.stmtACSN = stmtACSN; 64 this.stmtACSD = stmtACSD; 65 66 this.helpID = helpID; 67 68 initComponents(); 69 70 jTextField1.setText(stmt.getVariable()); 71 72 jComboBox2.setModel(new DefaultComboBoxModel (SQLStmt.scopes)); 73 jComboBox2.setSelectedIndex(stmt.getScopeIndex()); 74 75 jTextField2.setText(stmt.getDataSource()); 76 77 jTextArea1.setText(stmt.getStmt()); 78 } 79 80 public boolean showDialog() { 81 82 dialogOK = false; 83 84 descriptor = new DialogDescriptor 85 (this, NbBundle.getMessage(SQLStmtCustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true, 86 DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION, 87 new ActionListener () { 88 public void actionPerformed(ActionEvent e) { 89 if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) { 90 evaluateInput(); 91 dialogOK = true; 92 } 93 dialog.dispose(); 94 } 95 } 96 ); 97 98 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 99 dialog.setVisible(true); 100 repaint(); 101 102 return dialogOK; 103 } 104 105 private void evaluateInput() { 106 107 String variable = jTextField1.getText(); 108 stmt.setVariable(variable); 109 110 int scopeIndex = jComboBox2.getSelectedIndex(); 111 stmt.setScopeIndex(scopeIndex); 112 113 String dataSource = jTextField2.getText(); 114 stmt.setDataSource(dataSource); 115 116 String stmtString = jTextArea1.getText(); 117 stmt.setStmt(stmtString); 118 119 } 120 121 126 private void initComponents() { 128 java.awt.GridBagConstraints gridBagConstraints; 129 130 jFileChooser1 = new javax.swing.JFileChooser (); 131 jLabel4 = new javax.swing.JLabel (); 132 jLabel2 = new javax.swing.JLabel (); 133 jComboBox2 = new javax.swing.JComboBox (); 134 jTextField1 = new javax.swing.JTextField (); 135 jLabel1 = new javax.swing.JLabel (); 136 jScrollPane1 = new javax.swing.JScrollPane (); 137 jTextArea1 = new javax.swing.JTextArea (); 138 jLabel3 = new javax.swing.JLabel (); 139 jTextField2 = new javax.swing.JTextField (); 140 141 jFileChooser1.setCurrentDirectory(null); 142 143 setLayout(new java.awt.GridBagLayout ()); 144 145 jLabel4.setLabelFor(jComboBox2); 146 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "LBL_Stmt_Scope")); 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridx = 0; 149 gridBagConstraints.gridy = 1; 150 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 151 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 152 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 153 add(jLabel4, gridBagConstraints); 154 jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSN_Stmt_Scope")); 155 jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSD_Stmt_Scope")); 156 157 jLabel2.setLabelFor(jTextField1); 158 org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "LBL_Stmt_Variable")); 159 gridBagConstraints = new java.awt.GridBagConstraints (); 160 gridBagConstraints.gridx = 0; 161 gridBagConstraints.gridy = 0; 162 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 163 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 164 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 165 add(jLabel2, gridBagConstraints); 166 jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSN_Stmt_Variable")); 167 jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSD_Stmt_Variable")); 168 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 1; 171 gridBagConstraints.gridy = 1; 172 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 173 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 174 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 175 add(jComboBox2, gridBagConstraints); 176 177 gridBagConstraints = new java.awt.GridBagConstraints (); 178 gridBagConstraints.gridx = 1; 179 gridBagConstraints.gridy = 0; 180 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 181 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 182 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 183 add(jTextField1, gridBagConstraints); 184 185 jLabel1.setLabelFor(jTextArea1); 186 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, stmtLabel); 187 gridBagConstraints = new java.awt.GridBagConstraints (); 188 gridBagConstraints.gridx = 0; 189 gridBagConstraints.gridy = 3; 190 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 191 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 192 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 193 add(jLabel1, gridBagConstraints); 194 jLabel1.getAccessibleContext().setAccessibleName(stmtACSN); 195 jLabel1.getAccessibleContext().setAccessibleDescription(stmtACSD); 196 197 jTextArea1.setColumns(35); 198 jTextArea1.setRows(10); 199 jScrollPane1.setViewportView(jTextArea1); 200 201 gridBagConstraints = new java.awt.GridBagConstraints (); 202 gridBagConstraints.gridx = 0; 203 gridBagConstraints.gridy = 4; 204 gridBagConstraints.gridwidth = 2; 205 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 206 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 207 gridBagConstraints.weightx = 1.0; 208 gridBagConstraints.weighty = 1.0; 209 gridBagConstraints.insets = new java.awt.Insets (12, 12, 12, 12); 210 add(jScrollPane1, gridBagConstraints); 211 212 jLabel3.setLabelFor(jTextField2); 213 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "LBL_Stmt_DataSource")); 214 gridBagConstraints = new java.awt.GridBagConstraints (); 215 gridBagConstraints.gridx = 0; 216 gridBagConstraints.gridy = 2; 217 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 218 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 219 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 0); 220 add(jLabel3, gridBagConstraints); 221 jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSN_Stmt_DataSource")); 222 jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SQLStmtCustomizer.class, "ACSD_Stmt_DataSource")); 223 224 gridBagConstraints = new java.awt.GridBagConstraints (); 225 gridBagConstraints.gridx = 1; 226 gridBagConstraints.gridy = 2; 227 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 228 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 229 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 230 add(jTextField2, gridBagConstraints); 231 232 } 234 235 private javax.swing.JComboBox jComboBox2; 237 private javax.swing.JFileChooser jFileChooser1; 238 private javax.swing.JLabel jLabel1; 239 private javax.swing.JLabel jLabel2; 240 private javax.swing.JLabel jLabel3; 241 private javax.swing.JLabel jLabel4; 242 private javax.swing.JScrollPane jScrollPane1; 243 private javax.swing.JTextArea jTextArea1; 244 private javax.swing.JTextField jTextField1; 245 private javax.swing.JTextField jTextField2; 246 248 } 249 | Popular Tags |