Search in sources :

Example 16 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse 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 17 with XSDAttributeUse

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

the class XSDVisitorForFields method visitAttributeGroupDefinition.

public void visitAttributeGroupDefinition(XSDAttributeGroupDefinition attributeGroup) {
    for (Iterator it = attributeGroup.getContents().iterator(); it.hasNext(); ) {
        Object o = it.next();
        if (o instanceof XSDAttributeUse) {
            XSDAttributeUse attributeUse = (XSDAttributeUse) o;
            concreteComponentList.add(attributeUse.getAttributeDeclaration());
            thingsWeNeedToListenTo.add(attributeUse.getAttributeDeclaration());
        } else if (o instanceof XSDAttributeGroupDefinition) {
            XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) o;
            thingsWeNeedToListenTo.add(attrGroup);
            if (attrGroup.isAttributeGroupDefinitionReference()) {
                attrGroup = attrGroup.getResolvedAttributeGroupDefinition();
                visitAttributeGroupDefinition(attrGroup);
            }
        }
    }
    XSDWildcard anyAttribute = attributeGroup.getAttributeWildcardContent();
    if (anyAttribute != null) {
        concreteComponentList.add(anyAttribute);
        thingsWeNeedToListenTo.add(anyAttribute);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 18 with XSDAttributeUse

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

the class AddXSDAttributeDeclarationAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
        if (selection instanceof XSDAttributeDeclaration) {
            selection = ((XSDAttributeDeclaration) selection).getContainer();
        }
    }
    AddXSDAttributeDeclarationCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDAttributeUse) {
        XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDAttributeGroupDefinition group = null;
        for (parent = xsdAttributeUse.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                group = (XSDAttributeGroupDefinition) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = ct.getAttributeContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, ct, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            XSDAttributeUse sel = (XSDAttributeUse) selection;
            int index = group.eContents().indexOf(sel);
            command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, group, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    } else if (selection instanceof XSDAttributeGroupDefinition) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDAttributeGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDAttributeDeclarationCommand(Messages._UI_ACTION_ADD_ATTRIBUTE, (XSDSchema) selection);
        getCommandStack().execute(command);
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : AddXSDAttributeDeclarationCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDAttributeDeclarationCommand) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 19 with XSDAttributeUse

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

the class AddXSDAttributeGroupDefinitionCommand method updateNames.

private void updateNames(XSDComplexTypeDefinition ct) {
    Iterator iter = ct.getAttributeContents().iterator();
    while (iter.hasNext()) {
        Object obj = iter.next();
        if (obj instanceof XSDAttributeUse) {
            XSDAttributeUse use = (XSDAttributeUse) obj;
            XSDAttributeDeclaration attr = use.getAttributeDeclaration();
            String attrName = attr.getName();
            if (attrName != null) {
                names.add(attrName);
            }
        }
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 20 with XSDAttributeUse

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

the class AddXSDElementAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        selection = ((XSDBaseAdapter) selection).getTarget();
    }
    AddXSDElementCommand command = null;
    if (selection instanceof XSDComplexTypeDefinition) {
        command = new AddXSDElementCommand(getText(), (XSDComplexTypeDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDModelGroupDefinition) {
        command = new AddXSDElementCommand(getText(), (XSDModelGroupDefinition) selection);
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDSchema) {
        command = new AddXSDElementCommand(getText(), (XSDSchema) selection);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDModelGroup) {
        XSDModelGroup modelGroup = (XSDModelGroup) selection;
        XSDConcreteComponent component = modelGroup.getContainer();
        XSDComplexTypeDefinition ct = null;
        while (component != null) {
            if (component instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) component;
                break;
            }
            component = component.getContainer();
        }
        if (ct != null) {
            command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection, ct);
        } else {
            command = new AddXSDElementCommand(getText(), (XSDModelGroup) selection);
        }
        command.setReference(isReference);
        getCommandStack().execute(command);
    } else if (selection instanceof XSDElementDeclaration || selection instanceof XSDAttributeUse) {
        XSDConcreteComponent xsdConcreteComponent = (XSDConcreteComponent) selection;
        XSDConcreteComponent parent = null;
        XSDComplexTypeDefinition ct = null;
        XSDModelGroupDefinition group = null;
        XSDModelGroupImpl ctGroup = null;
        for (parent = xsdConcreteComponent.getContainer(); parent != null; ) {
            if (parent instanceof XSDComplexTypeDefinition) {
                ct = (XSDComplexTypeDefinition) parent;
                break;
            } else if (parent instanceof XSDModelGroupDefinition) {
                group = (XSDModelGroupDefinition) parent;
                break;
            } else if (parent instanceof XSDModelGroupImpl) {
                ctGroup = (XSDModelGroupImpl) parent;
                break;
            }
            parent = parent.getContainer();
        }
        if (ct != null) {
            command = new AddXSDElementCommand(getText(), ct);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (ctGroup != null) {
            XSDElementDeclaration sel = (XSDElementDeclaration) selection;
            int index = ctGroup.getContents().indexOf(sel.eContainer());
            command = new AddXSDElementCommand(getText(), ctGroup, getId(), index);
            command.setReference(isReference);
            getCommandStack().execute(command);
        } else if (group != null) {
            command = new AddXSDElementCommand(getText(), group);
            command.setReference(isReference);
            getCommandStack().execute(command);
        }
    }
    if (command != null) {
        addedComponent = command.getAddedComponent();
        Adapter adapter = XSDAdapterFactory.getInstance().adapt(addedComponent);
        selectAddedComponent(adapter);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AddXSDElementCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDElementCommand) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDModelGroupImpl(org.eclipse.xsd.impl.XSDModelGroupImpl)

Aggregations

XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)28 Iterator (java.util.Iterator)17 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)14 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)14 XSDParticle (org.eclipse.xsd.XSDParticle)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)11 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)10 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)9 XSDSchema (org.eclipse.xsd.XSDSchema)9 List (java.util.List)8 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 ArrayList (java.util.ArrayList)7 EList (org.eclipse.emf.common.util.EList)7 Element (org.w3c.dom.Element)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)6