KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > ui > ConnectionStatusPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ConnectionStatusPanl.java
21  *
22  * Created on March 16, 2005, 4:15 PM
23  */

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 JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import javax.swing.Icon JavaDoc;
31 import javax.swing.ImageIcon JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JDialog JavaDoc;
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 /**
41  * Shows the status of a connction in a dialog.
42  * This just presentss the results of a testConnection(), it
43  * does not do the actual test.
44  *
45  * @author jfbrown
46  */

47 public class ConnectionStatusPanel extends javax.swing.JPanel JavaDoc {
48
49     private JDialog JavaDoc dialog;
50     private DialogDescriptor dlg = null;
51
52     private JButton JavaDoc okButton = new JButton JavaDoc(NbBundle.getMessage(ConnectionStatusPanel.class, "OK")); // NOI18N
53

54     // private Image conGood = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/started.png"); // NOI18N
55
// private Image conFailed = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/disconnected.png"); // NOI18N
56
private Image JavaDoc conGood = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/ok.gif"); // NOI18N
57
private Image JavaDoc conFailed = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/error.gif"); // NOI18N
58
private Image JavaDoc conWarning = Utilities.loadImage("org/netbeans/modules/db/sql/visualeditor/resources/warning.gif"); // NOI18N
59
/** Creates new form ConnectionStatusDialog */
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 JavaDoc info) {
73         generalInfo.setText(info) ;
74         generalInfo.setVisible(true) ;
75     }
76     public void setFooterInfo(String JavaDoc info) {
77         footerInfo.setText(info) ;
78         footerInfo.setVisible(true) ;
79         footerSeparator.setVisible(true) ;
80     }
81     public void showDialog( String JavaDoc dsName, boolean connected, String JavaDoc sqlException ) {
82         showDialog( dsName, connected, sqlException, null, 0, false ) ;
83     }
84     public void showDialog( String JavaDoc dsName, boolean connected, String JavaDoc sqlException, String JavaDoc tableName, int rows ) {
85         showDialog( dsName, connected, sqlException, tableName, rows, true ) ;
86     }
87     public void showDialog( String JavaDoc dsName, boolean connected, String JavaDoc sqlException, String JavaDoc tableName, int rows, boolean showValTableInfo ) {
88
89         /* calculate the displayd values based on this method's input parameters.
90          */

91         configureDisplay(dsName, connected, sqlException, tableName, rows, showValTableInfo) ;
92
93         displayDialog(dsName) ;
94     }
95     public void displayDialog(String JavaDoc dsName) {
96         Log.log("ConnectionStatusDisplay.displayDialog for " +dsName) ;
97         // Add a listener to the dialog's buttons
98
ActionListener JavaDoc listener = new ActionListener JavaDoc() {
99             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
100                 dialog.dispose();
101             }
102         };
103         dlg = new DialogDescriptor(this,
104                 getMsg( "ConStat_title", dsName), // NOI18N
105
true, listener);
106         dlg.setOptions(new Object JavaDoc[] { okButton });
107         dlg.setClosingOptions( null );
108         dlg.setValid(false);
109         
110         dialog = (JDialog JavaDoc) 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 JavaDoc dsName, boolean connected, String JavaDoc sqlException, String JavaDoc tableName,
121             int rows, boolean showValTableInfo ) {
122         /* calculate the displayd values based on this method's input parameters.
123          */

124         if ( connected ) {
125             connectionStatusIcon.setIcon( new ImageIcon JavaDoc(conGood) ) ;
126             connectionStatusText.setText(getMsg("ConStat_succeeded_msg")) ; // NOI18N
127
connectionStatusMessage.setVisible(false) ;
128             validationInfo.setVisible(true) ;
129             if ( sqlException == null ) {
130                 valStatusText.setText(getMsg("ConStat_rows_selected_msg", tableName, new Integer JavaDoc(rows)) ) ; // NOI18N
131
valStatusIcon.setIcon( new ImageIcon JavaDoc(conGood) ) ;
132                 String JavaDoc valMsg ;
133                 if (rows > 1 ) {
134                     
135                     valMsg = getMsg("ConStat_valtable_bad_msg") ;// NOI18N
136
valStatusMessageIcon.setIcon( new ImageIcon JavaDoc(conWarning) ) ;
137                 } else {
138                     valMsg = getMsg("ConStat_valtable_good_msg") ;// NOI18N
139
valStatusMessageIcon.setIcon( new ImageIcon JavaDoc(conGood) ) ;
140                 }
141                 valMsg = valMsg + "\n" + getMsg("ConStat_validationTableInfo") ; // NOI18N
142
valStatusMessage.setText(valMsg) ;
143                 
144             } else if (tableName != null) {
145                 // validation table test failed.
146
valStatusIcon.setIcon( new ImageIcon JavaDoc(conFailed) ) ;
147
148                 // validation failed.
149
valStatusText.setText(getMsg("ConStat_failed_msg")) ;// NOI18N
150

151                 String JavaDoc 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             // connection failed.
166
connectionStatusIcon.setIcon( new ImageIcon JavaDoc(conFailed) ) ;
167             connectionStatusText.setText(getMsg("ConStat_failed_msg")) ;// NOI18N
168
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     /** This method is called from within the constructor to
179      * initialize the form.
180      * WARNING: Do NOT modify this code. The content of this method is
181      * always regenerated by the Form Editor.
182      */

183     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
184
private void initComponents() {
185         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
186
187         generalInfo = new javax.swing.JTextArea JavaDoc();
188         connectionStatusLabel = new javax.swing.JLabel JavaDoc();
189         connectionInfo = new javax.swing.JPanel JavaDoc();
190         connectionStatusIcon = new javax.swing.JLabel JavaDoc();
191         connectionStatusText = new javax.swing.JTextField JavaDoc();
192         connectionStatusMessage = new javax.swing.JTextArea JavaDoc();
193         valStatusLabel = new javax.swing.JLabel JavaDoc();
194         validationInfo = new javax.swing.JPanel JavaDoc();
195         valStatusIcon = new javax.swing.JLabel JavaDoc();
196         valStatusText = new javax.swing.JTextField JavaDoc();
197         valStatusMessageIcon = new javax.swing.JLabel JavaDoc();
198         valStatusMessage = new javax.swing.JTextArea JavaDoc();
199         footerSeparator = new javax.swing.JSeparator JavaDoc();
200         footerInfo = new javax.swing.JTextArea JavaDoc();
201
202         setLayout(new java.awt.GridBagLayout JavaDoc());
203
204         getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_title", new Object JavaDoc[] {}));
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 JavaDoc();
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 JavaDoc(5, 5, 5, 0);
216         add(generalInfo, gridBagConstraints);
217
218         connectionStatusLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_test_mnemonic", new Object JavaDoc[] {}).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 JavaDoc();
222         gridBagConstraints.gridx = 0;
223         gridBagConstraints.gridy = 1;
224         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
225         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
230
231         connectionStatusIcon.setFocusable(false);
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc();
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 JavaDoc(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 JavaDoc(1, 5, 2, 4));
254         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 5, 0, 0);
260         connectionInfo.add(connectionStatusMessage, gridBagConstraints);
261
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 11, 0, 0);
269         add(connectionInfo, gridBagConstraints);
270
271         valStatusLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ConnectionStatusPanel.class, "ConStat_valtable_mnemonic", new Object JavaDoc[] {}).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 JavaDoc();
275         gridBagConstraints.gridx = 0;
276         gridBagConstraints.gridy = 2;
277         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
278         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
284
285         valStatusIcon.setFocusable(false);
286         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc();
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 JavaDoc(5, 5, 0, 0);
300         validationInfo.add(valStatusText, gridBagConstraints);
301
302         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(1, 5, 2, 4));
313         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 5, 0, 0);
320         validationInfo.add(valStatusMessage, gridBagConstraints);
321
322         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 11, 0, 0);
329         add(validationInfo, gridBagConstraints);
330
331         footerSeparator.setEnabled(false);
332         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(5, 5, 5, 0);
353         add(footerInfo, gridBagConstraints);
354
355     }
356     // </editor-fold>//GEN-END:initComponents
357

