Search in sources :

Example 11 with XSDModelGroupDefinition

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

the class ModelGroupEditPart method getModelChildren.

protected List getModelChildren() {
    // XSDModelGroupAdapter modelGroupAdapter = (XSDModelGroupAdapter)getModel();
    // ArrayList ch = new ArrayList();
    // ITreeElement [] tree = modelGroupAdapter.getChildren();
    // int length = tree.length;
    // for (int i = 0; i < length; i++)
    // {
    // ch.add(tree[i]);
    // }
    List list = new ArrayList();
    XSDModelGroup xsdModelGroup = getXSDModelGroup();
    for (Iterator i = xsdModelGroup.getContents().iterator(); i.hasNext(); ) {
        XSDParticle next = (XSDParticle) i.next();
        if (next.getContent() instanceof XSDElementDeclaration) {
            XSDElementDeclaration elementDeclaration = (XSDElementDeclaration) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(elementDeclaration);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
        if (next.getContent() instanceof XSDModelGroupDefinition) {
            XSDModelGroupDefinition def = (XSDModelGroupDefinition) next.getContent();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(def);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDModelGroup) {
            XSDModelGroup modelGroup = (XSDModelGroup) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(modelGroup);
            list.add(adapter);
        } else if (next.getTerm() instanceof XSDWildcard) {
            XSDWildcard wildCard = (XSDWildcard) next.getTerm();
            Adapter adapter = XSDAdapterFactory.getInstance().adapt(wildCard);
            list.add(new TargetConnectionSpaceFiller((XSDBaseAdapter) adapter));
        }
    }
    if (list.size() == 0)
        list.add(new TargetConnectionSpaceFiller(null));
    return list;
// return ch;
}
Also used : XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDWildcard(org.eclipse.xsd.XSDWildcard) ArrayList(java.util.ArrayList) List(java.util.List) Adapter(org.eclipse.emf.common.notify.Adapter) XSDBaseAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDBaseAdapter) XSDModelGroupAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupAdapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) TargetConnectionSpaceFiller(org.eclipse.wst.xsd.ui.internal.design.editparts.model.TargetConnectionSpaceFiller) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 12 with XSDModelGroupDefinition

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

the class XSDGroupsForAnnotationEditPart method getModelChildren.

protected List getModelChildren() {
    List xsdModelGroupList = new ArrayList();
    List adapterList = new ArrayList();
    IStructure structure = ((Annotation) getModel()).getOwner();
    if (structure instanceof IComplexType) {
        complexType = (IComplexType) structure;
        if (complexType instanceof XSDComplexTypeDefinitionAdapter) {
            XSDComplexTypeDefinitionAdapter adapter = (XSDComplexTypeDefinitionAdapter) complexType;
            xsdModelGroupList = adapter.getModelGroups();
        }
        for (Iterator i = xsdModelGroupList.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (obj instanceof XSDModelGroup) {
                adapterList.add(XSDAdapterFactory.getInstance().adapt((XSDModelGroup) obj));
            } else if (obj instanceof XSDModelGroupDefinition) {
                adapterList.add(XSDAdapterFactory.getInstance().adapt((XSDModelGroupDefinition) obj));
            }
        }
    } else if (structure instanceof XSDModelGroupDefinitionAdapter) {
        XSDModelGroupDefinitionAdapter adapter = (XSDModelGroupDefinitionAdapter) structure;
        XSDModelGroup group = adapter.getXSDModelGroupDefinition().getModelGroup();
        if (group != null) {
            adapterList.add(XSDAdapterFactory.getInstance().adapt(group));
        }
    }
    return adapterList;
}
Also used : XSDComplexTypeDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDComplexTypeDefinitionAdapter) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDModelGroupDefinitionAdapter(org.eclipse.wst.xsd.ui.internal.adapters.XSDModelGroupDefinitionAdapter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IStructure(org.eclipse.wst.xsd.ui.internal.adt.facade.IStructure) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) Annotation(org.eclipse.wst.xsd.ui.internal.adt.design.editparts.model.Annotation) IComplexType(org.eclipse.wst.xsd.ui.internal.adt.facade.IComplexType)

Example 13 with XSDModelGroupDefinition

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

the class OpenOnSelectionHelper method openOnGlobalReference.

