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.schema.model.Schema; 26 import org.netbeans.modules.xml.schema.model.SchemaModel; 27 import org.netbeans.modules.xml.wsdl.model.Definitions; 28 import org.netbeans.modules.xml.wsdl.model.Types; 29 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 30 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 31 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema; 32 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.UIUtilities; 33 import org.netbeans.modules.xml.wsdl.ui.view.ImportSchemaCustomizer; 34 import org.openide.DialogDescriptor; 35 import org.openide.DialogDisplayer; 36 import org.openide.util.NbBundle; 37 import org.openide.util.datatransfer.NewType; 38 39 44 public class ImportSchemaNewType extends NewType { 45 46 private WSDLComponent component; 47 48 53 public ImportSchemaNewType(WSDLComponent component) { 54 this.component = component; 55 } 56 57 @Override 58 public String getName() { 59 return NbBundle.getMessage(ImportSchemaNewType.class, 60 "LBL_NewType_ImportSchema"); 61 } 62 63 @Override 64 public void create() throws IOException { 65 WSDLModel model = component.getModel(); 67 Definitions def = model.getDefinitions(); 68 model.startTransaction(); 69 Types types = def.getTypes(); 70 if (types == null) { 71 types = model.getFactory().createTypes(); 72 } 73 Schema schema = null; 74 String tns = def.getTargetNamespace(); 75 if (tns != null) { 76 Collection <Schema> schemas = types.getSchemas(); 77 if (schemas != null) { 78 for (Schema s : schemas) { 79 if (s.getTargetNamespace() != null && s.getTargetNamespace().equals(tns)) { 80 schema = s; 81 break; 82 } 83 } 84 } 85 } 86 WSDLSchema wsdlSchema = null; 87 if (schema == null) { 88 wsdlSchema = model.getFactory().createWSDLSchema(); 89 SchemaModel schemaModel = wsdlSchema.getSchemaModel(); 90 schema = schemaModel.getSchema(); 91 schema.setTargetNamespace(model.getDefinitions().getTargetNamespace()); 92 } 93 94 ImportSchemaCustomizer customizer = new ImportSchemaCustomizer(schema, model); 98 DialogDescriptor descriptor = UIUtilities.getCreatorDialog( 99 customizer, NbBundle.getMessage(ImportSchemaNewType.class, 100 "LBL_NewType_ImportCustomizer"), true); 101 descriptor.setValid(false); 102 Object result = DialogDisplayer.getDefault().notify(descriptor); 103 104 if (result == DialogDescriptor.OK_OPTION) { 106 if (def.getTypes() == null) { 109 def.setTypes(types); 110 } 111 if (wsdlSchema != null) { 112 types.addExtensibilityElement(wsdlSchema); 113 } 114 } 115 model.endTransaction(); 117 } 118 } 119 | Popular Tags |