358     
359     // Variables declaration - do not modify//GEN-BEGIN:variables
360
private javax.swing.JPanel JavaDoc connectionInfo;
361     private javax.swing.JLabel JavaDoc connectionStatusIcon;
362     private javax.swing.JLabel JavaDoc connectionStatusLabel;
363     private javax.swing.JTextArea JavaDoc connectionStatusMessage;
364     private javax.swing.JTextField JavaDoc connectionStatusText;
365     private javax.swing.JTextArea JavaDoc footerInfo;
366     private javax.swing.JSeparator JavaDoc footerSeparator;
367     private javax.swing.JTextArea JavaDoc generalInfo;
368     private javax.swing.JLabel JavaDoc valStatusIcon;
369     private javax.swing.JLabel JavaDoc valStatusLabel;
370     private javax.swing.JTextArea JavaDoc valStatusMessage;
371     private javax.swing.JLabel JavaDoc valStatusMessageIcon;
372     private javax.swing.JTextField JavaDoc valStatusText;
373     private javax.swing.JPanel JavaDoc validationInfo;
374     // End of variables declaration//GEN-END:variables
375

376     private String JavaDoc getMsg(String JavaDoc x) {
377         return NbBundle.getMessage(ConnectionStatusPanel.class, x) ;
378     }
379     private String JavaDoc getMsg(String JavaDoc x, Object JavaDoc y) {
380         return NbBundle.getMessage(ConnectionStatusPanel.class, x, y) ;
381     }
382     private String JavaDoc getMsg(String JavaDoc x, Object JavaDoc y, Object JavaDoc z ) {
383         return NbBundle.getMessage(ConnectionStatusPanel.class, x, y, z) ;
384     }
385 }
386
Popular Tags