Search in sources :

Example 81 with XSDElementDeclaration

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

the class XSDTypeReferenceEditManager method modifyComponentReference.

public void modifyComponentReference(Object referencingObject, ComponentSpecification component) {
    XSDConcreteComponent concreteComponent = null;
    if (referencingObject instanceof Adapter) {
        Adapter adpater = (Adapter) referencingObject;
        if (adpater.getTarget() instanceof XSDConcreteComponent) {
            concreteComponent = (XSDConcreteComponent) adpater.getTarget();
        }
    } else if (referencingObject instanceof XSDConcreteComponent) {
        concreteComponent = (XSDConcreteComponent) referencingObject;
    }
    if (concreteComponent != null) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (// This means we set to anonymous type
            component.getName() == null && concreteComponent instanceof XSDElementDeclaration) {
                XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
                XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) concreteComponent;
                // with the proper undo descriptions
                if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                    XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
                    elementDeclaration.setAnonymousTypeDefinition(complexType);
                } else {
                    XSDSimpleTypeDefinition simpleType = factory.createXSDSimpleTypeDefinition();
                    simpleType.setBaseTypeDefinition(// $NON-NLS-1$
                    elementDeclaration.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
                    elementDeclaration.setAnonymousTypeDefinition(simpleType);
                }
                // TODO use external literal string
                elementDeclaration.getElement().removeAttribute("type");
            } else if (component.getMetaName() == IXSDSearchConstants.COMPLEX_TYPE_META_NAME) {
                AddXSDComplexTypeDefinitionCommand command = new AddXSDComplexTypeDefinitionCommand(Messages._UI_ACTION_ADD_COMPLEX_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedComplexType();
            } else {
                AddXSDSimpleTypeDefinitionCommand command = new AddXSDSimpleTypeDefinitionCommand(Messages._UI_ACTION_ADD_SIMPLE_TYPE, concreteComponent.getSchema());
                command.setNameToAdd(component.getName());
                command.execute();
                td = command.getCreatedSimpleType();
            }
            if (td != null) {
                Command command = new UpdateTypeReferenceCommand(concreteComponent, td);
                command.setLabel(Messages._UI_ACTION_SET_TYPE);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new UpdateTypeReferenceAndManageDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_SET_TYPE);
            command.execute();
        }
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) XSDFactory(org.eclipse.xsd.XSDFactory) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) UpdateTypeReferenceCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceCommand) UpdateTypeReferenceAndManageDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.UpdateTypeReferenceAndManageDirectivesCommand) Command(org.eclipse.gef.commands.Command) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Adapter(org.eclipse.emf.common.notify.Adapter) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 82 with XSDElementDeclaration

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

the class AddXSDComplexTypeDefinitionCommand method execute.

/*
   * (non-Javadoc)
   * 
   * @see org.eclipse.gef.commands.Command#execute()
   */
