use of com.amalto.workbench.dialogs.ComplexTypeInputDialog in project tmdm-studio-se by Talend.
the class XSDNewComplexTypeDefinition method doAction.
public IStatus doAction() {
List<XSDComplexTypeDefinition> list = new ArrayList<XSDComplexTypeDefinition>();
EList<XSDTypeDefinition> types = schema.getTypeDefinitions();
for (XSDTypeDefinition type : types) {
if (type instanceof XSDComplexTypeDefinition)
list.add((XSDComplexTypeDefinition) type);
}
// $NON-NLS-1$
dialog = new ComplexTypeInputDialog(this, page.getSite().getShell(), "", schema, null, list, false);
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return Status.CANCEL_STATUS;
}
XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
XSDModelGroup group = factory.createXSDModelGroup();
XSDParticle subParticle = null;
XSDElementDeclaration subElement = null;
subElement = factory.createXSDElementDeclaration();
// $NON-NLS-1$
subElement.setName("subelement");
// $NON-NLS-1$
subElement.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));
subParticle = factory.createXSDParticle();
subParticle.unsetMaxOccurs();
subParticle.unsetMinOccurs();
subParticle.setContent(subElement);
subParticle.updateElement();
if (isChoice)
group.setCompositor(XSDCompositor.CHOICE_LITERAL);
else if (isAll)
group.setCompositor(XSDCompositor.ALL_LITERAL);
else
group.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
group.getContents().add(0, subParticle);
group.updateElement();
XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
// complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
XSDTypeDefinition superType = null;
for (XSDTypeDefinition type : list) {
if (type.getName().equals(superTypeName)) {
superType = type;
break;
}
}
complexType.setName(typeName);
if (superType != null) {
if (!checkParentType(superType, group)) {
return Status.CANCEL_STATUS;
}
complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
complexType.setBaseTypeDefinition(superType);
}
if (isAbstract)
complexType.setAbstract(isAbstract);
else
complexType.unsetAbstract();
schema.getContents().add(complexType);
complexType.updateElement();
// add the group
XSDParticle groupParticle = factory.createXSDParticle();
groupParticle.unsetMaxOccurs();
groupParticle.unsetMinOccurs();
groupParticle.setContent(group);
groupParticle.updateElement();
complexType.setContent(groupParticle);
complexType.updateElement();
page.refresh();
page.markDirty();
return Status.OK_STATUS;
}
Aggregations