KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbcore > ui > logicalview > entres > SelectDatabasePanel


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.j2ee.ejbcore.ui.logicalview.entres;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.awt.Color JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.beans.PropertyChangeEvent JavaDoc;
27 import java.beans.PropertyChangeListener JavaDoc;
28 import javax.swing.UIManager JavaDoc;
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 /**
39  * Provide an interface to support datasource selection.
40  * @author Chris Webster
41  */

42 public class SelectDatabasePanel extends javax.swing.JPanel JavaDoc {
43     
44     public static final String JavaDoc IS_VALID = "SelectDatabasePanel_isValid"; //NOI18N
45

46     private Color JavaDoc nbErrorForeground;
47     
48     private Node driverNode;
49     private static String JavaDoc PROTOTYPE_VALUE = "jdbc:pointbase://localhost/sample [pbpublic on PBPUBLIC] "; //NOI18N
50
private final ServiceLocatorStrategyPanel slPanel;
51     private final DatasourceComboBoxHelper comboHelper;
52     private final EJBPreferences ejbPreferences;
53
54     public SelectDatabasePanel(J2eeModuleProvider provider, String JavaDoc 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             // DS API is supported by the server plugin
62
if (Util.isValidServerInstance(provider)) {
63                 DatasourceUIHelper.connect(provider, dsCombo);
64             } else {
65                 // copied from WizardDescriptor
66
nbErrorForeground = UIManager.getColor("nb.errorForeground"); //NOI18N
67
if (nbErrorForeground == null) {
68                     //nbErrorForeground = new Color(89, 79, 191); // RGB suggested by Bruce in #28466
69
nbErrorForeground = new Color JavaDoc(255, 0, 0); // RGB suggested by jdinga in #65358
70
}
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 JavaDoc() {
81             public void actionPerformed(ActionEvent JavaDoc 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 JavaDoc() {
90             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
91                 if (evt.getPropertyName().equals(ServiceLocatorStrategyPanel.IS_VALID)) {
92                     Object JavaDoc newvalue = evt.getNewValue();
93                     if (newvalue instanceof Boolean JavaDoc) {
94                         boolean isServiceLocatorOk = ((Boolean JavaDoc)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 JavaDoc getServiceLocator() {
111         return slPanel.classSelected();
112     }
113     
114     public boolean createServerResources() {
115         return createResourcesCheckBox.isSelected();
116     }
117     
118     /** This method is called from within the constructor to
119      * initialize the form.
120      * WARNING: Do NOT modify this code. The content of this method is
121      * always regenerated by the Form Editor.
122      */

123     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
124
private void initComponents() {
125         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
126
127         dsCombo = new javax.swing.JComboBox JavaDoc();
128         dsLabel = new javax.swing.JLabel JavaDoc();
129         serviceLocatorPanel = new javax.swing.JPanel JavaDoc();
130         createResourcesCheckBox = new javax.swing.JCheckBox JavaDoc();
131         errorLabel = new javax.swing.JLabel JavaDoc();
132
133         setLayout(new java.awt.GridBagLayout JavaDoc());
134
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
149         gridBagConstraints.gridx = 0;
150         gridBagConstraints.gridy = 0;
151         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
157
158         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc(0, 0, 0, 0));
173         createResourcesCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
174             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
175                 createResourcesCheckBoxActionPerformed(evt);
176             }
177         });
178
179         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 12, 11, 11);
185         add(createResourcesCheckBox, gridBagConstraints);
186
187         org.openide.awt.Mnemonics.setLocalizedText(errorLabel, " ");
188         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 12, 5, 11);
194         add(errorLabel, gridBagConstraints);
195
196     }// </editor-fold>//GEN-END:initComponents
197

198     private void createResourcesCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_createResourcesCheckBoxActionPerformed
199
ejbPreferences.setAgreedCreateServerResources(createResourcesCheckBox.isSelected());
200     }//GEN-LAST:event_createResourcesCheckBoxActionPerformed
201

202     
203     // Variables declaration - do not modify//GEN-BEGIN:variables
204
private javax.swing.JCheckBox JavaDoc createResourcesCheckBox;
205     private javax.swing.JComboBox JavaDoc dsCombo;
206     private javax.swing.JLabel JavaDoc dsLabel;
207     private javax.swing.JLabel JavaDoc errorLabel;
208     private javax.swing.JPanel JavaDoc serviceLocatorPanel;
209     // End of variables declaration//GEN-END:variables
210

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