public void execute() {
    try {
        beginRecording(parent.getElement());
        XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory();
        XSDComplexTypeDefinition complexType = factory.createXSDComplexTypeDefinition();
        addedXSDConcreteComponent = complexType;
        // $NON-NLS-1$
        String newName = getNewName(nameToAdd == null ? "NewComplexType" : nameToAdd, parent.getSchema());
        complexType.setName(newName);
        if (parent instanceof XSDSchema) {
            try {
                XSDSchema xsdSchema = (XSDSchema) parent;
                ensureSchemaElement(xsdSchema);
                // $NON-NLS-1$
                Text textNode = xsdSchema.getDocument().createTextNode("\n");
                xsdSchema.getElement().appendChild(textNode);
                xsdSchema.getContents().add(complexType);
            } catch (Exception e) {
            }
        } else if (parent instanceof XSDElementDeclaration) {
            ((XSDElementDeclaration) parent).setAnonymousTypeDefinition(complexType);
            formatChild(parent.getElement());
        }
        createdComplexType = complexType;
    } finally {
        endRecording();
    }
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Text(org.w3c.dom.Text) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 83 with XSDElementDeclaration

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

the class AddXSDModelGroupAction method run.

public void run() {
    Object selection = ((IStructuredSelection) getSelection()).getFirstElement();
    if (selection instanceof XSDBaseAdapter) {
        XSDConcreteComponent xsdComponent = (XSDConcreteComponent) ((XSDBaseAdapter) selection).getTarget();
        AddXSDModelGroupCommand command = null;
        if (xsdComponent instanceof XSDElementDeclaration) {
            XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdElementDeclaration, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDModelGroup) {
            XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdComponent;
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdModelGroup, xsdCompositor);
            getCommandStack().execute(command);
        } else if (xsdComponent instanceof XSDComplexTypeDefinition || xsdComponent instanceof XSDModelGroupDefinition) {
            command = new AddXSDModelGroupCommand(getLabel(xsdCompositor), xsdComponent, xsdCompositor);
            getCommandStack().execute(command);
        }
        if (command != null) {
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(command.getAddedComponent());
            if (adapter != null)
                provider.setSelection(new StructuredSelection(adapter));
        }
    }
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) AddXSDModelGroupCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDModelGroupCommand) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Example 84 with XSDElementDeclaration

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

the class AddXSDElementCommand method createXSDElementReference.

protected XSDParticle createXSDElementReference() {
    List list = xsdModelGroup.getSchema().getElementDeclarations();
    XSDElementDeclaration referencedElement = null;
    if (list.size() > 0) {
        referencedElement = (XSDElementDeclaration) list.get(0);
    } else {
        referencedElement = createGlobalXSDElementDeclaration();
        // $NON-NLS-1$
        Text textNode = xsdSchema.getDocument().createTextNode("\n");
        xsdSchema.getElement().appendChild(textNode);
        xsdSchema.getContents().add(referencedElement);
    }
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    element.setResolvedElementDeclaration(referencedElement);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) Text(org.w3c.dom.Text) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 85 with XSDElementDeclaration

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

the class AddXSDElementCommand method createXSDElementDeclaration.

protected XSDParticle createXSDElementDeclaration() {
    // $NON-NLS-1$
    XSDSimpleTypeDefinition type = xsdModelGroup.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
    XSDElementDeclaration element = XSDFactory.eINSTANCE.createXSDElementDeclaration();
    XSDConcreteComponent comp = xsdModelGroup.getContainer();
    ArrayList usedAttributeNames = new ArrayList();
    XSDCommonUIUtils.resetVisitedGroupsStack();
    usedAttributeNames.addAll(XSDCommonUIUtils.getChildElements(xsdModelGroup));
    while (comp != null) {
        if (comp instanceof XSDModelGroupDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDModelGroupDefinition) comp));
            break;
        } else if (comp instanceof XSDComplexTypeDefinition) {
            usedAttributeNames.addAll(XSDCommonUIUtils.getAllAttributes((XSDComplexTypeDefinition) comp));
            usedAttributeNames.addAll(XSDCommonUIUtils.getInheritedAttributes((XSDComplexTypeDefinition) comp));
            break;
        }
        comp = comp.getContainer();
    }
    element.setName(XSDCommonUIUtils.createUniqueElementName(nameToAdd == null ? "NewElement" : nameToAdd, // $NON-NLS-1$
    usedAttributeNames));
    element.setTypeDefinition(type);
    XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();
    particle.setContent(element);
    addedXSDConcreteComponent = element;
    return particle;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)222 XSDParticle (org.eclipse.xsd.XSDParticle)103 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)93 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)87 ArrayList (java.util.ArrayList)60 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)57 XSDSchema (org.eclipse.xsd.XSDSchema)48 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)47 Test (org.junit.Test)44 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)38 XSDFactory (org.eclipse.xsd.XSDFactory)37 XSDTerm (org.eclipse.xsd.XSDTerm)32 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)30 EList (org.eclipse.emf.common.util.EList)29 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)28 Iterator (java.util.Iterator)27 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)21 Element (org.w3c.dom.Element)21