Search in sources :

Example 11 with XSDAttributeDeclaration

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

the class XSDCommonUIUtils method getInputXSDAnnotation.

public static XSDAnnotation getInputXSDAnnotation(XSDConcreteComponent input, boolean createIfNotExist) {
    XSDAnnotation xsdAnnotation = null;
    XSDFactory factory = XSDFactory.eINSTANCE;
    if (input instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration xsdComp = (XSDAttributeDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition xsdComp = (XSDAttributeGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDElementDeclaration) {
        XSDElementDeclaration xsdComp = (XSDElementDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDNotationDeclaration) {
        XSDNotationDeclaration xsdComp = (XSDNotationDeclaration) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDXPathDefinition) {
        XSDXPathDefinition xsdComp = (XSDXPathDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroup) {
        XSDModelGroup xsdComp = (XSDModelGroup) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDModelGroupDefinition) {
        XSDModelGroupDefinition xsdComp = (XSDModelGroupDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition xsdComp = (XSDIdentityConstraintDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDWildcard) {
        XSDWildcard xsdComp = (XSDWildcard) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDSchema) {
        XSDSchema xsdComp = (XSDSchema) input;
        List list = xsdComp.getAnnotations();
        if (list.size() > 0) {
            xsdAnnotation = (XSDAnnotation) list.get(0);
        } else {
            if (createIfNotExist && xsdAnnotation == null) {
                xsdAnnotation = factory.createXSDAnnotation();
                if (xsdComp.getContents() != null) {
                    xsdComp.getContents().add(0, xsdAnnotation);
                }
            }
        }
        return xsdAnnotation;
    } else if (input instanceof XSDFacet) {
        XSDFacet xsdComp = (XSDFacet) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDTypeDefinition) {
        XSDTypeDefinition xsdComp = (XSDTypeDefinition) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDInclude) {
        XSDInclude xsdComp = (XSDInclude) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDImport) {
        XSDImport xsdComp = (XSDImport) input;
        xsdAnnotation = xsdComp.getAnnotation();
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            xsdComp.setAnnotation(xsdAnnotation);
        }
    } else if (input instanceof XSDRedefine) {
        XSDRedefine xsdComp = (XSDRedefine) input;
        List contents = xsdComp.getContents();
        for (int i = 0; i < contents.size(); i++) {
            Object content = contents.get(i);
            if (content instanceof XSDAnnotation) {
                xsdAnnotation = (XSDAnnotation) content;
                break;
            }
        }
        if (createIfNotExist && xsdAnnotation == null) {
            xsdAnnotation = factory.createXSDAnnotation();
            contents.add(0, xsdAnnotation);
        }
        return xsdAnnotation;
    } else if (input instanceof XSDAnnotation) {
        xsdAnnotation = (XSDAnnotation) input;
    }
    if (createIfNotExist) {
        formatAnnotation(xsdAnnotation);
    }
    return xsdAnnotation;
}
Also used : XSDFactory(org.eclipse.xsd.XSDFactory) XSDRedefine(org.eclipse.xsd.XSDRedefine) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDNotationDeclaration(org.eclipse.xsd.XSDNotationDeclaration) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) XSDModelGroupDefinition(org.eclipse.xsd.XSDModelGroupDefinition) XSDImport(org.eclipse.xsd.XSDImport) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDSchema(org.eclipse.xsd.XSDSchema) XSDInclude(org.eclipse.xsd.XSDInclude)

Example 12 with XSDAttributeDeclaration

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

the class MakeAnonymousTypeGlobalAction method canEnable.

private boolean canEnable(XSDConcreteComponent xsdComponent) {
    if (xsdComponent instanceof XSDComplexTypeDefinition) {
        fSelectedComponent = (XSDComplexTypeDefinition) xsdComponent;
        isComplexType = true;
        XSDComplexTypeDefinition typeDef = (XSDComplexTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        }
    } else if (xsdComponent instanceof XSDSimpleTypeDefinition) {
        fSelectedComponent = (XSDSimpleTypeDefinition) xsdComponent;
        isComplexType = false;
        XSDSimpleTypeDefinition typeDef = (XSDSimpleTypeDefinition) xsdComponent;
        XSDConcreteComponent parent = typeDef.getContainer();
        if (parent instanceof XSDElementDeclaration) {
            fParentName = ((XSDElementDeclaration) parent).getName();
            return true;
        } else if (parent instanceof XSDAttributeDeclaration) {
            fParentName = ((XSDAttributeDeclaration) parent).getName();
            return true;
        }
    }
    return false;
}
Also used : XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 13 with XSDAttributeDeclaration

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

the class XSDAttributeDragAndDropCommand method doDrop.

protected void doDrop(List siblings, GraphicalEditPart movingEditPart) {
    commonSetup(siblings, movingEditPart);
    if ((previousRefComponent instanceof XSDAttributeDeclaration || previousRefComponent instanceof XSDWildcard) && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == BELOW_IS_CLOSER) {
            parent = nextRefComponent.getContainer().getContainer();
        }
        action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
    } else if (previousRefComponent == null && (nextRefComponent instanceof XSDAttributeDeclaration || nextRefComponent instanceof XSDWildcard)) {
        XSDConcreteComponent parent = nextRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            if (leftSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else if (parentEditPart != null) {
                action = new MoveXSDAttributeAction(parentEditPart.getXSDConcreteComponent(), xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        } else {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        }
    } else if (previousRefComponent instanceof XSDAttributeDeclaration && nextRefComponent == null) {
        XSDConcreteComponent parent = previousRefComponent.getContainer().getContainer();
        if (closerSibling == ABOVE_IS_CLOSER) {
            action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
        } else {
            if (rightSiblingEditPart == null) {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            } else {
                action = new MoveXSDAttributeAction(parent, xsdComponentToDrag, previousRefComponent, nextRefComponent);
            }
        }
    }
    if (action != null)
        canExecute = action.canMove();
}
Also used : MoveXSDAttributeAction(org.eclipse.wst.xsd.ui.internal.actions.MoveXSDAttributeAction) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 14 with XSDAttributeDeclaration

use of org.eclipse.xsd.XSDAttributeDeclaration 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 15 with XSDAttributeDeclaration

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

Aggregations

XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)49 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)27 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)18 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)17 Iterator (java.util.Iterator)16 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)16 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)15 XSDSchema (org.eclipse.xsd.XSDSchema)15 XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)14 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)13 List (java.util.List)10 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)10 XSDModelGroupDefinition (org.eclipse.xsd.XSDModelGroupDefinition)9 ArrayList (java.util.ArrayList)8 Element (org.w3c.dom.Element)8 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)7 XSDParticle (org.eclipse.xsd.XSDParticle)7 XSDNamedComponent (org.eclipse.xsd.XSDNamedComponent)6 XSDWildcard (org.eclipse.xsd.XSDWildcard)6 EList (org.eclipse.emf.common.util.EList)5