public XSDNamedComponent openOnGlobalReference(XSDConcreteComponent comp) {
    XSDSchema schema = xsdSchema;
    String name = null;
    String namespace = null;
    if (comp instanceof XSDNamedComponent) {
        name = ((XSDNamedComponent) comp).getName();
        namespace = ((XSDNamedComponent) comp).getTargetNamespace();
    }
    if (name == null) {
        // For Anonymous types, just show the element
        if (comp instanceof XSDTypeDefinition) {
            XSDTypeDefinition type = (XSDTypeDefinition) comp;
            comp = type.getContainer();
            if (comp instanceof XSDNamedComponent) {
                name = ((XSDNamedComponent) comp).getName();
                namespace = ((XSDNamedComponent) comp).getTargetNamespace();
            }
        }
    }
    if (schema == null || name == null) {
        return null;
    }
    List objects = null;
    if (comp instanceof XSDElementDeclaration) {
        objects = schema.getElementDeclarations();
    } else if (comp instanceof XSDTypeDefinition) {
        objects = schema.getTypeDefinitions();
    } else if (comp instanceof XSDAttributeGroupDefinition) {
        objects = schema.getAttributeGroupDefinitions();
    } else if (comp instanceof XSDIdentityConstraintDefinition) {
        objects = schema.getIdentityConstraintDefinitions();
    } else if (comp instanceof XSDModelGroupDefinition) {
        objects = schema.getModelGroupDefinitions();
    } else if (comp instanceof XSDAttributeDeclaration) {
        objects = schema.getAttributeDeclarations();
    }
    if (objects != null) {
        if (namespace != null) {
            // First, look for a namespace and name match
            for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
                XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
                String targetNamespace = namedComp.getTargetNamespace();
                if (namedComp.getName().equals(name) && targetNamespace != null && targetNamespace.equals(namespace)) {
                    revealObject(namedComp);
                    return namedComp;
                }
            }
        }
        // Next, look for just a name match
        for (Iterator iter = objects.iterator(); iter.hasNext(); ) {
            XSDNamedComponent namedComp = (XSDNamedComponent) iter.next();
            if (namedComp.getName().equals(name)) {
                revealObject(namedComp);
                return namedComp;
            }
        }
    }
    return null;
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Example 14 with XSDModelGroupDefinition

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

the class OpenOnSelectionHelper method openOnSelection.

