KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ServicePanel.java
22  *
23  * Created on February 19, 2006, 8:55 AM
24  */

25
26 package org.netbeans.modules.websvc.customization.multiview;
27
28 import java.awt.Color JavaDoc;
29 import java.awt.event.ItemEvent JavaDoc;
30 import java.awt.event.ItemListener JavaDoc;
31 import java.util.List 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.customization.model.CustomizationComponentFactory;
36 import org.netbeans.modules.websvc.customization.model.JavaClass;
37 import org.netbeans.modules.websvc.customization.model.ServiceCustomization;
38 import org.netbeans.modules.xml.multiview.ui.SectionView;
39 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme;
40 import org.netbeans.modules.xml.wsdl.model.Service;
41 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
42 import org.openide.util.WeakListeners;
43 import org.netbeans.modules.xml.multiview.Error;
44
45 /**
46  *
47  * @author Roderico Cruz
48  */

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

234     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
235
private void initComponents() {
236         javaClassLabel = new javax.swing.JLabel JavaDoc();
237         javaClassText = new javax.swing.JTextField JavaDoc();
238         defaultJavaClassCB = new javax.swing.JCheckBox JavaDoc();
239
240         javaClassLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
241         javaClassLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
242
243         javaClassText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_SERVICE_CLASS"));
244         javaClassText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
245         javaClassText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS"));
246
247         defaultJavaClassCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0));
248         defaultJavaClassCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
249         defaultJavaClassCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
250         defaultJavaClassCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
251         defaultJavaClassCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
252         defaultJavaClassCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT"));
253
254         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
255         this.setLayout(layout);
256         layout.setHorizontalGroup(
257             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
258             .add(layout.createSequentialGroup()
259                 .addContainerGap()
260                 .add(javaClassLabel)
261                 .add(21, 21, 21)
262                 .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 172, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
263                 .add(20, 20, 20)
264                 .add(defaultJavaClassCB)
265                 .addContainerGap(70, Short.MAX_VALUE))
266         );
267         layout.setVerticalGroup(
268             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
269             .add(layout.createSequentialGroup()
270                 .add(31, 31, 31)
271                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
272                     .add(javaClassLabel)
273                     .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
274                     .add(defaultJavaClassCB))
275                 .addContainerGap(29, Short.MAX_VALUE))
276         );
277     }// </editor-fold>//GEN-END:initComponents
278

279     
280     // Variables declaration - do not modify//GEN-BEGIN:variables
281
private javax.swing.JCheckBox JavaDoc defaultJavaClassCB;
282     private javax.swing.JLabel JavaDoc javaClassLabel;
283     private javax.swing.JTextField JavaDoc javaClassText;
284     // End of variables declaration//GEN-END:variables
285

286 }
287
Popular Tags