KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.netbeans.modules.xml.wsdl.ui.view;
27
28 import javax.swing.event.DocumentEvent JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import javax.swing.text.Document JavaDoc;
31 import org.netbeans.modules.xml.wsdl.model.Binding;
32
33 import org.netbeans.modules.xml.wsdl.model.Service;
34 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
35 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator;
36 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate;
37 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplateGroup;
38
39 /**
40  *
41  * @author skini
42  */

43 public class BindingConfigurationDialogPanel extends javax.swing.JPanel JavaDoc {
44     
45     private String JavaDoc mErrorMessage = null;
46     
47     public static final String JavaDoc APPLY_CHANGE = "APPLY_CHANGE";
48     /** Creates new form BindingConfigurationDialogPanel */
49     public BindingConfigurationDialogPanel(WSDLModel model) {
50         mModel = model;
51         initComponents();
52         initGUI();
53     }
54     
55     /** This method is called from within the constructor to
56      * initialize the form.
57      * WARNING: Do NOT modify this code. The content of this method is
58      * always regenerated by the Form Editor.
59      */

60     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
61
private void initComponents() {
62         bindingConfigurationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationPanel();
63         commonMessagePanel1 = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel();
64
65         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
66         this.setLayout(layout);
67         layout.setHorizontalGroup(
68             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
69             .add(bindingConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE)
70             .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
71                 .addContainerGap()
72                 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 301, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
73                 .add(10, 10, 10))
74         );
75         layout.setVerticalGroup(
76             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
77             .add(layout.createSequentialGroup()
78                 .add(bindingConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
79                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
80                 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
81                 .addContainerGap())
82         );
83     }// </editor-fold>//GEN-END:initComponents
84

85     private void initGUI() {
86         DocumentListener JavaDoc bindingNameListener = new BindingNameChangeListener();
87         DocumentListener JavaDoc serviceNameListener = new ServiceNameChangeListener();
88         DocumentListener JavaDoc servicePortNameListener = new ServicePortNameChangeListener();
89         
90         this.bindingConfigurationPanel1.getBindingNameTextField().getDocument().addDocumentListener(bindingNameListener);
91         this.bindingConfigurationPanel1.getServiceNameTextField().getDocument().addDocumentListener(serviceNameListener);
92         this.bindingConfigurationPanel1.getServicePortTextField().getDocument().addDocumentListener(servicePortNameListener);
93     }
94     
95     
96     public String JavaDoc getBindingName() {
97         return bindingConfigurationPanel1.getBindingName();
98     }
99     
100     public void setBindingName(String JavaDoc bindingName) {
101         bindingConfigurationPanel1.setBindingName(bindingName);
102         
103     }
104
105     public void setServiceName(String JavaDoc svcName) {
106         bindingConfigurationPanel1.setServiceName(svcName);
107         
108     }
109
110     public void setServicePortName(String JavaDoc string) {
111         bindingConfigurationPanel1.setServicePortName(string);
112         
113     }
114
115     public LocalizedTemplateGroup getBindingType() {
116         return bindingConfigurationPanel1.getBindingType();
117     }
118
119     public LocalizedTemplate getBindingSubType() {
120         return bindingConfigurationPanel1.getBindingSubType();
121     }
122
123     public String JavaDoc getServiceName() {
124         return bindingConfigurationPanel1.getServiceName();
125     }
126
127     public String JavaDoc getServicePortName() {
128         return bindingConfigurationPanel1.getServicePortName();
129     }
130     
131     
132     private boolean isValidName(String JavaDoc text) {
133         try {
134             boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text);
135             if(!isValid) {
136                 mErrorMessage = "Name \"" + text + "\" is not a valid NCName";
137             } else {
138                 mErrorMessage = null;
139             }
140             
141         } catch(Exception JavaDoc ex) {
142             ex.printStackTrace();
143         }
144         
145         return mErrorMessage == null;
146     }
147     
148     private void validateAll() {
149         boolean validBinding = isValidName(this.bindingConfigurationPanel1.getBindingName());
150         if(!validBinding) {
151             updateMessagePanel();
152             return;
153         }
154         
155         
156         boolean isBindingExist = isBindingExists();
157         if(isBindingExist) {
158             updateMessagePanel();
159             return;
160         }
161         
162         boolean validService = isValidName(this.bindingConfigurationPanel1.getServiceName());
163         if(!validService) {
164             updateMessagePanel();
165             return;
166         }
167         
168         
169         boolean validPort = isValidName(this.bindingConfigurationPanel1.getServicePortName());
170         if(!validPort) {
171             updateMessagePanel();
172             return;
173         }
174         
175         
176         String JavaDoc serviceName = this.bindingConfigurationPanel1.getServiceName();
177         String JavaDoc portName = this.bindingConfigurationPanel1.getServicePortName();
178         
179         boolean isServicePortExist = isServicePortExists(serviceName, portName);
180         if(isServicePortExist) {
181             updateMessagePanel();
182             return;
183         }
184         
185         
186         this.mErrorMessage = null;
187         updateMessagePanel();
188         
189     }
190     
191     private boolean isBindingExists() {
192         boolean exist = false;
193         
194         String JavaDoc text = this.bindingConfigurationPanel1.getBindingName();
195         Binding b = mModel.findComponentByName(text, Binding.class);
196             
197         if(b != null) {
198             this.mErrorMessage = "Binding \"" + text + "\" already exists.";
199             exist = true;
200         }
201                 
202         return exist;
203     }
204  
205     
206     
207     public boolean isServicePortExists(String JavaDoc serviceName, String JavaDoc portName) {
208         boolean exist = false;
209         if(serviceName != null && portName != null) {
210             Service service = mModel.findComponentByName(serviceName, Service.class);
211             if(service != null) {
212                 exist = NameGenerator.getInstance().isServicePortExists(getServicePortName(), service);
213                 if (exist) {
214                     this.mErrorMessage = "Service port" + getServicePortName() + " already exists.";
215                 }
216             }
217         }
218         return exist;
219     }
220     
221     private void updateMessagePanel() {
222         if(this.mErrorMessage != null) {
223             commonMessagePanel1.setErrorMessage(mErrorMessage);
224             firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid());
225         } else {
226             commonMessagePanel1.setMessage("");
227             firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid());
228         }
229     }
230     
231     private void isValidName(DocumentEvent JavaDoc e) {
232         Document JavaDoc doc = e.getDocument();
233         try {
234             String JavaDoc text = doc.getText(0, doc.getLength());
235             boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text);
236             if(!isValid) {
237                 commonMessagePanel1.setErrorMessage("Name \"" + text + "\" is not a valid NCName");
238             } else {
239                 commonMessagePanel1.setMessage("");
240             }
241             firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid());
242         } catch(Exception JavaDoc ex) {
243             ex.printStackTrace();
244         }
245     }
246     
247
248     class BindingNameChangeListener implements DocumentListener JavaDoc {
249         
250         public void changedUpdate(DocumentEvent JavaDoc e) {
251             validateAll();
252         }
253         
254         public void insertUpdate(DocumentEvent JavaDoc e) {
255             validateAll();
256         }
257         
258         public void removeUpdate(DocumentEvent JavaDoc e) {
259             validateAll();
260         }
261     }
262     
263     class ServiceNameChangeListener implements DocumentListener JavaDoc {
264         
265         public void changedUpdate(DocumentEvent JavaDoc e) {
266             validateAll();
267         }
268         
269         public void insertUpdate(DocumentEvent JavaDoc e) {
270             validateAll();
271         }
272         
273         public void removeUpdate(DocumentEvent JavaDoc e) {
274             validateAll();
275         }
276     }
277     class ServicePortNameChangeListener implements DocumentListener JavaDoc {
278         
279         public void changedUpdate(DocumentEvent JavaDoc e) {
280             validateAll();
281         }
282         
283         public void insertUpdate(DocumentEvent JavaDoc e) {
284             validateAll();
285         }
286         
287         public void removeUpdate(DocumentEvent JavaDoc e) {
288             validateAll();
289         }
290     }
291     // Variables declaration - do not modify//GEN-BEGIN:variables
292
private org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationPanel bindingConfigurationPanel1;
293     private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel commonMessagePanel1;
294     // End of variables declaration//GEN-END:variables
295
private WSDLModel mModel;
296     
297 // public void doesBindingExist() {
298
// boolean exists = NameGenerator.getInstance().isBindingExists(getBindingName(), mModel);
299
// if (commonMessagePanel1.isStateValid()) {
300
// if (exists)
301
// commonMessagePanel1.setErrorMessage("Binding Name " + getBindingName() + " already exists.");
302
// }
303
// }
304
//
305
// public boolean doesServiceExists() {
306
// return NameGenerator.getInstance().isServiceExists(getServiceName(), mModel);
307
// }
308
//
309
// public void doesServicePortExists() {
310
// if (doesServiceExists()) {
311
// Service service = mModel.findComponentByName(getServiceName(), Service.class);
312
// boolean exists = NameGenerator.getInstance().isServicePortExists(getServicePortName(), service);
313
// if (commonMessagePanel1.isStateValid()) {
314
// if (exists)
315
// commonMessagePanel1.setErrorMessage("Service port" + getServicePortName() + " already exists.");
316
// }
317
// }
318
// }
319
}
320
Popular Tags