Search in sources :

Example 96 with XSDSimpleTypeDefinition

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

the class DeleteCommand method execute.

public void execute() {
    XSDVisitor visitor = new XSDVisitor() {

        public void visitElementDeclaration(org.eclipse.xsd.XSDElementDeclaration element) {
            if (element.getTypeDefinition() == target) {
                // $NON-NLS-1$
                XSDSimpleTypeDefinition type = target.getSchema().getSchemaForSchema().resolveSimpleTypeDefinition("string");
                element.setTypeDefinition(type);
            }
            super.visitElementDeclaration(element);
        }
    };
    XSDConcreteComponent parent = target.getContainer();
    XSDSchema schema = target.getSchema();
    try {
        beginRecording(parent.getElement());
        boolean doCleanup = false;
        if (target instanceof XSDModelGroup || target instanceof XSDElementDeclaration || target instanceof XSDModelGroupDefinition) {
            doCleanup = true;
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                } else if (parent.getContainer() instanceof XSDComplexTypeDefinition) {
                    XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) parent.getContainer();
                    complexType.setContent(null);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDModelGroupDefinitionAdapter) {
                    ((XSDModelGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDModelGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                ((XSDRedefine) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeDeclaration) {
            doCleanup = true;
            if (parent instanceof XSDAttributeUse) {
                EObject obj = parent.eContainer();
                XSDComplexTypeDefinition complexType = null;
                while (obj != null) {
                    if (obj instanceof XSDComplexTypeDefinition) {
                        complexType = (XSDComplexTypeDefinition) obj;
                        break;
                    }
                    obj = obj.eContainer();
                }
                if (complexType != null) {
                    complexType.getAttributeContents().remove(parent);
                }
                if (parent.getContainer() instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroup = (XSDAttributeGroupDefinition) parent.getContainer();
                    attrGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDSchema) {
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            }
        } else if (target instanceof XSDAttributeGroupDefinition && parent instanceof XSDComplexTypeDefinition) {
            doCleanup = true;
            ((XSDComplexTypeDefinition) parent).getAttributeContents().remove(target);
        } else if (target instanceof XSDEnumerationFacet) {
            XSDEnumerationFacet enumerationFacet = (XSDEnumerationFacet) target;
            enumerationFacet.getSimpleTypeDefinition().getFacetContents().remove(enumerationFacet);
        } else if (target instanceof XSDWildcard) {
            if (parent instanceof XSDParticle) {
                if (parent.getContainer() instanceof XSDModelGroup) {
                    XSDModelGroup modelGroup = (XSDModelGroup) ((XSDParticle) parent).getContainer();
                    modelGroup.getContents().remove(parent);
                }
            } else if (parent instanceof XSDComplexTypeDefinition) {
                ((XSDComplexTypeDefinition) parent).setAttributeWildcardContent(null);
            } else if (parent instanceof XSDAttributeGroupDefinition) {
                ((XSDAttributeGroupDefinition) parent).setAttributeWildcardContent(null);
            }
        } else if (target instanceof XSDTypeDefinition && parent instanceof XSDElementDeclaration) {
            doCleanup = true;
            ((XSDElementDeclaration) parent).setTypeDefinition(target.resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001, "string"));
        } else {
            if (parent instanceof XSDSchema) {
                doCleanup = true;
                visitor.visitSchema(target.getSchema());
                ((XSDSchema) parent).getContents().remove(target);
            } else if (parent instanceof XSDRedefine) {
                doCleanup = false;
                EList contents = ((XSDRedefine) parent).getContents();
                Object adapter = target.eAdapters().get(0);
                if (adapter instanceof XSDComplexTypeDefinitionAdapter) {
                    ((XSDComplexTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDComplexTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDSimpleTypeDefinitionAdapter) {
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDSimpleTypeDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                } else if (adapter instanceof XSDAttributeGroupDefinitionAdapter) {
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setReadOnly(true);
                    ((XSDAttributeGroupDefinitionAdapter) adapter).setChangeReadOnlyField(true);
                }
                contents.remove(target);
            }
        }
        if (doCleanup)
            XSDDirectivesManager.removeUnusedXSDImports(schema);
    } finally {
        endRecording();
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDVisitor(org.eclipse.wst.xsd.ui.internal.adapters.XSDVisitor) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSimpleTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDSimpleTypeDefinitionAdapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) EObject(org.eclipse.emf.ecore.EObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDAttributeGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDAttributeGroupDefinitionAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) EList(org.eclipse.emf.common.util.EList) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 97 with XSDSimpleTypeDefinition

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

the class SetBaseTypeCommand method execute.

public void execute() {
    try {
        beginRecording(concreteComponent.getElement());
        if (concreteComponent instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) concreteComponent;
            XSDComplexTypeContent contentType = (baseType instanceof XSDComplexTypeDefinition) ? ((XSDComplexTypeDefinition) baseType).getContentType() : null;
            // Complex type simple content
            if (baseType instanceof XSDSimpleTypeDefinition || (contentType != null && contentType instanceof XSDSimpleTypeDefinition)) {
                if (!(complexType.getContent() instanceof XSDSimpleTypeDefinition)) {
                    XSDSimpleTypeDefinition simpleContent = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
                    complexType.setContent(simpleContent);
                }
            } else // Complex type complex content
            if (baseType instanceof XSDComplexTypeDefinition) {
                if (!(complexType.getContent() instanceof XSDComplexTypeDefinition)) {
                    XSDComplexTypeDefinition complexContent = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
                    complexType.setContent(complexContent.getContent());
                }
            }
            complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL);
            complexType.setBaseTypeDefinition(baseType);
            // vb This call should not be needed. The XSD Infoset model should reconcile itself properly.
            complexType.updateElement(true);
            formatChild(complexType.getElement());
        } else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
            XSDSimpleTypeDefinition simpleType = (XSDSimpleTypeDefinition) concreteComponent;
            if (baseType instanceof XSDSimpleTypeDefinition) {
                XSDVariety variety = simpleType.getVariety();
                if (variety.getValue() == XSDVariety.ATOMIC) {
                    simpleType.setBaseTypeDefinition((XSDSimpleTypeDefinition) baseType);
                } else if (variety.getValue() == XSDVariety.UNION) {
                    simpleType.getMemberTypeDefinitions().add(baseType);
                } else if (variety.getValue() == XSDVariety.LIST) {
                    simpleType.setItemTypeDefinition((XSDSimpleTypeDefinition) baseType);
                }
            }
        }
    } finally {
        endRecording();
    }
}
Also used : XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDVariety(org.eclipse.xsd.XSDVariety) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition)

Example 98 with XSDSimpleTypeDefinition

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

the class XSDComplexTypeBaseTypeEditManager method modifyComponentReference.

// TODO common this up
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 instanceof XSDComplexTypeDefinition) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            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 SetBaseTypeCommand(concreteComponent, td);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new SetBaseTypeAndManagerDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.setLabel(Messages._UI_ACTION_SET_BASE_TYPE);
            command.execute();
        }
    } else if (concreteComponent instanceof XSDSimpleTypeDefinition) {
        if (component.isNew()) {
            XSDTypeDefinition td = null;
            if (component.getMetaName() == IXSDSearchConstants.SIMPLE_TYPE_META_NAME) {
                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 SetBaseTypeCommand(concreteComponent, td);
                command.execute();
            }
            XSDDirectivesManager.removeUnusedXSDImports(concreteComponent.getSchema());
        } else {
            Command command = new SetBaseTypeAndManagerDirectivesCommand(concreteComponent, component.getName(), component.getQualifier(), component.getFile());
            command.execute();
        }
    }
}
Also used : AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) SetBaseTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeCommand) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) SetBaseTypeAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeAndManagerDirectivesCommand) AddXSDComplexTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDComplexTypeDefinitionCommand) SetBaseTypeCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeCommand) AddXSDSimpleTypeDefinitionCommand(org.eclipse.wst.xsd.ui.internal.common.commands.AddXSDSimpleTypeDefinitionCommand) Command(org.eclipse.gef.commands.Command) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) SetBaseTypeAndManagerDirectivesCommand(org.eclipse.wst.xsd.ui.internal.common.commands.SetBaseTypeAndManagerDirectivesCommand) 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 99 with XSDSimpleTypeDefinition

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

