1 19 20 25 26 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype; 27 28 import java.util.ArrayList ; 29 import java.util.Collection ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 import javax.swing.event.DocumentEvent ; 33 import javax.swing.event.DocumentListener ; 34 import javax.swing.text.Document ; 35 import org.netbeans.api.project.Project; 36 import org.netbeans.modules.xml.wsdl.model.Port; 37 import org.netbeans.modules.xml.wsdl.model.PortType; 38 import org.netbeans.modules.xml.wsdl.model.Service; 39 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 40 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 41 import org.netbeans.modules.xml.wsdl.ui.api.property.PropertyUtil; 42 import org.netbeans.modules.xml.wsdl.ui.view.OperationConfigurationPanel; 43 import org.netbeans.modules.xml.xam.ModelSource; 44 import org.openide.DialogDescriptor; 45 import org.openide.ErrorManager; 46 import org.openide.filesystems.FileObject; 47 import org.openide.util.NbBundle; 48 49 53 public class OperationPanel extends javax.swing.JPanel { 54 55 private Project mProject; 56 57 private WSDLModel mModel; 58 59 private DialogDescriptor mDD; 60 61 private List existingMeessages = new ArrayList (); 62 63 String mErrorMessage = null; 64 65 66 public OperationPanel() { 67 initComponents(); 68 } 69 70 public OperationPanel(Project project, WSDLModel model) { 71 this.mProject = project; 72 this.mModel = model; 73 initComponents(); 74 initGUI(); 75 } 76 77 public void setDialogDescriptor(DialogDescriptor dd) { 78 this.mDD = dd; 79 } 80 81 86 private void initComponents() { 88 operationConfigurationPanel1 = new OperationConfigurationPanel(this.mProject, true, mModel); 89 commonMessagePanel1 = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel(); 90 91 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 92 this.setLayout(layout); 93 layout.setHorizontalGroup( 94 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 95 .add(layout.createSequentialGroup() 96 .addContainerGap() 97 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 98 .add(org.jdesktop.layout.GroupLayout.TRAILING, operationConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 99 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 100 .add(96, 96, 96) 101 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE))) 102 .addContainerGap()) 103 ); 104 layout.setVerticalGroup( 105 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 106 .add(layout.createSequentialGroup() 107 .addContainerGap() 108 .add(operationConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 109 .add(17, 17, 17) 110 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 111 .add(60, 60, 60)) 112 ); 113 } 115 public OperationConfigurationPanel getOperationConfigurationPanel() { 116 return this.operationConfigurationPanel1; 117 } 118 119 private void initGUI() { 120 121 ModelSource modelSource = this.mModel.getModelSource(); 122 FileObject wsdlFile = (FileObject) modelSource.getLookup().lookup(FileObject.class); 123 if(wsdlFile != null) { 124 String fileName = wsdlFile.getName(); 125 126 String operationName = fileName + NbBundle.getMessage(OperationPanel.class, "LBL_Operation_suffix"); 127 this.operationConfigurationPanel1.setOperationName(operationName); 128 129 String [] messages = PropertyUtil.getAllMessages(this.mModel); 130 if(messages != null) { 131 for(int i = 0; i < messages.length; i++) { 132 existingMeessages.add(messages[i]); 133 } 134 } 135 136 String inputMessageName = NameGenerator.getInstance().generateUniqueInputMessageName(operationName, mModel); 137 String outputMessageName = NameGenerator.getInstance().generateUniqueOutputMessageName(operationName, mModel); 138 String faultMessageName = NameGenerator.getInstance().generateUniqueFaultMessageName(operationName, mModel); 139 140 MessageNameTextChangeListener messageListener = new MessageNameTextChangeListener(); 141 142 this.operationConfigurationPanel1.setInputMessages(messages, inputMessageName, messageListener); 143 this.operationConfigurationPanel1.setOutputMessages(messages, outputMessageName, messageListener); 144 this.operationConfigurationPanel1.setFaultMessages(messages, faultMessageName, messageListener); 145 146 147 } 148 149 150 OperationNameTextChangeListener operationListener = new OperationNameTextChangeListener(); 151 this.operationConfigurationPanel1.getOperationNameTextField().getDocument().addDocumentListener(operationListener); 152 } 153 154 155 private boolean isValidName(String text) { 156 try { 157 boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text); 158 if(!isValid) { 159 mErrorMessage = "Name \"" + text + "\" is not a valid NCName"; 160 } else { 161 mErrorMessage = null; 162 } 163 164 } catch(Exception ex) { 165 ex.printStackTrace(); 166 } 167 168 return mErrorMessage == null; 169 } 170 171 private void validateAll() { 172 173 boolean validOperation = isValidName(this.operationConfigurationPanel1.getOperationNameTextField().getText()); 174 if(!validOperation) { 175 updateMessagePanel(); 176 return; 177 } 178 179 180 boolean isValidInputMessage = isValidInputMessage(); 181 if(!isValidInputMessage) { 182 updateMessagePanel(); 183 return; 184 } 185 186 boolean isValidOutputMessage = isValidOutputMessage(); 187 if(!isValidOutputMessage) { 188 updateMessagePanel(); 189 return; 190 } 191 192 boolean isValidFaultMessage = isValidFaultMessage(); 193 if(!isValidFaultMessage) { 194 updateMessagePanel(); 195 return; 196 } 197 198 this.mErrorMessage = null; 199 updateMessagePanel(); 200 201 } 202 203 204 private boolean isValidInputMessage() { 205 boolean valid = true; 206 207 String messageName = this.operationConfigurationPanel1.getInputMessageName(); 208 if(messageName != null) { 209 if(!isExistingMessage(messageName)) { 211 valid = isValidName(messageName); 212 } 213 } 214 return valid; 215 } 216 217 private boolean isValidOutputMessage() { 218 boolean valid = true; 219 220 String messageName = this.operationConfigurationPanel1.getOutputMessageName(); 221 if(messageName != null) { 222 if(!isExistingMessage(messageName)) { 224 valid = isValidName(messageName); 225 } 226 } 227 return valid; 228 } 229 230 231 private boolean isValidFaultMessage() { 232 boolean valid = true; 233 234 String messageName = this.operationConfigurationPanel1.getFaultMessageName(); 235 if(messageName != null) { 236 if(!isExistingMessage(messageName)) { 238 valid = isValidName(messageName); 239 } 240 } 241 return valid; 242 } 243 244 245 private boolean isExistingMessage(String messageName) { 246 return existingMeessages.contains(messageName); 247 } 248 249 private void updateMessagePanel() { 250 if(this.mErrorMessage != null) { 251 commonMessagePanel1.setErrorMessage(mErrorMessage); 252 if(this.mDD != null) { 253 this.mDD.setValid(false); 254 } 255 } else { 256 commonMessagePanel1.setMessage(""); 257 if(this.mDD != null) { 258 this.mDD.setValid(true); 259 } 260 } 261 } 262 263 264 class OperationNameTextChangeListener implements DocumentListener { 265 266 public void changedUpdate(DocumentEvent e) { 267 validateAll(); 268 } 269 270 public void insertUpdate(DocumentEvent e) { 271 validateAll(); 272 } 273 274 public void removeUpdate(DocumentEvent e) { 275 validateAll(); 276 } 277 278 } 279 280 class MessageNameTextChangeListener implements DocumentListener { 281 282 public void changedUpdate(DocumentEvent e) { 283 validateAll(); 284 } 285 286 public void insertUpdate(DocumentEvent e) { 287 validateAll(); 288 } 289 290 public void removeUpdate(DocumentEvent e) { 291 validateAll(); 292 } 293 294 295 } 296 297 298 private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel commonMessagePanel1; 300 private org.netbeans.modules.xml.wsdl.ui.view.OperationConfigurationPanel operationConfigurationPanel1; 301 303 } 304 | Popular Tags |