KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ExternalBindingPanel.java
22  *
23  * Created on March 7, 2006, 11:21 PM
24  */

25
26 package org.netbeans.modules.websvc.customization.multiview;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.Set JavaDoc;
31 import javax.swing.JComponent JavaDoc;
32 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.Binding;
34 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
35 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
36 import org.netbeans.modules.websvc.api.jaxws.project.config.Service;
37 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
38 import org.netbeans.modules.xml.multiview.ui.SectionView;
39 import org.openide.ErrorManager;
40 import org.openide.cookies.EditorCookie;
41 import org.openide.cookies.SaveCookie;
42 import org.openide.filesystems.FileObject;
43 import org.openide.filesystems.FileUtil;
44 import org.openide.loaders.DataObject;
45 import org.openide.nodes.Node;
46
47 /**
48  *
49  * @author Roderico Cruz
50  */

51 public class ExternalBindingPanel extends SaveableSectionInnerPanel {
52     private ExternalBindingTablePanel panel;
53     private Node node;
54     private JaxWsModel jmodel;
55     private boolean jaxwsIsDirty;
56     
57     /** Creates new form ExternalBindingPanel */
58     public ExternalBindingPanel(SectionView sectionView,
59             Node node, JaxWsModel jmodel) {
60         super(sectionView);
61         this.node = node;
62         this.jmodel = jmodel;
63         
64         ExternalBindingTablePanel.EBTableModel model = new ExternalBindingTablePanel.EBTableModel();
65         panel = new ExternalBindingTablePanel(model, node, jmodel);
66         panel.populateModel();
67         initComponents2();
68     }
69     
70     public JComponent JavaDoc getErrorComponent(String JavaDoc errorId) {
71         return null;
72     }
73     
74     public void linkButtonPressed(Object JavaDoc ddBean, String JavaDoc ddProperty) {
75     }
76     
77     public void setValue(JComponent JavaDoc source, Object JavaDoc value) {
78         
79     }
80     
81     private void initComponents2() {
82         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
83         this.setLayout(layout);
84         layout.setHorizontalGroup(
85                 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
86                 .add(layout.createSequentialGroup()
87                 .add(panel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
88                 .addContainerGap())
89                 );
90         layout.setVerticalGroup(
91                 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
92                 .add(layout.createSequentialGroup()
93                 .addContainerGap()
94                 .add(panel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
95                 .addContainerGap(19, Short.MAX_VALUE))
96                 );
97     }// </editor-fold>
98

99     public boolean wsdlIsDirty() {
100         return false;
101     }
102     
103     public boolean jaxwsIsDirty(){
104         return jaxwsIsDirty;
105     }
106     
107     public void save() {
108         FileObject srcRoot = (FileObject)node.getLookup().lookup(FileObject.class);
109         FileObject bindingsFolder = null;
110         if(isClient()){
111             JAXWSClientSupport support = JAXWSClientSupport.getJaxWsClientSupport(srcRoot);
112             bindingsFolder = support.getBindingsFolderForClient(node.getName(), true);
113             
114         } else{
115             JAXWSSupport support = JAXWSSupport.getJAXWSSupport(srcRoot);
116             bindingsFolder = support.getBindingsFolderForService(node.getName(), true);
117         }
118         assert srcRoot != null : "Cannot find srcRoot";
119         
120         Client client = (Client)node.getLookup().lookup(Client.class);
121         Service service = (Service)node.getLookup().lookup(Service.class);
122         Map JavaDoc<String JavaDoc, FileObject> addedBindings = panel.getAddedBindings();
123         Set JavaDoc<String JavaDoc> removedBindings = panel.getRemovedBindings();
124         
125         if(addedBindings.size() > 0 || removedBindings.size() > 0){
126             jaxwsIsDirty = true;
127         }
128         
129         //add new binding files
130
for(String JavaDoc bindingName : addedBindings.keySet()){
131             FileObject bindingFO = addedBindings.get(bindingName);
132             if(bindingFO != null){
133                 String JavaDoc normalizedBindingName = bindingName;
134                 String JavaDoc ext = bindingFO.getExt();
135                 if(!ext.equals("")){
136                     int index = bindingName.indexOf(ext);
137                     normalizedBindingName = bindingName.substring(0, index - 1);
138                 }
139                 try{
140                     FileObject copiedBinding = FileUtil.copyFile(bindingFO, bindingsFolder,
141                             normalizedBindingName, bindingFO.getExt());
142                     
143                     DataObject dobj = DataObject.find(copiedBinding);
144                     String JavaDoc relativePath = panel.getRelativePathToWsdl();
145                     boolean changed = org.netbeans.modules.websvc.core.JaxWsUtils.addRelativeWsdlLocation(copiedBinding, relativePath);
146                     if(changed){
147                         if(dobj != null){
148                             SaveCookie sc = (SaveCookie)dobj.getCookie(SaveCookie.class);
149                             if(sc != null){
150                                 sc.save();
151                             }
152                         }
153                     }
154                     if(dobj != null){
155                         EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class);
156                         ec.open();
157                     }
158                 }catch(IOException JavaDoc e){
159                     ErrorManager.getDefault().notify(e);
160                 }
161                 
162                 
163                 
164             }
165             if(client != null){
166                 Binding binding = client.newBinding();
167                 binding.setFileName(bindingName);
168                 //binding.setOriginalFileUrl(bindingFileUri.toString());
169
client.addBinding(binding);
170             } else{
171                 if(service != null){
172                     Binding binding = service.newBinding();
173                     binding.setFileName(bindingName);
174                     //binding.setOriginalFileUrl(bindingFileUri.toString());
175
service.addBinding(binding);
176                 }
177             }
178         }
179         //remove deleted bindings from the metadata file
180
//TODO Shd we also delete the binding file from the bindings directory?
181

182         for(String JavaDoc removedBinding : removedBindings){
183             if(client != null){
184                 Binding binding = client.getBindingByFileName(removedBinding);
185                 if(binding != null){
186                     client.removeBinding(binding);
187                 }
188             } else if(service != null){
189                 Binding binding = service.getBindingByFileName(removedBinding);
190                 if(binding != null){
191                     service.removeBinding(binding);
192                 }
193             }
194         }
195         
196     }
197     
198     private boolean isClient(){
199         Client client = (Client)node.getLookup().lookup(Client.class);
200         if(client != null){
201             return true;
202         }
203         return false;
204     }
205     
206     /** This method is called from within the constructor to
207      * initialize the form.
208      * WARNING: Do NOT modify this code. The content of this method is
209      * always regenerated by the Form Editor.
210      */

211     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
212
private void initComponents() {
213
214         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
215         this.setLayout(layout);
216         layout.setHorizontalGroup(
217             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
218             .add(0, 400, Short.MAX_VALUE)
219         );
220         layout.setVerticalGroup(
221             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
222             .add(0, 300, Short.MAX_VALUE)
223         );
224     }// </editor-fold>//GEN-END:initComponents
225

226     
227     // Variables declaration - do not modify//GEN-BEGIN:variables
228
// End of variables declaration//GEN-END:variables
229

230 }
231
Popular Tags