public boolean openOnSelection() {
    List selectedNodes = null;
    ISelection selection = textEditor.getSelectionProvider().getSelection();
    if (selection instanceof IStructuredSelection) {
        selectedNodes = ((IStructuredSelection) selection).toList();
    }
    if (selectedNodes != null && !selectedNodes.isEmpty()) {
        for (Iterator i = selectedNodes.iterator(); i.hasNext(); ) {
            Object obj = i.next();
            if (xsdSchema != null) {
                XSDConcreteComponent xsdComp = xsdSchema.getCorrespondingComponent((Node) obj);
                XSDConcreteComponent objectToReveal = null;
                if (xsdComp instanceof XSDElementDeclaration) {
                    XSDElementDeclaration elementDecl = (XSDElementDeclaration) xsdComp;
                    if (elementDecl.isElementDeclarationReference()) {
                        objectToReveal = elementDecl.getResolvedElementDeclaration();
                    } else {
                        XSDConcreteComponent typeDef = null;
                        if (elementDecl.getAnonymousTypeDefinition() == null) {
                            typeDef = elementDecl.getTypeDefinition();
                        }
                        XSDConcreteComponent subGroupAffiliation = elementDecl.getSubstitutionGroupAffiliation();
                        if (typeDef != null && subGroupAffiliation != null) {
                            // then jump to that, otherwise just go to the typeDef.
                            if (obj instanceof Attr && ((Attr) obj).getLocalName().equals(XSDConstants.SUBSTITUTIONGROUP_ATTRIBUTE)) {
                                objectToReveal = subGroupAffiliation;
                            } else {
                                // if we fail, set the substitution group as the object to reveal as a backup plan.
                                if (revealObject(typeDef)) {
                                    return true;
                                } else {
                                    objectToReveal = subGroupAffiliation;
                                }
                            }
                        } else {
                            // one or more of these is null.  If the typeDef is non-null, use it.  Otherwise
                            // try and use the substitution group
                            objectToReveal = typeDef != null ? typeDef : subGroupAffiliation;
                        }
                    }
                } else if (xsdComp instanceof XSDModelGroupDefinition) {
                    XSDModelGroupDefinition elementDecl = (XSDModelGroupDefinition) xsdComp;
                    if (elementDecl.isModelGroupDefinitionReference()) {
                        objectToReveal = elementDecl.getResolvedModelGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeDeclaration) {
                    XSDAttributeDeclaration attrDecl = (XSDAttributeDeclaration) xsdComp;
                    if (attrDecl.isAttributeDeclarationReference()) {
                        objectToReveal = attrDecl.getResolvedAttributeDeclaration();
                    } else if (attrDecl.getAnonymousTypeDefinition() == null) {
                        objectToReveal = attrDecl.getTypeDefinition();
                    }
                } else if (xsdComp instanceof XSDAttributeGroupDefinition) {
                    XSDAttributeGroupDefinition attrGroupDef = (XSDAttributeGroupDefinition) xsdComp;
                    if (attrGroupDef.isAttributeGroupDefinitionReference()) {
                        objectToReveal = attrGroupDef.getResolvedAttributeGroupDefinition();
                    }
                } else if (xsdComp instanceof XSDIdentityConstraintDefinition) {
                    XSDIdentityConstraintDefinition idConstraintDef = (XSDIdentityConstraintDefinition) xsdComp;
                    if (idConstraintDef.getReferencedKey() != null) {
                        objectToReveal = idConstraintDef.getReferencedKey();
                    }
                } else if (xsdComp instanceof XSDSimpleTypeDefinition) {
                    XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getItemTypeDefinition();
                    if (objectToReveal == null) {
                        // if itemType attribute is not set, then check for memberType
                        List memberTypes = typeDef.getMemberTypeDefinitions();
                        if (memberTypes != null && memberTypes.size() > 0) {
                            objectToReveal = (XSDConcreteComponent) memberTypes.get(0);
                        }
                    }
                } else if (xsdComp instanceof XSDTypeDefinition) {
                    XSDTypeDefinition typeDef = (XSDTypeDefinition) xsdComp;
                    objectToReveal = typeDef.getBaseType();
                } else if (xsdComp instanceof XSDSchemaDirective) {
                    XSDSchemaDirective directive = (XSDSchemaDirective) xsdComp;
                    // String schemaLocation = URIHelper.removePlatformResourceProtocol(directive.getResolvedSchema().getSchemaLocation());
                    // openXSDEditor(schemaLocation);
                    // return false;
                    objectToReveal = directive.getResolvedSchema();
                }
                // now reveal the object if this isn't null
                if (objectToReveal != null) {
                    return revealObject(objectToReveal);
                }
            }
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDSchemaDirective(org.eclipse.xsd.XSDSchemaDirective) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 15 with XSDModelGroupDefinition

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

the class XSDBaseAdapter method getGlobalXSDContainer.

protected IADTObject getGlobalXSDContainer(XSDConcreteComponent component) {
    XSDConcreteComponent c = component.getContainer();
    // We want the top most structural component
    while (c != null && !(c.getContainer() instanceof XSDSchema) && !(c instanceof XSDComplexTypeDefinition) && !(c instanceof XSDSimpleTypeDefinition) && !(c instanceof XSDModelGroupDefinition) && !(c instanceof XSDAttributeGroupDefinition)) {
        c = c.getContainer();
    }
    Adapter adapter = XSDAdapterFactory.getInstance().adapt(c);
    if (adapter instanceof IADTObject)
        return (IADTObject) adapter;
    return null;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) IADTObject(org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Adapter(org.eclipse.emf.common.notify.Adapter) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDSchema(org.eclipse.xsd.XSDSchema) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition)

Aggregations

XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)43 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)19 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)18 List (java.util.List)15 ArrayList (java.util.ArrayList)13 Iterator (java.util.Iterator)12 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)11 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)11 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)11 XSDParticle (org.eclipse.xsd.XSDParticle)10 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)10 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)9 XSDSchema (org.eclipse.xsd.XSDSchema)9 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)8 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)7 XSDRedefine (org.eclipse.xsd.XSDRedefine)6 XSDWildcard (org.eclipse.xsd.XSDWildcard)6 Adapter (org.eclipse.emf.common.notify.Adapter)5 EObject (org.eclipse.emf.ecore.EObject)4 IADTObject (org.eclipse.wst.xsd.ui.internal.adt.facade.IADTObject)4