1 19 20 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 25 import org.netbeans.modules.xml.wsdl.model.Binding; 26 import org.netbeans.modules.xml.wsdl.model.BindingFault; 27 import org.netbeans.modules.xml.wsdl.model.BindingInput; 28 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 29 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 30 import org.netbeans.modules.xml.wsdl.model.Fault; 31 import org.netbeans.modules.xml.wsdl.model.Input; 32 import org.netbeans.modules.xml.wsdl.model.Operation; 33 import org.netbeans.modules.xml.wsdl.model.Output; 34 import org.netbeans.modules.xml.wsdl.model.PortType; 35 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 36 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 37 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility; 38 import org.netbeans.modules.xml.wsdl.ui.view.BindingOperationView; 39 import org.openide.DialogDescriptor; 40 import org.openide.DialogDisplayer; 41 import org.openide.ErrorManager; 42 import org.openide.NotifyDescriptor; 43 import org.openide.util.NbBundle; 44 import org.openide.util.datatransfer.NewType; 45 46 public class BindingOperationNewType extends NewType { 47 private WSDLComponent mDef = null; 48 49 public BindingOperationNewType(WSDLComponent def) { 50 mDef = def; 51 } 52 53 54 @Override 55 public String getName() { 56 return NbBundle.getMessage(BindingOperationNewType.class, "LBL_NewType_BindingOperation"); 57 } 58 59 60 @Override 61 public void create() throws IOException { 62 Binding binding = (Binding) mDef; 63 if(!isValidBinding(binding)) { 64 return; 65 } 66 67 PortType portType = binding.getType().get(); 68 Operation[] selectedOperations = null; 69 Collection <Operation> operations = Utility.getImplementableOperations(portType, binding); 71 if (operations != null && operations.size() == 1) { 72 selectedOperations = new Operation[]{operations.iterator().next()}; 73 } else { 74 BindingOperationView operationView = new BindingOperationView(operations); 75 76 DialogDescriptor dd = 77 new DialogDescriptor(operationView, 78 NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_SELECT_OPERATION") , 79 true, 80 DialogDescriptor.OK_CANCEL_OPTION, 81 DialogDescriptor.CANCEL_OPTION, 82 null); 83 84 if(DialogDisplayer.getDefault().notify(dd) == DialogDescriptor.OK_OPTION) { 85 selectedOperations = operationView.getSelectedOperations(); 86 } 87 } 88 if (selectedOperations != null && selectedOperations.length > 0) { 89 WSDLModel document = binding.getModel(); 90 document.startTransaction(); 91 for (Operation operation : selectedOperations) { 92 BindingOperation bindingOperation = document.getFactory().createBindingOperation(); 93 if(operation != null) { 94 bindingOperation.setName(operation.getName()); 95 Input input = operation.getInput(); 96 Output output = operation.getOutput(); 97 Collection <Fault> faults = operation.getFaults(); 98 if(input != null) { 99 BindingInput bIn = document.getFactory().createBindingInput(); 100 if(input.getName() != null) { 101 bIn.setName(input.getName()); 102 } 103 bindingOperation.setBindingInput(bIn); 104 } 105 106 if(output != null) { 107 BindingOutput bOut = document.getFactory().createBindingOutput(); 108 if(output.getName() != null) { 109 bOut.setName(output.getName()); 110 } 111 bindingOperation.setBindingOutput(bOut); 112 } 113 114 if(faults != null) { 115 for (Fault fault : faults) { 116 BindingFault bFault = document.getFactory().createBindingFault(); 117 if(fault.getName() != null) { 118 bFault.setName(fault.getName()); 119 } 120 bindingOperation.addBindingFault(bFault); 121 } 122 123 } 124 } 125 binding.addBindingOperation(bindingOperation); 126 } 127 document.endTransaction(); 128 } 129 } 130 131 132 private boolean isValidBinding(Binding binding) { 133 boolean valid = false; 134 String message = null; 135 if(binding != null && binding.getType() != null) { 136 PortType portType = binding.getType().get(); 137 if(portType != null && portType.getOperations() != null && portType.getOperations().size() > 0) { 138 139 valid = true; 140 } else { 141 valid = false; 142 message = NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_LONG_DESCRIPTION_MISSING_OPERATION_IN_BINDING_PORTTYPE"); 143 } 144 } else { 145 valid = false; 146 message = NbBundle.getMessage(BindingOperationNewType.class, "AddBindingOperationView_LONG_DESCRIPTION1_MISSING_PORTTYPE_IN_BINDING"); 147 } 148 149 if(!valid) { 150 151 NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE); 152 DialogDisplayer.getDefault().notify(nd); 153 } 154 155 return valid; 156 } 157 } 158 | Popular Tags |