1 19 20 package org.netbeans.modules.dbschema.jdbcimpl.wizard; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.HashSet ; 25 import java.util.ResourceBundle ; 26 import java.util.Set ; 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 list; 48 private DBSchemaWizardData data; 49 private Node dbNode; 50 private Node[] drvNodes; 51 52 53 public DBSchemaConnectionPanel(DBSchemaWizardData data, ArrayList list) { 54 this.list = list; 55 this.data = data; 56 57 putClientProperty("WizardPanel_contentSelectedIndex", new Integer (1)); setName(bundle.getString("ConnectionChooser")); 60 initComponents (); 61 initAccessibility(); 62 63 FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource("UI/Runtime"); DataFolder df; 65 try { 66 df = (DataFolder) DataObject.find(fo); 67 } catch (DataObjectNotFoundException exc) { 68 return; 69 } 70 dbNode = df.getNodeDelegate().getChildren().findChild("Databases"); DatabaseExplorerUIs.connect(existingConnComboBox, ConnectionManager.getDefault()); 72 existingConnComboBox.getModel().addListDataListener(this); 73 } 74 75 private void initAccessibility() { 76 this.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ConnectionPanelA11yDesc")); descriptionTextArea.getAccessibleContext().setAccessibleName(bundle.getString("ACS_DescriptionA11yName")); descriptionTextArea.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_DescriptionA11yDesc")); existingConnComboBox.getAccessibleContext().setAccessibleName(bundle.getString("ACS_ExistingConnectionA11yName")); existingConnComboBox.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ExistingConnectionA11yDesc")); } 82 83 88 private void initComponents() { 90 java.awt.GridBagConstraints gridBagConstraints; 91 92 descriptionTextArea = new javax.swing.JTextArea (); 93 existingConnComboBox = new javax.swing.JComboBox (); 94 95 setLayout(new java.awt.GridBagLayout ()); 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 (); 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 (12, 12, 0, 11); 113 add(descriptionTextArea, gridBagConstraints); 114 115 existingConnComboBox.setToolTipText(bundle.getString("ACS_ExistingConnectionComboBoxA11yDesc")); 116 existingConnComboBox.addActionListener(new java.awt.event.ActionListener () { 117 public void actionPerformed(java.awt.event.ActionEvent evt) { 118 existingConnComboBoxActionPerformed(evt); 119 } 120 }); 121 122 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 12, 0, 5); 130 add(existingConnComboBox, gridBagConstraints); 131 132 } 134 private void existingConnComboBoxActionPerformed(java.awt.event.ActionEvent evt) { Object selectedItem = existingConnComboBox.getSelectedItem(); 136 if (selectedItem instanceof DatabaseConnection) { 137 data.setDatabaseConnection((DatabaseConnection)selectedItem); 138 } 139 fireChange(this); 140 } 142 private javax.swing.JTextArea descriptionTextArea; 144 private javax.swing.JComboBox existingConnComboBox; 145 147 private final ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.dbschema.jdbcimpl.resources.Bundle"); 149 public boolean isValid() { 150 return existingConnComboBox.getSelectedItem() instanceof DatabaseConnection; 151 } 152 153 public void intervalAdded(final javax.swing.event.ListDataEvent p1) { 154 fireChange(this); 155 } 156 157 public void intervalRemoved(final javax.swing.event.ListDataEvent p1) { 158 fireChange(this); 159 } 160 161 public void contentsChanged(final javax.swing.event.ListDataEvent p1) { 162 fireChange(this); 163 } 164 165 public void initData() { 166 data.setExistingConn(true); 167 Object selectedItem = existingConnComboBox.getSelectedItem(); 168 if (selectedItem instanceof DatabaseConnection) { 169 data.setDatabaseConnection((DatabaseConnection)selectedItem); 170 } 171 } 172 173 public void fireChange (Object source) { 174 ArrayList lst; 175 176 synchronized (this) { 177 lst = (ArrayList ) 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 |