the class XSDComponentDescriptionProvider method getImage.

public Image getImage(Object component) {
    Image result = null;
    if (component instanceof SearchMatch) {
        SearchMatch searchMatch = (SearchMatch) component;
        QualifiedName qualifiedName = (QualifiedName) searchMatch.map.get("metaName");
        if (qualifiedName != null) {
            if (qualifiedName.equals(IXSDSearchConstants.SIMPLE_TYPE_META_NAME))
                result = SIMPLE_TYPE_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.COMPLEX_TYPE_META_NAME))
                result = COMPLEX_TYPE_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.ELEMENT_META_NAME))
                result = ELEMENT_IMAGE;
            else if (qualifiedName.equals(IXSDSearchConstants.ATTRIBUTE_META_NAME))
                result = ATTRIBUTE_IMAGE;
        }
    } else if (component instanceof XSDComplexTypeDefinition)
        result = COMPLEX_TYPE_IMAGE;
    else if (component instanceof XSDSimpleTypeDefinition)
        result = SIMPLE_TYPE_IMAGE;
    else if (component instanceof XSDElementDeclaration)
        result = ELEMENT_IMAGE;
    else if (component instanceof XSDAttributeDeclaration)
        result = ATTRIBUTE_IMAGE;
    return result;
}
Also used : SearchMatch(org.eclipse.wst.common.core.search.SearchMatch) QualifiedName(org.eclipse.wst.common.core.search.pattern.QualifiedName) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Image(org.eclipse.swt.graphics.Image) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 100 with XSDSimpleTypeDefinition

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

