KickJava   Java API By Example, From Geeks To Geeks.

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


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  * PortTypeOperationFaultPanel.java
21  *
22  * Created on February 19, 2006, 8:44 AM
23  */

24
25 package org.netbeans.modules.websvc.customization.multiview;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.event.ItemEvent JavaDoc;
29 import java.awt.event.ItemListener JavaDoc;
30 import java.util.List JavaDoc;
31 import javax.swing.JButton JavaDoc;
32 import javax.swing.JComponent JavaDoc;
33 import javax.swing.text.JTextComponent JavaDoc;
34 import org.netbeans.modules.websvc.core.JaxWsUtils;
35 import org.netbeans.modules.websvc.core.wseditor.spi.SaveSetter;
36 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory;
37 import org.netbeans.modules.websvc.customization.model.JavaClass;
38 import org.netbeans.modules.websvc.customization.model.PortTypeOperationFaultCustomization;
39 import org.netbeans.modules.xml.multiview.ui.SectionView;
40 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
41 import org.netbeans.modules.xml.wsdl.model.Fault;
42 import org.netbeans.modules.xml.wsdl.model.Operation;
43 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
44 import org.openide.util.WeakListeners;
45 import org.netbeans.modules.xml.multiview.Error;
46
47 /**
48  *
49  * @author Roderico Cruz
50  */

51 public class PortTypeOperationFaultPanel extends SaveableSectionInnerPanel {
52     private Fault fault;
53     private SaveSetter setter;
54     private WSDLModel model;
55     private boolean wsdlDirty;
56     private DefaultItemListener defaultListener;
57     /**
58      * Creates new form PortTypeOperationFaultPanel
59      */

60     public PortTypeOperationFaultPanel(SectionView view, Fault fault){
61         super(view);
62         this.fault = fault;
63         this.model = this.fault.getModel();
64         initComponents();
65         operationLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
66         operationName.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
67         operationName.setText(getParentOfFault(fault));
68         javaClassLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
69         javaClassText.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
70         defaultJavaClassCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
71         
72         sync();
73         addModifier(javaClassText);
74         addModifier(defaultJavaClassCB);
75         addValidatee(javaClassText);
76         
77         defaultListener = new DefaultItemListener();
78         ItemListener JavaDoc il = (ItemListener JavaDoc)WeakListeners.create(ItemListener JavaDoc.class, defaultListener,
79                 defaultJavaClassCB);
80         defaultJavaClassCB.addItemListener(il);
81     }
82     
83     class DefaultItemListener implements ItemListener JavaDoc{
84         public void itemStateChanged(ItemEvent JavaDoc e) {
85             if(defaultJavaClassCB.isSelected()){
86                 javaClassText.setEnabled(false);
87                 javaClassText.setBackground(Color.LIGHT_GRAY);
88             } else{
89                 javaClassText.setEnabled(true);
90                 javaClassText.setBackground(Color.WHITE);
91                 javaClassText.requestFocus();
92             }
93         }
94         
95     }
96     
97     private String JavaDoc getParentOfFault(Fault fault){
98         Operation op = (Operation)fault.getParent();
99         return op.getName();
100     }
101     
102     private void sync(){
103         List JavaDoc<PortTypeOperationFaultCustomization> ee =
104                 fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class);
105         if(ee.size() == 1){
106             PortTypeOperationFaultCustomization ptof = ee.get(0);
107             JavaClass jc = ptof.getJavaClass();
108             if(jc != null){
109                 setJavaClass(jc.getName());
110             } else{
111                 defaultJavaClassCB.setSelected(true);
112                 javaClassText.setEnabled(false);
113                 javaClassText.setBackground(Color.LIGHT_GRAY);
114             }
115         } else{
116             defaultJavaClassCB.setSelected(true);
117             javaClassText.setEnabled(false);
118             javaClassText.setBackground(Color.LIGHT_GRAY);
119         }
120     }
121     
122     public void setJavaClass(String JavaDoc name){
123         javaClassText.setText(name);
124     }
125     
126     public String JavaDoc getJavaClass(){
127         return javaClassText.getText();
128     }
129     
130     public JComponent JavaDoc getErrorComponent(String JavaDoc string) {
131         return new JButton JavaDoc("error");
132     }
133     
134     public void linkButtonPressed(Object JavaDoc object, String JavaDoc string) {
135     }
136     
137     public void setValue(JComponent JavaDoc jComponent, Object JavaDoc object) {
138         List JavaDoc <PortTypeOperationFaultCustomization> ee =
139                 fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class);
140         CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault();
141         if(jComponent == javaClassText ||
142                 jComponent == defaultJavaClassCB ){
143             String JavaDoc text = javaClassText.getText();
144             if(text != null && !text.trim().equals("")
145             && !defaultJavaClassCB.isSelected()){
146                 if(!JaxWsUtils.isJavaIdentifier(text)){
147                     return;
148                 }
149                 if(ee.size() == 1){ //there is existing extensibility element
150
PortTypeOperationFaultCustomization ptofc = ee.get(0);
151                     JavaClass jc = ptofc.getJavaClass();
152                     if(jc == null){ //there is no JavaClass, create one
153
try{
154                             jc = factory.createJavaClass(model);
155                             model.startTransaction();
156                             jc.setName(text); //TODO Need to validate this before setting it
157
ptofc.setJavaClass(jc);
158                             wsdlDirty = true;
159                         }finally{
160                                 model.endTransaction();
161                         }
162                     } else{ //javaclass already exists
163
//reset the JavaClass
164
try{
165                             model.startTransaction();
166                             jc.setName(text);
167                             wsdlDirty = true;
168                         } finally{
169                                 model.endTransaction();
170                         }
171                     }
172                 }else{ //there is no ExtensibilityElement
173
//create extensibility element and add JavaClass
174
PortTypeOperationFaultCustomization ptofc =
175                             factory.createPortTypeOperationFaultCustomization(model);
176                     JavaClass jc = factory.createJavaClass(model);
177                     try{
178                         model.startTransaction();
179                         jc.setName(text);
180                         ptofc.setJavaClass(jc);
181                         fault.addExtensibilityElement(ptofc);
182                         wsdlDirty = true;
183                     } finally{
184                             model.endTransaction();
185                     }
186                 }
187             } else{ //no JavaClass is specified, remove from the model if it is there
188
if(ee.size() == 1){
189                     try{
190                         PortTypeOperationFaultCustomization ptofc = ee.get(0);
191                         JavaClass jc = ptofc.getJavaClass();
192                         if(jc != null){
193                             model.startTransaction();
194                             ptofc.removeJavaClass(jc);
195                             //if(ptofc has no more children, remove it as well)
196
if(ptofc.getChildren().size() == 0){
197                                 fault.removeExtensibilityElement(ptofc);
198                             }
199                             
200                             wsdlDirty = true;
201                         }
202                     } finally{
203                             model.endTransaction();
204                     }
205                 }
206             }
207         }
208     }
209     
210     public void documentChanged(JTextComponent JavaDoc comp, String JavaDoc val) {
211         if(comp == javaClassText){
212             if(!JaxWsUtils.isJavaIdentifier(val)){
213                 getSectionView().getErrorPanel().
214                         setError(new Error JavaDoc(Error.TYPE_FATAL,
215                         Error.ERROR_MESSAGE, val, comp));
216                 return;
217             }
218         }
219         getSectionView().getErrorPanel().clearError();
220     }
221     
222     public void rollbackValue(JTextComponent JavaDoc source) {
223         if(source == javaClassText){
224             String JavaDoc className = "";
225             List JavaDoc <PortTypeOperationFaultCustomization> ee =
226                     fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class);
227             if(ee.size() == 1){
228                 PortTypeOperationFaultCustomization ptc = ee.get(0);
229                 JavaClass jc = ptc.getJavaClass();
230                 if(jc != null){
231                     className = jc.getName();
232                 }
233             }
234             javaClassText.setText(className);
235         }
236     }
237     
238     public boolean wsdlIsDirty() {
239         return wsdlDirty;
240     }
241     
242     public void save() {
243         if(wsdlDirty){
244             this.setModelDirty(model);
245         }
246     }
247     
248     /** This method is called from within the constructor to
249      * initialize the form.
250      * WARNING: Do NOT modify this code. The content of this method is
251      * always regenerated by the Form Editor.
252      */

