KickJava   Java API By Example, From Geeks To Geeks.

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


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.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.beans.PropertyChangeEvent JavaDoc;
26 import java.beans.PropertyChangeListener JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
33 import org.openide.DialogDisplayer;
34 import org.openide.NotifyDescriptor;
35
36 /**
37  * Provide an action to select message destinations
38  * @author Chris Webster
39  */

40 public class MessageDestinationPanel extends javax.swing.JPanel JavaDoc {
41
42     public static final String JavaDoc IS_VALID = "MessageDestinationPanel_isValid"; //NOI18N
43

44     private final MessageDestinationPanelController controller;
45     private DefaultComboBoxModel JavaDoc destinationModel;
46     private final ServiceLocatorStrategyPanel slPanel;
47     
48     /** Creates new form MessageDestinationPanel */
49     public MessageDestinationPanel(final JButton JavaDoc okButton, String JavaDoc lastLocator) {
50         initComponents();
51         controller = new MessageDestinationPanelController();
52         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc(controller.getJMSProjectRepresentation());
53         project.setModel(model);
54         destinationModel = new DefaultComboBoxModel JavaDoc();
55         okButton.setEnabled(false);
56         destination.addActionListener(new ActionListener JavaDoc() {
57             public void actionPerformed(ActionEvent JavaDoc event) {
58                 okButton.setEnabled(destination.getSelectedIndex() > -1);
59             }
60         });
61         if (model.getSize() > 0) {
62             project.setSelectedIndex(0);
63         }
64         slPanel = new ServiceLocatorStrategyPanel(lastLocator);
65         slPanel.addPropertyChangeListener(new PropertyChangeListener JavaDoc() {
66             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
67                 if (evt.getPropertyName().equals(ServiceLocatorStrategyPanel.IS_VALID)) {
68                     Object JavaDoc newvalue = evt.getNewValue();
69                     if ((newvalue != null) && (newvalue instanceof Boolean JavaDoc)) {
70                         boolean isServiceLocatorOk = ((Boolean JavaDoc)newvalue).booleanValue();
71                         if (isServiceLocatorOk) {
72                             checkDestination();
73                         } else {
74                             firePropertyChange(IS_VALID, true, false);
75                         }
76                     }
77                 }
78             }
79         });
80         serviceLocatorPanel.add(slPanel, BorderLayout.CENTER);
81     }
82     
83     public JMSDestination getSelectedDestination() {
84         return (JMSDestination) destination.getSelectedItem();
85     }
86     
87     public String JavaDoc getServiceLocator() {
88         return slPanel.classSelected();
89     }
90     
91     private void populateDestinationCombo(Object JavaDoc selectedItem) {
92         destinationModel = new DefaultComboBoxModel JavaDoc();
93         try {
94             populateEjbDestinationCombo(selectedItem);
95         } catch (IOException JavaDoc ioe) {
96              NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(ioe.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
97              DialogDisplayer.getDefault().notify(notifyDescriptor);
98         }
99         destination.setModel(destinationModel);
100         if (destinationModel.getSize()>0) {
101             destination.setSelectedIndex(0);
102         }
103     }
104      
105     private void populateEjbDestinationCombo(Object JavaDoc selectedItem) throws IOException JavaDoc {
106         EjbJar ejbJar = controller.getEjbJar(selectedItem);
107         if (ejbJar != null) {
108             List JavaDoc list = controller.extractEjbProjectDestinations(ejbJar, selectedItem);
109             Iterator JavaDoc iterator = list.iterator();
110             while (iterator.hasNext()) {
111                 destinationModel.addElement(iterator.next());
112             }
113         }
114     }
115     /** This method is called from within the constructor to
116      * initialize the form.
117      * WARNING: Do NOT modify this code. The content of this method is
118      * always regenerated by the Form Editor.
119      */

120     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
121
private void initComponents() {
122         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
123         javax.swing.JLabel JavaDoc jLabel3;
124
125         project = new javax.swing.JComboBox JavaDoc();
126         destination = new javax.swing.JComboBox JavaDoc();
127         jLabel1 = new javax.swing.JLabel JavaDoc();
128         jLabel2 = new javax.swing.JLabel JavaDoc();
129         serviceLocatorPanel = new javax.swing.JPanel JavaDoc();
130         jLabel3 = new javax.swing.JLabel JavaDoc();
131
132         setLayout(new java.awt.GridBagLayout JavaDoc());
133
134         project.addActionListener(new java.awt.event.ActionListener JavaDoc() {
135             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
136                 projectActionPerformed(evt);
137             }
138         });
139
140         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
141         gridBagConstraints.gridx = 1;
142         gridBagConstraints.gridy = 1;
143         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
144         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
145         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146         gridBagConstraints.weightx = 1.0;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 5, 5);
148         add(project, gridBagConstraints);
149         project.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MessageDestinationPanel.class, "ACSD_Project_Combo"));
150
151         destination.addActionListener(new java.awt.event.ActionListener JavaDoc() {
152             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
153                 destinationActionPerformed(evt);
154             }
155         });
156
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridx = 1;
159         gridBagConstraints.gridy = 2;
160         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
163         gridBagConstraints.weightx = 1.0;
164         gridBagConstraints.weighty = 1.0;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 5);
166         add(destination, gridBagConstraints);
167         destination.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MessageDestinationPanel.class, "ACSD_Destination_Combo"));
168
169         jLabel1.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_ProjectMneumonic").charAt(0));
170         jLabel1.setLabelFor(project);
171         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_Project"));
172         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
173         gridBagConstraints.gridx = 0;
174         gridBagConstraints.gridy = 1;
175         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
176         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
177         add(jLabel1, gridBagConstraints);
178
179         jLabel2.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_DestinationMneumonic").charAt(0));
180         jLabel2.setLabelFor(destination);
181         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_Destination"));
182         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridx = 0;
184         gridBagConstraints.gridy = 2;
185         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
186         gridBagConstraints.weighty = 1.0;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 5);
188         add(jLabel2, gridBagConstraints);
189
190         serviceLocatorPanel.setLayout(new java.awt.BorderLayout JavaDoc());
191
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 0;
194         gridBagConstraints.gridy = 3;
195         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
196         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
197         gridBagConstraints.weighty = 1.0;
198         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 5, 5);
199         add(serviceLocatorPanel, gridBagConstraints);
200
201         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ejbcore/ui/logicalview/entres/Bundle").getString("LBL_ProjectMustBeInSameApplication"));
202         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
203         gridBagConstraints.gridx = 0;
204         gridBagConstraints.gridy = 0;
205         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
206         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 5, 0, 5);
208         add(jLabel3, gridBagConstraints);
209
210     }
211     // </editor-fold>//GEN-END:initComponents
212

213     private void destinationActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_destinationActionPerformed
214
checkDestination();
215     }//GEN-LAST:event_destinationActionPerformed
216

217     private void projectActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_projectActionPerformed
218
Object JavaDoc selectedItem = project.getSelectedItem();
219         populateDestinationCombo(selectedItem);
220     }//GEN-LAST:event_projectActionPerformed
221

222     
223     // Variables declaration - do not modify//GEN-BEGIN:variables
224
private javax.swing.JComboBox JavaDoc destination;
225     private javax.swing.JLabel JavaDoc jLabel1;
226     private javax.swing.JLabel JavaDoc jLabel2;
227     private javax.swing.JComboBox JavaDoc project;
228     private javax.swing.JPanel JavaDoc serviceLocatorPanel;
229     // End of variables declaration//GEN-END:variables
230

231     protected void checkDestination() {
232         if (destination.getSelectedItem() == null) {
233             firePropertyChange(IS_VALID, true, false);
234         } else {
235             firePropertyChange(IS_VALID, false, true);
236         }
237     }
238     
239 }
240
Popular Tags