KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > customization > multiview > PortPanel


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

19
20 /*
21  * PortPanel.java
22  *
23  * Created on February 19, 2006, 8:58 AM
24  */

25
26 package org.netbeans.modules.websvc.customization.multiview;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.awt.event.ItemEvent JavaDoc;
32 import java.awt.event.ItemListener JavaDoc;
33 import java.util.List JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import javax.swing.text.JTextComponent JavaDoc;
36 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
37 import org.netbeans.modules.websvc.core.JaxWsUtils;
38 import org.netbeans.modules.websvc.customization.model.JavaMethod;
39 import org.netbeans.modules.websvc.customization.model.PortCustomization;
40 import org.netbeans.modules.websvc.customization.model.Provider;
41 import org.netbeans.modules.websvc.customization.model.impl.JAXWSQName;
42 import org.netbeans.modules.xml.multiview.ui.SectionView;
43 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
44 import org.netbeans.modules.xml.wsdl.model.Port;
45 import org.netbeans.modules.xml.wsdl.model.Service;
46 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory;
47 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
48 import org.openide.DialogDisplayer;
49 import org.openide.NotifyDescriptor;
50 import org.openide.nodes.Node;
51 import org.openide.util.NbBundle;
52 import org.openide.util.WeakListeners;
53 import org.netbeans.modules.xml.multiview.Error;
54
55 /**
56  *
57  * @author Roderico Cruz
58  */

