KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > newtype > OperationPanel


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  * OperationPanel.java
22  *
23  * Created on September 8, 2006, 5:21 PM
24  */

25
26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
32 import javax.swing.event.DocumentEvent JavaDoc;
33 import javax.swing.event.DocumentListener JavaDoc;
34 import javax.swing.text.Document JavaDoc;
35 import org.netbeans.api.project.Project;
36 import org.netbeans.modules.xml.wsdl.model.Port;
37 import org.netbeans.modules.xml.wsdl.model.PortType;
38 import org.netbeans.modules.xml.wsdl.model.Service;
39 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
40 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
41 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyUtil;
42 import org.netbeans.modules.xml.wsdl.ui.view.OperationConfigurationPanel;
43 import org.netbeans.modules.xml.xam.ModelSource;
44 import org.openide.DialogDescriptor;
45 import org.openide.ErrorManager;
46 import org.openide.filesystems.FileObject;
47 import org.openide.util.NbBundle;
48
49 /**
50  *
51  * @author radval
52  */

53 public class OperationPanel extends javax.swing.JPanel JavaDoc {
54     
55     private Project mProject;
56     
57     private WSDLModel mModel;
58     
59     private DialogDescriptor mDD;
60     
61     private List JavaDoc existingMeessages = new ArrayList JavaDoc();
62     
63     String JavaDoc mErrorMessage = null;
64     
65     /** Creates new form OperationPanel */
66     public OperationPanel() {
67         initComponents();
68     }
69     
70     public OperationPanel(Project project, WSDLModel model) {
71         this.mProject = project;
72         this.mModel = model;
73         initComponents();
74         initGUI();
75     }
76     
77     public void setDialogDescriptor(DialogDescriptor dd) {
78         this.mDD = dd;
79     }
80     
81     /** This method is called from within the constructor to
82      * initialize the form.
83      * WARNING: Do NOT modify this code. The content of this method is
84      * always regenerated by the Form Editor.
85      */

86     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
87
private void initComponents() {
88         operationConfigurationPanel1 = new OperationConfigurationPanel(this.mProject, true, mModel);
89         commonMessagePanel1 = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel();
90
91         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
92         this.setLayout(layout);
93         layout.setHorizontalGroup(
94             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
95             .add(layout.createSequentialGroup()
96                 .addContainerGap()
97                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
98                     .add(org.jdesktop.layout.GroupLayout.TRAILING, operationConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
99                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
100                         .add(96, 96, 96)
101                         .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)))
102                 .addContainerGap())
103         );
104         layout.setVerticalGroup(
105             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
106             .add(layout.createSequentialGroup()
107                 .addContainerGap()
108                 .add(operationConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
109                 .add(17, 17, 17)
110                 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
111                 .add(60, 60, 60))
112         );
113     }// </editor-fold>//GEN-END:initComponents
114

