use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class BugFixesTest method testEnumerationsInSimpleTypeHierarchy.
public void testEnumerationsInSimpleTypeHierarchy() {
// See bug 424276
Bundle bundle = Platform.getBundle(XSDCoreTestsPlugin.PLUGIN_ID);
// $NON-NLS-1$
URL url = bundle.getEntry("/testresources/samples/bugzilla424276.xsd");
CMDocument cmDocument = XSDImpl.buildCMDocument(url.toExternalForm());
assertNotNull(cmDocument);
XSDSchema xsdSchema = XSDImpl.buildXSDModel(url.toExternalForm());
// $NON-NLS-1$
assertNotNull("failed to build model for " + url.toExternalForm());
// $NON-NLS-1$
assertTrue("Number of types in the test schema is 8", xsdSchema.getTypeDefinitions().size() == 8);
for (Iterator<XSDTypeDefinition> types = xsdSchema.getTypeDefinitions().iterator(); types.hasNext(); ) {
XSDTypeDefinition type = types.next();
if (type instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) type;
// System.out.println(simpleType.getName());
if ("A".equals(simpleType.getName())) {
String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
assertEquals(1, enumeratedValuesForType.length);
assertEquals(enumeratedValuesForType[0], "01");
}
if ("B0".equals(simpleType.getName())) {
String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
assertEquals(1, enumeratedValuesForType.length);
assertEquals(enumeratedValuesForType[0], "01");
}
if ("C0".equals(simpleType.getName())) {
String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
assertEquals(2, enumeratedValuesForType.length);
assertEquals(enumeratedValuesForType[0], "01");
assertEquals(enumeratedValuesForType[1], "02");
}
if ("D0".equals(simpleType.getName())) {
String[] enumeratedValuesForType = XSDImpl.getEnumeratedValuesForType(simpleType);
assertEquals(4, enumeratedValuesForType.length);
assertEquals(enumeratedValuesForType[0], "01");
assertEquals(enumeratedValuesForType[1], "02");
assertEquals(enumeratedValuesForType[2], "03");
assertEquals(enumeratedValuesForType[3], "04");
}
}
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDFacetSection method init.
protected void init() {
hasMaxMinFacets = false;
try {
updateInput();
if (xsdSimpleTypeDefinition != null) {
isSimpleTypeRestriction = xsdSimpleTypeDefinition.getVariety().getValue() == XSDVariety.ATOMIC;
XSDSimpleTypeDefinition targetST = xsdSimpleTypeDefinition;
while (!XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001.equals(targetST.getTargetNamespace()) && targetST != null) {
targetST = targetST.getBaseTypeDefinition();
}
// $NON-NLS-1$
minLengthString = "";
// $NON-NLS-1$
maxLengthString = "";
if (// $NON-NLS-1$
targetST.getValidFacets().contains("length")) {
minLengthString = Messages._UI_LABEL_MINIMUM_LENGTH;
maxLengthString = Messages._UI_LABEL_MAXIMUM_LENGTH;
simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONSTRAINTS_ON_LENGTH_OF + targetST.getName();
isNumericBaseType = false;
hasMaxMinFacets = true;
} else if (// $NON-NLS-1$
targetST.getValidFacets().contains("maxInclusive")) {
simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONSTRAINTS_ON_VALUE_OF + targetST.getName();
minLengthString = Messages._UI_LABEL_MINIMUM_VALUE;
maxLengthString = Messages._UI_LABEL_MAXIMUM_VALUE;
isNumericBaseType = true;
hasMaxMinFacets = true;
} else {
// $NON-NLS-1$
simpleTypeModifierGroupTitle = Messages._UI_LABEL_CONTRAINTS_ON + (targetST != null ? targetST.getName() : "anyType");
}
}
} catch (Exception e) {
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method setInput.
public void setInput(IWorkbenchPart part, ISelection selection) {
super.setInput(part, selection);
setListenerEnabled(false);
if (input instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input;
hideHyperLink = !(simpleType.getContainer() instanceof XSDSchema);
}
// Don't have to call relayout() here
setListenerEnabled(true);
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class XSDSimpleTypeSection method fillTypesCombo.
private void fillTypesCombo() {
typesCombo.removeAll();
IEditorPart editor = getActiveEditor();
ComponentReferenceEditManager manager = (ComponentReferenceEditManager) editor.getAdapter(XSDTypeReferenceEditManager.class);
if (manager != null) {
ComponentSpecification[] items = manager.getQuickPicks();
typesCombo.add(Messages._UI_COMBO_BROWSE);
typesCombo.add(Messages._UI_COMBO_NEW);
for (int i = 0; i < items.length; i++) {
typesCombo.add(items[i].getName());
}
// Add the current Type of this attribute if needed
XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) input;
XSDTypeDefinition baseType = simpleType.getBaseType();
if (baseType != null && baseType.getQName() != null) {
// no prefix
String currentTypeName = baseType.getQName(xsdSchema);
ComponentSpecification ret = getComponentSpecFromQuickPickForValue(currentTypeName, manager);
if (// not in quickPick
ret == null && currentTypeName != null) {
typesCombo.add(currentTypeName);
}
}
}
}
use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.
the class AddXSDElementCommand method createXSDElementDeclarationForComplexType.
protected XSDParticle createXSDElementDeclarationForComplexType() {
// $NON-NLS-1$
XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
ArrayList usedAttributeNames = new ArrayList();
usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes(xsdComplexTypeDefinition));
usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes(xsdComplexTypeDefinition));
element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
usedAttributeNames));
element.setTypeDefinition(type);
XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
particle.setContent(element);
addedXSDConcreteComponent = element;
return particle;
}
Aggregations