001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.dbschema.jdbcimpl.wizard;
043:
044: import java.util.ArrayList;
045: import java.util.Arrays;
046: import java.util.HashSet;
047: import java.util.ResourceBundle;
048: import java.util.Set;
049:
050: import javax.swing.*;
051: import javax.swing.event.*;
052: import org.netbeans.api.db.explorer.ConnectionListener;
053: import org.netbeans.api.db.explorer.ConnectionManager;
054: import org.netbeans.api.db.explorer.DatabaseConnection;
055: import org.netbeans.api.db.explorer.support.DatabaseExplorerUIs;
056:
057: import org.openide.filesystems.FileObject;
058: import org.openide.filesystems.Repository;
059: import org.openide.loaders.DataFolder;
060: import org.openide.loaders.DataObject;
061: import org.openide.loaders.DataObjectNotFoundException;
062: import org.openide.nodes.Node;
063: import org.openide.util.NbBundle;
064:
065: public class DBSchemaConnectionPanel extends JPanel implements
066: ListDataListener {
067:
068: static final long serialVersionUID = 5364628520334696421L;
069:
070: private ArrayList list;
071: private DBSchemaWizardData data;
072: private Node dbNode;
073: private Node[] drvNodes;
074:
075: /** Creates new form DBSchemaConnectionpanel */
076: public DBSchemaConnectionPanel(DBSchemaWizardData data,
077: ArrayList list) {
078: this .list = list;
079: this .data = data;
080:
081: putClientProperty("WizardPanel_contentSelectedIndex",
082: new Integer(1)); //NOI18N
083: setName(bundle.getString("ConnectionChooser")); //NOI18N
084:
085: initComponents();
086: initAccessibility();
087:
088: FileObject fo = Repository.getDefault().getDefaultFileSystem()
089: .findResource("UI/Runtime"); //NOI18N
090: DataFolder df;
091: try {
092: df = (DataFolder) DataObject.find(fo);
093: } catch (DataObjectNotFoundException exc) {
094: return;
095: }
096: dbNode = df.getNodeDelegate().getChildren().findChild(
097: "Databases"); //NOI18N
098: DatabaseExplorerUIs.connect(existingConnComboBox,
099: ConnectionManager.getDefault());
100: existingConnComboBox.getModel().addListDataListener(this );
101: }
102:
103: private void initAccessibility() {
104: this .getAccessibleContext().setAccessibleDescription(
105: bundle.getString("ACS_ConnectionPanelA11yDesc")); // NOI18N
106: descriptionTextArea.getAccessibleContext().setAccessibleName(
107: bundle.getString("ACS_DescriptionA11yName")); // NOI18N
108: descriptionTextArea.getAccessibleContext()
109: .setAccessibleDescription(
110: bundle.getString("ACS_DescriptionA11yDesc")); // NOI18N
111: existingConnComboBox.getAccessibleContext().setAccessibleName(
112: bundle.getString("ACS_ExistingConnectionA11yName")); // NOI18N
113: existingConnComboBox
114: .getAccessibleContext()
115: .setAccessibleDescription(
116: bundle
117: .getString("ACS_ExistingConnectionA11yDesc")); // NOI18N
118: }
119:
120: /** This method is called from within the constructor to
121: * initialize the form.
122: * WARNING: Do NOT modify this code. The content of this method is
123: * always regenerated by the FormEditor.
124: */
125: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
126: private void initComponents() {
127: java.awt.GridBagConstraints gridBagConstraints;
128:
129: descriptionTextArea = new javax.swing.JTextArea();
130: existingConnComboBox = new javax.swing.JComboBox();
131:
132: setLayout(new java.awt.GridBagLayout());
133:
134: descriptionTextArea.setEditable(false);
135: descriptionTextArea.setFont(javax.swing.UIManager
136: .getFont("Label.font"));
137: descriptionTextArea.setLineWrap(true);
138: descriptionTextArea.setText(bundle.getString("Description"));
139: descriptionTextArea.setWrapStyleWord(true);
140: descriptionTextArea.setDisabledTextColor(javax.swing.UIManager
141: .getColor("Label.foreground"));
142: descriptionTextArea.setEnabled(false);
143: descriptionTextArea.setOpaque(false);
144: descriptionTextArea.setRequestFocusEnabled(false);
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 0;
147: gridBagConstraints.gridy = 0;
148: gridBagConstraints.gridwidth = 2;
149: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
150: gridBagConstraints.weightx = 1.0;
151: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
152: add(descriptionTextArea, gridBagConstraints);
153:
154: existingConnComboBox.setToolTipText(bundle
155: .getString("ACS_ExistingConnectionComboBoxA11yDesc"));
156: existingConnComboBox
157: .addActionListener(new java.awt.event.ActionListener() {
158: public void actionPerformed(
159: java.awt.event.ActionEvent evt) {
160: existingConnComboBoxActionPerformed(evt);
161: }
162: });
163:
164: gridBagConstraints = new java.awt.GridBagConstraints();
165: gridBagConstraints.gridx = 0;
166: gridBagConstraints.gridy = 1;
167: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
169: gridBagConstraints.weightx = 1.0;
170: gridBagConstraints.weighty = 1.0;
171: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 5);
172: add(existingConnComboBox, gridBagConstraints);
173:
174: }// </editor-fold>//GEN-END:initComponents
175:
176: private void existingConnComboBoxActionPerformed(
177: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_existingConnComboBoxActionPerformed
178: Object selectedItem = existingConnComboBox.getSelectedItem();
179: if (selectedItem instanceof DatabaseConnection) {
180: data
181: .setDatabaseConnection((DatabaseConnection) selectedItem);
182: }
183: fireChange(this );
184: }//GEN-LAST:event_existingConnComboBoxActionPerformed
185:
186: // Variables declaration - do not modify//GEN-BEGIN:variables
187: private javax.swing.JTextArea descriptionTextArea;
188: private javax.swing.JComboBox existingConnComboBox;
189: // End of variables declaration//GEN-END:variables
190:
191: private final ResourceBundle bundle = NbBundle
192: .getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); //NOI18N
193:
194: public boolean isValid() {
195: return existingConnComboBox.getSelectedItem() instanceof DatabaseConnection;
196: }
197:
198: public void intervalAdded(final javax.swing.event.ListDataEvent p1) {
199: fireChange(this );
200: }
201:
202: public void intervalRemoved(final javax.swing.event.ListDataEvent p1) {
203: fireChange(this );
204: }
205:
206: public void contentsChanged(final javax.swing.event.ListDataEvent p1) {
207: fireChange(this );
208: }
209:
210: public void initData() {
211: data.setExistingConn(true);
212: Object selectedItem = existingConnComboBox.getSelectedItem();
213: if (selectedItem instanceof DatabaseConnection) {
214: data
215: .setDatabaseConnection((DatabaseConnection) selectedItem);
216: }
217: }
218:
219: public void fireChange(Object source) {
220: ArrayList lst;
221:
222: synchronized (this ) {
223: lst = (ArrayList) this .list.clone();
224: }
225:
226: ChangeEvent event = new ChangeEvent(source);
227: for (int i = 0; i < lst.size(); i++) {
228: ChangeListener listener = (ChangeListener) lst.get(i);
229: listener.stateChanged(event);
230: }
231: }
232: }
|