KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > dbschema > jdbcimpl > wizard > DBSchemaConnectionPanel


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.dbschema.jdbcimpl.wizard;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import javax.swing.*;
29 import javax.swing.event.*;
30 import org.netbeans.api.db.explorer.ConnectionListener;
31 import org.netbeans.api.db.explorer.ConnectionManager;
32 import org.netbeans.api.db.explorer.DatabaseConnection;
33 import org.netbeans.api.db.explorer.support.DatabaseExplorerUIs;
34
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.Repository;
37 import org.openide.loaders.DataFolder;
38 import org.openide.loaders.DataObject;
39 import org.openide.loaders.DataObjectNotFoundException;
40 import org.openide.nodes.Node;
41 import org.openide.util.NbBundle;
42
43 public class DBSchemaConnectionPanel extends JPanel implements ListDataListener {
44
45     static final long serialVersionUID = 5364628520334696421L;
46
47     private ArrayList JavaDoc list;
48     private DBSchemaWizardData data;
49     private Node dbNode;
50     private Node[] drvNodes;
51
52     /** Creates new form DBSchemaConnectionpanel */
53     public DBSchemaConnectionPanel(DBSchemaWizardData data, ArrayList JavaDoc list) {
54         this.list = list;
55         this.data = data;
56
57         putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(1)); //NOI18N
58
setName(bundle.getString("ConnectionChooser")); //NOI18N
59

60         initComponents ();
61         initAccessibility();
62
63         FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("UI/Runtime"); //NOI18N
64
DataFolder df;
65         try {
66             df = (DataFolder) DataObject.find(fo);
67         } catch (DataObjectNotFoundException exc) {
68             return;
69         }
70         dbNode = df.getNodeDelegate().getChildren().findChild("Databases"); //NOI18N
71
DatabaseExplorerUIs.connect(existingConnComboBox, ConnectionManager.getDefault());
72         existingConnComboBox.getModel().addListDataListener(this);
73     }
74     
75     private void initAccessibility() {
76         this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ConnectionPanelA11yDesc")); // NOI18N
77
descriptionTextArea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_DescriptionA11yName")); // NOI18N
78
descriptionTextArea.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_DescriptionA11yDesc")); // NOI18N
79
existingConnComboBox.getAccessibleContext().setAccessibleName(bundle.getString("ACS_ExistingConnectionA11yName")); // NOI18N
80
existingConnComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ExistingConnectionA11yDesc")); // NOI18N
81
}
82
83     /** This method is called from within the constructor to
84      * initialize the form.
85      * WARNING: Do NOT modify this code. The content of this method is
86      * always regenerated by the FormEditor.
87      */

88     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
89
private void initComponents() {
90         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
91
92         descriptionTextArea = new javax.swing.JTextArea JavaDoc();
93         existingConnComboBox = new javax.swing.JComboBox JavaDoc();
94
95         setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         descriptionTextArea.setEditable(false);
98         descriptionTextArea.setFont(javax.swing.UIManager.getFont("Label.font"));
99         descriptionTextArea.setLineWrap(true);
100         descriptionTextArea.setText(bundle.getString("Description"));
101         descriptionTextArea.setWrapStyleWord(true);
102         descriptionTextArea.setDisabledTextColor(javax.swing.UIManager.getColor("Label.foreground"));
103         descriptionTextArea.setEnabled(false);
104         descriptionTextArea.setOpaque(false);
105         descriptionTextArea.setRequestFocusEnabled(false);
106         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107         gridBagConstraints.gridx = 0;
108         gridBagConstraints.gridy = 0;
109         gridBagConstraints.gridwidth = 2;
110         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
111         gridBagConstraints.weightx = 1.0;
112         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
113         add(descriptionTextArea, gridBagConstraints);
114
115         existingConnComboBox.setToolTipText(bundle.getString("ACS_ExistingConnectionComboBoxA11yDesc"));
116         existingConnComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
117             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
118                 existingConnComboBoxActionPerformed(evt);
119             }
120         });
121
122         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 0;
124         gridBagConstraints.gridy = 1;
125         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
127         gridBagConstraints.weightx = 1.0;
128         gridBagConstraints.weighty = 1.0;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 5);
130         add(existingConnComboBox, gridBagConstraints);
131
132     }// </editor-fold>//GEN-END:initComponents
133

134     private void existingConnComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_existingConnComboBoxActionPerformed
135
Object JavaDoc selectedItem = existingConnComboBox.getSelectedItem();
136         if (selectedItem instanceof DatabaseConnection) {
137             data.setDatabaseConnection((DatabaseConnection)selectedItem);
138         }
139         fireChange(this);
140     }//GEN-LAST:event_existingConnComboBoxActionPerformed
141

142     // Variables declaration - do not modify//GEN-BEGIN:variables
143
private javax.swing.JTextArea JavaDoc descriptionTextArea;
144     private javax.swing.JComboBox JavaDoc existingConnComboBox;
145     // End of variables declaration//GEN-END:variables
146

147     private final ResourceBundle JavaDoc bundle = NbBundle.getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
148

149     public boolean isValid() {
150         return existingConnComboBox.getSelectedItem() instanceof DatabaseConnection;
151     }
152
153     public void intervalAdded(final javax.swing.event.ListDataEvent JavaDoc p1) {
154         fireChange(this);
155     }
156
157     public void intervalRemoved(final javax.swing.event.ListDataEvent JavaDoc p1) {
158         fireChange(this);
159     }
160
161     public void contentsChanged(final javax.swing.event.ListDataEvent JavaDoc p1) {
162         fireChange(this);
163     }
164
165     public void initData() {
166         data.setExistingConn(true);
167         Object JavaDoc selectedItem = existingConnComboBox.getSelectedItem();
168         if (selectedItem instanceof DatabaseConnection) {
169             data.setDatabaseConnection((DatabaseConnection)selectedItem);
170         }
171     }
172
173     public void fireChange (Object JavaDoc source) {
174         ArrayList JavaDoc lst;
175
176         synchronized (this) {
177             lst = (ArrayList JavaDoc) this.list.clone();
178         }
179
180         ChangeEvent event = new ChangeEvent(source);
181         for (int i=0; i< lst.size(); i++){
182             ChangeListener listener = (ChangeListener) lst.get(i);
183             listener.stateChanged(event);
184         }
185     }
186 }
187
Popular Tags