KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > OperationConfigurationPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * OperationConfigurationPanel.java
22  *
23  * Created on August 25, 2006, 1:15 PM
24  */

25
26 package org.netbeans.modules.xml.wsdl.ui.view;
27
28 import java.awt.CardLayout JavaDoc;
29 import java.awt.Component JavaDoc;
30 import java.awt.event.ActionEvent JavaDoc;
31 import java.awt.event.ActionListener JavaDoc;
32 import java.awt.event.ItemEvent JavaDoc;
33 import java.awt.event.ItemListener JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.List JavaDoc;
36 import java.util.Map JavaDoc;
37
38 import javax.swing.DefaultComboBoxModel JavaDoc;
39 import javax.swing.JComboBox JavaDoc;
40 import javax.swing.JPanel JavaDoc;
41 import javax.swing.JTextField JavaDoc;
42 import javax.swing.text.Document JavaDoc;
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 /**
51  *
52  * @author radval
53  */

54 public class OperationConfigurationPanel extends javax.swing.JPanel JavaDoc {
55     
56     private Project mProject;
57     
58     private Document JavaDoc mCommonOperationTextFieldDocument = new JTextField JavaDoc().getDocument();
59     private Map JavaDoc<String JavaDoc, String JavaDoc> namespaceToPrefixMap;
60     private WSDLModel mModel;
61     
62     
63     private boolean mIsShowMessageComboBoxes = false;
64     
65     /** Creates new form OperationConfigurationPanel */
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 JavaDoc<String JavaDoc, String JavaDoc>();
72             Map JavaDoc<String JavaDoc, String JavaDoc> prefixes = ((AbstractDocumentComponent)model.getDefinitions()).getPrefixes();
73             if (prefixes != null) {
74                 for (String JavaDoc prefix : prefixes.keySet()) {
75                     namespaceToPrefixMap.put(prefixes.get(prefix), prefix);
76                 }
77             }
78         } else {
79             namespaceToPrefixMap = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
80             if (!namespaceToPrefixMap.containsKey("xsd")) {
81                 namespaceToPrefixMap.put("http://www.w3.org/2001/XMLSchema", "xsd");
82             }
83         }
84         initComponents();
85         initGUI();
86     }
87     
88     /** Mattise require default constructor otherwise will not load in design view of mattise
89      **/

90     public OperationConfigurationPanel() {
91         initComponents();
92         initGUI();
93     }
94     
95     /** This method is called from within the constructor to
96      * initialize the form.
97      * WARNING: Do NOT modify this code. The content of this method is
98      * always regenerated by the Form Editor.
99      */

100     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
101
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 JavaDoc();
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 JavaDoc());
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     }// </editor-fold>//GEN-END:initComponents
127

