1 19 20 25 26 package org.netbeans.modules.websvc.customization.multiview; 27 28 import java.awt.Color ; 29 import java.awt.event.ItemEvent ; 30 import java.awt.event.ItemListener ; 31 import java.util.List ; 32 import javax.swing.JComponent ; 33 import javax.swing.text.JTextComponent ; 34 import org.netbeans.modules.websvc.core.JaxWsUtils; 35 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory; 36 import org.netbeans.modules.websvc.customization.model.JavaClass; 37 import org.netbeans.modules.websvc.customization.model.ServiceCustomization; 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.Service; 41 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 42 import org.openide.util.WeakListeners; 43 import org.netbeans.modules.xml.multiview.Error; 44 45 49 public class ServicePanel extends SaveableSectionInnerPanel { 50 private Service service; 51 private WSDLModel model; 52 private boolean wsdlDirty; 53 private DefaultItemListener itemListener; 54 55 56 public ServicePanel(SectionView view, Service service){ 57 super(view); 58 this.service = service; 59 this.model = this.service.getModel(); 60 initComponents(); 61 javaClassLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 62 javaClassText.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 63 defaultJavaClassCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 64 sync(); 65 66 itemListener = new DefaultItemListener(); 67 ItemListener il = (ItemListener )WeakListeners.create(ItemListener .class, 68 itemListener,defaultJavaClassCB); 69 defaultJavaClassCB.addItemListener(il); 70 71 addModifier(javaClassText); 72 addModifier(defaultJavaClassCB); 73 addValidatee(javaClassText); 74 } 75 76 class DefaultItemListener implements ItemListener { 77 public void itemStateChanged(ItemEvent e) { 78 if(defaultJavaClassCB.isSelected()){ 79 javaClassText.setEnabled(false); 80 javaClassText.setBackground(Color.LIGHT_GRAY); 81 } else{ 82 javaClassText.setEnabled(true); 83 javaClassText.setBackground(Color.WHITE); 84 javaClassText.requestFocus(); 85 } 86 } 87 } 88 89 private void sync(){ 90 List <ServiceCustomization> ee = service.getExtensibilityElements(ServiceCustomization.class); 91 if(ee.size() > 0 ){ 92 ServiceCustomization sc = ee.get(0); 93 JavaClass jc = sc.getJavaClass(); 94 if(jc != null){ 95 setJavaClass(jc.getName()); 96 } else{ 97 defaultJavaClassCB.setSelected(true); 98 javaClassText.setEnabled(false); 99 javaClassText.setBackground(Color.LIGHT_GRAY); 100 } 101 } else{ 102 defaultJavaClassCB.setSelected(true); 103 javaClassText.setEnabled(false); 104 javaClassText.setBackground(Color.LIGHT_GRAY); 105 } 106 } 107 108 public void setJavaClass(String name){ 109 javaClassText.setText(name); 110 } 111 112 public JComponent getErrorComponent(String string) { 113 return new javax.swing.JButton ("error"); 114 } 115 116 public void linkButtonPressed(Object object, String string) { 117 } 118 119 public void setValue(JComponent jComponent, Object object) { 120 List <ServiceCustomization> ee = 121 service.getExtensibilityElements(ServiceCustomization.class); 122 CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault(); 123 if(jComponent == javaClassText || 124 jComponent == defaultJavaClassCB ){ 125 String text = javaClassText.getText(); 126 if(text != null && !text.trim().equals("") && 127 !defaultJavaClassCB.isSelected()){ 128 if(!JaxWsUtils.isJavaIdentifier(text)){ 129 return; 130 } 131 if(ee.size() == 1){ ServiceCustomization sc = ee.get(0); 133 JavaClass jc = sc.getJavaClass(); 134 if(jc == null){ 135 try{ 136 jc = factory.createJavaClass(model); 137 model.startTransaction(); 138 jc.setName(text); sc.setJavaClass(jc); 140 wsdlDirty = true; 141 } finally{ 142 model.endTransaction(); 143 } 144 } else{ try{ 147 model.startTransaction(); 148 jc.setName(text); 149 wsdlDirty = true; 150 } finally{ 151 model.endTransaction(); 152 } 153 } 154 155 } else{ ServiceCustomization sc = factory.createServiceCustomization(model); 158 JavaClass jc = factory.createJavaClass(model); 159 try{ 160 model.startTransaction(); 161 jc.setName(text); 162 sc.setJavaClass(jc); 163 service.addExtensibilityElement(sc); 164 wsdlDirty = true; 165 } finally{ 166 model.endTransaction(); 167 } 168 } 169 } else{ if(ee.size() == 1){ 171 ServiceCustomization sc = ee.get(0); 172 JavaClass jc = sc.getJavaClass(); 173 if(jc != null){ 174 try{ 175 model.startTransaction(); 176 sc.removeJavaClass(jc); 177 if(sc.getChildren().size() == 0){ 179 service.removeExtensibilityElement(sc); 180 } 181 wsdlDirty = true; 182 } finally{ 183 model.endTransaction(); 184 } 185 } 186 } 187 } 188 } 189 } 190 191 public void documentChanged(JTextComponent comp, String val) { 192 if(comp == javaClassText){ 193 if(!JaxWsUtils.isJavaIdentifier(val)){ 194 getSectionView().getErrorPanel(). 195 setError(new Error (Error.TYPE_FATAL, 196 Error.ERROR_MESSAGE, val, comp)); 197 return; 198 } 199 } 200 getSectionView().getErrorPanel().clearError(); 201 } 202 203 public void rollbackValue(JTextComponent source) { 204 if(source == javaClassText){ 205 String className = ""; 206 List <ServiceCustomization> ee = 207 service.getExtensibilityElements(ServiceCustomization.class); 208 if(ee.size() == 1){ 209 ServiceCustomization sc = ee.get(0); 210 JavaClass jc = sc.getJavaClass(); 211 if(jc != null){ 212 className = jc.getName(); 213 } 214 } 215 javaClassText.setText(className); 216 } 217 } 218 219 public boolean wsdlIsDirty() { 220 return wsdlDirty; 221 } 222 223 public void save() { 224 if(wsdlDirty){ 225 this.setModelDirty(model); 226 } 227 } 228 229 234 private void initComponents() { 236 javaClassLabel = new javax.swing.JLabel (); 237 javaClassText = new javax.swing.JTextField (); 238 defaultJavaClassCB = new javax.swing.JCheckBox (); 239 240 javaClassLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 241 javaClassLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 242 243 javaClassText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_SERVICE_CLASS")); 244 javaClassText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 245 javaClassText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 246 247 defaultJavaClassCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0)); 248 defaultJavaClassCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 249 defaultJavaClassCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 250 defaultJavaClassCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 251 defaultJavaClassCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 252 defaultJavaClassCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 253 254 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 255 this.setLayout(layout); 256 layout.setHorizontalGroup( 257 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 258 .add(layout.createSequentialGroup() 259 .addContainerGap() 260 .add(javaClassLabel) 261 .add(21, 21, 21) 262 .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 172, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 263 .add(20, 20, 20) 264 .add(defaultJavaClassCB) 265 .addContainerGap(70, Short.MAX_VALUE)) 266 ); 267 layout.setVerticalGroup( 268 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 269 .add(layout.createSequentialGroup() 270 .add(31, 31, 31) 271 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 272 .add(javaClassLabel) 273 .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 274 .add(defaultJavaClassCB)) 275 .addContainerGap(29, Short.MAX_VALUE)) 276 ); 277 } 279 280 private javax.swing.JCheckBox defaultJavaClassCB; 282 private javax.swing.JLabel javaClassLabel; 283 private javax.swing.JTextField javaClassText; 284 286 } 287 | Popular Tags |