KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.netbeans.modules.websvc.customization.multiview;
27
28 import java.beans.PropertyChangeEvent JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.io.IOException JavaDoc;
31 import java.util.List JavaDoc;
32 import javax.swing.JComponent JavaDoc;
33 import org.netbeans.modules.websvc.customization.model.BindingCustomization;
34 import org.netbeans.modules.websvc.customization.model.BindingOperationCustomization;
35 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory;
36 import org.netbeans.modules.websvc.customization.model.DefinitionsCustomization;
37 import org.netbeans.modules.websvc.customization.model.EnableMIMEContent;
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.Binding;
41 import org.netbeans.modules.xml.wsdl.model.BindingOperation;
42 import org.netbeans.modules.xml.wsdl.model.Definitions;
43 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
44 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
45 import org.openide.ErrorManager;
46 import org.openide.util.NbBundle;
47 import org.openide.util.WeakListeners;
48
49 /**
50  *
51  * @author Roderico Cruz
52  */

53 public class BindingOperationPanel extends SaveableSectionInnerPanel {
54     private BindingOperation bindingOperation;
55     private WSDLModel model;
56     private boolean wsdlDirty;
57     private ModelChangeListener modelListener;
58     private ModelChangeListener primaryModelListener;
59     private Definitions primaryDefinitions;
60     private WSDLModel primaryModel;
61     
62     /** Creates new form BindingOperationPanel */
63     public BindingOperationPanel(SectionView view,
64             BindingOperation bindingOperation, Definitions primaryDefinitions){
65         super(view);
66         this.bindingOperation = bindingOperation;
67         this.primaryDefinitions = primaryDefinitions;
68         this.model = this.bindingOperation.getModel();
69         this.primaryModel = this.primaryDefinitions.getModel();
70         initComponents();
71         enableMIMEContentCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
72         bindingLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
73         bindingName.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
74         bindingName.setText(getParentOfBindingOperation(bindingOperation));
75         
76         sync();
77         
78         addModifier(enableMIMEContentCB);
79         
80         modelListener = new ModelChangeListener();
81         PropertyChangeListener JavaDoc pcl = WeakListeners.propertyChange(modelListener, model);
82         model.addPropertyChangeListener(pcl);
83         
84         if(primaryModel != model){
85             primaryModelListener = new ModelChangeListener();
86             PropertyChangeListener JavaDoc l = WeakListeners.propertyChange(primaryModelListener, primaryModel);
87             primaryModel.addPropertyChangeListener(l);
88         }
89     }
90     
91     private String JavaDoc getParentOfBindingOperation(BindingOperation op){
92         Binding binding = (Binding)op.getParent();
93         return binding.getName();
94     }
95     
96     class ModelChangeListener implements PropertyChangeListener JavaDoc{
97         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
98             Object JavaDoc source = evt.getSource();
99             if (source instanceof EnableMIMEContent){
100                 EnableMIMEContent emc = (EnableMIMEContent)source;
101                 WSDLComponent parent = emc.getParent();
102                 if(parent instanceof DefinitionsCustomization ||
103                         parent instanceof BindingCustomization){
104                     sync();
105                 }
106             }
107         }
108     }
109     
110     private void sync(){
111         List JavaDoc<BindingOperationCustomization> ee =
112                 bindingOperation.getExtensibilityElements(BindingOperationCustomization.class);
113         if(ee.size() == 1){
114             BindingOperationCustomization boc = ee.get(0);
115             EnableMIMEContent emc = boc.getEnableMIMEContent();
116             if(emc != null){
117                 setEnableMIMEContent(emc.isEnabled());
118             } else{
119                 setEnableMIMEContent(getMIMEContentOfParent());
120             }
121         } else{
122             setEnableMIMEContent(getMIMEContentOfParent());
123         }
124     }
125     
126     private boolean getMIMEContentOfParent(){
127         boolean isMIMEContent = false;
128         Binding binding = (Binding)bindingOperation.getParent();
129         List JavaDoc<BindingCustomization> bcs = binding.getExtensibilityElements(BindingCustomization.class);
130         if(bcs.size() > 0) { //there is a BindingCustomization
131
BindingCustomization bc = bcs.get(0);
132             EnableMIMEContent mimeContent = bc.getEnableMIMEContent();
133             if(mimeContent != null){ //there is a mime content
134
isMIMEContent = mimeContent.isEnabled();
135             }else{
136                 isMIMEContent = getMIMEContentFromDefinitions(primaryDefinitions);
137             }
138         } else{ //there is no BindingCustomization, look in Definitions
139
isMIMEContent = getMIMEContentFromDefinitions(primaryDefinitions);
140         }
141         return isMIMEContent;
142     }
143     
144     private boolean getMIMEContentFromDefinitions(Definitions definitions){
145         List JavaDoc<DefinitionsCustomization> dcs = definitions.getExtensibilityElements(DefinitionsCustomization.class);
146         if(dcs.size() > 0){
147             DefinitionsCustomization dc = dcs.get(0);
148             EnableMIMEContent mimeContent = dc.getEnableMIMEContent();
149             if(mimeContent != null){
150                 return mimeContent.isEnabled();
151             }
152         }
153         return false;
154     }
155     
156     public void setEnableMIMEContent(boolean enable){
157         enableMIMEContentCB.setSelected(enable);
158     }
159     
160     public Boolean JavaDoc getEnableMIMEContent(){
161         return enableMIMEContentCB.isSelected();
162     }
163     
164     public JComponent JavaDoc getErrorComponent(String JavaDoc string) {
165         return new javax.swing.JButton JavaDoc("error");
166     }
167     
168     public void linkButtonPressed(Object JavaDoc object, String JavaDoc string) {
169     }
170     
171     public void setValue(JComponent JavaDoc jComponent, Object JavaDoc object) {
172         List JavaDoc <BindingOperationCustomization> ee =
173                 bindingOperation.getExtensibilityElements(BindingOperationCustomization.class);
174         CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault();
175         if(jComponent == enableMIMEContentCB){
176             if(ee.size() > 0){ //there is an extensibility element
177
BindingOperationCustomization boc = ee.get(0);
178                 EnableMIMEContent emc = boc.getEnableMIMEContent();
179                 if(emc == null){ //there is no EnableMIMEContent, create one
180
try{
181                         model.startTransaction();
182                         emc = factory.createEnableMIMEContent(model);
183                         emc.setEnabled(this.getEnableMIMEContent());
184                         boc.setEnableMIMEContent(emc);
185                         wsdlDirty = true;
186                     } finally{
187                             model.endTransaction();
188                     }
189                 } else{ //there is an EnableMIMEContent, reset it
190
try{
191                         model.startTransaction();
192                         emc.setEnabled(this.getEnableMIMEContent());
193                         wsdlDirty = true;
194                     } finally{
195                             model.endTransaction();
196                     }
197                 }
198             } else{ //there is no extensibility element, add a new one and add a new
199
//MIME content element
200
BindingOperationCustomization boc = factory.createBindingOperationCustomization(model);
201                 EnableMIMEContent emc = factory.createEnableMIMEContent(model);
202                 try{
203                     model.startTransaction();
204                     emc.setEnabled(this.getEnableMIMEContent());
205                     boc.setEnableMIMEContent(emc);
206                     bindingOperation.addExtensibilityElement(boc);
207                     wsdlDirty = true;
208                 } finally{
209                         model.endTransaction();
210                 }
211             }
212         }
213         
214     }
215     
216     public boolean wsdlIsDirty() {
217         return wsdlDirty;
218     }
219     
220     public void save() {
221         if(wsdlDirty){
222            this.setModelDirty(model);
223         }
224     }
225     
226     /** This method is called from within the constructor to
227      * initialize the form.
228      * WARNING: Do NOT modify this code. The content of this method is
229      * always regenerated by the Form Editor.
230      */

