Search in sources :

Example 81 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDRedefineAdapter method notifyChanged.

public void notifyChanged(final Notification msg) {
    class CategoryNotification extends NotificationImpl {

        protected Object category;

        public CategoryNotification(Object category) {
            super(msg.getEventType(), msg.getOldValue(), msg.getNewValue(), msg.getPosition());
            this.category = category;
        }

        public Object getNotifier() {
            return category;
        }

        public Object getFeature() {
            return msg.getFeature();
        }
    }
    if (children == null) {
        getChildren();
    }
    Object newValue = msg.getNewValue();
    Object oldValue = msg.getOldValue();
    if (XSDPackage.eINSTANCE.getXSDRedefine_Contents() == msg.getFeature()) {
        if ((newValue instanceof XSDAttributeGroupDefinition) || oldValue instanceof XSDAttributeGroupDefinition) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.ATTRIBUTES);
            Assert.isTrue(adapter != null);
            List list = getCategoryChildren(CategoryAdapter.ATTRIBUTES);
            adapter.setChildren(list);
            adapter.setAllChildren(list);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if ((newValue instanceof XSDComplexTypeDefinition || newValue instanceof XSDSimpleTypeDefinition) || (oldValue instanceof XSDComplexTypeDefinition || oldValue instanceof XSDSimpleTypeDefinition)) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.TYPES);
            Assert.isTrue(adapter != null);
            List types = getCategoryChildren(CategoryAdapter.TYPES);
            adapter.setChildren(types);
            adapter.setAllChildren(types);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if (newValue instanceof XSDModelGroupDefinition || oldValue instanceof XSDModelGroupDefinition) {
            CategoryAdapter adapter = getCategory(CategoryAdapter.GROUPS);
            Assert.isTrue(adapter != null);
            List list = getCategoryChildren(CategoryAdapter.GROUPS);
            adapter.setChildren(list);
            adapter.setAllChildren(list);
            if (adapter.getModel() instanceof XSDSchemaAdapter) {
                XSDSchemaAdapter schemaAdapter = (XSDSchemaAdapter) adapter.getModel();
                schemaAdapter.notifyChanged(msg);
            }
            notifyListeners(new CategoryNotification(adapter), adapter.getText());
            return;
        } else if (msg.getFeature() == XSDPackage.eINSTANCE.getXSDSchema_Annotations()) {
            return;
        }
    }
    super.notifyChanged(msg);
}
Also used : NotificationImpl(org.eclipse.emf.common.notify.impl.NotificationImpl) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) ArrayList(java.util.ArrayList) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 82 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDImpl method getEnumeratedValuesForType.

