Search in sources :

Example 6 with XSDAttributeUse

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

the class XSDVisitorForFields method visitComplexTypeDefinition.

public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) {
    if (type.getAttributeContents() != null) {
        for (Iterator iter = type.getAttributeContents().iterator(); iter.hasNext(); ) {
            XSDAttributeGroupContent attrGroupContent = (XSDAttributeGroupContent) iter.next();
            if (attrGroupContent instanceof XSDAttributeUse) {
                XSDAttributeUse attrUse = (XSDAttributeUse) attrGroupContent;
                visitAttributeDeclaration(attrUse.getContent());
            // if (attrUse.getAttributeDeclaration() != attrUse.getContent())
            // {
            // visitAttributeDeclaration(attrUse.getContent());
            // }
            // else
            // {
            // thingsWeNeedToListenTo.add(attrUse.getAttributeDeclaration());
            // concreteComponentList.add(attrUse.getAttributeDeclaration());
            // }
            } else if (attrGroupContent instanceof XSDAttributeGroupDefinition) {
                XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) attrGroupContent;
                thingsWeNeedToListenTo.add(attrGroup);
                if (attrGroup.isAttributeGroupDefinitionReference()) {
                    attrGroup = attrGroup.getResolvedAttributeGroupDefinition();
                    visitAttributeGroupDefinition(attrGroup);
                }
            }
        }
    }
    if (type.getAttributeWildcard() != null) {
        thingsWeNeedToListenTo.add(type.getAttributeWildcard());
        concreteComponentList.add(type.getAttributeWildcard());
    }
    super.visitComplexTypeDefinition(type);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 7 with XSDAttributeUse

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

the class AddXSDAttributeDeclarationCommand method execute.

