1 19 24 25 package org.netbeans.modules.websvc.customization.multiview; 26 27 import java.awt.Color ; 28 import java.awt.event.ItemEvent ; 29 import java.awt.event.ItemListener ; 30 import java.util.List ; 31 import javax.swing.JButton ; 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.core.wseditor.spi.SaveSetter; 36 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory; 37 import org.netbeans.modules.websvc.customization.model.JavaClass; 38 import org.netbeans.modules.websvc.customization.model.PortTypeOperationFaultCustomization; 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.Fault; 42 import org.netbeans.modules.xml.wsdl.model.Operation; 43 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 44 import org.openide.util.WeakListeners; 45 import org.netbeans.modules.xml.multiview.Error; 46 47 51 public class PortTypeOperationFaultPanel extends SaveableSectionInnerPanel { 52 private Fault fault; 53 private SaveSetter setter; 54 private WSDLModel model; 55 private boolean wsdlDirty; 56 private DefaultItemListener defaultListener; 57 60 public PortTypeOperationFaultPanel(SectionView view, Fault fault){ 61 super(view); 62 this.fault = fault; 63 this.model = this.fault.getModel(); 64 initComponents(); 65 operationLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 66 operationName.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 67 operationName.setText(getParentOfFault(fault)); 68 javaClassLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 69 javaClassText.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 70 defaultJavaClassCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 71 72 sync(); 73 addModifier(javaClassText); 74 addModifier(defaultJavaClassCB); 75 addValidatee(javaClassText); 76 77 defaultListener = new DefaultItemListener(); 78 ItemListener il = (ItemListener )WeakListeners.create(ItemListener .class, defaultListener, 79 defaultJavaClassCB); 80 defaultJavaClassCB.addItemListener(il); 81 } 82 83 class DefaultItemListener implements ItemListener { 84 public void itemStateChanged(ItemEvent e) { 85 if(defaultJavaClassCB.isSelected()){ 86 javaClassText.setEnabled(false); 87 javaClassText.setBackground(Color.LIGHT_GRAY); 88 } else{ 89 javaClassText.setEnabled(true); 90 javaClassText.setBackground(Color.WHITE); 91 javaClassText.requestFocus(); 92 } 93 } 94 95 } 96 97 private String getParentOfFault(Fault fault){ 98 Operation op = (Operation)fault.getParent(); 99 return op.getName(); 100 } 101 102 private void sync(){ 103 List <PortTypeOperationFaultCustomization> ee = 104 fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class); 105 if(ee.size() == 1){ 106 PortTypeOperationFaultCustomization ptof = ee.get(0); 107 JavaClass jc = ptof.getJavaClass(); 108 if(jc != null){ 109 setJavaClass(jc.getName()); 110 } else{ 111 defaultJavaClassCB.setSelected(true); 112 javaClassText.setEnabled(false); 113 javaClassText.setBackground(Color.LIGHT_GRAY); 114 } 115 } else{ 116 defaultJavaClassCB.setSelected(true); 117 javaClassText.setEnabled(false); 118 javaClassText.setBackground(Color.LIGHT_GRAY); 119 } 120 } 121 122 public void setJavaClass(String name){ 123 javaClassText.setText(name); 124 } 125 126 public String getJavaClass(){ 127 return javaClassText.getText(); 128 } 129 130 public JComponent getErrorComponent(String string) { 131 return new JButton ("error"); 132 } 133 134 public void linkButtonPressed(Object object, String string) { 135 } 136 137 public void setValue(JComponent jComponent, Object object) { 138 List <PortTypeOperationFaultCustomization> ee = 139 fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class); 140 CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault(); 141 if(jComponent == javaClassText || 142 jComponent == defaultJavaClassCB ){ 143 String text = javaClassText.getText(); 144 if(text != null && !text.trim().equals("") 145 && !defaultJavaClassCB.isSelected()){ 146 if(!JaxWsUtils.isJavaIdentifier(text)){ 147 return; 148 } 149 if(ee.size() == 1){ PortTypeOperationFaultCustomization ptofc = ee.get(0); 151 JavaClass jc = ptofc.getJavaClass(); 152 if(jc == null){ try{ 154 jc = factory.createJavaClass(model); 155 model.startTransaction(); 156 jc.setName(text); ptofc.setJavaClass(jc); 158 wsdlDirty = true; 159 }finally{ 160 model.endTransaction(); 161 } 162 } else{ try{ 165 model.startTransaction(); 166 jc.setName(text); 167 wsdlDirty = true; 168 } finally{ 169 model.endTransaction(); 170 } 171 } 172 }else{ PortTypeOperationFaultCustomization ptofc = 175 factory.createPortTypeOperationFaultCustomization(model); 176 JavaClass jc = factory.createJavaClass(model); 177 try{ 178 model.startTransaction(); 179 jc.setName(text); 180 ptofc.setJavaClass(jc); 181 fault.addExtensibilityElement(ptofc); 182 wsdlDirty = true; 183 } finally{ 184 model.endTransaction(); 185 } 186 } 187 } else{ if(ee.size() == 1){ 189 try{ 190 PortTypeOperationFaultCustomization ptofc = ee.get(0); 191 JavaClass jc = ptofc.getJavaClass(); 192 if(jc != null){ 193 model.startTransaction(); 194 ptofc.removeJavaClass(jc); 195 if(ptofc.getChildren().size() == 0){ 197 fault.removeExtensibilityElement(ptofc); 198 } 199 200 wsdlDirty = true; 201 } 202 } finally{ 203 model.endTransaction(); 204 } 205 } 206 } 207 } 208 } 209 210 public void documentChanged(JTextComponent comp, String val) { 211 if(comp == javaClassText){ 212 if(!JaxWsUtils.isJavaIdentifier(val)){ 213 getSectionView().getErrorPanel(). 214 setError(new Error (Error.TYPE_FATAL, 215 Error.ERROR_MESSAGE, val, comp)); 216 return; 217 } 218 } 219 getSectionView().getErrorPanel().clearError(); 220 } 221 222 public void rollbackValue(JTextComponent source) { 223 if(source == javaClassText){ 224 String className = ""; 225 List <PortTypeOperationFaultCustomization> ee = 226 fault.getExtensibilityElements(PortTypeOperationFaultCustomization.class); 227 if(ee.size() == 1){ 228 PortTypeOperationFaultCustomization ptc = ee.get(0); 229 JavaClass jc = ptc.getJavaClass(); 230 if(jc != null){ 231 className = jc.getName(); 232 } 233 } 234 javaClassText.setText(className); 235 } 236 } 237 238 public boolean wsdlIsDirty() { 239 return wsdlDirty; 240 } 241 242 public void save() { 243 if(wsdlDirty){ 244 this.setModelDirty(model); 245 } 246 } 247 248 253 private void initComponents() { 255 javaClassLabel = new javax.swing.JLabel (); 256 javaClassText = new javax.swing.JTextField (); 257 defaultJavaClassCB = new javax.swing.JCheckBox (); 258 operationLabel = new javax.swing.JLabel (); 259 operationName = new javax.swing.JLabel (); 260 261 javaClassLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 262 javaClassLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 263 264 javaClassText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_PORTTYPE_FAULT_CLASS")); 265 javaClassText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 266 javaClassText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_JAVA_CLASS")); 267 268 defaultJavaClassCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0)); 269 defaultJavaClassCB.setText("Use Default"); 270 defaultJavaClassCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 271 defaultJavaClassCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 272 defaultJavaClassCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 273 defaultJavaClassCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 274 275 operationLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_OPERATION")); 276 operationLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_OPERATION")); 277 278 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 279 this.setLayout(layout); 280 layout.setHorizontalGroup( 281 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 282 .add(layout.createSequentialGroup() 283 .addContainerGap() 284 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 285 .add(layout.createSequentialGroup() 286 .add(javaClassLabel) 287 .add(15, 15, 15) 288 .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 227, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 289 .add(20, 20, 20) 290 .add(defaultJavaClassCB)) 291 .add(layout.createSequentialGroup() 292 .add(operationLabel) 293 .add(15, 15, 15) 294 .add(operationName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 295 .addContainerGap(76, Short.MAX_VALUE)) 296 ); 297 layout.setVerticalGroup( 298 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 299 .add(layout.createSequentialGroup() 300 .addContainerGap() 301 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 302 .add(operationLabel) 303 .add(operationName)) 304 .add(18, 18, 18) 305 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 306 .add(javaClassLabel) 307 .add(javaClassText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 308 .add(defaultJavaClassCB)) 309 .addContainerGap(19, Short.MAX_VALUE)) 310 ); 311 } 313 314 private javax.swing.JCheckBox defaultJavaClassCB; 316 private javax.swing.JLabel javaClassLabel; 317 private javax.swing.JTextField javaClassText; 318 private javax.swing.JLabel operationLabel; 319 private javax.swing.JLabel operationName; 320 322 } 323 | Popular Tags |