public static String[] getEnumeratedValuesForType(XSDTypeDefinition type) {
    List result = new ArrayList();
    // type with simple content
    if (type instanceof XSDComplexTypeDefinition) {
        type = ((XSDComplexTypeDefinition) type).getSimpleType();
    }
    if (type instanceof XSDSimpleTypeDefinition) {
        if (TYPE_NAME_BOOLEAN.equals(type.getName()) && type.getSchema().getSchemaForSchema() == type.getSchema()) {
            result.add(TYPE_VALUE_TRUE);
            result.add(TYPE_VALUE_FALSE);
        } else {
            // Simple types can be one of: atomic, list or union.
            int varietyType = ((XSDSimpleTypeDefinition) type).getVariety().getValue();
            switch(varietyType) {
                case XSDVariety.ATOMIC:
                    {
                        XSDTypeDefinition baseType = type.getBaseType();
                        if (baseType != null && !(type.getSchema().getSchemaForSchema() == baseType.getSchema())) {
                            getEnumeratedValuesForSimpleType(baseType, result);
                            // If there are none, then we should be able to add the enumerations for the current type
                            if (result.isEmpty()) {
                                getEnumeratedValuesForSimpleType(type, result);
                            } else // There are enumerations on the base type
                            {
                                // If there are enumerations on the current type also, then we should just add the ones from the current type
                                // since we're restricting the values
                                List enumerationsForCurrentType = new ArrayList();
                                getEnumeratedValuesForSimpleType(type, enumerationsForCurrentType);
                                if (!enumerationsForCurrentType.isEmpty()) {
                                    result.clear();
                                    result.addAll(enumerationsForCurrentType);
                                }
                            // Otherwise, just use the enumerations on the base type
                            }
                        } else {
                            getEnumeratedValuesForSimpleType(type, result);
                        }
                    }
                    break;
                case XSDVariety.LIST:
                    {
                        XSDSimpleTypeDefinition itemTypeDefinition = ((XSDSimpleTypeDefinition) type).getItemTypeDefinition();
                        String[] values = getEnumeratedValuesForType(itemTypeDefinition);
                        for (int j = 0; j < values.length; j++) {
                            if (result.indexOf(values[j]) == -1) {
                                result.add(values[j]);
                            }
                        }
                    }
                    break;
                case XSDVariety.UNION:
                    {
                        List memberTypes = ((XSDSimpleTypeDefinition) type).getMemberTypeDefinitions();
                        if (memberTypes != null && memberTypes.size() > 0) {
                            Iterator i = memberTypes.iterator();
                            while (i.hasNext()) {
                                XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) i.next();
                                String[] values = getEnumeratedValuesForType(simpleType);
                                for (int j = 0; j < values.length; j++) {
                                    if (result.indexOf(values[j]) == -1) {
                                        result.add(values[j]);
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        }
    }
    String[] array = new String[result.size()];
    result.toArray(array);
    return array;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDConstraint(org.eclipse.xsd.XSDConstraint) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 83 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDComplexTypeDefinitionAdapter method getActions.

public String[] getActions(Object object) {
    List list = new ArrayList();
    Object schema = getEditorSchema();
    XSDComplexTypeDefinition complexType = getXSDComplexTypeDefinition();
    Object contentType = getContentType();
    XSDDerivationMethod derivation = complexType.getDerivationMethod();
    if (contentType instanceof XSDSimpleTypeDefinition) {
        List fields = getFields();
        boolean hasSimpleContentAttributes = false;
        for (Iterator iterator = fields.iterator(); iterator.hasNext(); ) {
            Object field = iterator.next();
            // We have attributes, so we need to add the compartment for housing the attributes
            if (field instanceof XSDAttributeDeclarationAdapter) {
                hasSimpleContentAttributes = true;
                break;
            }
        }
        if (hasSimpleContentAttributes || XSDDerivationMethod.EXTENSION_LITERAL.equals(derivation)) {
            list.add(AddXSDAttributeDeclarationAction.ID);
        } else if (XSDDerivationMethod.RESTRICTION_LITERAL.equals(derivation)) {
            list.add(AddXSDEnumerationFacetAction.ID);
        }
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(SetBaseTypeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(DeleteAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
    } else {
        list.add(AddXSDElementAction.ID);
        list.add(AddXSDElementAction.REF_ID);
        list.add(AddXSDAnyElementAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(AddXSDAttributeDeclarationAction.ID);
        list.add(AddXSDAttributeDeclarationAction.REF_ID);
        list.add(AddXSDAttributeGroupDefinitionAction.REF_ID);
        list.add(AddXSDAnyAttributeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(AddXSDModelGroupAction.SEQUENCE_ID);
        list.add(AddXSDModelGroupAction.CHOICE_ID);
        list.add(AddXSDModelGroupAction.ALL_ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(DeleteAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
        list.add(SetBaseTypeAction.ID);
        list.add(BaseSelectionAction.SEPARATOR_ID);
    }
    if (complexType.getSchema() == schema) {
        XSDConcreteComponent container = complexType.getContainer();
        if (container == schema || container instanceof XSDRedefine) {
            list.add(SetInputToGraphView.ID);
        }
    } else {
        list.add(OpenInNewEditor.ID);
    }
    list.add(BaseSelectionAction.SEPARATOR_ID);
    list.add(ShowPropertiesViewAction.ID);
    String[] result = new String[list.size()];
    list.toArray(result);
    return result;
}
Also used : XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDDerivationMethod(org.eclipse.xsd.XSDDerivationMethod) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Example 84 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class XSDComplexTypeDefinitionAdapter method getChildren.

public ITreeElement[] getChildren() {
    XSDComplexTypeDefinition xsdComplexTypeDefinition = getXSDComplexTypeDefinition();
    List list = new ArrayList();
    // Add attributes
    for (Iterator i = xsdComplexTypeDefinition.getAttributeContents().iterator(); i.hasNext(); ) {
        Object obj = i.next();
        if (obj instanceof XSDAttributeUse) {
            list.add(((XSDAttributeUse) obj).getAttributeDeclaration());
        } else if (obj instanceof XSDAttributeGroupDefinition) {
            getAttributeUses((XSDAttributeGroupDefinition) obj, list);
        }
    }
    // Add enumerations
    boolean canHaveEnumerations = xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition && XSDDerivationMethod.RESTRICTION_LITERAL.equals(xsdComplexTypeDefinition.getDerivationMethod());
    if (canHaveEnumerations) {
        Object contentType = getContentType();
        if (contentType != null) {
            for (Iterator iterator = ((XSDSimpleTypeDefinition) contentType).getEnumerationFacets().iterator(); iterator.hasNext(); ) {
                XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) iterator.next();
                list.add(enumerationFacet);
            }
        }
    }
    XSDWildcard anyAttr = xsdComplexTypeDefinition.getAttributeWildcard();
    if (anyAttr != null)
        list.add(anyAttr);
    // get immediate XSD Model Group of this complex type
    if (xsdComplexTypeDefinition.getContent() != null) {
        XSDComplexTypeContent xsdComplexTypeContent = xsdComplexTypeDefinition.getContent();
        if (xsdComplexTypeContent instanceof XSDParticle) {
            XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
            if (particleContent instanceof XSDModelGroup) {
                list.add(particleContent);
            }
        }
    }
    // get inherited XSD Model Group of this complex type
    boolean showInheritedContent = XSDEditorPlugin.getPlugin().getShowInheritedContent();
    if (showInheritedContent) {
        XSDTypeDefinition typeDef = xsdComplexTypeDefinition.getBaseTypeDefinition();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition baseCT = (XSDComplexTypeDefinition) typeDef;
            if (baseCT.getTargetNamespace() != null && !baseCT.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001)) {
                if (baseCT.getContent() != null) {
                    XSDComplexTypeContent xsdComplexTypeContent = baseCT.getContent();
                    if (xsdComplexTypeContent instanceof XSDParticle) {
                        XSDParticleContent particleContent = ((XSDParticle) xsdComplexTypeContent).getContent();
                        if (particleContent instanceof XSDModelGroup) {
                            list.add(particleContent);
                        }
                    }
                }
            }
        }
    }
    List adapterList = new ArrayList();
    populateAdapterList(list, adapterList);
    return (ITreeElement[]) adapterList.toArray(new ITreeElement[0]);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) ArrayList(java.util.ArrayList) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) ITreeElement(org.eclipse.wst.xsd.ui.internal.adt.outline.ITreeElement) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 85 with XSDSimpleTypeDefinition

use of org.eclipse.xsd.XSDSimpleTypeDefinition in project webtools.sourceediting by eclipse.

the class TypesHelper method getUserSimpleTypeNamesList.

public java.util.List getUserSimpleTypeNamesList() {
    Vector items = new Vector();
    if (xsdSchema != null) {
        updateExternalImportGlobals();
        Iterator i = xsdSchema.getTypeDefinitions().iterator();
        while (i.hasNext()) {
            XSDTypeDefinition typeDefinition = (XSDTypeDefinition) i.next();
            if (typeDefinition instanceof XSDSimpleTypeDefinition) {
                items.addAll(getPrefixedNames(typeDefinition.getTargetNamespace(), typeDefinition.getName()));
            }
        }
        items = (Vector) sortList(items);
    }
    return items;
}
Also used : XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) Vector(java.util.Vector) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

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