1 19 20 package org.netbeans.modules.j2ee.ejbcore.ui.logicalview.entres; 21 22 import java.awt.BorderLayout ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.beans.PropertyChangeEvent ; 26 import java.beans.PropertyChangeListener ; 27 import java.io.IOException ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import javax.swing.DefaultComboBoxModel ; 31 import javax.swing.JButton ; 32 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 33 import org.openide.DialogDisplayer; 34 import org.openide.NotifyDescriptor; 35 36 40 public class MessageDestinationPanel extends javax.swing.JPanel { 41 42 public static final String IS_VALID = "MessageDestinationPanel_isValid"; 44 private final MessageDestinationPanelController controller; 45 private DefaultComboBoxModel destinationModel; 46 private final ServiceLocatorStrategyPanel slPanel; 47 48 49 public MessageDestinationPanel(final JButton okButton, String lastLocator) { 50 initComponents(); 51 controller = new MessageDestinationPanelController(); 52 DefaultComboBoxModel model = new DefaultComboBoxModel (controller.getJMSProjectRepresentation()); 53 project.setModel(model); 54 destinationModel = new DefaultComboBoxModel (); 55 okButton.setEnabled(false); 56 destination.addActionListener(new ActionListener () { 57 public void actionPerformed(ActionEvent 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 () { 66 public void propertyChange(PropertyChangeEvent evt) { 67 if (evt.getPropertyName().equals(ServiceLocatorStrategyPanel.IS_VALID)) { 68 Object newvalue = evt.getNewValue(); 69 if ((newvalue != null) && (newvalue instanceof Boolean )) { 70 boolean isServiceLocatorOk = ((Boolean )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 getServiceLocator() { 88 return slPanel.classSelected(); 89 } 90 91 private void populateDestinationCombo(Object selectedItem) { 92 destinationModel = new DefaultComboBoxModel (); 93 try { 94 populateEjbDestinationCombo(selectedItem); 95 } catch (IOException 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 selectedItem) throws IOException { 106 EjbJar ejbJar = controller.getEjbJar(selectedItem); 107 if (ejbJar != null) { 108 List list = controller.extractEjbProjectDestinations(ejbJar, selectedItem); 109 Iterator iterator = list.iterator(); 110 while (iterator.hasNext()) { 111 destinationModel.addElement(iterator.next()); 112 } 113 } 114 } 115 120 private void initComponents() { 122 java.awt.GridBagConstraints gridBagConstraints; 123 javax.swing.JLabel jLabel3; 124 125 project = new javax.swing.JComboBox (); 126 destination = new javax.swing.JComboBox (); 127 jLabel1 = new javax.swing.JLabel (); 128 jLabel2 = new javax.swing.JLabel (); 129 serviceLocatorPanel = new javax.swing.JPanel (); 130 jLabel3 = new javax.swing.JLabel (); 131 132 setLayout(new java.awt.GridBagLayout ()); 133 134 project.addActionListener(new java.awt.event.ActionListener () { 135 public void actionPerformed(java.awt.event.ActionEvent evt) { 136 projectActionPerformed(evt); 137 } 138 }); 139 140 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 () { 152 public void actionPerformed(java.awt.event.ActionEvent evt) { 153 destinationActionPerformed(evt); 154 } 155 }); 156 157 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 173 gridBagConstraints.gridx = 0; 174 gridBagConstraints.gridy = 1; 175 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 176 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (0, 5, 5, 5); 188 add(jLabel2, gridBagConstraints); 189 190 serviceLocatorPanel.setLayout(new java.awt.BorderLayout ()); 191 192 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 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 (5, 5, 0, 5); 208 add(jLabel3, gridBagConstraints); 209 210 } 211 213 private void destinationActionPerformed(java.awt.event.ActionEvent evt) { checkDestination(); 215 } 217 private void projectActionPerformed(java.awt.event.ActionEvent evt) { Object selectedItem = project.getSelectedItem(); 219 populateDestinationCombo(selectedItem); 220 } 222 223 private javax.swing.JComboBox destination; 225 private javax.swing.JLabel jLabel1; 226 private javax.swing.JLabel jLabel2; 227 private javax.swing.JComboBox project; 228 private javax.swing.JPanel serviceLocatorPanel; 229 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 |