231     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
232
private void initComponents() {
233         emcButtonGroup = new javax.swing.ButtonGroup JavaDoc();
234         enableMIMEContentCB = new javax.swing.JCheckBox JavaDoc();
235         bindingLabel = new javax.swing.JLabel JavaDoc();
236         bindingName = new javax.swing.JLabel JavaDoc();
237
238         enableMIMEContentCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_ENABLE_MIME_CONTENT").charAt(0));
239         enableMIMEContentCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
240         enableMIMEContentCB.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_ENABLE_MIME"));
241         enableMIMEContentCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
242         enableMIMEContentCB.setLabel(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
243         enableMIMEContentCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
244         enableMIMEContentCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
245         enableMIMEContentCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
246
247         bindingLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_BINDING"));
248         bindingLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_BINDING"));
249
250         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
251         this.setLayout(layout);
252         layout.setHorizontalGroup(
253             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
254             .add(layout.createSequentialGroup()
255                 .add(21, 21, 21)
256                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
257                     .add(layout.createSequentialGroup()
258                         .add(bindingLabel)
259                         .add(22, 22, 22)
260                         .add(bindingName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
261                     .add(enableMIMEContentCB))
262                 .addContainerGap(201, Short.MAX_VALUE))
263         );
264         layout.setVerticalGroup(
265             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
266             .add(layout.createSequentialGroup()
267                 .add(11, 11, 11)
268                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
269                     .add(bindingLabel)
270                     .add(bindingName))
271                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 21, Short.MAX_VALUE)
272                 .add(enableMIMEContentCB)
273                 .addContainerGap())
274         );
275     }// </editor-fold>//GEN-END:initComponents
276

277     
278     // Variables declaration - do not modify//GEN-BEGIN:variables
279
private javax.swing.JLabel JavaDoc bindingLabel;
280     private javax.swing.JLabel JavaDoc bindingName;
281     private javax.swing.ButtonGroup JavaDoc emcButtonGroup;
282     private javax.swing.JCheckBox JavaDoc enableMIMEContentCB;
283     // End of variables declaration//GEN-END:variables
284

285 }
286
Popular Tags