1 19 20 25 26 package org.netbeans.modules.websvc.customization.multiview; 27 28 import java.awt.event.ActionEvent ; 29 import java.awt.event.ActionListener ; 30 import java.beans.PropertyChangeEvent ; 31 import java.beans.PropertyChangeListener ; 32 import java.io.IOException ; 33 import java.util.List ; 34 import javax.swing.JComponent ; 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 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 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 pcl = WeakListeners.propertyChange(modelListener, primaryModel); 75 primaryModel.addPropertyChangeListener(pcl); 76 77 actionListener = new BindingActionListener(); 78 ActionListener al = (ActionListener )WeakListeners.create(ActionListener .class, actionListener, 79 enableMIMEContentCB); 80 enableMIMEContentCB.addActionListener(al); 81 } 82 83 class ModelChangeListener implements PropertyChangeListener { 84 public void propertyChange(PropertyChangeEvent evt) { 85 Object 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 { 97 public void actionPerformed(ActionEvent e) { 98 setValue((JComponent )e.getSource(), null); 99 } 100 } 101 102 private boolean getMIMEContentOfParent(){ 103 List <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 <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 getErrorComponent(String string) { 139 return new javax.swing.JButton ("error"); 140 } 141 142 public void linkButtonPressed(Object object, String string) { 143 } 144 145 public void setValue(JComponent jComponent, Object object) { 146 List <BindingCustomization> ee = 147 binding.getExtensibilityElements(BindingCustomization.class); 148 CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault(); 149 if(jComponent == enableMIMEContentCB){ 150 if(ee.size() > 0){ BindingCustomization bc = ee.get(0); 152 EnableMIMEContent emc = bc.getEnableMIMEContent(); 153 if(emc == null){ 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{ try{ 166 model.startTransaction(); 167 emc.setEnabled(this.getEnableMIMEContent()); 168 wsdlDirty = true; 169 } finally{ 170 model.endTransaction(); 171 } 172 } 173 } else{ 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 205 private void initComponents() { 207 emcButtonGroup = new javax.swing.ButtonGroup (); 208 enableMIMEContentCB = new javax.swing.JCheckBox (); 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 (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 } 238 239 private javax.swing.ButtonGroup emcButtonGroup; 241 private javax.swing.JCheckBox enableMIMEContentCB; 242 244 } 245 | Popular Tags |