Search in sources :

Example 51 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.

the class XSDSkipToFKAction method run.

@Override
public void run() {
    TreeViewer treeViewer = page.getTreeViewer();
    ISelection selection = treeViewer.getSelection();
    Object selObj = ((IStructuredSelection) selection).getFirstElement();
    if (selObj instanceof XSDParticle) {
        XSDTerm term = ((XSDParticle) selObj).getTerm();
        if (term instanceof XSDElementDeclaration) {
            XSDElementDeclaration element = (XSDElementDeclaration) term;
            String fkPath = getFKInfo(element);
            if (fkPath == null) {
                MessageDialog.openInformation(null, Messages.XSDSkipToFKAction_actionTitle, Messages.XSDSkipToFKAction_NotFoundFkInfo);
                return;
            }
            String entityName = getEntityName(fkPath);
            EList<XSDElementDeclaration> elementDeclarations = page.getXSDSchema().getElementDeclarations();
            for (XSDElementDeclaration elementDeclaration : elementDeclarations) {
                String name = elementDeclaration.getName();
                if (entityName.equals(name)) {
                    StructuredSelection fkSelection = new StructuredSelection(elementDeclaration);
                    page.getElementsViewer().setSelection(fkSelection);
                    break;
                }
            }
        }
    }
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTerm(org.eclipse.xsd.XSDTerm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 52 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.

the class XPathTreeContentProvider method getXSDParticleChildren.

private Object[] getXSDParticleChildren(XSDParticle particle) {
    // System.out.println("getXSDParticleChildren() CLASS "+particle.getClass().getName());
    // System.out.println("getXSDParticleChildren() TERM "+particle.getTerm().getClass().getName()+": "+particle.getTerm());
    XSDTerm term = particle.getTerm();
    if (term instanceof XSDElementDeclaration) {
        XSDTypeDefinition typeDef = ((XSDElementDeclaration) term).getTypeDefinition();
        if (typeDef == null)
            // elements with not type declaration (allowed)
            return new Object[0];
        ArrayList<Object> list = new ArrayList<Object>();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            list.addAll(getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDef));
        } else {
            list.add(typeDef);
        }
        // }
        return list.toArray(new Object[list.size()]);
    }
    if (term instanceof XSDModelGroup) {
        // a ModelGroup skip it and get children directtly
        EList list = ((XSDModelGroup) term).getContents();
        return list.toArray(new XSDParticle[list.size()]);
    }
    if (term instanceof XSDWildcard) {
    }
    return new Object[] {};
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDWildcard(org.eclipse.xsd.XSDWildcard) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 53 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.

the class XSDTreeContentProvider method getXSDParticleChildren.

private Object[] getXSDParticleChildren(XSDParticle particle) {
    // System.out.println("getXSDParticleChildren() CLASS "+particle.getClass().getName());
    // System.out.println("getXSDParticleChildren() TERM "+particle.getTerm().getClass().getName()+": "+particle.getTerm());
    XSDTerm term = particle.getTerm();
    if (term instanceof XSDElementDeclaration) {
        XSDTypeDefinition typeDef = ((XSDElementDeclaration) term).getTypeDefinition();
        if (typeDef == null)
            // elements with not type declaration (allowed)
            return new Object[0];
        ArrayList<Object> list = new ArrayList<Object>();
        if (typeDef instanceof XSDComplexTypeDefinition) {
            list.addAll(Util.getComplexTypeDefinitionChildren((XSDComplexTypeDefinition) typeDef));
        } else {
            list.add(typeDef);
        }
        list.addAll(((XSDElementDeclaration) term).getIdentityConstraintDefinitions());
        XSDAnnotation annotation = ((XSDElementDeclaration) term).getAnnotation();
        if (filter != null && !filter.isAll()) {
        } else {
            if (annotation != null) {
                list.add(annotation);
            }
        }
        return list.toArray(new Object[list.size()]);
    }
    if (term instanceof XSDModelGroup) {
        // a ModelGroup skip it and get children directtly
        EList list = ((XSDModelGroup) term).getContents();
        return list.toArray(new XSDParticle[list.size()]);
    }
    if (term instanceof XSDWildcard) {
    }
    return new Object[] {};
}
Also used : EList(org.eclipse.emf.common.util.EList) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDTerm(org.eclipse.xsd.XSDTerm) XSDWildcard(org.eclipse.xsd.XSDWildcard) TreeObject(com.amalto.workbench.models.TreeObject) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition)