59 public class PortPanel extends SaveableSectionInnerPanel {
60     private Port port;
61     private WSDLModel model;
62     private boolean wsdlDirty;
63     private DefaultItemListener defaultListener;
64     private ProviderActionListener providerActionListener;
65     private Node node;
66     
67     /** Creates new form PortPanel */
68     public PortPanel(SectionView view, Port port,
69             Node node) {
70         super(view);
71         this.port = port;
72         this.model = this.port.getModel();
73         this.node = node;
74         initComponents();
75         serviceLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
76         serviceName.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
77         serviceName.setText(getParentOfPort(port));
78         defaultMethodCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
79         portAccessMethodText.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
80         portAccessLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
81         
82         sync();
83         
84         defaultListener = new DefaultItemListener();
85         ItemListener JavaDoc itemListener = (ItemListener JavaDoc)WeakListeners.create(ItemListener JavaDoc.class, defaultListener,
86                 defaultMethodCB);
87         defaultMethodCB.addItemListener(itemListener);
88         
89         if(!isClient()){
90             providerCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
91             providerActionListener = new ProviderActionListener();
92             ActionListener JavaDoc providerListener = (ActionListener JavaDoc)WeakListeners.create(ActionListener JavaDoc.class,
93                     providerActionListener, providerCB);
94             providerCB.addActionListener(providerListener);
95         } else{
96             providerCB.setVisible(false);
97         }
98         
99         addModifier(portAccessMethodText);
100         addModifier(defaultMethodCB);
101         addValidatee(portAccessMethodText);
102     }
103     
104     class DefaultItemListener implements ItemListener JavaDoc{
105         public void itemStateChanged(ItemEvent JavaDoc e) {
106             if(defaultMethodCB.isSelected()){
107                 portAccessMethodText.setEnabled(false);
108                 portAccessMethodText.setBackground(Color.LIGHT_GRAY);
109             } else{
110                 portAccessMethodText.setEnabled(true);
111                 portAccessMethodText.setBackground(Color.WHITE);
112                 portAccessMethodText.requestFocus();
113             }
114         }
115     }
116     
117     class ProviderActionListener implements ActionListener JavaDoc{
118         public void actionPerformed(ActionEvent JavaDoc e) {
119             if(e.getSource() == providerCB){
120                 if(providerCB.isSelected()){
121                     NotifyDescriptor.Confirmation notifyDesc =
122                             new NotifyDescriptor.Confirmation(NbBundle.getMessage
123                             (ExternalBindingTablePanel.class, "WARN_PROVIDER_INTERFACE"),
124                             NotifyDescriptor.YES_NO_OPTION);
125                     DialogDisplayer.getDefault().notify(notifyDesc);
126                     if((notifyDesc.getValue() == NotifyDescriptor.NO_OPTION)){
127                         providerCB.setSelected(false);
128                         return;
129                     }
130                 }
131                 setValue(providerCB, null);
132             }
133         }
134     }
135     
136     private boolean isClient(){
137         Client client = (Client)node.getLookup().lookup(Client.class);
138         return client != null;
139     }
140     
141     private String JavaDoc getParentOfPort(Port port){
142         Service service = (Service)port.getParent();
143         return service.getName();
144     }
145     private void sync(){
146         List JavaDoc<PortCustomization> ee = port.getExtensibilityElements(PortCustomization.class);
147         if(ee.size() == 1){
148             PortCustomization pc = ee.get(0);
149             JavaMethod jm = pc.getJavaMethod();
150             if(jm != null){
151                 setPortAccessMethod(jm.getName());
152             } else{
153                 defaultMethodCB.setSelected(true);
154                 portAccessMethodText.setEnabled(false);
155                 portAccessMethodText.setBackground(Color.LIGHT_GRAY);
156             }
157             Provider provider = pc.getProvider();
158             if(provider != null){
159                 if(provider.isEnabled()){
160                     providerCB.setSelected(true);
161                 }else{
162                     providerCB.setSelected(false);
163                 }
164             } else{
165                 providerCB.setSelected(false);
166             }
167         } else{
168             providerCB.setSelected(false);
169             defaultMethodCB.setSelected(true);
170             portAccessMethodText.setEnabled(false);
171             portAccessMethodText.setBackground(Color.LIGHT_GRAY);
172         }
173     }
174     
175     public void setPortAccessMethod(String JavaDoc name){
176         portAccessMethodText.setText(name);
177     }
178     
179     public String JavaDoc getPortAccessMethod(){
180         return portAccessMethodText.getText();
181     }
182     
183     public void setProvider(boolean enable){
184         providerCB.setSelected(enable);
185     }
186     
187     public boolean isProvider(){
188         return providerCB.isSelected();
189     }
190     
191     public JComponent JavaDoc getErrorComponent(String JavaDoc string) {
192         return new javax.swing.JButton JavaDoc("error");
193     }
194     
195     public void linkButtonPressed(Object JavaDoc object, String JavaDoc string) {
196     }
197     
198     public void setValue(JComponent JavaDoc jComponent, Object JavaDoc object) {
199         List JavaDoc <PortCustomization> ee =
200                 port.getExtensibilityElements(PortCustomization.class);
201         if(jComponent == providerCB){
202             if(ee.size() == 1){ //there is a PortCustomization element
203
PortCustomization pc = ee.get(0);
204                 Provider provider = pc.getProvider();
205                 if(isProvider()){ //provider is selected
206
if(provider == null){ //there is no provider
207
try{
208                             provider = (Provider) model.getFactory().create(pc, JAXWSQName.PROVIDER.getQName());
209                             model.startTransaction();
210                             provider.setEnabled(true);
211                             pc.setProvider(provider);
212                             wsdlDirty = true;
213                         } finally{
214                             model.endTransaction();
215                         }
216                     }
217                 } else{ //provider is not selected, remove the Provider element
218
if(provider != null){
219                         try{
220                             model.startTransaction();
221                             pc.removeProvider(provider);
222                             //if there are no more children, remove PortCustomization
223
if(pc.getChildren().size() == 0){
224                                 port.removeExtensibilityElement(pc);
225                             }
226                             wsdlDirty = true;
227                         } finally{
228                             model.endTransaction();
229                         }
230                     }
231                 }
232             } else{ //no port customization
233
//if provider is set, create extensibility element and add Provider
234
if(isProvider()){
235                     WSDLComponentFactory factory = model.getFactory();
236                     PortCustomization pc = (PortCustomization) factory.create(port,
237                             JAXWSQName.BINDINGS.getQName());
238                     Provider provider = (Provider) factory.create(pc, JAXWSQName.PROVIDER.getQName());
239                     try{
240                         model.startTransaction();
241                         provider.setEnabled(true);
242                         pc.setProvider(provider);
243                         port.addExtensibilityElement(pc);
244                         wsdlDirty = true;
245                     } finally{
246                         model.endTransaction();
247                     }
248                 }
249             }
250         } else if(jComponent == portAccessMethodText
251                 || jComponent == defaultMethodCB ){
252             String JavaDoc text = portAccessMethodText.getText();
253             if(text != null && !text.trim().equals("")
254             && !defaultMethodCB.isSelected()){ //Java method was specified
255
if(!JaxWsUtils.isJavaIdentifier(text)){
256                     return;
257                 }
258                 if(ee.size() == 1){ //there is existing extensibility element
259
PortCustomization pc = ee.get(0);
260                     JavaMethod jm = pc.getJavaMethod();
261                     if(jm == null){ //no JavaMethod
262
try{
263                             jm = (JavaMethod) model.getFactory().create(pc, JAXWSQName.METHOD.getQName());
264                             model.startTransaction();
265                             jm.setName(text); //TODO Need to validate this before setting it
266
pc.setJavaMethod(jm);
267                             wsdlDirty = true;
268                         } finally{
269                             model.endTransaction();
270                         }
271                     } else{ //javamethod already exists
272
//reset the JavaMethod
273
try{
274                             model.startTransaction();
275                             jm.setName(text);
276                             wsdlDirty = true;
277                         }finally{
278                             model.endTransaction();
279                         }
280                     }
281                 }else{ //there is no ExtensibilityElement
282
//create extensibility element and add JavaMethod
283
WSDLComponentFactory factory = model.getFactory();
284                     PortCustomization pc = (PortCustomization) factory.create(port,
285                             JAXWSQName.BINDINGS.getQName());
286                     JavaMethod jm = (JavaMethod) factory.create(pc, JAXWSQName.METHOD.getQName());
287                     try{
288                         model.startTransaction();
289                         jm.setName(text);
290                         pc.setJavaMethod(jm);
291                         port.addExtensibilityElement(pc);
292                         
293                         wsdlDirty = true;
294                     }finally{
295                         model.endTransaction();
296                     }
297                 }
298             } else{ //text is empty, use default
299
if(ee.size() == 1){
300                     PortCustomization pc = ee.get(0);
301                     JavaMethod jm = pc.getJavaMethod();
302                     if(jm != null){
303                         try{
304                             model.startTransaction();
305                             pc.removeJavaMethod(jm);
306                             //if there are no more children, remove PortCustomization
307
if(pc.getChildren().size() == 0){
308                                 port.removeExtensibilityElement(pc);
309                             }
310                             wsdlDirty = true;
311                         }finally{
312                             model.endTransaction();
313                         }
314                     }
315                 }
316             }
317         }
318     }
319     
320     public void documentChanged(JTextComponent JavaDoc comp, String JavaDoc val) {
321         if(comp == portAccessMethodText){
322             if(!JaxWsUtils.isJavaIdentifier(val)){
323                 getSectionView().getErrorPanel().
324                         setError(new Error JavaDoc(Error.TYPE_FATAL,
325                         Error.ERROR_MESSAGE, val, comp));
326                 return;
327             }
328         }
329         getSectionView().getErrorPanel().clearError();
330     }
331     
332     public void rollbackValue(JTextComponent JavaDoc source) {
333         if(source == portAccessMethodText){
334             String JavaDoc methodName = "";
335             List JavaDoc <PortCustomization> ee =
336                     port.getExtensibilityElements(PortCustomization.class);
337             if(ee.size() == 1){
338                 PortCustomization pc = ee.get(0);
339                 JavaMethod jm = pc.getJavaMethod();
340                 if(jm != null){
341                     methodName = jm.getName();
342                 }
343             }
344             portAccessMethodText.setText(methodName);
345         }
346     }
347     
348     public boolean wsdlIsDirty() {
349         return wsdlDirty;
350     }
351     
352     public void save() {
353         if(wsdlDirty){
354             this.setModelDirty(model);
355         }
356     }
357     
358     /** This method is called from within the constructor to
359      * initialize the form.
360      * WARNING: Do NOT modify this code. The content of this method is
361      * always regenerated by the Form Editor.
362      */

363     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
364
private void initComponents() {
365         portAccessLabel = new javax.swing.JLabel JavaDoc();
366         portAccessMethodText = new javax.swing.JTextField JavaDoc();
367         providerCB = new javax.swing.JCheckBox JavaDoc();
368         defaultMethodCB = new javax.swing.JCheckBox JavaDoc();
369         serviceLabel = new javax.swing.JLabel JavaDoc();
370         serviceName = new javax.swing.JLabel JavaDoc();
371
372         portAccessLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD"));
373         portAccessLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD"));
374
375         portAccessMethodText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_GET_PORT"));
376         portAccessMethodText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD"));
377         portAccessMethodText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD"));
378
379         providerCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_PROVIDER").charAt(0));
380         providerCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER"));
381         providerCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
382         providerCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
383         providerCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER"));
384         providerCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER"));
385
386         defaultMethodCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0));
387         defaultMethodCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
388         defaultMethodCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
389         defaultMethodCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
390         defaultMethodCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
391         defaultMethodCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
392
393         serviceLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_SERVICE"));
394         serviceLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_SERVICE"));
395
396         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
397         this.setLayout(layout);
398         layout.setHorizontalGroup(
399             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
400             .add(layout.createSequentialGroup()
401                 .addContainerGap()
402                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
403                     .add(layout.createSequentialGroup()
404                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
405                             .add(serviceLabel)
406                             .add(portAccessLabel))
407                         .add(14, 14, 14)
408                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
409                             .add(layout.createSequentialGroup()
410                                 .add(portAccessMethodText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
411                                 .add(20, 20, 20)
412                                 .add(defaultMethodCB))
413                             .add(serviceName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 182, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
414                     .add(providerCB))
415                 .addContainerGap(77, Short.MAX_VALUE))
416         );
417         layout.setVerticalGroup(
418             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
419             .add(layout.createSequentialGroup()
420                 .addContainerGap()
421                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
422                     .add(serviceLabel)
423                     .add(serviceName))
424                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
425                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
426                     .add(portAccessLabel)
427                     .add(portAccessMethodText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
428                     .add(defaultMethodCB))
429                 .add(21, 21, 21)
430                 .add(providerCB)
431                 .add(19, 19, 19))
432         );
433     }// </editor-fold>//GEN-END:initComponents
434

435     
436     // Variables declaration - do not modify//GEN-BEGIN:variables
437
private javax.swing.JCheckBox JavaDoc defaultMethodCB;
438     private javax.swing.JLabel JavaDoc portAccessLabel;
439     private javax.swing.JTextField JavaDoc portAccessMethodText;
440     private javax.swing.JCheckBox JavaDoc providerCB;
441     private javax.swing.JLabel JavaDoc serviceLabel;
442     private javax.swing.JLabel JavaDoc serviceName;
443     // End of variables declaration//GEN-END:variables
444

445 }
446
Popular Tags