1 19 20 25 26 package org.netbeans.modules.websvc.customization.multiview; 27 28 import java.io.IOException ; 29 import java.util.Map ; 30 import java.util.Set ; 31 import javax.swing.JComponent ; 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 51 public class ExternalBindingPanel extends SaveableSectionInnerPanel { 52 private ExternalBindingTablePanel panel; 53 private Node node; 54 private JaxWsModel jmodel; 55 private boolean jaxwsIsDirty; 56 57 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 getErrorComponent(String errorId) { 71 return null; 72 } 73 74 public void linkButtonPressed(Object ddBean, String ddProperty) { 75 } 76 77 public void setValue(JComponent source, Object 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 } 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 <String , FileObject> addedBindings = panel.getAddedBindings(); 123 Set <String > removedBindings = panel.getRemovedBindings(); 124 125 if(addedBindings.size() > 0 || removedBindings.size() > 0){ 126 jaxwsIsDirty = true; 127 } 128 129 for(String bindingName : addedBindings.keySet()){ 131 FileObject bindingFO = addedBindings.get(bindingName); 132 if(bindingFO != null){ 133 String normalizedBindingName = bindingName; 134 String 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 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 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 client.addBinding(binding); 170 } else{ 171 if(service != null){ 172 Binding binding = service.newBinding(); 173 binding.setFileName(bindingName); 174 service.addBinding(binding); 176 } 177 } 178 } 179 182 for(String 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 211 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 } 226 227 230 } 231 | Popular Tags |