Search in sources :

Example 56 with XSDParticle

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

the class AddXSDElementCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see org.eclipse.gef.commands.Command#execute()
   */
public void execute() {
    try {
        if (xsdSchema != null) {
            beginRecording(xsdSchema.getElement());
            XSDElementDeclaration element = createGlobalXSDElementDeclaration();
            // $NON-NLS-1$
            Text textNode = xsdSchema.getDocument().createTextNode("\n");
            xsdSchema.getElement().appendChild(textNode);
            xsdSchema.getContents().add(element);
            addedXSDConcreteComponent = element;
        } else if (xsdModelGroupDefinition != null) {
            beginRecording(xsdModelGroupDefinition.getElement());
            if (xsdModelGroup == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDParticle particle = factory.createXSDParticle();
                xsdModelGroup = factory.createXSDModelGroup();
                xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                particle.setContent(xsdModelGroup);
                xsdModelGroupDefinition.setModelGroup(xsdModelGroup);
            }
            xsdSchema = xsdModelGroupDefinition.getSchema();
            if (!isReference) {
                xsdModelGroup.getContents().add(createXSDElementDeclarationForModelGroupDefinitions());
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdModelGroupDefinition.getElement());
        } else if (xsdModelGroup != null && (xsdComplexTypeDefinition == null || xsdModelGroupDefinition == null)) {
            xsdSchema = xsdModelGroup.getSchema();
            beginRecording(xsdSchema.getElement());
            if (!isReference) {
                index = getInsertionIndex();
                if (index >= 0 && index < xsdModelGroup.getContents().size()) {
                    xsdModelGroup.getContents().add(index, createXSDElementDeclaration());
                } else {
                    xsdModelGroup.getContents().add(createXSDElementDeclaration());
                }
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdModelGroup.getElement());
        } else {
            xsdSchema = xsdComplexTypeDefinition.getSchema();
            beginRecording(xsdSchema.getElement());
            if (xsdModelGroup == null) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDParticle particle = factory.createXSDParticle();
                xsdModelGroup = factory.createXSDModelGroup();
                xsdModelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
                particle.setContent(xsdModelGroup);
                xsdComplexTypeDefinition.setContent(particle);
            }
            if (!isReference) {
                xsdModelGroup.getContents().add(createXSDElementDeclarationForComplexType());
            } else {
                xsdModelGroup.getContents().add(createXSDElementReference());
            }
            formatChild(xsdComplexTypeDefinition.getElement());
        }
    } finally {
        endRecording();
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Text(org.w3c.dom.Text) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 57 with XSDParticle

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

the class XSDVisitor method visitModelGroup.

public void visitModelGroup(XSDModelGroup modelGroup) {
    if (modelGroup.getContents() != null) {
        for (Iterator iterator = modelGroup.getContents().iterator(); iterator.hasNext(); ) {
            XSDParticle particle = (XSDParticle) iterator.next();
            visitParticle(particle);
        }
    }
}
Also used : Iterator(java.util.Iterator) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 58 with XSDParticle

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

the class AddXSDModelGroupCommand method getOwner.

private XSDConcreteComponent getOwner() {
    XSDConcreteComponent owner = null;
    if (parent instanceof XSDElementDeclaration) {
        XSDElementDeclaration ed = (XSDElementDeclaration) parent;
        if (ed.getTypeDefinition() != null) {
            if (ed.getAnonymousTypeDefinition() == null) {
                ed.setTypeDefinition(null);
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = ed.getTypeDefinition();
            } else {
                XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                ed.setAnonymousTypeDefinition(td);
                owner = td;
            }
        } else if (ed.getAnonymousTypeDefinition() == null) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDComplexTypeDefinition) {
            owner = ed.getAnonymousTypeDefinition();
        } else if (ed.getAnonymousTypeDefinition() instanceof XSDSimpleTypeDefinition) {
            XSDComplexTypeDefinition td = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
            ed.setAnonymousTypeDefinition(td);
            owner = td;
        }
    } else if (parent instanceof XSDModelGroup) {
        newModelGroup = createModelGroup();
        ((XSDModelGroup) parent).getContents().add(newModelGroup.getContainer());
    } else if (parent instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ct = (XSDComplexTypeDefinition) parent;
        owner = parent;
        if (ct.getContent() instanceof XSDParticle) {
            XSDParticle particle = (XSDParticle) ct.getContent();
            if (particle.getContent() instanceof XSDModelGroup) {
                owner = null;
                newModelGroup = createModelGroup();
                XSDModelGroup newParent = (XSDModelGroup) particle.getContent();
                newParent.getContents().add(newModelGroup.getContainer());
            }
        }
    } else if (parent instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition modelGroupDefinition = (XSDModelGroupDefinition) parent;
        owner = null;
        newModelGroup = createModelGroup();
        if (modelGroupDefinition.getModelGroup() != null) {
            XSDModelGroup newParent = modelGroupDefinition.getModelGroup();
            newParent.getContents().add(newModelGroup.getContainer());
        } else {
            modelGroupDefinition.setModelGroup(newModelGroup);
        }
    }
    return owner;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 59 with XSDParticle

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

the class AddXSDModelGroupCommand method execute.

public void execute() {
    try {
        beginRecording(parent.getElement());
        XSDConcreteComponent owner = getOwner();
        if (owner != null) {
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            newModelGroup = createModelGroup();
            particle.setContent(newModelGroup);
            XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) owner;
            ctd.setContent(particle);
        }
        formatChild(parent.getElement());
    } finally {
        endRecording();
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 60 with XSDParticle

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

the class MultiplicitySection method updateMinAttribute.

protected void updateMinAttribute() {
    setErrorMessage(null);
    XSDParticle particle = null;
    if (input instanceof XSDParticleContent) {
        particle = getAssociatedParticle((XSDParticleContent) input);
    }
    if (particle != null) {
        String newValue = minCombo.getText();
        if (newValue.length() == 0) {
            particle.unsetMinOccurs();
        }
        try {
            int newMin = 1;
            if (// $NON-NLS-1$ //$NON-NLS-2$
            newValue.equals("unbounded") || newValue.equals("*")) {
                newMin = XSDParticle.UNBOUNDED;
            } else {
                newMin = Integer.parseInt(newValue);
            }
            UpdateMinOccursCommand command = new UpdateMinOccursCommand(Messages._UI_ACTION_CHANGE_MINIMUM_OCCURRENCE, particle, newMin);
            getCommandStack().execute(command);
        } catch (NumberFormatException e) {
        }
    }
}
Also used : XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDParticle(org.eclipse.xsd.XSDParticle) UpdateMinOccursCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateMinOccursCommand)

Aggregations

XSDParticle (org.eclipse.xsd.XSDParticle)146 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)103 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)93 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)75 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)36 ArrayList (java.util.ArrayList)34 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)34 XSDTerm (org.eclipse.xsd.XSDTerm)31 XSDFactory (org.eclipse.xsd.XSDFactory)27 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)24 XSDSchema (org.eclipse.xsd.XSDSchema)24 Test (org.junit.Test)23 Iterator (java.util.Iterator)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)21 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)19 EList (org.eclipse.emf.common.util.EList)17 XSDParticleContent (org.eclipse.xsd.XSDParticleContent)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 Element (org.w3c.dom.Element)16 List (java.util.List)15