115     public OperationConfigurationPanel getOperationConfigurationPanel() {
116         return this.operationConfigurationPanel1;
117     }
118     
119     private void initGUI() {
120         
121         ModelSource modelSource = this.mModel.getModelSource();
122         FileObject wsdlFile = (FileObject) modelSource.getLookup().lookup(FileObject.class);
123         if(wsdlFile != null) {
124             String JavaDoc fileName = wsdlFile.getName();
125             
126             String JavaDoc operationName = fileName + NbBundle.getMessage(OperationPanel.class, "LBL_Operation_suffix");
127             this.operationConfigurationPanel1.setOperationName(operationName);
128             
129             String JavaDoc[] messages = PropertyUtil.getAllMessages(this.mModel);
130             if(messages != null) {
131                 for(int i = 0; i < messages.length; i++) {
132                  existingMeessages.add(messages[i]);
133                 }
134             }
135             
136             String JavaDoc inputMessageName = NameGenerator.getInstance().generateUniqueInputMessageName(operationName, mModel);
137             String JavaDoc outputMessageName = NameGenerator.getInstance().generateUniqueOutputMessageName(operationName, mModel);
138             String JavaDoc faultMessageName = NameGenerator.getInstance().generateUniqueFaultMessageName(operationName, mModel);
139                     
140             MessageNameTextChangeListener messageListener = new MessageNameTextChangeListener();
141             
142             this.operationConfigurationPanel1.setInputMessages(messages, inputMessageName, messageListener);
143             this.operationConfigurationPanel1.setOutputMessages(messages, outputMessageName, messageListener);
144             this.operationConfigurationPanel1.setFaultMessages(messages, faultMessageName, messageListener);
145             
146             
147         }
148         
149                 
150         OperationNameTextChangeListener operationListener = new OperationNameTextChangeListener();
151         this.operationConfigurationPanel1.getOperationNameTextField().getDocument().addDocumentListener(operationListener);
152     }
153     
154     
155     private boolean isValidName(String JavaDoc text) {
156         try {
157             boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text);
158             if(!isValid) {
159                 mErrorMessage = "Name \"" + text + "\" is not a valid NCName";
160             } else {
161                 mErrorMessage = null;
162             }
163             
164         } catch(Exception JavaDoc ex) {
165             ex.printStackTrace();
166         }
167         
168         return mErrorMessage == null;
169     }
170     
171     private void validateAll() {
172         
173         boolean validOperation = isValidName(this.operationConfigurationPanel1.getOperationNameTextField().getText());
174         if(!validOperation) {
175             updateMessagePanel();
176             return;
177         }
178         
179                 
180         boolean isValidInputMessage = isValidInputMessage();
181         if(!isValidInputMessage) {
182             updateMessagePanel();
183             return;
184         }
185         
186         boolean isValidOutputMessage = isValidOutputMessage();
187         if(!isValidOutputMessage) {
188             updateMessagePanel();
189             return;
190         }
191         
192         boolean isValidFaultMessage = isValidFaultMessage();
193         if(!isValidFaultMessage) {
194             updateMessagePanel();
195             return;
196         }
197         
198         this.mErrorMessage = null;
199         updateMessagePanel();
200         
201     }
202     
203
204     private boolean isValidInputMessage() {
205         boolean valid = true;
206         
207         String JavaDoc messageName = this.operationConfigurationPanel1.getInputMessageName();
208         if(messageName != null) {
209             //if message is not existing message
210
if(!isExistingMessage(messageName)) {
211                 valid = isValidName(messageName);
212             }
213         }
214         return valid;
215     }
216     
217     private boolean isValidOutputMessage() {
218         boolean valid = true;
219         
220         String JavaDoc messageName = this.operationConfigurationPanel1.getOutputMessageName();
221         if(messageName != null) {
222             //if message is not existing message
223
if(!isExistingMessage(messageName)) {
224                 valid = isValidName(messageName);
225             }
226         }
227         return valid;
228     }
229
230         
231     private boolean isValidFaultMessage() {
232         boolean valid = true;
233         
234         String JavaDoc messageName = this.operationConfigurationPanel1.getFaultMessageName();
235         if(messageName != null) {
236             //if message is not existing message
237
if(!isExistingMessage(messageName)) {
238                 valid = isValidName(messageName);
239             }
240         }
241         return valid;
242     }
243     
244     
245     private boolean isExistingMessage(String JavaDoc messageName) {
246          return existingMeessages.contains(messageName);
247      }
248     
249     private void updateMessagePanel() {
250         if(this.mErrorMessage != null) {
251             commonMessagePanel1.setErrorMessage(mErrorMessage);
252             if(this.mDD != null) {
253                 this.mDD.setValid(false);
254             }
255         } else {
256             commonMessagePanel1.setMessage("");
257             if(this.mDD != null) {
258                 this.mDD.setValid(true);
259             }
260         }
261     }
262     
263     
264     class OperationNameTextChangeListener implements DocumentListener JavaDoc {
265      
266          public void changedUpdate(DocumentEvent JavaDoc e) {
267             validateAll();
268          }
269          
270          public void insertUpdate(DocumentEvent JavaDoc e) {
271              validateAll();
272          }
273
274          public void removeUpdate(DocumentEvent JavaDoc e) {
275              validateAll();
276          }
277  
278     }
279     
280     class MessageNameTextChangeListener implements DocumentListener JavaDoc {
281      
282          public void changedUpdate(DocumentEvent JavaDoc e) {
283              validateAll();
284          }
285          
286          public void insertUpdate(DocumentEvent JavaDoc e) {
287              validateAll();
288          }
289
290          public void removeUpdate(DocumentEvent JavaDoc e) {
291              validateAll();
292          }
293          
294         
295     }
296
297     
298     // Variables declaration - do not modify//GEN-BEGIN:variables
299
private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel commonMessagePanel1;
300     private org.netbeans.modules.xml.wsdl.ui.view.OperationConfigurationPanel operationConfigurationPanel1;
301     // End of variables declaration//GEN-END:variables
302

303 }
304
Popular Tags