1 19 24 25 package org.netbeans.modules.db.sql.visualeditor.ui; 26 27 import org.netbeans.modules.db.sql.visualeditor.Log; 28 import java.awt.Image ; 29 import java.awt.event.ActionListener ; 30 import javax.swing.Icon ; 31 import javax.swing.ImageIcon ; 32 import javax.swing.JButton ; 33 import javax.swing.JDialog ; 34 import org.openide.NotifyDescriptor; 35 import org.openide.DialogDisplayer; 36 import org.openide.DialogDescriptor; 37 import org.openide.util.NbBundle; 38 import org.openide.util.HelpCtx; 39 import org.openide.util.Utilities; 40 47 public class ConnectionStatusPanel extends javax.swing.JPanel { 48 49 private JDialog dialog; 50 private DialogDescriptor dlg = null; 51 52 private JButton okButton = new JButton (NbBundle.getMessage(ConnectionStatusPanel.class, "OK")); 54 private Image conGood = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/ok.gif"); private Image conFailed = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/error.gif"); private Image conWarning = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/warning.gif"); 60 public ConnectionStatusPanel() { 61 initComponents(); 62 connectionStatusMessage.setBackground( connectionStatusText.getBackground() ) ; 63 valStatusMessage.setBackground( valStatusText.getBackground() ) ; 64 generalInfo.setBackground( connectionStatusText.getBackground()) ; 65 footerInfo.setBackground( connectionStatusText.getBackground()) ; 66 generalInfo.setVisible(false) ; 67 footerSeparator.setVisible(false) ; 68 footerInfo.setVisible(false) ; 69 okButton.getAccessibleContext().setAccessibleName(okButton.getText() ) ; 70 okButton.getAccessibleContext().setAccessibleDescription(okButton.getText() ) ; 71 } 72 public void setGeneralInfo(String info) { 73 generalInfo.setText(info) ; 74 generalInfo.setVisible(true) ; 75 } 76 public void setFooterInfo(String info) { 77 footerInfo.setText(info) ; 78 footerInfo.setVisible(true) ; 79 footerSeparator.setVisible(true) ; 80 } 81 public void showDialog( String dsName, boolean connected, String sqlException ) { 82 showDialog( dsName, connected, sqlException, null, 0, false ) ; 83 } 84 public void showDialog( String dsName, boolean connected, String sqlException, String tableName, int rows ) { 85 showDialog( dsName, connected, sqlException, tableName, rows, true ) ; 86 } 87 public void showDialog( String dsName, boolean connected, String sqlException, String tableName, int rows, boolean showValTableInfo ) { 88 89 91 configureDisplay(dsName, connected, sqlException, tableName, rows, showValTableInfo) ; 92 93 displayDialog(dsName) ; 94 } 95 public void displayDialog(String dsName) { 96 Log.log("ConnectionStatusDisplay.displayDialog for " +dsName) ; 97 ActionListener listener = new ActionListener () { 99 public void actionPerformed(java.awt.event.ActionEvent evt) { 100 dialog.dispose(); 101 } 102 }; 103 dlg = new DialogDescriptor(this, 104 getMsg( "ConStat_title", dsName), true, listener); 106 dlg.setOptions(new Object [] { okButton }); 107 dlg.setClosingOptions( null ); 108 dlg.setValid(false); 109 110 dialog = (JDialog ) DialogDisplayer.getDefault().createDialog(dlg); 111 dialog.getAccessibleContext().setAccessibleName(getMsg( "ConStat_title", dsName)) ; 112 dialog.getAccessibleContext().setAccessibleDescription(getMsg( "ConStat_title", dsName)) ; 113 this.getAccessibleContext().setAccessibleName(getMsg( "ConStat_title", dsName)) ; 114 this.getAccessibleContext().setAccessibleDescription(getMsg( "ConStat_title", dsName)) ; 115 dialog.setResizable(true); 116 dialog.pack() ; 117 118 dialog.show(); 119 } 120 public void configureDisplay( String dsName, boolean connected, String sqlException, String tableName, 121 int rows, boolean showValTableInfo ) { 122 124 if ( connected ) { 125 connectionStatusIcon.setIcon( new ImageIcon (conGood) ) ; 126 connectionStatusText.setText(getMsg("ConStat_succeeded_msg")) ; connectionStatusMessage.setVisible(false) ; 128 validationInfo.setVisible(true) ; 129 if ( sqlException == null ) { 130 valStatusText.setText(getMsg("ConStat_rows_selected_msg", tableName, new Integer (rows)) ) ; valStatusIcon.setIcon( new ImageIcon (conGood) ) ; 132 String valMsg ; 133 if (rows > 1 ) { 134 135 valMsg = getMsg("ConStat_valtable_bad_msg") ; valStatusMessageIcon.setIcon( new ImageIcon (conWarning) ) ; 137 } else { 138 valMsg = getMsg("ConStat_valtable_good_msg") ; valStatusMessageIcon.setIcon( new ImageIcon (conGood) ) ; 140 } 141 valMsg = valMsg + "\n" + getMsg("ConStat_validationTableInfo") ; valStatusMessage.setText(valMsg) ; 143 144 } else if (tableName != null) { 145 valStatusIcon.setIcon( new ImageIcon (conFailed) ) ; 147 148 valStatusText.setText(getMsg("ConStat_failed_msg")) ; 151 String valMsg ; 152 if ( tableName != null && tableName.trim().length() < 1 ) { 153 valMsg = getMsg("ConStat_valtable_needtable_msg" ) ; 154 } else { 155 valMsg = sqlException ; 156 } 157 valMsg += "\n" + getMsg("ConStat_validationTableInfo") ; 158 valStatusMessage.setText(valMsg) ; 159 160 } else { 161 validationInfo.setVisible(false) ; 162 valStatusLabel.setVisible(false) ; 163 } 164 } else { 165 connectionStatusIcon.setIcon( new ImageIcon (conFailed) ) ; 167 connectionStatusText.setText(getMsg("ConStat_failed_msg")) ; connectionStatusMessage.setText(sqlException) ; 169 validationInfo.setVisible(false) ; 170 valStatusLabel.setVisible(false) ; 171 } 172 generalInfo.setVisible(false) ; 173 footerSeparator.setVisible(false) ; 174 footerInfo.setVisible(false) ; 175 176 } 177 178 183 private void initComponents() { 185 java.awt.GridBagConstraints gridBagConstraints; 186 187 generalInfo = new javax.swing.JTextArea (); 188 connectionStatusLabel = new javax.swing.JLabel (); 189 connectionInfo = new javax.swing.JPanel (); 190 connectionStatusIcon = new javax.swing.JLabel (); 191 connectionStatusText = new javax.swing.JTextField (); 192 connectionStatusMessage = new javax.swing.JTextArea (); 193 valStatusLabel = new javax.swing.JLabel (); 194 validationInfo = new javax.swing.JPanel (); 195 valStatusIcon = new javax.swing.JLabel (); 196 valStatusText = new javax.swing.JTextField (); 197 valStatusMessageIcon = new javax.swing.JLabel (); 198 valStatusMessage = new javax.swing.JTextArea (); 199 footerSeparator = new javax.swing.JSeparator (); 200 footerInfo = new javax.swing.JTextArea (); 201 202 setLayout(new java.awt.GridBagLayout ()); 203 204 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_title", new Object [] {})); 205 generalInfo.setColumns(50); 206 generalInfo.setEditable(false); 207 generalInfo.setLineWrap(true); 208 generalInfo.setText("General info text goes here"); 209 generalInfo.setWrapStyleWord(true); 210 gridBagConstraints = new java.awt.GridBagConstraints (); 211 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 212 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 213 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 214 gridBagConstraints.weightx = 1.0; 215 gridBagConstraints.insets = new java.awt.Insets (5, 5, 5, 0); 216 add(generalInfo, gridBagConstraints); 217 218 connectionStatusLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_test_mnemonic", new Object [] {}).charAt(0)); 219 connectionStatusLabel.setLabelFor(connectionStatusText); 220 connectionStatusLabel.setText(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_test_label")); 221 gridBagConstraints = new java.awt.GridBagConstraints (); 222 gridBagConstraints.gridx = 0; 223 gridBagConstraints.gridy = 1; 224 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 225 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 226 add(connectionStatusLabel, gridBagConstraints); 227 connectionStatusLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_test_label")); 228 229 connectionInfo.setLayout(new java.awt.GridBagLayout ()); 230 231 connectionStatusIcon.setFocusable(false); 232 gridBagConstraints = new java.awt.GridBagConstraints (); 233 gridBagConstraints.gridx = 0; 234 gridBagConstraints.gridy = 0; 235 connectionInfo.add(connectionStatusIcon, gridBagConstraints); 236 237 connectionStatusText.setEditable(false); 238 connectionStatusText.setText("Succeeded"); 239 gridBagConstraints = new java.awt.GridBagConstraints (); 240 gridBagConstraints.gridx = 1; 241 gridBagConstraints.gridy = 0; 242 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 243 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 244 gridBagConstraints.weightx = 1.0; 245 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 246 connectionInfo.add(connectionStatusText, gridBagConstraints); 247 248 connectionStatusMessage.setColumns(50); 249 connectionStatusMessage.setEditable(false); 250 connectionStatusMessage.setLineWrap(true); 251 connectionStatusMessage.setText("SQL exception goes here."); 252 connectionStatusMessage.setWrapStyleWord(true); 253 connectionStatusMessage.setMargin(new java.awt.Insets (1, 5, 2, 4)); 254 gridBagConstraints = new java.awt.GridBagConstraints (); 255 gridBagConstraints.gridx = 1; 256 gridBagConstraints.gridy = 1; 257 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 258 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 259 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 260 connectionInfo.add(connectionStatusMessage, gridBagConstraints); 261 262 gridBagConstraints = new java.awt.GridBagConstraints (); 263 gridBagConstraints.gridx = 1; 264 gridBagConstraints.gridy = 1; 265 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 266 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 267 gridBagConstraints.weightx = 1.0; 268 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 269 add(connectionInfo, gridBagConstraints); 270 271 valStatusLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_valtable_mnemonic", new Object [] {}).charAt(0)); 272 valStatusLabel.setLabelFor(valStatusText); 273 valStatusLabel.setText(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_valtable_label")); 274 gridBagConstraints = new java.awt.GridBagConstraints (); 275 gridBagConstraints.gridx = 0; 276 gridBagConstraints.gridy = 2; 277 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 278 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 279 add(valStatusLabel, gridBagConstraints); 280 valStatusLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_valtable_label")); 281 valStatusLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_valtable_label")); 282 283 validationInfo.setLayout(new java.awt.GridBagLayout ()); 284 285 valStatusIcon.setFocusable(false); 286 gridBagConstraints = new java.awt.GridBagConstraints (); 287 gridBagConstraints.gridx = 0; 288 gridBagConstraints.gridy = 0; 289 validationInfo.add(valStatusIcon, gridBagConstraints); 290 291 valStatusText.setEditable(false); 292 valStatusText.setText("Succeeded"); 293 gridBagConstraints = new java.awt.GridBagConstraints (); 294 gridBagConstraints.gridx = 1; 295 gridBagConstraints.gridy = 0; 296 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 297 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 298 gridBagConstraints.weightx = 1.0; 299 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 300 validationInfo.add(valStatusText, gridBagConstraints); 301 302 gridBagConstraints = new java.awt.GridBagConstraints (); 303 gridBagConstraints.gridx = 0; 304 gridBagConstraints.gridy = 1; 305 validationInfo.add(valStatusMessageIcon, gridBagConstraints); 306 307 valStatusMessage.setColumns(50); 308 valStatusMessage.setEditable(false); 309 valStatusMessage.setLineWrap(true); 310 valStatusMessage.setText("SQL exception goes here."); 311 valStatusMessage.setWrapStyleWord(true); 312 valStatusMessage.setMargin(new java.awt.Insets (1, 5, 2, 4)); 313 gridBagConstraints = new java.awt.GridBagConstraints (); 314 gridBagConstraints.gridx = 1; 315 gridBagConstraints.gridy = 1; 316 gridBagConstraints.gridwidth = 2; 317 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 318 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 319 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 320 validationInfo.add(valStatusMessage, gridBagConstraints); 321 322 gridBagConstraints = new java.awt.GridBagConstraints (); 323 gridBagConstraints.gridx = 1; 324 gridBagConstraints.gridy = 2; 325 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 326 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 327 gridBagConstraints.weightx = 1.0; 328 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 0); 329 add(validationInfo, gridBagConstraints); 330 331 footerSeparator.setEnabled(false); 332 gridBagConstraints = new java.awt.GridBagConstraints (); 333 gridBagConstraints.gridx = 0; 334 gridBagConstraints.gridy = 3; 335 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 336 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 337 gridBagConstraints.weightx = 1.0; 338 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 339 add(footerSeparator, gridBagConstraints); 340 341 footerInfo.setColumns(25); 342 footerInfo.setEditable(false); 343 footerInfo.setLineWrap(true); 344 footerInfo.setText("footer text goes here"); 345 footerInfo.setWrapStyleWord(true); 346 gridBagConstraints = new java.awt.GridBagConstraints (); 347 gridBagConstraints.gridx = 0; 348 gridBagConstraints.gridy = 4; 349 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 350 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 351 gridBagConstraints.weightx = 1.0; 352 gridBagConstraints.insets = new java.awt.Insets (5, 5, 5, 0); 353 add(footerInfo, gridBagConstraints); 354 355 } 356 358 359 private javax.swing.JPanel connectionInfo; 361 private javax.swing.JLabel connectionStatusIcon; 362 private javax.swing.JLabel connectionStatusLabel; 363 private javax.swing.JTextArea connectionStatusMessage; 364 private javax.swing.JTextField connectionStatusText; 365 private javax.swing.JTextArea footerInfo; 366 private javax.swing.JSeparator footerSeparator; 367 private javax.swing.JTextArea generalInfo; 368 private javax.swing.JLabel valStatusIcon; 369 private javax.swing.JLabel valStatusLabel; 370 private javax.swing.JTextArea valStatusMessage; 371 private javax.swing.JLabel valStatusMessageIcon; 372 private javax.swing.JTextField valStatusText; 373 private javax.swing.JPanel validationInfo; 374 376 private String getMsg(String x) { 377 return NbBundle.getMessage(ConnectionStatusPanel.class, x) ; 378 } 379 private String getMsg(String x, Object y) { 380 return NbBundle.getMessage(ConnectionStatusPanel.class, x, y) ; 381 } 382 private String getMsg(String x, Object y, Object z ) { 383 return NbBundle.getMessage(ConnectionStatusPanel.class, x, y, z) ; 384 } 385 } 386 | Popular Tags |