Search in sources :

Example 96 with XSDModelGroup

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

the class AddXSDElementCommand method getModelGroup.

// PORT
public XSDModelGroup getModelGroup(XSDComplexTypeDefinition cType) {
    XSDParticle particle = null;
    XSDComplexTypeContent xsdComplexTypeContent = cType.getContent();
    if (xsdComplexTypeContent instanceof XSDParticle) {
        particle = (XSDParticle) xsdComplexTypeContent;
    }
    if (particle == null) {
        return null;
    }
    Object particleContent = particle.getContent();
    XSDModelGroup group = null;
    if (particleContent instanceof XSDModelGroupDefinition) {
        group = ((XSDModelGroupDefinition) particleContent).getResolvedModelGroupDefinition().getModelGroup();
    } else if (particleContent instanceof XSDModelGroup) {
        group = (XSDModelGroup) particleContent;
    }
    if (group == null) {
        return null;
    }
    return group;
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 97 with XSDModelGroup

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

the class AddXSDModelGroupDefinitionCommand method createModelGroup.

protected XSDModelGroup createModelGroup() {
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    XSDParticle particle = factory.createXSDParticle();
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
    particle.setContent(modelGroup);
    return modelGroup;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 98 with XSDModelGroup

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

the class AddXSDModelGroupDefinitionCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see org.eclipse.gef.commands.Command#execute()
   */
public void execute() {
    if (parent instanceof XSDSchema) {
        ensureSchemaElement((XSDSchema) parent);
    }
    try {
        beginRecording(parent.getElement());
        if (!isReference) {
            XSDModelGroupDefinition def = createXSDModelGroupDefinition();
            addedXSDConcreteComponent = def;
        } else {
            XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
            XSDModelGroupDefinition def = factory.createXSDModelGroupDefinition();
            XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
            particle.setContent(def);
            List list = parent.getSchema().getModelGroupDefinitions();
            int length = list.size();
            if (length > 1) {
                for (int i = 0; i < length; i++) {
                    XSDModelGroupDefinition gr = (XSDModelGroupDefinition) list.get(i);
                    if (gr.getModelGroup() != parent) {
                        def.setResolvedModelGroupDefinition(gr);
                    }
                }
            } else if (length <= 1) {
                XSDModelGroupDefinition newGroupDef = createXSDModelGroupDefinition();
                def.setResolvedModelGroupDefinition(newGroupDef);
            }
            if (parent instanceof XSDModelGroup) {
                ((XSDModelGroup) parent).getContents().add(particle);
            }
            formatChild(def.getElement());
            addedXSDConcreteComponent = def;
        }
    } finally {
        endRecording();
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 99 with XSDModelGroup

use of org.eclipse.xsd.XSDModelGroup 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)

Example 100 with XSDModelGroup

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

the class AddXSDModelGroupCommand method createModelGroup.

protected XSDModelGroup createModelGroup() {
    XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
    XSDParticle particle = factory.createXSDParticle();
    XSDModelGroup modelGroup = factory.createXSDModelGroup();
    modelGroup.setCompositor(xsdCompositor);
    particle.setContent(modelGroup);
    addedXSDConcreteComponent = modelGroup;
    return modelGroup;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDModelGroup (org.eclipse.xsd.XSDModelGroup)119 XSDParticle (org.eclipse.xsd.XSDParticle)93 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)87 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)76 ArrayList (java.util.ArrayList)33 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)32 XSDTerm (org.eclipse.xsd.XSDTerm)28 XSDFactory (org.eclipse.xsd.XSDFactory)26 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)26 Test (org.junit.Test)25 XSDSchema (org.eclipse.xsd.XSDSchema)23 XSDComplexTypeContent (org.eclipse.xsd.XSDComplexTypeContent)22 EList (org.eclipse.emf.common.util.EList)21 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)20 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)19 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 Iterator (java.util.Iterator)16 XSDWildcard (org.eclipse.xsd.XSDWildcard)16 TreeObject (com.amalto.workbench.models.TreeObject)15