1 19 20 25 26 package org.netbeans.modules.xml.wsdl.ui.view; 27 28 import java.awt.CardLayout ; 29 import java.awt.Component ; 30 import java.awt.event.ActionEvent ; 31 import java.awt.event.ActionListener ; 32 import java.awt.event.ItemEvent ; 33 import java.awt.event.ItemListener ; 34 import java.util.HashMap ; 35 import java.util.List ; 36 import java.util.Map ; 37 38 import javax.swing.DefaultComboBoxModel ; 39 import javax.swing.JComboBox ; 40 import javax.swing.JPanel ; 41 import javax.swing.JTextField ; 42 import javax.swing.text.Document ; 43 44 import org.netbeans.api.project.Project; 45 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 46 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 47 import org.openide.util.NbBundle; 48 49 50 54 public class OperationConfigurationPanel extends javax.swing.JPanel { 55 56 private Project mProject; 57 58 private Document mCommonOperationTextFieldDocument = new JTextField ().getDocument(); 59 private Map <String , String > namespaceToPrefixMap; 60 private WSDLModel mModel; 61 62 63 private boolean mIsShowMessageComboBoxes = false; 64 65 66 public OperationConfigurationPanel(Project project, boolean isShowMessageComboBoxes, WSDLModel model) { 67 mProject = project; 68 this.mIsShowMessageComboBoxes = isShowMessageComboBoxes; 69 if (model != null) { 70 mModel = model; 71 namespaceToPrefixMap = new HashMap <String , String >(); 72 Map <String , String > prefixes = ((AbstractDocumentComponent)model.getDefinitions()).getPrefixes(); 73 if (prefixes != null) { 74 for (String prefix : prefixes.keySet()) { 75 namespaceToPrefixMap.put(prefixes.get(prefix), prefix); 76 } 77 } 78 } else { 79 namespaceToPrefixMap = new HashMap <String , String >(); 80 if (!namespaceToPrefixMap.containsKey("xsd")) { 81 namespaceToPrefixMap.put("http://www.w3.org/2001/XMLSchema", "xsd"); 82 } 83 } 84 initComponents(); 85 initGUI(); 86 } 87 88 90 public OperationConfigurationPanel() { 91 initComponents(); 92 initGUI(); 93 } 94 95 100 private void initComponents() { 102 notificationOperationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.NotificationOperationPanel(this.mProject, this.mCommonOperationTextFieldDocument, namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel); 103 solicitResponseOperationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.SolicitResponseOperationPanel(this.mProject, this.mCommonOperationTextFieldDocument, namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel); 104 contentPanel = new javax.swing.JPanel (); 105 requestReplyOperationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.RequestReplyOperationPanel(this.mProject, this.mCommonOperationTextFieldDocument, namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel); 106 oneWayOperationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.OneWayOperationPanel(this.mProject, this.mCommonOperationTextFieldDocument, namespaceToPrefixMap, mIsShowMessageComboBoxes, mModel); 107 108 contentPanel.setLayout(new java.awt.CardLayout ()); 109 110 contentPanel.setFocusable(false); 111 requestReplyOperationPanel1.setFocusable(false); 112 contentPanel.add(requestReplyOperationPanel1, "OPERATION_REQUEST_REPLY"); 113 114 contentPanel.add(oneWayOperationPanel1, "OPERATION_ONE_WAY"); 115 116 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 117 this.setLayout(layout); 118 layout.setHorizontalGroup( 119 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 120 .add(org.jdesktop.layout.GroupLayout.TRAILING, contentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE) 121 ); 122 layout.setVerticalGroup( 123 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 124 .add(contentPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE) 125 ); 126 } 128 129 public void setInputMessages(String [] existingMessages, String newMessageName, javax.swing.event.DocumentListener msgNameDocumentListener) { 130 this.requestReplyOperationPanel1.setInputMessages(existingMessages, newMessageName, msgNameDocumentListener); 131 this.oneWayOperationPanel1.setInputMessages(existingMessages, newMessageName, msgNameDocumentListener); 132 this.solicitResponseOperationPanel1.setInputMessages(existingMessages, newMessageName, msgNameDocumentListener); 133 } 134 135 public void setOutputMessages(String [] existingMessages, String newMessageName, javax.swing.event.DocumentListener msgNameDocumentListener) { 136 this.requestReplyOperationPanel1.setOutputMessages(existingMessages, newMessageName, msgNameDocumentListener); 137 this.notificationOperationPanel1.setOutputMessages(existingMessages, newMessageName, msgNameDocumentListener); 138 this.solicitResponseOperationPanel1.setOutputMessages(existingMessages, newMessageName, msgNameDocumentListener); 139 } 140 141 public void setFaultMessages(String [] existingMessages, String newMessageName, javax.swing.event.DocumentListener msgNameDocumentListener) { 142 this.requestReplyOperationPanel1.setFaultMessages(existingMessages, newMessageName, msgNameDocumentListener); 143 this.solicitResponseOperationPanel1.setFaultMessages(existingMessages, newMessageName, msgNameDocumentListener); 144 } 145 146 public boolean isNewOutputMessage() { 147 return selectedOperationConfiguration.isNewOutputMessage(); 148 } 149 150 public boolean isNewInputMessage() { 151 return selectedOperationConfiguration.isNewInputMessage(); 152 } 153 154 155 public boolean isNewFaultMessage() { 156 return selectedOperationConfiguration.isNewFaultMessage(); 157 } 158 159 public String getOperationName() { 160 return selectedOperationConfiguration.getOperationName(); 161 } 163 164 public Map <String , String > getNamespaceToPrefixMap() { 165 return namespaceToPrefixMap; 166 } 167 168 public void setOperationName(String operationName) { 169 selectedOperationConfiguration.setOperationName(operationName); 170 } 172 173 public OperationType getOperationType() { 174 return selectedOperationType; 175 } 176 177 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getInputMessageParts() { 178 return selectedOperationConfiguration.getInputMessageParts(); 179 } 180 181 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getOutputMessageParts() { 182 return selectedOperationConfiguration.getOutputMessageParts(); 183 } 184 185 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getFaultMessageParts() { 186 return selectedOperationConfiguration.getFaultMessageParts(); 187 } 188 189 190 public String getOutputMessageName() { 191 return this.selectedOperationConfiguration.getOutputMessageName(); 192 } 193 194 195 public String getInputMessageName() { 196 return this.selectedOperationConfiguration.getInputMessageName(); 197 } 198 199 200 public String getFaultMessageName() { 201 return this.selectedOperationConfiguration.getFaultMessageName(); 202 } 203 204 public JTextField getOperationNameTextField() { 205 return selectedOperationConfiguration.getOperationNameTextField(); 206 } 207 208 private void initGUI() { 209 OperationType op1 = new OperationType(OperationType.OPERATION_REQUEST_REPLY, 210 NbBundle.getMessage(OperationConfigurationPanel.class, "OperationConfigurationPanel.REQUEST_RESPONSE")); 211 OperationType op2 = new OperationType(OperationType.OPERATION_ONE_WAY, 212 NbBundle.getMessage(OperationConfigurationPanel.class, "OperationConfigurationPanel.ONE_WAY")); 213 OperationType op3 = new OperationType(OperationType.OPERATION_SOLICIT_RESPONSE, 214 NbBundle.getMessage(OperationConfigurationPanel.class, "OperationConfigurationPanel.SOLICIT_RESPONSE")); 215 OperationType op4 = new OperationType(OperationType.OPERATION_NOTIFICATION, 216 NbBundle.getMessage(OperationConfigurationPanel.class, "OperationConfigurationPanel.NOTIFICATION")); 217 218 DefaultComboBoxModel model = new DefaultComboBoxModel (new OperationType[] {op1, op2}); 219 220 222 requestReplyOperationPanel1.getOperationTypeComboBox().setModel(model); 223 oneWayOperationPanel1.getOperationTypeComboBox().setModel(model); 224 solicitResponseOperationPanel1.getOperationTypeComboBox().setModel(model); 225 notificationOperationPanel1.getOperationTypeComboBox().setModel(model); 226 227 229 234 OperationTypeActionListener al = new OperationTypeActionListener(); 235 requestReplyOperationPanel1.getOperationTypeComboBox().addActionListener(al); 236 oneWayOperationPanel1.getOperationTypeComboBox().addActionListener(al); 237 solicitResponseOperationPanel1.getOperationTypeComboBox().addActionListener(al); 238 notificationOperationPanel1.getOperationTypeComboBox().addActionListener(al); 239 240 this.selectedOperationType = op1; 241 selectedOperationConfiguration = requestReplyOperationPanel1; 242 } 243 244 245 private OperationConfiguration findVisibleConfiguration() { 246 OperationConfiguration conf = null; 247 248 Component [] comps = contentPanel.getComponents(); 249 for(int i = 0; i < comps.length; i++) { 250 if(comps[i].isVisible()) { 251 conf = (OperationConfiguration) comps[i]; 252 break; 253 } 254 } 255 256 return conf; 257 } 258 259 class OperationTypeItemListener implements ItemListener { 260 public void itemStateChanged(ItemEvent evt) { 261 OperationType ot = (OperationType) evt.getItem(); 262 263 String operationName = selectedOperationConfiguration.getOperationName(); 264 CardLayout operationCardLayout = (CardLayout ) contentPanel.getLayout(); 265 266 operationCardLayout.show(contentPanel, ot.getOperationType()); 267 selectedOperationConfiguration = (OperationConfiguration) findVisibleConfiguration(); 268 contentPanel.revalidate(); 269 selectedOperationConfiguration.setOperationName(operationName); 270 selectedOperationType = ot; 271 } 272 273 } 274 275 class OperationTypeActionListener implements ActionListener { 276 277 public void actionPerformed(ActionEvent e) { 278 if (e.getSource() instanceof JComboBox ) { 279 JComboBox jcb = (JComboBox ) e.getSource(); 280 OperationType ot = (OperationType) jcb.getSelectedItem(); 281 String operationName = selectedOperationConfiguration.getOperationName(); 282 CardLayout operationCardLayout = (CardLayout ) contentPanel.getLayout(); 283 284 operationCardLayout.show(contentPanel, ot.getOperationType()); 285 selectedOperationConfiguration = (OperationConfiguration) findVisibleConfiguration(); 286 contentPanel.revalidate(); 287 selectedOperationConfiguration.setOperationName(operationName); 288 selectedOperationType = ot; 289 selectedOperationConfiguration.getOperationTypeComboBox().requestFocus(); 290 } 291 } 292 293 } 294 295 public interface OperationConfiguration { 296 297 public static final String PROP_ERROR_MESSAGE = "PROP_ERROR_MESSAGE"; 298 299 public String getOperationName(); 300 301 public void setOperationName(String operationName); 302 303 public OperationType getOperationType(); 304 305 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getInputMessageParts(); 306 307 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getOutputMessageParts(); 308 309 public List <PartAndElementOrTypeTableModel.PartAndElementOrType> getFaultMessageParts(); 310 311 public JTextField getOperationNameTextField(); 312 313 public JComboBox getOperationTypeComboBox(); 314 315 public boolean isNewOutputMessage(); 316 317 318 public boolean isNewInputMessage(); 319 320 321 public boolean isNewFaultMessage(); 322 323 public String getOutputMessageName(); 324 325 326 public String getInputMessageName(); 327 328 329 public String getFaultMessageName(); 330 331 } 332 333 public static void main(String [] args) { 334 335 342 343 } 344 345 private OperationConfiguration selectedOperationConfiguration; 346 347 private OperationType selectedOperationType; 348 private JPanel operationCardPanel; 349 350 private javax.swing.JPanel contentPanel; 352 private org.netbeans.modules.xml.wsdl.ui.view.NotificationOperationPanel notificationOperationPanel1; 353 private org.netbeans.modules.xml.wsdl.ui.view.OneWayOperationPanel oneWayOperationPanel1; 354 private org.netbeans.modules.xml.wsdl.ui.view.RequestReplyOperationPanel requestReplyOperationPanel1; 355 private org.netbeans.modules.xml.wsdl.ui.view.SolicitResponseOperationPanel solicitResponseOperationPanel1; 356 358 } 359 | Popular Tags |