KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 package org.netbeans.modules.websvc.customization.multiview;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.io.IOException JavaDoc;
33 import java.util.List JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import org.netbeans.modules.websvc.customization.model.BindingCustomization;
36 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory;
37 import org.netbeans.modules.websvc.customization.model.DefinitionsCustomization;
38 import org.netbeans.modules.websvc.customization.model.EnableMIMEContent;
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.Binding;
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 BindingPanel extends SaveableSectionInnerPanel {
54     private Binding binding;
55     private WSDLModel model;
56     private boolean wsdlDirty;
57     private ModelChangeListener modelListener;
58     private BindingActionListener actionListener;
59     private Definitions primaryDefinitions;
60     
61     /** Creates new form BindingPanel */
62     public BindingPanel(SectionView view, Binding binding, Definitions primaryDefinitions){
63         super(view);
64         this.binding = binding;
65         this.primaryDefinitions = primaryDefinitions;
66         this.model = this.binding.getModel();
67         initComponents();
68         this.enableMIMEContentCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor());
69         
70         sync();
71         
72         modelListener = new ModelChangeListener();
73         WSDLModel primaryModel = primaryDefinitions.getModel();
74         PropertyChangeListener JavaDoc pcl = WeakListeners.propertyChange(modelListener, primaryModel);
75         primaryModel.addPropertyChangeListener(pcl);
76         
77         actionListener = new BindingActionListener();
78         ActionListener JavaDoc al = (ActionListener JavaDoc)WeakListeners.create(ActionListener JavaDoc.class, actionListener,
79                 enableMIMEContentCB);
80         enableMIMEContentCB.addActionListener(al);
81     }
82     
83     class ModelChangeListener implements PropertyChangeListener JavaDoc{
84         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
85             Object JavaDoc source = evt.getSource();
86             if (source instanceof EnableMIMEContent){
87                 EnableMIMEContent emc = (EnableMIMEContent)source;
88                 WSDLComponent parent = emc.getParent();
89                 if(parent instanceof DefinitionsCustomization){
90                     sync();
91                 }
92             }
93         }
94     }
95     
96     class BindingActionListener implements ActionListener JavaDoc{
97         public void actionPerformed(ActionEvent JavaDoc e) {
98             setValue((JComponent JavaDoc)e.getSource(), null);
99         }
100     }
101     
102     private boolean getMIMEContentOfParent(){
103         List JavaDoc<DefinitionsCustomization> dcs = primaryDefinitions.getExtensibilityElements(DefinitionsCustomization.class);
104         if(dcs.size() > 0) {
105             DefinitionsCustomization dc = dcs.get(0);
106             EnableMIMEContent mimeContent = dc.getEnableMIMEContent();
107             if(mimeContent != null){
108                 return mimeContent.isEnabled();
109             }
110         }
111         return false;
112     }
113     
114     private void sync(){
115         List JavaDoc<BindingCustomization> ee =
116                 binding.getExtensibilityElements(BindingCustomization.class);
117         if(ee.size() == 1){
118             BindingCustomization bc = ee.get(0);
119             EnableMIMEContent emc = bc.getEnableMIMEContent();
120             if(emc != null){
121                 setEnableMIMEContent(emc.isEnabled());
122             } else{
123                 setEnableMIMEContent(getMIMEContentOfParent());
124             }
125         } else{
126             setEnableMIMEContent(getMIMEContentOfParent());
127         }
128     }
129     
130     public void setEnableMIMEContent(boolean enable){
131         enableMIMEContentCB.setSelected(enable);
132     }
133     
134     public boolean getEnableMIMEContent(){
135         return enableMIMEContentCB.isSelected();
136     }
137     
138     public JComponent JavaDoc getErrorComponent(String JavaDoc string) {
139         return new javax.swing.JButton JavaDoc("error");
140     }
141     
142     public void linkButtonPressed(Object JavaDoc object, String JavaDoc string) {
143     }
144     
145     public void setValue(JComponent JavaDoc jComponent, Object JavaDoc object) {
146         List JavaDoc <BindingCustomization> ee =
147                 binding.getExtensibilityElements(BindingCustomization.class);
148         CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault();
149         if(jComponent == enableMIMEContentCB){
150             if(ee.size() > 0){ //there is an extensibility element
151
BindingCustomization bc = ee.get(0);
152                 EnableMIMEContent emc = bc.getEnableMIMEContent();
153                 if(emc == null){ //there is no EnableMIMEContent, create one
154
try{
155                         model.startTransaction();
156                         emc = factory.createEnableMIMEContent(model);
157                         emc.setEnabled(this.getEnableMIMEContent());
158                         bc.setEnableMIMEContent(emc);
159                         wsdlDirty = true;
160                     } finally{
161                             model.endTransaction();
162                         
163                     }
164                 } else{ //there is an EnableWrapperStyle, reset it
165
try{
166                         model.startTransaction();
167                         emc.setEnabled(this.getEnableMIMEContent());
168                         wsdlDirty = true;
169                     } finally{
170                             model.endTransaction();
171                     }
172                 }
173             } else{ //there is no extensibility element, add a new one and add a new
174
//wrapper style element
175
BindingCustomization bc = factory.createBindingCustomization(model);
176                 EnableMIMEContent emc = factory.createEnableMIMEContent(model);
177                 try{
178                     model.startTransaction();
179                     emc.setEnabled(this.getEnableMIMEContent());
180                     bc.setEnableMIMEContent(emc);
181                     binding.addExtensibilityElement(bc);
182                     wsdlDirty = true;
183                 } finally{
184                     model.endTransaction();
185                 }
186             }
187         }
188     }
189     
190     public boolean wsdlIsDirty() {
191         return wsdlDirty;
192     }
193     
194     public void save() {
195         if(wsdlDirty){
196            this.setModelDirty(model);
197         }
198     }
199     
200     /** This method is called from within the constructor to
201      * initialize the form.
202      * WARNING: Do NOT modify this code. The content of this method is
203      * always regenerated by the Form Editor.
204      */

205     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
206
private void initComponents() {
207         emcButtonGroup = new javax.swing.ButtonGroup JavaDoc();
208         enableMIMEContentCB = new javax.swing.JCheckBox JavaDoc();
209
210         enableMIMEContentCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_ENABLE_MIME_CONTENT").charAt(0));
211         enableMIMEContentCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
212         enableMIMEContentCB.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_ENABLE_MIME"));
213         enableMIMEContentCB.setActionCommand(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
214         enableMIMEContentCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
215         enableMIMEContentCB.setLabel(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
216         enableMIMEContentCB.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
217         enableMIMEContentCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
218         enableMIMEContentCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT"));
219
220         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
221         this.setLayout(layout);
222         layout.setHorizontalGroup(
223             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
224             .add(layout.createSequentialGroup()
225                 .addContainerGap()
226                 .add(enableMIMEContentCB)
227                 .addContainerGap(301, Short.MAX_VALUE))
228         );
229         layout.setVerticalGroup(
230             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
231             .add(layout.createSequentialGroup()
232                 .add(25, 25, 25)
233                 .add(enableMIMEContentCB)
234                 .addContainerGap(28, Short.MAX_VALUE))
235         );
236     }// </editor-fold>//GEN-END:initComponents
237

238     
239     // Variables declaration - do not modify//GEN-BEGIN:variables
240
private javax.swing.ButtonGroup JavaDoc emcButtonGroup;
241     private javax.swing.JCheckBox JavaDoc enableMIMEContentCB;
242     // End of variables declaration//GEN-END:variables
243

244 }
245
Popular Tags