Search in sources :

Example 86 with XSDSimpleTypeDefinition

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");
            }
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Bundle(org.osgi.framework.Bundle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) URL(java.net.URL) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 87 with XSDSimpleTypeDefinition

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) {
    }
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition)

Example 88 with XSDSimpleTypeDefinition

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);
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 89 with XSDSimpleTypeDefinition

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);
            }
        }
    }
}
Also used : XSDTypeReferenceEditManager(org.eclipse.wst.xsd.ui.internal.editor.XSDTypeReferenceEditManager) ComponentSpecification(org.eclipse.wst.common.ui.internal.search.dialogs.ComponentSpecification) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ComponentReferenceEditManager(org.eclipse.wst.xsd.ui.internal.adt.edit.ComponentReferenceEditManager) IEditorPart(org.eclipse.ui.IEditorPart) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 90 with XSDSimpleTypeDefinition

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;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11