1 19 20 25 26 package org.netbeans.modules.websvc.customization.multiview; 27 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyChangeListener ; 30 import java.io.IOException ; 31 import java.util.List ; 32 import javax.swing.JComponent ; 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 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 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 pcl = WeakListeners.propertyChange(modelListener, model); 82 model.addPropertyChangeListener(pcl); 83 84 if(primaryModel != model){ 85 primaryModelListener = new ModelChangeListener(); 86 PropertyChangeListener l = WeakListeners.propertyChange(primaryModelListener, primaryModel); 87 primaryModel.addPropertyChangeListener(l); 88 } 89 } 90 91 private String getParentOfBindingOperation(BindingOperation op){ 92 Binding binding = (Binding)op.getParent(); 93 return binding.getName(); 94 } 95 96 class ModelChangeListener implements PropertyChangeListener { 97 public void propertyChange(PropertyChangeEvent evt) { 98 Object 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 <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 <BindingCustomization> bcs = binding.getExtensibilityElements(BindingCustomization.class); 130 if(bcs.size() > 0) { BindingCustomization bc = bcs.get(0); 132 EnableMIMEContent mimeContent = bc.getEnableMIMEContent(); 133 if(mimeContent != null){ isMIMEContent = mimeContent.isEnabled(); 135 }else{ 136 isMIMEContent = getMIMEContentFromDefinitions(primaryDefinitions); 137 } 138 } else{ isMIMEContent = getMIMEContentFromDefinitions(primaryDefinitions); 140 } 141 return isMIMEContent; 142 } 143 144 private boolean getMIMEContentFromDefinitions(Definitions definitions){ 145 List <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 getEnableMIMEContent(){ 161 return enableMIMEContentCB.isSelected(); 162 } 163 164 public JComponent getErrorComponent(String string) { 165 return new javax.swing.JButton ("error"); 166 } 167 168 public void linkButtonPressed(Object object, String string) { 169 } 170 171 public void setValue(JComponent jComponent, Object object) { 172 List <BindingOperationCustomization> ee = 173 bindingOperation.getExtensibilityElements(BindingOperationCustomization.class); 174 CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault(); 175 if(jComponent == enableMIMEContentCB){ 176 if(ee.size() > 0){ BindingOperationCustomization boc = ee.get(0); 178 EnableMIMEContent emc = boc.getEnableMIMEContent(); 179 if(emc == null){ 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{ try{ 191 model.startTransaction(); 192 emc.setEnabled(this.getEnableMIMEContent()); 193 wsdlDirty = true; 194 } finally{ 195 model.endTransaction(); 196 } 197 } 198 } else{ 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 231 private void initComponents() { 233 emcButtonGroup = new javax.swing.ButtonGroup (); 234 enableMIMEContentCB = new javax.swing.JCheckBox (); 235 bindingLabel = new javax.swing.JLabel (); 236 bindingName = new javax.swing.JLabel (); 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 (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 } 277 278 private javax.swing.JLabel bindingLabel; 280 private javax.swing.JLabel bindingName; 281 private javax.swing.ButtonGroup emcButtonGroup; 282 private javax.swing.JCheckBox enableMIMEContentCB; 283 285 } 286 | Popular Tags |