public void execute() {
    XSDAttributeDeclaration attribute = XSDFactory.eINSTANCE.createXSDAttributeDeclaration();
    try {
        if (parent == null) {
            beginRecording(xsdComplexTypeDefinition.getElement());
            if (!isReference) {
                // $NON-NLS-1$
                attribute.setName(getNewName(nameToAdd == null ? "NewAttribute" : nameToAdd));
                // $NON-NLS-1$
                attribute.setTypeDefinition(xsdComplexTypeDefinition.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
            } else {
                attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(xsdComplexTypeDefinition.getSchema()));
            }
            XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse();
            attributeUse.setAttributeDeclaration(attribute);
            attributeUse.setContent(attribute);
            if (xsdComplexTypeDefinition.getAttributeContents() != null) {
                index = getInsertionIndex();
                if (index >= 0 && index < xsdComplexTypeDefinition.getAttributeContents().size()) {
                    xsdComplexTypeDefinition.getAttributeContents().add(index, attributeUse);
                } else {
                    xsdComplexTypeDefinition.getAttributeContents().add(attributeUse);
                }
                formatChild(xsdComplexTypeDefinition.getElement());
            }
        } else {
            beginRecording(parent.getElement());
            if (parent instanceof XSDSchema) {
                XSDSchema xsdSchema = (XSDSchema) parent;
                attribute = createGlobalXSDAttributeDeclaration(xsdSchema);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                if (!isReference) {
                    // $NON-NLS-1$
                    attribute.setTypeDefinition(parent.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string"));
                    List list = new ArrayList();
                    Iterator i = ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getAttributeUses().iterator();
                    while (i.hasNext()) {
                        XSDAttributeUse use = (XSDAttributeUse) i.next();
                        list.add(use.getAttributeDeclaration());
                    }
                    // $NON-NLS-1$
                    attribute.setName(XSDCommonUIUtils.createUniqueElementName("NewAttribute", list));
                } else {
                    attribute.setResolvedAttributeDeclaration(setGlobalAttributeReference(parent.getSchema()));
                }
                XSDAttributeUse attributeUse = XSDFactory.eINSTANCE.createXSDAttributeUse();
                attributeUse.setAttributeDeclaration(attribute);
                attributeUse.setContent(attribute);
                index = getInsertionIndex();
                if (index >= 0 && index < (((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().size())) {
                    ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(index, attributeUse);
                } else {
                    ((XSDAttributeGroupDefinition) parent).getResolvedAttributeGroupDefinition().getContents().add(attributeUse);
                }
                formatChild(parent.getElement());
            }
        }
    } finally {
        endRecording();
    }
    addedXSDConcreteComponent = attribute;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 8 with XSDAttributeUse

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

the class XSDVisitor method visitAttributeGroupDefinition.

public void visitAttributeGroupDefinition(XSDAttributeGroupDefinition attributeGroup) {
    if (attributeGroup.getAttributeUses() != null) {
        for (Iterator iter = attributeGroup.getAttributeUses().iterator(); iter.hasNext(); ) {
            XSDAttributeUse attrUse = (XSDAttributeUse) iter.next();
            visitAttributeDeclaration(attrUse.getContent());
        }
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) Iterator(java.util.Iterator)

Example 9 with XSDAttributeUse

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

the class XSDVisitor method visitComplexTypeDefinition.

public void visitComplexTypeDefinition(XSDComplexTypeDefinition type) {
    XSDComplexTypeContent complexContent = type.getContent();
    if (complexContent != null) {
        if (complexContent instanceof XSDSimpleTypeDefinition) {
            visitSimpleTypeDefinition((XSDSimpleTypeDefinition) complexContent);
        } else if (complexContent instanceof XSDParticle) {
            visitParticle((XSDParticle) complexContent);
        }
    }
    if (type.getAttributeContents() != null) {
        for (Iterator iter = type.getAttributeContents().iterator(); iter.hasNext(); ) {
            XSDAttributeGroupContent attrGroupContent = (XSDAttributeGroupContent) iter.next();
            if (attrGroupContent instanceof XSDAttributeUse) {
                XSDAttributeUse attrUse = (XSDAttributeUse) attrGroupContent;
                visitAttributeDeclaration(attrUse.getContent());
            } else if (attrGroupContent instanceof XSDAttributeGroupDefinition) {
                visitAttributeGroupDefinition((XSDAttributeGroupDefinition) attrGroupContent);
            }
        }
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Iterator(java.util.Iterator) XSDParticle(org.eclipse.xsd.XSDParticle) XSDAttributeGroupContent(org.eclipse.xsd.XSDAttributeGroupContent) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 10 with XSDAttributeUse

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

the class CreateElementAction method run.

/*
   * @see IAction#run()
   */
public void run() {
    beginRecording(getDescription());
    final Element child = createAndAddNewChildElement();
    endRecording();
    if (selectionProvider != null) {
        final XSDConcreteComponent comp = xsdSchema.getCorrespondingComponent(child);
        // selectionProvider.setSelection(new StructuredSelection(comp));
        Runnable runnable = new Runnable() {

            public void run() {
                if (comp instanceof XSDAttributeDeclaration) {
                    if (((XSDAttributeDeclaration) comp).getContainer() instanceof XSDAttributeUse) {
                        if (comp.getContainer().getContainer() instanceof XSDAttributeGroupDefinition) {
                            selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                        } else if (comp.getContainer().getContainer() instanceof XSDComplexTypeDefinition) {
                            if (XSDDOMHelper.inputEquals(child, XSDConstants.ATTRIBUTE_ELEMENT_TAG, true)) {
                                selectionProvider.setSelection(new StructuredSelection(comp.getContainer()));
                            } else {
                                selectionProvider.setSelection(new StructuredSelection(comp));
                            }
                        } else {
                            selectionProvider.setSelection(new StructuredSelection(comp));
                        }
                    } else {
                        selectionProvider.setSelection(new StructuredSelection(comp));
                    }
                } else {
                    selectionProvider.setSelection(new StructuredSelection(comp));
                }
                if (comp instanceof XSDNamedComponent) {
                    if (sourceContext instanceof AbstractEditPartViewer) {
                    // AbstractEditPartViewer viewer = (AbstractEditPartViewer)sourceContext;
                    // Object obj = viewer.getSelectedEditParts().get(0);
                    // if (obj instanceof GraphicalEditPart)
                    // {
                    // if (obj instanceof ElementDeclarationEditPart)
                    // {
                    // XSDElementDeclaration elem = ((ElementDeclarationEditPart)obj).getXSDElementDeclaration();
                    // if (!elem.isElementDeclarationReference())
                    // {
                    // ((ElementDeclarationEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ModelGroupDefinitionEditPart)
                    // {
                    // XSDModelGroupDefinition group = ((ModelGroupDefinitionEditPart)obj).getXSDModelGroupDefinition();
                    // if (!group.isModelGroupDefinitionReference())
                    // {
                    // ((ModelGroupDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof ComplexTypeDefinitionEditPart)
                    // {
                    // XSDComplexTypeDefinition ct = ((ComplexTypeDefinitionEditPart)obj).getXSDComplexTypeDefinition();
                    // if (ct.getName() != null)
                    // {
                    // ((ComplexTypeDefinitionEditPart)obj).doEditName();
                    // }
                    // }
                    // else if (obj instanceof TopLevelComponentEditPart)
                    // {
                    // ((TopLevelComponentEditPart)obj).doEditName();
                    // }
                    // }
                    }
                }
            }
        };
        Display.getDefault().timerExec(50, runnable);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) Element(org.w3c.dom.Element) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AbstractEditPartViewer(org.eclipse.gef.ui.parts.AbstractEditPartViewer) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

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