1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Color ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import javax.swing.UIManager ; 29 import org.netbeans.modules.j2ee.common.DatasourceUIHelper; 30 import org.netbeans.modules.j2ee.common.Util; 31 import org.netbeans.modules.j2ee.deployment.common.api.Datasource; 32 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 33 import org.netbeans.modules.j2ee.ejbcore.ui.EJBPreferences; 34 import org.openide.nodes.Node; 35 import org.openide.util.NbBundle; 36 37 38 42 public class SelectDatabasePanel extends javax.swing.JPanel { 43 44 public static final String IS_VALID = "SelectDatabasePanel_isValid"; 46 private Color nbErrorForeground; 47 48 private Node driverNode; 49 private static String PROTOTYPE_VALUE = "jdbc:pointbase://localhost/sample [pbpublic on PBPUBLIC] "; private final ServiceLocatorStrategyPanel slPanel; 51 private final DatasourceComboBoxHelper comboHelper; 52 private final EJBPreferences ejbPreferences; 53 54 public SelectDatabasePanel(J2eeModuleProvider provider, String lastLocator) { 55 initComponents(); 56 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(SelectDatabasePanel.class, "ACSD_ChooseDatabase")); 57 ejbPreferences = new EJBPreferences(); 58 59 dsCombo.setPrototypeDisplayValue(PROTOTYPE_VALUE); 60 if (provider != null && provider.isDatasourceCreationSupported()) { 61 if (Util.isValidServerInstance(provider)) { 63 DatasourceUIHelper.connect(provider, dsCombo); 64 } else { 65 nbErrorForeground = UIManager.getColor("nb.errorForeground"); if (nbErrorForeground == null) { 68 nbErrorForeground = new Color (255, 0, 0); } 71 72 errorLabel.setForeground(nbErrorForeground); 73 errorLabel.setText(NbBundle.getMessage(SelectDatabasePanel.class, "ERR_MissingServer")); 74 } 75 comboHelper = null; 76 } else { 77 comboHelper = new DatasourceComboBoxHelper(dsCombo); 78 } 79 80 dsCombo.addActionListener(new ActionListener () { 81 public void actionPerformed(ActionEvent actionEvent) { 82 checkDatasource(); 83 } 84 }); 85 86 slPanel = new ServiceLocatorStrategyPanel(lastLocator); 87 serviceLocatorPanel.add(slPanel, BorderLayout.CENTER); 88 createResourcesCheckBox.setSelected(ejbPreferences.isAgreedCreateServerResources()); 89 slPanel.addPropertyChangeListener(new PropertyChangeListener () { 90 public void propertyChange(PropertyChangeEvent evt) { 91 if (evt.getPropertyName().equals(ServiceLocatorStrategyPanel.IS_VALID)) { 92 Object newvalue = evt.getNewValue(); 93 if (newvalue instanceof Boolean ) { 94 boolean isServiceLocatorOk = ((Boolean )newvalue).booleanValue(); 95 if (isServiceLocatorOk) { 96 checkDatasource(); 97 } else { 98 firePropertyChange(IS_VALID, true, false); 99 } 100 } 101 } 102 } 103 }); 104 } 105 106 public Datasource getDatasource() { 107 return (Datasource)dsCombo.getSelectedItem(); 108 } 109 110 public String getServiceLocator() { 111 return slPanel.classSelected(); 112 } 113 114 public boolean createServerResources() { 115 return createResourcesCheckBox.isSelected(); 116 } 117 118 123 private void initComponents() { 125 java.awt.GridBagConstraints gridBagConstraints; 126 127 dsCombo = new javax.swing.JComboBox (); 128 dsLabel = new javax.swing.JLabel (); 129 serviceLocatorPanel = new javax.swing.JPanel (); 130 createResourcesCheckBox = new javax.swing.JCheckBox (); 131 errorLabel = new javax.swing.JLabel (); 132 133 setLayout(new java.awt.GridBagLayout ()); 134 135 gridBagConstraints = new java.awt.GridBagConstraints (); 136 gridBagConstraints.gridx = 1; 137 gridBagConstraints.gridy = 0; 138 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 139 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 140 gridBagConstraints.weightx = 1.0; 141 gridBagConstraints.insets = new java.awt.Insets (12, 0, 11, 11); 142 add(dsCombo, gridBagConstraints); 143 dsCombo.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SelectDatabasePanel.class, "ACSD_dsCombo")); 144 145 dsLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(SelectDatabasePanel.class, "LBL_ConnectionMnemonic").charAt(0)); 146 dsLabel.setLabelFor(dsCombo); 147 org.openide.awt.Mnemonics.setLocalizedText(dsLabel, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_DataSource")); 148 gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridx = 0; 150 gridBagConstraints.gridy = 0; 151 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 152 gridBagConstraints.insets = new java.awt.Insets (12, 12, 11, 11); 153 add(dsLabel, gridBagConstraints); 154 dsLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SelectDatabasePanel.class, "ACSD_DataSource")); 155 156 serviceLocatorPanel.setLayout(new java.awt.BorderLayout ()); 157 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 0; 160 gridBagConstraints.gridy = 2; 161 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 162 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 163 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 164 gridBagConstraints.weightx = 1.0; 165 gridBagConstraints.weighty = 1.0; 166 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 167 add(serviceLocatorPanel, gridBagConstraints); 168 169 org.openide.awt.Mnemonics.setLocalizedText(createResourcesCheckBox, org.openide.util.NbBundle.getBundle(SelectDatabasePanel.class).getString("LBL_CreateServerResources")); 170 createResourcesCheckBox.setToolTipText(org.openide.util.NbBundle.getBundle(SelectDatabasePanel.class).getString("ToolTip_CreateServerResources")); 171 createResourcesCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 172 createResourcesCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 173 createResourcesCheckBox.addActionListener(new java.awt.event.ActionListener () { 174 public void actionPerformed(java.awt.event.ActionEvent evt) { 175 createResourcesCheckBoxActionPerformed(evt); 176 } 177 }); 178 179 gridBagConstraints = new java.awt.GridBagConstraints (); 180 gridBagConstraints.gridx = 0; 181 gridBagConstraints.gridy = 1; 182 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 183 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 184 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 185 add(createResourcesCheckBox, gridBagConstraints); 186 187 org.openide.awt.Mnemonics.setLocalizedText(errorLabel, " "); 188 gridBagConstraints = new java.awt.GridBagConstraints (); 189 gridBagConstraints.gridx = 0; 190 gridBagConstraints.gridy = 3; 191 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 192 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 193 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 11); 194 add(errorLabel, gridBagConstraints); 195 196 } 198 private void createResourcesCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { ejbPreferences.setAgreedCreateServerResources(createResourcesCheckBox.isSelected()); 200 } 202 203 private javax.swing.JCheckBox createResourcesCheckBox; 205 private javax.swing.JComboBox dsCombo; 206 private javax.swing.JLabel dsLabel; 207 private javax.swing.JLabel errorLabel; 208 private javax.swing.JPanel serviceLocatorPanel; 209 211 protected void checkDatasource() { 212 if (dsCombo.getSelectedItem() instanceof Datasource) { 213 firePropertyChange(IS_VALID, false, true); 214 } else { 215 firePropertyChange(IS_VALID, true, false); 216 } 217 } 218 219 } 220 | Popular Tags |