1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.awt.BorderLayout ; 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 import java.util.Vector ; 26 import javax.swing.JComponent ; 27 import javax.swing.SwingUtilities ; 28 import org.netbeans.api.progress.ProgressHandle; 29 import org.netbeans.api.progress.ProgressHandleFactory; 30 31 import org.openide.util.NbBundle; 32 33 import org.netbeans.modules.db.explorer.DatabaseConnection; 34 import org.openide.util.RequestProcessor; 35 36 public class SchemaPanel extends javax.swing.JPanel { 37 38 private ConnectionDialogMediator mediator; 39 private DatabaseConnection dbcon; 40 private ProgressHandle progressHandle; 41 private JComponent progressComponent; 42 43 48 public SchemaPanel(ConnectionDialogMediator mediator, DatabaseConnection dbcon) { 49 this.mediator = mediator; 50 this.dbcon = dbcon; 51 initComponents(); 52 initAccessibility(); 53 54 ConnectionProgressListener progressListener = new ConnectionProgressListener() { 55 public void connectionStarted() { 56 startProgress(); 57 } 58 59 public void connectionStep(String step) { 60 setProgressMessage(step); 61 } 62 63 public void connectionFinished() { 64 stopProgress(true); 65 } 66 67 public void connectionFailed() { 68 stopProgress(false); 69 } 70 }; 71 mediator.addConnectionProgressListener(progressListener); 72 } 73 74 private void initAccessibility() { 75 schemaLabel.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_SchemaDialogTextA11yDesc")); schemaComboBox.getAccessibleContext().setAccessibleName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_SchemaDialogTextComboBoxA11yName")); commentTextArea.getAccessibleContext().setAccessibleName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_SchemaPanelCommentA11yName")); commentTextArea.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_SchemaPanelCommentA11yDesc")); connectProgressPanel.getAccessibleContext().setAccessibleName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_ConnectionProgressBarA11yName")); connectProgressPanel.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_ConnectionProgressBarA11yDesc")); schemaButton.getAccessibleContext().setAccessibleName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_GetSchemasButtonA11yName")); schemaButton.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_GetSchemasButtonA11yDesc")); this.getAccessibleContext().setAccessibleName(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_GetSchemasPanelA11yName")); this.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_GetSchemasPanelA11yDesc")); } 86 87 92 private void initComponents() { 94 java.awt.GridBagConstraints gridBagConstraints; 95 96 commentTextArea = new javax.swing.JTextArea (); 97 schemaLabel = new javax.swing.JLabel (); 98 schemaComboBox = new javax.swing.JComboBox (); 99 schemaButton = new javax.swing.JButton (); 100 connectProgressPanel = new javax.swing.JPanel (); 101 progressMessageLabel = new javax.swing.JLabel (); 102 progressContainerPanel = new javax.swing.JPanel (); 103 104 FormListener formListener = new FormListener(); 105 106 setLayout(new java.awt.GridBagLayout ()); 107 108 commentTextArea.setEditable(false); 109 commentTextArea.setFont(javax.swing.UIManager.getFont("Label.font")); 110 commentTextArea.setLineWrap(true); 111 commentTextArea.setText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("MSG_SchemaPanelComment")); commentTextArea.setWrapStyleWord(true); 113 commentTextArea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground")); 114 commentTextArea.setEnabled(false); 115 commentTextArea.setOpaque(false); 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.gridwidth = 3; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 119 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 11); 120 add(commentTextArea, gridBagConstraints); 121 122 schemaLabel.setLabelFor(schemaComboBox); 123 org.openide.awt.Mnemonics.setLocalizedText(schemaLabel, NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("SchemaDialogText")); gridBagConstraints = new java.awt.GridBagConstraints (); 125 gridBagConstraints.gridx = 0; 126 gridBagConstraints.gridy = 1; 127 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 128 gridBagConstraints.weighty = 1.0; 129 gridBagConstraints.insets = new java.awt.Insets (5, 12, 0, 0); 130 add(schemaLabel, gridBagConstraints); 131 132 schemaComboBox.setToolTipText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_SchemaDialogTextComboBoxA11yDesc")); schemaComboBox.setEnabled(false); 134 gridBagConstraints = new java.awt.GridBagConstraints (); 135 gridBagConstraints.gridx = 1; 136 gridBagConstraints.gridy = 1; 137 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 138 gridBagConstraints.weightx = 1.0; 139 gridBagConstraints.weighty = 1.0; 140 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 141 add(schemaComboBox, gridBagConstraints); 142 143 org.openide.awt.Mnemonics.setLocalizedText(schemaButton, NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("SchemaDialogGetButton")); schemaButton.setToolTipText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_GetSchemasButtonA11yDesc")); schemaButton.addActionListener(formListener); 146 gridBagConstraints = new java.awt.GridBagConstraints (); 147 gridBagConstraints.gridx = 2; 148 gridBagConstraints.gridy = 1; 149 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 150 gridBagConstraints.weighty = 1.0; 151 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 11); 152 add(schemaButton, gridBagConstraints); 153 154 connectProgressPanel.setToolTipText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ACS_ConnectionProgressBarA11yDesc")); connectProgressPanel.setLayout(new java.awt.BorderLayout (0, 5)); 156 157 org.openide.awt.Mnemonics.setLocalizedText(progressMessageLabel, " "); 158 connectProgressPanel.add(progressMessageLabel, java.awt.BorderLayout.NORTH); 159 160 progressContainerPanel.setMinimumSize(new java.awt.Dimension (20, 20)); 161 progressContainerPanel.setPreferredSize(new java.awt.Dimension (20, 20)); 162 progressContainerPanel.setLayout(new java.awt.BorderLayout ()); 163 connectProgressPanel.add(progressContainerPanel, java.awt.BorderLayout.CENTER); 164 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 0; 167 gridBagConstraints.gridy = 2; 168 gridBagConstraints.gridwidth = 3; 169 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 170 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 171 gridBagConstraints.weightx = 1.0; 172 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 11); 173 add(connectProgressPanel, gridBagConstraints); 174 } 175 176 178 private class FormListener implements java.awt.event.ActionListener { 179 FormListener() {} 180 public void actionPerformed(java.awt.event.ActionEvent evt) { 181 if (evt.getSource() == schemaButton) { 182 SchemaPanel.this.schemaButtonActionPerformed(evt); 183 } 184 } 185 } 187 private void schemaButtonActionPerformed(java.awt.event.ActionEvent evt) { schemaComboBox.setEnabled(false); 189 schemaComboBox.removeAllItems(); 190 191 Connection con = dbcon.getConnection(); 192 try { 193 if (con == null || con.isClosed()) 194 dbcon.connect(); 195 else { 196 RequestProcessor.getDefault().post(new Runnable () { 197 public void run() { 198 mediator.fireConnectionStarted(); 199 mediator.retrieveSchemas(SchemaPanel.this, dbcon, dbcon.getUser()); 200 mediator.fireConnectionFinished(); 201 } 202 }); 203 } 204 } catch (SQLException exc) { 205 dbcon.connect(); 207 } 208 } 210 211 private javax.swing.JTextArea commentTextArea; 213 private javax.swing.JPanel connectProgressPanel; 214 private javax.swing.JPanel progressContainerPanel; 215 private javax.swing.JLabel progressMessageLabel; 216 private javax.swing.JButton schemaButton; 217 private javax.swing.JComboBox schemaComboBox; 218 private javax.swing.JLabel schemaLabel; 219 221 public String getSchema() { 222 Object schema = schemaComboBox.getSelectedItem(); 223 if (schema != null && !schema.toString().equals(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("TXT_NoSchema"))) return schema.toString(); 225 else 226 return null; 227 } 228 229 public boolean setSchemas(Vector items, String schema) { 230 schemaComboBox.removeAllItems(); 231 for (int i = 0; i < items.size(); i++) 232 schemaComboBox.addItem(items.elementAt(i)); 233 234 if (items.size() == 0) { 235 schemaComboBox.addItem(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("TXT_NoSchema")); schemaComboBox.setEnabled(false); 237 } else 238 schemaComboBox.setEnabled(true); 239 240 if (items.size() == 1) 241 return true; 243 244 int idx = items.indexOf(schema); 245 if (idx == -1) 246 idx = items.indexOf(schema.toLowerCase()); 247 if (idx == -1) 248 idx = items.indexOf(schema.toUpperCase()); 249 if (idx != -1) { 250 schemaComboBox.setSelectedIndex(idx); 251 return true; 253 } 254 255 return false; 257 } 258 259 public void setComment(String msg) { 260 commentTextArea.setText(msg); 261 } 262 263 private void startProgress() { 264 SwingUtilities.invokeLater(new Runnable () { 265 public void run() { 266 progressHandle = ProgressHandleFactory.createHandle(null); 267 progressComponent = ProgressHandleFactory.createProgressComponent(progressHandle); 268 progressContainerPanel.add(progressComponent, BorderLayout.CENTER); 269 progressHandle.start(); 270 progressMessageLabel.setText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ConnectionProgress_Connecting")); 271 schemaButton.setEnabled(false); 272 } 273 }); 274 } 275 276 private void setProgressMessage(final String message) { 277 SwingUtilities.invokeLater(new Runnable () { 278 public void run() { 279 progressMessageLabel.setText(message); 280 schemaButton.setEnabled(false); 281 } 282 }); 283 } 284 285 private void stopProgress(final boolean connected) { 286 SwingUtilities.invokeLater(new Runnable () { 287 public void run() { 288 progressHandle.finish(); 289 progressContainerPanel.remove(progressComponent); 290 progressContainerPanel.repaint(); 292 if (connected) { 293 progressMessageLabel.setText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ConnectionProgress_Established")); 294 } else { 295 progressMessageLabel.setText(NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle").getString("ConnectionProgress_Failed")); 296 } 297 schemaButton.setEnabled(true); 298 } 299 }); 300 } 301 302 public void resetProgress() { 303 progressMessageLabel.setText(" "); } 305 } 306 | Popular Tags |