KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PortTypePanel.java
22  *
23  * Created on September 7, 2006, 4:28 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.List JavaDoc;
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33 import javax.swing.event.ListDataEvent JavaDoc;
34 import javax.swing.event.ListDataListener JavaDoc;
35 import javax.swing.text.Document JavaDoc;
36 import org.netbeans.api.project.Project;
37 import org.netbeans.modules.xml.wsdl.model.PortType;
38 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
39 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
40 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyUtil;
41 import org.netbeans.modules.xml.wsdl.ui.view.PortTypeConfigurationPanel;
42 import org.netbeans.modules.xml.xam.ModelSource;
43 import org.openide.DialogDescriptor;
44 import org.openide.ErrorManager;
45 import org.openide.filesystems.FileObject;
46 import org.openide.util.NbBundle;
47
48 /**
49  *
50  * @author radval
51  */

52 public class PortTypePanel extends javax.swing.JPanel JavaDoc {
53     
54     private Project mProject;
55     
56     private WSDLModel mModel;
57     
58     private DialogDescriptor mDD;
59     
60     String JavaDoc mErrorMessage = null;
61     
62     private List JavaDoc existingMeessages = new ArrayList JavaDoc();
63             
64     /** Creates new form PortTypePanel */
65     public PortTypePanel() {
66         initComponents();
67         initGUI();
68     }
69     
70     public PortTypePanel(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         portTypeConfigurationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.PortTypeConfigurationPanel(this.mProject, true, mModel);
89         commonMessagePanel1 = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel();
90
91         portTypeConfigurationPanel1.setFocusCycleRoot(false);
92
93         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
94         this.setLayout(layout);
95         layout.setHorizontalGroup(
96             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
97             .add(layout.createSequentialGroup()
98                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
99                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
100                         .addContainerGap()
101                         .add(portTypeConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 594, Short.MAX_VALUE))
102                     .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
103                         .add(107, 107, 107)
104                         .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 497, Short.MAX_VALUE)))
105                 .addContainerGap())
106         );
107         layout.setVerticalGroup(
108             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
109             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
110                 .addContainerGap()
111                 .add(portTypeConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 596, Short.MAX_VALUE)
112                 .add(36, 36, 36)
113                 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
114                 .addContainerGap())
115         );
116     }// </editor-fold>//GEN-END:initComponents
117