128     
129     public void setInputMessages(String JavaDoc[] existingMessages, String JavaDoc newMessageName, javax.swing.event.DocumentListener JavaDoc 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 JavaDoc[] existingMessages, String JavaDoc newMessageName, javax.swing.event.DocumentListener JavaDoc 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 JavaDoc[] existingMessages, String JavaDoc newMessageName, javax.swing.event.DocumentListener JavaDoc 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 JavaDoc getOperationName() {
160         return selectedOperationConfiguration.getOperationName();
161 // return this.operationNameTextField.getText();
162
}
163     
164     public Map JavaDoc<String JavaDoc, String JavaDoc> getNamespaceToPrefixMap() {
165         return namespaceToPrefixMap;
166     }
167     
168     public void setOperationName(String JavaDoc operationName) {
169         selectedOperationConfiguration.setOperationName(operationName);
170 // this.operationNameTextField.setText(operationName);
171
}
172     
173     public OperationType getOperationType() {
174         return selectedOperationType;
175     }
176     
177     public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getInputMessageParts() {
178         return selectedOperationConfiguration.getInputMessageParts();
179     }
180     
181     public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getOutputMessageParts() {
182         return selectedOperationConfiguration.getOutputMessageParts();
183     }
184     
185     public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getFaultMessageParts() {
186         return selectedOperationConfiguration.getFaultMessageParts();
187     }
188     
189     
190     public String JavaDoc getOutputMessageName() {
191         return this.selectedOperationConfiguration.getOutputMessageName();
192     }
193     
194     
195     public String JavaDoc getInputMessageName() {
196         return this.selectedOperationConfiguration.getInputMessageName();
197     }
198     
199     
200     public String JavaDoc getFaultMessageName() {
201         return this.selectedOperationConfiguration.getFaultMessageName();
202     }
203     
204     public JTextField JavaDoc 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 JavaDoc model = new DefaultComboBoxModel JavaDoc(new OperationType[] {op1, op2/*, op3, op4*/});
219         
220 // operationTypeComboBox.setModel(model);
221

222         requestReplyOperationPanel1.getOperationTypeComboBox().setModel(model);
223         oneWayOperationPanel1.getOperationTypeComboBox().setModel(model);
224         solicitResponseOperationPanel1.getOperationTypeComboBox().setModel(model);
225         notificationOperationPanel1.getOperationTypeComboBox().setModel(model);
226         
227 // OperationTypeItemListener l = new OperationTypeItemListener();
228

229 // requestReplyOperationPanel1.getOperationTypeComboBox().addItemListener(l);
230
// oneWayOperationPanel1.getOperationTypeComboBox().addItemListener(l);
231
// solicitResponseOperationPanel1.getOperationTypeComboBox().addItemListener(l);
232
// notificationOperationPanel1.getOperationTypeComboBox().addItemListener(l);
233

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 JavaDoc[] 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 JavaDoc {
260         public void itemStateChanged(ItemEvent JavaDoc evt) {
261             OperationType ot = (OperationType) evt.getItem();
262             
263             String JavaDoc operationName = selectedOperationConfiguration.getOperationName();
264             CardLayout JavaDoc operationCardLayout = (CardLayout JavaDoc) 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 JavaDoc {
276         
277         public void actionPerformed(ActionEvent JavaDoc e) {
278             if (e.getSource() instanceof JComboBox JavaDoc) {
279                 JComboBox JavaDoc jcb = (JComboBox JavaDoc) e.getSource();
280                 OperationType ot = (OperationType) jcb.getSelectedItem();
281                 String JavaDoc operationName = selectedOperationConfiguration.getOperationName();
282                 CardLayout JavaDoc operationCardLayout = (CardLayout JavaDoc) 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 JavaDoc PROP_ERROR_MESSAGE = "PROP_ERROR_MESSAGE";
298         
299         public String JavaDoc getOperationName();
300         
301         public void setOperationName(String JavaDoc operationName);
302         
303         public OperationType getOperationType();
304         
305         public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getInputMessageParts();
306         
307         public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getOutputMessageParts();
308         
309         public List JavaDoc<PartAndElementOrTypeTableModel.PartAndElementOrType> getFaultMessageParts();
310         
311         public JTextField JavaDoc getOperationNameTextField();
312         
313         public JComboBox JavaDoc getOperationTypeComboBox();
314         
315         public boolean isNewOutputMessage();
316         
317         
318         public boolean isNewInputMessage();
319         
320         
321         public boolean isNewFaultMessage();
322         
323         public String JavaDoc getOutputMessageName();
324         
325         
326         public String JavaDoc getInputMessageName();
327         
328         
329         public String JavaDoc getFaultMessageName();
330         
331     }
332     
333     public static void main(String JavaDoc[] args) {
334         
335 // JFrame frame = new JFrame();
336
// frame.getContentPane().setLayout(new BorderLayout());
337
// OperationConfigurationPanel p = new OperationConfigurationPanel();
338
// frame.getContentPane().add(p, BorderLayout.CENTER);
339
// frame.setSize(200, 200);
340
// frame.setVisible(true);
341

342         
343     }
344     
345     private OperationConfiguration selectedOperationConfiguration;
346     
347     private OperationType selectedOperationType;
348     private JPanel JavaDoc operationCardPanel;
349     
350     // Variables declaration - do not modify//GEN-BEGIN:variables
351
private javax.swing.JPanel JavaDoc 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     // End of variables declaration//GEN-END:variables
357

358 }
359
Popular Tags