the class XSDAdapterFactory method createAdapter.

public Adapter createAdapter(Notifier target) {
    XSDSwitch xsdSwitch = new XSDSwitch() {

        public Object caseXSDSchemaDirective(XSDSchemaDirective object) {
            return new XSDSchemaDirectiveAdapter();
        }

        public Object caseXSDWildcard(XSDWildcard object) {
            return new XSDWildcardAdapter();
        }

        public Object caseXSDAttributeGroupDefinition(XSDAttributeGroupDefinition object) {
            return new XSDAttributeGroupDefinitionAdapter();
        }

        public Object caseXSDModelGroupDefinition(XSDModelGroupDefinition object) {
            return new XSDModelGroupDefinitionAdapter();
        }

        public Object caseXSDAttributeDeclaration(XSDAttributeDeclaration object) {
            return new XSDAttributeDeclarationAdapter();
        }

        public Object caseXSDAttributeUse(XSDAttributeUse object) {
            return new XSDAttributeUseAdapter();
        }

        public Object caseXSDParticle(XSDParticle object) {
            return new XSDParticleAdapter();
        }

        public Object caseXSDElementDeclaration(XSDElementDeclaration object) {
            return new XSDElementDeclarationAdapter();
        }

        public Object caseXSDSimpleTypeDefinition(XSDSimpleTypeDefinition object) {
            return new XSDSimpleTypeDefinitionAdapter();
        }

        public Object caseXSDComplexTypeDefinition(XSDComplexTypeDefinition object) {
            // 
            if (// $NON-NLS-1$
            "anyType".equals(object.getName())) {
                return new XSDAnyTypeDefinitionAdapter();
            } else {
                return new XSDComplexTypeDefinitionAdapter();
            }
        }

        public Object caseXSDModelGroup(XSDModelGroup object) {
            return new XSDModelGroupAdapter();
        }

        public Object caseXSDSchema(XSDSchema object) {
            return new XSDSchemaAdapter();
        }

        public Object caseXSDEnumerationFacet(XSDEnumerationFacet object) {
            return new XSDEnumerationFacetAdapter();
        }

        public Object caseXSDRedefine(XSDRedefine object) {
            return new XSDRedefineAdapter();
        }
    };
    Object o = xsdSwitch.doSwitch((EObject) target);
    Adapter result = null;
    if (o instanceof Adapter) {
        result = (Adapter) o;
    } else {
    // Thread.dumpStack();
    }
    return result;
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) Adapter(org.eclipse.emf.common.notify.Adapter) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDSwitch(org.eclipse.xsd.util.XSDSwitch) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Aggregations

XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)106 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)53 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)47 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)46 XSDParticle (org.eclipse.xsd.XSDParticle)34 ArrayList (java.util.ArrayList)33 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)26 Iterator (java.util.Iterator)24 List (java.util.List)18 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)18 XSDSchema (org.eclipse.xsd.XSDSchema)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)16 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)15 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)15 XSDFactory (org.eclipse.xsd.XSDFactory)15 EList (org.eclipse.emf.common.util.EList)14 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)12 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)12 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)11