118     public PortTypeConfigurationPanel getPortTypeConfiguration() {
119         return this.portTypeConfigurationPanel1;
120     }
121     
122     private void initGUI() {
123         
124         ModelSource modelSource = this.mModel.getModelSource();
125         FileObject wsdlFile = (FileObject) modelSource.getLookup().lookup(FileObject.class);
126         if(wsdlFile != null) {
127             String JavaDoc fileName = wsdlFile.getName();
128             String JavaDoc portTypePrefix = fileName + NbBundle.getMessage(PortTypePanel.class, "LBL_PortType_suffix");
129             String JavaDoc portTypeName = NameGenerator.getInstance().generateUniquePortTypeName(this.mModel, portTypePrefix);
130             this.portTypeConfigurationPanel1.setPortTypeName(portTypeName);
131
132             String JavaDoc operationName = fileName + NbBundle.getMessage(PortTypePanel.class, "LBL_Operation_suffix");
133             this.portTypeConfigurationPanel1.setOperationName(operationName);
134             
135             String JavaDoc[] messages = PropertyUtil.getAllMessages(this.mModel);
136             if(messages != null) {
137                 for(int i = 0; i < messages.length; i++) {
138                  existingMeessages.add(messages[i]);
139                 }
140             }
141             
142             String JavaDoc inputMessageName = NameGenerator.getInstance().generateUniqueInputMessageName(operationName, mModel);
143             String JavaDoc outputMessageName = NameGenerator.getInstance().generateUniqueOutputMessageName(operationName, mModel);
144             String JavaDoc faultMessageName = NameGenerator.getInstance().generateUniqueFaultMessageName(operationName, mModel);
145
146             MessageNameTextChangeListener messageListener = new MessageNameTextChangeListener();
147                     
148             this.portTypeConfigurationPanel1.setInputMessages(messages, inputMessageName, messageListener);
149             this.portTypeConfigurationPanel1.setOutputMessages(messages, outputMessageName, messageListener);
150             this.portTypeConfigurationPanel1.setFaultMessages(messages, faultMessageName, messageListener);
151             
152             
153         }
154         
155                 
156         PortTypeNameTextChangeListener portTypeListner = new PortTypeNameTextChangeListener();
157         OperationNameTextChangeListener operationListener = new OperationNameTextChangeListener();
158         
159         this.portTypeConfigurationPanel1.getPortTypeNameTextField().getDocument().addDocumentListener(portTypeListner);
160         this.portTypeConfigurationPanel1.getOperationNameTextField().getDocument().addDocumentListener(operationListener);
161     }
162     
163     private boolean isValidName(String JavaDoc text) {
164         try {
165             boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text);
166             if(!isValid) {
167                 mErrorMessage = "Name \"" + text + "\" is not a valid NCName";
168             } else {
169                 mErrorMessage = null;
170             }
171             
172         } catch(Exception JavaDoc ex) {
173             ex.printStackTrace();
174         }
175         
176         return mErrorMessage == null;
177     }
178     
179     private void validateAll() {
180         boolean validPortType = isValidName(this.portTypeConfigurationPanel1.getPortTypeNameTextField().getText());
181         if(!validPortType) {
182             updateMessagePanel();
183             return;
184         }
185         
186         
187         boolean isPortTypeExist = isPortTypeExists();
188         if(isPortTypeExist) {
189             updateMessagePanel();
190             return;
191         }
192         
193         
194         boolean validOperation = isValidName(this.portTypeConfigurationPanel1.getOperationNameTextField().getText());
195         if(!validOperation) {
196             updateMessagePanel();
197             return;
198         }
199         
200                 
201         boolean isValidInputMessage = isValidInputMessage();
202         if(!isValidInputMessage) {
203             updateMessagePanel();
204             return;
205         }
206         
207         boolean isValidOutputMessage = isValidOutputMessage();
208         if(!isValidOutputMessage) {
209             updateMessagePanel();
210             return;
211         }
212         
213         boolean isValidFaultMessage = isValidFaultMessage();
214         if(!isValidFaultMessage) {
215             updateMessagePanel();
216             return;
217         }
218         
219         this.mErrorMessage = null;
220         updateMessagePanel();
221         
222     }
223     
224     private boolean isPortTypeExists() {
225         boolean exist = false;
226         
227         String JavaDoc text = this.portTypeConfigurationPanel1.getPortTypeNameTextField().getText();
228         PortType pt = mModel.findComponentByName(text, PortType.class);
229             
230         if(pt != null) {
231             this.mErrorMessage = "PortType \"" + text + "\" already exists.";
232             exist = true;
233         }
234                 
235         return exist;
236     }
237
238     private boolean isValidInputMessage() {
239         boolean valid = true;
240         
241         String JavaDoc messageName = this.portTypeConfigurationPanel1.getNewInputMessageName();
242         if(messageName != null) {
243             //if message is not existing message
244
if(!isExistingMessage(messageName)) {
245                 valid = isValidName(messageName);
246             }
247         }
248         return valid;
249     }
250     
251     private boolean isValidOutputMessage() {
252         boolean valid = true;
253         
254         String JavaDoc messageName = this.portTypeConfigurationPanel1.getNewOutputMessageName();
255         if(messageName != null) {
256             //if message is not existing message
257
if(!isExistingMessage(messageName)) {
258                 valid = isValidName(messageName);
259             }
260         }
261         return valid;
262     }
263
264         
265     private boolean isValidFaultMessage() {
266         boolean valid = true;
267         
268         String JavaDoc messageName = this.portTypeConfigurationPanel1.getNewFaultMessageName();
269         if(messageName != null) {
270             //if message is not existing message
271
if(!isExistingMessage(messageName)) {
272                 valid = isValidName(messageName);
273             }
274         }
275         return valid;
276     }
277     
278     
279     private boolean isExistingMessage(String JavaDoc messageName) {
280          return existingMeessages.contains(messageName);
281      }
282     
283     private void updateMessagePanel() {
284         if(this.mErrorMessage != null) {
285             commonMessagePanel1.setErrorMessage(mErrorMessage);
286             if(this.mDD != null) {
287                 this.mDD.setValid(false);
288             }
289         } else {
290             commonMessagePanel1.setMessage("");
291             if(this.mDD != null) {
292                 this.mDD.setValid(true);
293             }
294         }
295     }
296     
297     
298     class PortTypeNameTextChangeListener implements DocumentListener JavaDoc {
299      
300          public void changedUpdate(DocumentEvent JavaDoc e) {
301             validateAll();
302          }
303          
304          public void insertUpdate(DocumentEvent JavaDoc e) {
305              validateAll();
306          }
307
308          public void removeUpdate(DocumentEvent JavaDoc e) {
309              validateAll();
310          }
311  
312     }
313     
314     class OperationNameTextChangeListener implements DocumentListener JavaDoc {
315      
316          public void changedUpdate(DocumentEvent JavaDoc e) {
317             validateAll();
318          }
319          
320          public void insertUpdate(DocumentEvent JavaDoc e) {
321              validateAll();
322          }
323
324          public void removeUpdate(DocumentEvent JavaDoc e) {
325              validateAll();
326          }
327  
328
329         
330     }
331     
332     class MessageNameTextChangeListener implements DocumentListener JavaDoc {
333      
334          public void changedUpdate(DocumentEvent JavaDoc e) {
335              validateAll();
336          }
337          
338          public void insertUpdate(DocumentEvent JavaDoc e) {
339              validateAll();
340          }
341
342          public void removeUpdate(DocumentEvent JavaDoc e) {
343              validateAll();
344          }
345          
346          
347         
348     }
349     
350     
351     // Variables declaration - do not modify//GEN-BEGIN:variables
352
private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel commonMessagePanel1;
353     private org.netbeans.modules.xml.wsdl.ui.view.PortTypeConfigurationPanel portTypeConfigurationPanel1;
354     // End of variables declaration//GEN-END:variables
355

356 }
357
Popular Tags