253     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
254
private void initComponents() {
255         javaClassLabel = new javax.swing.JLabel JavaDoc();
256         javaClassText = new javax.swing.JTextField JavaDoc();
257         defaultJavaClassCB = new javax.swing.JCheckBox JavaDoc();
258         operationLabel = new javax.swing.JLabel JavaDoc();
259         operationName = new javax.swing.JLabel JavaDoc();
260
261         javaClassLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
262         javaClassLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
263
264         javaClassText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_PORTTYPE_FAULT_CLASS"));
265         javaClassText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
266         javaClassText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
267
268         defaultJavaClassCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0));
269         defaultJavaClassCB.setText("Use Default");
270         defaultJavaClassCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
271         defaultJavaClassCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
272         defaultJavaClassCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
273         defaultJavaClassCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
274
275         operationLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_OPERATION"));
276         operationLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_OPERATION"));
277
278         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
279         this.setLayout(layout);
280         layout.setHorizontalGroup(
281             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
282             .add(layout.createSequentialGroup()
283                 .addContainerGap()
284                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
285                     .add(layout.createSequentialGroup()
286                         .add(javaClassLabel)
287                         .add(15, 15, 15)
288                         .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 227, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
289                         .add(20, 20, 20)
290                         .add(defaultJavaClassCB))
291                     .add(layout.createSequentialGroup()
292                         .add(operationLabel)
293                         .add(15, 15, 15)
294                         .add(operationName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
295                 .addContainerGap(76, Short.MAX_VALUE))
296         );
297         layout.setVerticalGroup(
298             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
299             .add(layout.createSequentialGroup()
300                 .addContainerGap()
301                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
302                     .add(operationLabel)
303                     .add(operationName))
304                 .add(18, 18, 18)
305                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
306                     .add(javaClassLabel)
307                     .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
308                     .add(defaultJavaClassCB))
309                 .addContainerGap(19, Short.MAX_VALUE))
310         );
311     }// </editor-fold>//GEN-END:initComponents
312

313     
314     // Variables declaration - do not modify//GEN-BEGIN:variables
315
private javax.swing.JCheckBox JavaDoc defaultJavaClassCB;
316     private javax.swing.JLabel JavaDoc javaClassLabel;
317     private javax.swing.JTextField JavaDoc javaClassText;
318     private javax.swing.JLabel JavaDoc operationLabel;
319     private javax.swing.JLabel JavaDoc operationName;
320     // End of variables declaration//GEN-END:variables
321

322 }
323
Popular Tags