Example 54 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.

the class XSDTreeLabelProvider method getText.

@Override
public String getText(Object obj) {
    if (obj instanceof XSDElementDeclaration) {
        String name = ((XSDElementDeclaration) obj).getName();
        if (((XSDElementDeclaration) obj).isAbstract()) {
            name += Messages.XSDTreeLabelProvider_0;
        }
        String tail = ((XSDElementDeclaration) obj).getTargetNamespace() != null ? // $NON-NLS-1$
        " : " + ((XSDElementDeclaration) obj).getTargetNamespace() : // $NON-NLS-1$
        "";
        return name + tail;
    }
    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDParticleContent content = xsdParticle.getContent();
        XSDTerm xsdTerm = xsdParticle.getTerm();
        // $NON-NLS-1$
        String name = "";
        if (content instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) content;
            // $NON-NLS-1$
            name += (decl.getName() == null ? "" : decl.getName());
            if (decl.getTypeDefinition() == null) {
                // $NON-NLS-1$//$NON-NLS-2$
                name += " [" + ((XSDElementDeclaration) xsdTerm).getName() + "]";
            }
        } else if (content instanceof XSDModelGroup) {
            // log.info("SHOULD NOT HAPPEN????");
            if (xsdParticle.getContainer() instanceof XSDComplexTypeDefinition) {
                String ctdName = ((XSDComplexTypeDefinition) xsdParticle.getContainer()).getName();
                // $NON-NLS-1$
                name = (ctdName != null ? ctdName : "");
            }
        } else {
            // $NON-NLS-1$
            name = "[Any]";
        }
        if (!((xsdParticle.getMinOccurs() == 1) && (xsdParticle.getMaxOccurs() == 1))) {
            // $NON-NLS-1$
            name += "  [";
            name += xsdParticle.getMinOccurs();
            // $NON-NLS-1$
            name += "...";
            // $NON-NLS-1$//$NON-NLS-2$
            name += (xsdParticle.getMaxOccurs() == -1) ? "many" : "" + xsdParticle.getMaxOccurs();
            // $NON-NLS-1$
            name += "]";
        }
        return name;
    }
    if (obj instanceof XSDSimpleTypeDefinition) {
        return getSimpleTypeDefinition((XSDSimpleTypeDefinition) obj);
    }
    if (obj instanceof XSDModelGroup) {
        // return the name of the complex type definition
        XSDParticle particle = (XSDParticle) (((XSDModelGroup) obj).getContainer());
        XSDComplexTypeDefinition complexTypeDefinition = (XSDComplexTypeDefinition) particle.getContainer();
        String name = complexTypeDefinition.getName();
        if (name == null) {
            // $NON-NLS-1$
            name = "anonymous type ";
        }
        // return the occurrence
        if (!((particle.getMinOccurs() == 1) && (particle.getMaxOccurs() == 1))) {
            // $NON-NLS-1$
            name += "  [";
            name += particle.getMinOccurs();
            // $NON-NLS-1$
            name += "...";
            // $NON-NLS-1$//$NON-NLS-2$
            name += (particle.getMaxOccurs() == -1) ? "many" : "" + particle.getMaxOccurs();
            // $NON-NLS-1$
            name += "]";
        }
        // get extend type
        XSDTypeDefinition extendType = complexTypeDefinition.getBaseTypeDefinition();
        // $NON-NLS-1$
        String extendTypeName = "";
        if (extendType != null && extendType != complexTypeDefinition && !"anyType".equals(extendType.getName())) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            extendTypeName = ":" + extendType.getName();
        }
        XSDSchema schema = particle.getSchema();
        // $NON-NLS-1$
        String tail = "";
        if (schema != null && schema.getTargetNamespace() != null) {
            tail = // $NON-NLS-1$
            " : " + schema.getTargetNamespace();
        }
        return name + tail + extendTypeName;
    }
    if (obj instanceof XSDFacet) {
        // $NON-NLS-1$
        return ((XSDFacet) obj).getFacetName() + ": " + ((XSDFacet) obj).getLexicalValue();
    }
    if (obj instanceof XSDIdentityConstraintDefinition) {
        return ((XSDIdentityConstraintDefinition) obj).getName();
    }
    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        return xpath.getValue();
    }
    if (obj instanceof XSDAttributeGroupDefinition) {
        XSDAttributeGroupDefinition attributeGroupDefinition = (XSDAttributeGroupDefinition) obj;
        // $NON-NLS-1$
        String name = (attributeGroupDefinition.getName() == null ? "" : attributeGroupDefinition.getName());
        if (attributeGroupDefinition.getContents().size() == 0) {
            // $NON-NLS-1$//$NON-NLS-2$
            name += " [" + attributeGroupDefinition.getResolvedAttributeGroupDefinition().getName() + "]";
        }
        return name;
    }
    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse attributeUse = (XSDAttributeUse) obj;
        String name = attributeUse.getAttributeDeclaration().getName();
        if (name == null) {
            // $NON-NLS-1$//$NON-NLS-2$
            name = " [" + attributeUse.getAttributeDeclaration().getResolvedAttributeDeclaration().getName() + "]";
        }
        return name;
    }
    if (obj instanceof XSDAttributeDeclaration) {
        XSDAttributeDeclaration attributeDec = (XSDAttributeDeclaration) obj;
        String name = attributeDec.getName();
        if (name == null) {
            name = attributeDec.getAliasName();
            if (name == null) {
                // $NON-NLS-1$
                name = " [null]";
            }
        }
        return name;
    }
    if (obj instanceof XSDAnnotation) {
        // $NON-NLS-1$
        return "Annotations";
    }
    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {
                // $NON-NLS-1$
                return "Documentation: " + e.getChildNodes().item(0).getNodeValue();
            } else if (e.getLocalName().equals("appinfo")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                String source = e.getAttribute("source");
                if (source != null) {
                    if (source.startsWith("X_Label_")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_1, Util.iso2lang.get(source.substring(8).toLowerCase()), e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKey")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_2, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKey_NotSep")) {
                        // $NON-NLS-1$
                        Boolean v = Boolean.valueOf(e.getChildNodes().item(0).getNodeValue());
                        return Messages.bind(Messages.XSDTreeLabelProvider_3, Messages.SimpleXpathInputDialog_sepFkTabPanel, v);
                    } else if (source.equals("X_Visible_Rule")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_4, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Default_Value_Rule")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_5, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKeyInfo")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_6, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_ForeignKeyInfoFormat")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_20, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_PrimaryKeyInfo")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_7, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_SourceSystem")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_8, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_TargetSystem")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_9, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.startsWith("X_Description_")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_10, Util.iso2lang.get(source.substring(14).toLowerCase()), e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Write")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_11, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_Create")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_12, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_LogicalDelete")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_13, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_14, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Lookup_Field")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_15, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Workflow")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_16, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_Hide")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_17, e.getChildNodes().item(0).getNodeValue());
                    // add by ymli; bugId 0009157
                    } else if (source.equals("X_AutoExpand")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_18, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.startsWith("X_Facet")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_19, source.substring(2, 7), source.substring(8), e.getChildNodes().item(0).getNodeValue());
                    // made schematron show:Schematron: schematron
                    } else if (source.startsWith("X_Display_Format_")) {
                        // $NON-NLS-1$
                        return source + ": " + e.getChildNodes().item(0).getNodeValue();
                    } else if (source.equals("X_Schematron")) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        String pattern = (String) e.getFirstChild().getUserData("pattern_name");
                        if (pattern == null) {
                            Element el = Util.parse(e.getChildNodes().item(0).getNodeValue()).getDocumentElement();
                            if (el.getAttributes().getNamedItem("name") != null) {
                                // $NON-NLS-1$
                                // $NON-NLS-1$
                                pattern = el.getAttributes().getNamedItem("name").getTextContent();
                            }
                        }
                        return Messages.bind(Messages.XSDTreeLabelProvider_21, // e.getChildNodes().item(0).getNodeValue();
                        (pattern == null ? Messages.XSDTreeLabelProvider_22 : pattern));
                    // end
                    } else if (source.equals("X_Retrieve_FKinfos")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_23, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_24, e.getChildNodes().item(0).getNodeValue());
                    } else if (source.equals("X_FKIntegrity_Override")) {
                        // $NON-NLS-1$
                        return Messages.bind(Messages.XSDTreeLabelProvider_25, e.getChildNodes().item(0).getNodeValue());
                    }
                    if (source.equals("X_ForeignKey_Filter")) {
                        // $NON-NLS-1$
                        String nodeValue = e.getChildNodes().item(0).getNodeValue();
                        if (nodeValue.startsWith("$CFFP:")) {
                            // $NON-NLS-1$
                            nodeValue = StringEscapeUtils.unescapeXml(nodeValue).substring(6);
                        }
                        return Messages.bind(Messages.XSDTreeLabelProvider_26, nodeValue);
                    } else {
                        // $NON-NLS-1$
                        return source + ": " + Util.nodeToString((Element) obj);
                    }
                } else {
                    return Util.nodeToString((Element) obj);
                }
            } else {
                return Util.nodeToString((Element) obj);
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    if (obj == null) {
        // $NON-NLS-1$
        return "NULL";
    }
    // $NON-NLS-1$//$NON-NLS-2$
    return "?? " + obj.getClass().getName() + " : " + obj.toString();
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) XSDParticleContent(org.eclipse.xsd.XSDParticleContent) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDFacet(org.eclipse.xsd.XSDFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTerm(org.eclipse.xsd.XSDTerm) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 55 with XSDElementDeclaration

use of org.eclipse.xsd.XSDElementDeclaration in project tmdm-studio-se by Talend.

the class SchemaTreeContentProvider method getXSDSchemaChildren.

protected Object[] getXSDSchemaChildren(XSDSchema schema) {
    List<XSDElementDeclaration> declarations = new ArrayList<XSDElementDeclaration>();
    List<Object> attributeDeclarations = new ArrayList<Object>();
    if (null != xsdSchema) {
        for (XSDSchemaContent cnt : xsdSchema.getContents()) {
            if (cnt instanceof XSDInclude) {
                XSDInclude incu = (XSDInclude) cnt;
                String schemaLocation = incu.getSchemaLocation();
                XSDSchema schemaInc = createSchema(schemaLocation);
                addElementDeclarationFromSchema(schemaInc, declarations);
            } else if (cnt instanceof XSDAttributeDeclaration) {
                XSDAttributeDeclaration attriDec = (XSDAttributeDeclaration) cnt;
                attributeDeclarations.add(attriDec);
            }
        }
    }
    addElementDeclarationFromSchema(schema, declarations);
    Object[] schemaChildren = Util.filterOutDuplicatedElems(declarations.toArray(new XSDNamedComponent[declarations.size()]));
    attributeDeclarations.addAll(Arrays.asList(schemaChildren));
    return attributeDeclarations.toArray();
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ArrayList(java.util.ArrayList) XSDSchemaContent(org.eclipse.xsd.XSDSchemaContent) TreeObject(com.amalto.workbench.models.TreeObject) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) XSDInclude(org.eclipse.xsd.XSDInclude) XSDSchema(org.eclipse.xsd.XSDSchema)

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