Search in sources :

Example 1 with XSDAttributeUse

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

the class XSDGenerateHTML method loadAndPrint.

/**
 * Load the XML Schema file and print the documentation based on it.
 *
 * @param xsdFile the name of an XML Schema file.
 */
public void loadAndPrint(String xsdFile) throws Exception {
    XSDFactory xsdFactory = XSDFactory.eINSTANCE;
    // Create a resource set and load the main schema file into it.
    // 
    ResourceSet resourceSet = new ResourceSetImpl();
    XSDResourceImpl xsdResource = (XSDResourceImpl) resourceSet.getResource(URI.createFileURI(xsdFile), true);
    XSDSchema xsdSchema = xsdResource.getSchema();
    // $NON-NLS-1$
    String elementContentHeaderDocumentation = getContentDocumentation("element-header");
    if (elementContentHeaderDocumentation != null) {
        System.out.println(elementContentHeaderDocumentation);
    }
    List all = new ArrayList(xsdSchema.getElementDeclarations());
    // $NON-NLS-1$
    XSDElementDeclaration simpleContent = xsdSchema.resolveElementDeclaration("simpleContent");
    // $NON-NLS-1$
    XSDElementDeclaration complexContent = xsdSchema.resolveElementDeclaration("complexContent");
    for (int i = 0; i <= 1; ++i) {
        for (int j = 0; j <= 1; ++j) {
            XSDElementDeclaration parentElement = (i == 0 ? complexContent : simpleContent);
            XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) parentElement.getTypeDefinition();
            XSDElementDeclaration specialElementDeclaration = (XSDElementDeclaration) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) ((XSDModelGroup) ((XSDParticle) (xsdComplexTypeDefinition.getContentType())).getTerm()).getParticles().get(1)).getTerm()).getParticles().get(j)).getTerm();
            all.add(specialElementDeclaration);
            specialAnchorMap.put(specialElementDeclaration, parentElement);
        }
    }
    all = XSDNamedComponentImpl.sortNamedComponents(all);
    for (Iterator i = all.iterator(); i.hasNext(); ) {
        XSDElementDeclaration xsdElementDeclaration = (XSDElementDeclaration) i.next();
        XSDElementDeclaration parentElementDeclaration = (XSDElementDeclaration) specialAnchorMap.get(xsdElementDeclaration);
        String elementDeclarationName = xsdElementDeclaration.getName();
        String key = // $NON-NLS-1$ //$NON-NLS-2$
        (parentElementDeclaration == null ? "" : parentElementDeclaration.getName() + "::") + elementDeclarationName;
        String elementDeclarationMarkup = getElementDeclarationMarkup(key);
        // $NON-NLS-1$
        System.out.print("<h2>");
        System.out.print(elementDeclarationName.substring(0, 1).toUpperCase());
        System.out.print(elementDeclarationName.substring(1));
        // $NON-NLS-1$
        System.out.println("</h2>");
        // $NON-NLS-1$
        System.out.println("<div class='reprdef'>");
        // $NON-NLS-1$
        System.out.println("<table cols=1 width='100%'><tr><td>");
        System.out.print(// $NON-NLS-1$
        "<div class='reprHeader'><span class='reprdef'>XML&nbsp;Representation&nbsp;Summary:&nbsp;</span><code>");
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.print("<a name='" + getLocalAnchor(xsdElementDeclaration) + "'>");
        System.out.print(getStandardLink(xsdElementDeclaration));
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.print("</a></a></code>");
        // $NON-NLS-1$
        System.out.print("&nbsp;Element&nbsp;Information&nbsp;Item&nbsp;");
        if (parentElementDeclaration != null) {
            // $NON-NLS-1$
            System.out.print("<small>(");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.print("<a href='#" + getLocalAnchor(parentElementDeclaration) + "'>");
            System.out.print(parentElementDeclaration.getName());
            // $NON-NLS-1$
            System.out.print("</a>)</small>");
        } else if ("restriction".equals(elementDeclarationName)) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            System.out.print("<small>(simpleType)</small>");
        }
        // $NON-NLS-1$
        System.out.println("</div>");
        // $NON-NLS-1$
        System.out.println("<div class='reprBody'>");
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.print("<div class='" + elementDeclarationMarkup + "'>");
        }
        // $NON-NLS-1$
        System.out.print("<tt>&lt;");
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.print("</tt>");
        String componentLinks = getComponentLinks(xsdElementDeclaration);
        if (componentLinks != null) {
            System.out.print(componentLinks);
        }
        // $NON-NLS-1$
        System.out.println("<br>");
        StringBuffer attributeDocumentationBuffer = new StringBuffer();
        Map repeatedDocumentationMap = new HashMap();
        XSDTypeDefinition xsdTypeDefinition = xsdElementDeclaration.getTypeDefinition();
        XSDComplexTypeDefinition generalType = xsdSchema.resolveComplexTypeDefinitionURI(xsdElementDeclaration.getURI());
        if (generalType.getContainer() != null) {
            xsdTypeDefinition = generalType;
        }
        if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition) {
            // $NON-NLS-1$
            System.out.println("<tt>></tt><br>");
        } else if (xsdTypeDefinition instanceof XSDComplexTypeDefinition) {
            XSDComplexTypeDefinition xsdComplexTypeDefinition = (XSDComplexTypeDefinition) xsdTypeDefinition;
            for (Iterator attributeUses = xsdComplexTypeDefinition.getAttributeUses().iterator(); attributeUses.hasNext(); ) {
                XSDAttributeUse xsdAttributeUse = (XSDAttributeUse) attributeUses.next();
                XSDAttributeDeclaration xsdAttributeDeclaration = xsdAttributeUse.getAttributeDeclaration();
                String attributeDeclarationName = xsdAttributeDeclaration.getName();
                // $NON-NLS-1$
                System.out.print("<tt>&nbsp;&nbsp;");
                if (xsdAttributeDeclaration.getTargetNamespace() != null) {
                    // $NON-NLS-1$
                    System.out.print("xml:");
                }
                String attributeDeclarationMarkup = null;
                String attributeDeclarationDocumentation = null;
                if (!"ignored".equals(elementDeclarationMarkup)) {
                    // $NON-NLS-1$
                    attributeDeclarationMarkup = getAttributeDeclarationMarkup(attributeDeclarationName);
                    if (attributeDeclarationMarkup == null) {
                        attributeDeclarationMarkup = getAttributeDeclarationMarkup(// $NON-NLS-1$
                        elementDeclarationName + "." + attributeDeclarationName);
                    }
                    attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(attributeDeclarationName);
                    if (attributeDeclarationDocumentation == null) {
                        attributeDeclarationDocumentation = getAttributeDeclarationDocumentation(// $NON-NLS-1$
                        elementDeclarationName + "." + attributeDeclarationName);
                    }
                }
                if (attributeDeclarationDocumentation != null) {
                    Integer oldInsertIndex = (Integer) repeatedDocumentationMap.get(attributeDeclarationDocumentation);
                    if (oldInsertIndex != null) {
                        // $NON-NLS-1$
                        String insertion = "<br>" + attributeDeclarationName;
                        attributeDocumentationBuffer.insert(oldInsertIndex.intValue(), insertion);
                        repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(oldInsertIndex.intValue() + insertion.length()));
                    } else {
                        if (attributeDocumentationBuffer.length() == 0) {
                            // $NON-NLS-1$
                            attributeDocumentationBuffer.append("<table cols=2 width='100%'>\n");
                            attributeDocumentationBuffer.append(// $NON-NLS-1$
                            "<tr>\n<th width=25% valign=top align=left><b>Attribute</b></th>\n");
                            attributeDocumentationBuffer.append(// $NON-NLS-1$
                            "<th width=75% valign=top align=left><b>Description</b></th>\n</tr>\n");
                        }
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("<tr><td><b>");
                        if (attributeDeclarationMarkup != null) {
                            // $NON-NLS-1$ //$NON-NLS-2$
                            attributeDocumentationBuffer.append("<span class='" + attributeDeclarationMarkup + "'>");
                        }
                        attributeDocumentationBuffer.append(attributeDeclarationName);
                        int insertIndex = attributeDocumentationBuffer.length();
                        if (attributeDeclarationMarkup != null) {
                            // $NON-NLS-1$
                            attributeDocumentationBuffer.append("</span>");
                        }
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("</b></td>\n<td valign=top>\n");
                        attributeDocumentationBuffer.append(attributeDeclarationDocumentation);
                        // $NON-NLS-1$
                        attributeDocumentationBuffer.append("</td></tr>");
                        repeatedDocumentationMap.put(attributeDeclarationDocumentation, new Integer(insertIndex));
                    }
                }
                if (attributeDeclarationMarkup != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    System.out.print("<span class='" + attributeDeclarationMarkup + "'>");
                }
                if (xsdAttributeUse.isRequired()) {
                    // $NON-NLS-1$
                    System.out.print("<b>");
                    System.out.print(attributeDeclarationName);
                    // $NON-NLS-1$
                    System.out.print("</b>");
                } else {
                    System.out.print(attributeDeclarationName);
                }
                if (attributeDeclarationMarkup != null) {
                    // $NON-NLS-1$
                    System.out.print("</span>");
                }
                // $NON-NLS-1$
                System.out.print("&nbsp;=&nbsp;</tt>");
                XSDSimpleTypeDefinition xsdSimpleTypeDefinition = xsdAttributeDeclaration.getTypeDefinition();
                printSimpleTypeDefinition(xsdSimpleTypeDefinition);
                if (xsdAttributeUse.getLexicalValue() != null) {
                    // $NON-NLS-1$
                    System.out.print("&nbsp;:&nbsp;");
                    if ("".equals(xsdAttributeUse.getLexicalValue())) {
                        // $NON-NLS-1$
                        // $NON-NLS-1$
                        System.out.print("\"\"");
                    } else {
                        System.out.print(xsdAttributeUse.getLexicalValue());
                    }
                }
                if (attributeUses.hasNext()) {
                    // $NON-NLS-1$
                    System.out.println("<br>");
                }
            }
            if (xsdComplexTypeDefinition.getAttributeWildcard() != null) {
                // $NON-NLS-1$
                System.out.println("<br>");
                System.out.println(// $NON-NLS-1$
                "<span class='" + ALLOWS + // $NON-NLS-1$
                "'><tt><em>&nbsp;&nbsp;{&nbsp;any&nbsp;attributes&nbsp;with&nbsp;non-schema&nbsp;namespace&nbsp;.&nbsp;.&nbsp;.&nbsp;}</em></tt></span>");
            }
            // $NON-NLS-1$
            System.out.println("<tt>></tt><br>");
            if (xsdComplexTypeDefinition.getContentType() instanceof XSDParticle) {
                // $NON-NLS-1$
                System.out.print("<tt><em>&nbsp;&nbsp;Content:</em>&nbsp;");
                printParticle((XSDParticle) xsdComplexTypeDefinition.getContentType(), elementDeclarationMarkup);
                // $NON-NLS-1$
                System.out.print("</tt>");
            } else if (xsdComplexTypeDefinition.getContentType() instanceof XSDSimpleTypeDefinition) {
                // $NON-NLS-1$
                System.out.print("<b>***** simple</b>");
            } else {
                // $NON-NLS-1$
                System.out.print("<b>{ **** empty }</b>");
            }
            // $NON-NLS-1$
            System.out.println("<br>");
        }
        // $NON-NLS-1$
        System.out.print("<tt>&lt;/");
        System.out.print(elementDeclarationName);
        // $NON-NLS-1$
        System.out.println("></tt>");
        if (elementDeclarationMarkup != null) {
            // $NON-NLS-1$
            System.out.print("</div>");
        }
        // $NON-NLS-1$
        System.out.println("</div>");
        String elementDeclarationDocumentation = getElementDeclarationDocumentation(key);
        if (elementDeclarationDocumentation != null) {
            // $NON-NLS-1$
            System.out.println("<div class='reprBody'>");
            System.out.println(elementDeclarationDocumentation);
            // $NON-NLS-1$
            System.out.println("</div>");
        }
        if (attributeDocumentationBuffer.length() > 0) {
            // $NON-NLS-1$
            System.out.println("<div class='reprBody'>");
            System.out.print(attributeDocumentationBuffer);
            // $NON-NLS-1$
            System.out.println("</table>");
            // $NON-NLS-1$
            System.out.println("</div>");
        }
        // $NON-NLS-1$
        System.out.println("</td></tr></table>");
        // $NON-NLS-1$
        System.out.println("</div>");
    }
    // System.out.println("<h1>Built-in Datatypes</h1>");
    // $NON-NLS-1$
    String typeContentHeaderDocumentation = getContentDocumentation("type-header");
    if (typeContentHeaderDocumentation != null) {
        System.out.println(typeContentHeaderDocumentation);
    }
    // $NON-NLS-1$
    System.out.println("<table border=true cols=3 width='100%'>");
    // $NON-NLS-1$
    System.out.println("<tr>");
    // $NON-NLS-1$
    System.out.println("<th width=33% valign=top align=left><b>Type</b></th>");
    // $NON-NLS-1$
    System.out.println("<th width=33% valign=top align=left><b>Properties&nbsp;&amp;&nbsp;Facets</b></th>");
    // $NON-NLS-1$
    System.out.println("<th width=34% valign=top align=left><b>Effective&nbsp;Value</b></th>");
    // $NON-NLS-1$
    System.out.println("</tr>");
    // $NON-NLS-1$
    XSDSimpleTypeDefinition anyTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition("anyType");
    XSDSimpleTypeDefinition anySimpleTypeDefinition = xsdSchema.getSchemaForSchema().resolveSimpleTypeDefinition(// $NON-NLS-1$
    "anySimpleType");
    XSDSimpleTypeDefinition anyListTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
    anyListTypeDefinition.setVariety(XSDVariety.LIST_LITERAL);
    // $NON-NLS-1$
    anyListTypeDefinition.setName("anyListType");
    anyListTypeDefinition.setItemTypeDefinition(anySimpleTypeDefinition);
    xsdSchema.getContents().add(anyListTypeDefinition);
    // $NON-NLS-1$
    anyListTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyListType");
    XSDSimpleTypeDefinition anyUnionTypeDefinition = xsdFactory.createXSDSimpleTypeDefinition();
    anyUnionTypeDefinition.setVariety(XSDVariety.UNION_LITERAL);
    // $NON-NLS-1$
    anyUnionTypeDefinition.setName("anyUnionType");
    anyUnionTypeDefinition.getMemberTypeDefinitions().add(anySimpleTypeDefinition);
    xsdSchema.getContents().add(anyUnionTypeDefinition);
    // $NON-NLS-1$
    anyUnionTypeDefinition.getElement().setAttribute(XSDConstants.ID_ATTRIBUTE, "anyUnionType");
    List allTypeDefinitions = new ArrayList(xsdSchema.getTypeDefinitions());
    allTypeDefinitions.add(0, anySimpleTypeDefinition);
    allTypeDefinitions.add(0, anyTypeDefinition);
    for (Iterator i = allTypeDefinitions.iterator(); i.hasNext(); ) {
        XSDTypeDefinition xsdTypeDefinition = (XSDTypeDefinition) i.next();
        if (xsdTypeDefinition instanceof XSDSimpleTypeDefinition && xsdTypeDefinition.getElement() != null && xsdTypeDefinition.getName().equals(xsdTypeDefinition.getElement().getAttribute(XSDConstants.ID_ATTRIBUTE))) {
            XSDSimpleTypeDefinition xsdSimpleTypeDefinition = (XSDSimpleTypeDefinition) xsdTypeDefinition;
            // $NON-NLS-1$
            System.out.println("<tr>");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.out.println("<a name='" + xsdSimpleTypeDefinition.getName() + "-simple-type'>");
            // $NON-NLS-1$
            System.out.println("<td>");
            boolean isPrimitive = XSDVariety.ATOMIC_LITERAL == xsdSimpleTypeDefinition.getVariety() && xsdSimpleTypeDefinition.getBaseTypeDefinition() == anySimpleTypeDefinition;
            if (isPrimitive) {
                // $NON-NLS-1$
                System.out.print("<b>");
            }
            System.out.print(getSimpleTypeDefinitionLink(xsdSimpleTypeDefinition));
            if (isPrimitive) {
                // $NON-NLS-1$
                System.out.print("</b>");
            }
            for (XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition; ; baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition()) {
                String javaClass = (String) schemaTypeToJavaClassMap.get(baseTypeDefinition.getName());
                if (javaClass != null) {
                    // $NON-NLS-1$
                    System.out.println("<br>&nbsp;<br>");
                    if (baseTypeDefinition == xsdSimpleTypeDefinition) {
                        // ) //$NON-NLS-1$
                        System.out.print("<b>");
                    }
                    // $NON-NLS-1$
                    int dotIndex = javaClass.lastIndexOf(".");
                    // $NON-NLS-1$
                    System.out.print("<font size=-2>");
                    System.out.print(javaClass.substring(0, dotIndex + 1));
                    // $NON-NLS-1$
                    System.out.print("</font><br>&nbsp;&nbsp;");
                    System.out.print(javaClass.substring(dotIndex + 1));
                    if (baseTypeDefinition == xsdSimpleTypeDefinition) {
                        // (
                        // $NON-NLS-1$
                        System.out.print("<b>");
                    }
                    System.out.println();
                    break;
                }
            }
            // $NON-NLS-1$
            System.out.println("<br>");
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.println("</a>");
            StringBuffer validFacets = new StringBuffer();
            StringBuffer effectiveFacetValues = new StringBuffer();
            // $NON-NLS-1$
            validFacets.append("variety<br>\n");
            effectiveFacetValues.append(xsdSimpleTypeDefinition.isSetVariety() ? // $NON-NLS-1$
            "<b>" + xsdSimpleTypeDefinition.getVariety() + "</b>" : // $NON-NLS-1$ //$NON-NLS-2$
            "<em>absent</em>");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("base type definition<br>\n");
            XSDSimpleTypeDefinition baseTypeDefinition = xsdSimpleTypeDefinition.getBaseTypeDefinition();
            while (baseTypeDefinition.getName() == null) {
                baseTypeDefinition = baseTypeDefinition.getBaseTypeDefinition();
            }
            // $NON-NLS-1$
            effectiveFacetValues.append("<a href='#");
            effectiveFacetValues.append(baseTypeDefinition.getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("-simple-type'>");
            effectiveFacetValues.append(baseTypeDefinition.getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("</a><br>\n");
            // $NON-NLS-1$
            validFacets.append("ordered<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : xsdSimpleTypeDefinition.getOrderedFacet().getValue().getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("bounded<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : // $NON-NLS-1$ //$NON-NLS-2$
            xsdSimpleTypeDefinition.getBoundedFacet().isValue() ? "true" : "false");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("cardinality<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : XSDCardinality.COUNTABLY_INFINITE_LITERAL == xsdSimpleTypeDefinition.getCardinalityFacet().getValue() ? "countably infinite" : // $NON-NLS-1$
            xsdSimpleTypeDefinition.getCardinalityFacet().getValue().getName());
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            // $NON-NLS-1$
            validFacets.append("numeric<br>\n");
            effectiveFacetValues.append(// $NON-NLS-1$ //$NON-NLS-2$
            "anyUnionType".equals(xsdSimpleTypeDefinition.getName()) ? // $NON-NLS-1$ //$NON-NLS-2$
            "*" : // $NON-NLS-1$ //$NON-NLS-2$
            xsdSimpleTypeDefinition.getNumericFacet().isValue() ? "true" : "false");
            // $NON-NLS-1$
            effectiveFacetValues.append("<br>\n");
            if (xsdSimpleTypeDefinition.getValidFacets().contains("length")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("length<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveLengthFacet() != null) {
                    XSDLengthFacet xsdLengthFacet = xsdSimpleTypeDefinition.getEffectiveLengthFacet();
                    if (xsdLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdLengthFacet.getValue());
                    if (xsdLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minLength")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("minLength<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinLengthFacet() != null) {
                    XSDMinLengthFacet xsdMinLengthFacet = xsdSimpleTypeDefinition.getEffectiveMinLengthFacet();
                    if (xsdMinLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinLengthFacet.getValue());
                    if (xsdMinLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxLength")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxLength<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet() != null) {
                    XSDMaxLengthFacet xsdMaxLengthFacet = xsdSimpleTypeDefinition.getEffectiveMaxLengthFacet();
                    if (xsdMaxLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxLengthFacet.getValue());
                    if (xsdMaxLengthFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("pattern")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("pattern<br>\n");
                if (xsdSimpleTypeDefinition.getEffectivePatternFacet() != null) {
                    // XSDPatternFacet xsdPatternFacet =
                    // xsdSimpleTypeDefinition.getEffectivePatternFacet();
                    // $NON-NLS-1$
                    effectiveFacetValues.append("*");
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("enumeration")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("enumeration<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveEnumerationFacet() != null) {
                    XSDEnumerationFacet xsdEnumerationFacet = xsdSimpleTypeDefinition.getEffectiveEnumerationFacet();
                    for (Iterator enumerators = xsdEnumerationFacet.getValue().iterator(); enumerators.hasNext(); ) {
                        String enumerator = (String) enumerators.next();
                        effectiveFacetValues.append(enumerator);
                        // $NON-NLS-1$
                        effectiveFacetValues.append("&nbsp;");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("whiteSpace")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("whiteSpace<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet() != null) {
                    XSDWhiteSpaceFacet xsdWhiteSpaceFacet = xsdSimpleTypeDefinition.getEffectiveWhiteSpaceFacet();
                    if (xsdWhiteSpaceFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdWhiteSpaceFacet.getValue());
                    if (xsdWhiteSpaceFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxInclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxInclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxInclusiveFacet) {
                    XSDMaxInclusiveFacet xsdMaxInclusiveFacet = (XSDMaxInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
                    if (xsdMaxInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxInclusiveFacet.getValue());
                    if (xsdMaxInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("maxExclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxExclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMaxFacet() instanceof XSDMaxExclusiveFacet) {
                    XSDMaxExclusiveFacet xsdMaxExclusiveFacet = (XSDMaxExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMaxFacet();
                    if (xsdMaxExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMaxExclusiveFacet.getValue());
                    if (xsdMaxExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minInclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxInclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinInclusiveFacet) {
                    XSDMinInclusiveFacet xsdMinInclusiveFacet = (XSDMinInclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
                    if (xsdMinInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinInclusiveFacet.getValue());
                    if (xsdMinInclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("minExclusive")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("maxExclusive<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveMinFacet() instanceof XSDMinExclusiveFacet) {
                    XSDMinExclusiveFacet xsdMinExclusiveFacet = (XSDMinExclusiveFacet) xsdSimpleTypeDefinition.getEffectiveMinFacet();
                    if (xsdMinExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdMinExclusiveFacet.getValue());
                    if (xsdMinExclusiveFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("totalDigits")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("totalDigits<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet() != null) {
                    XSDTotalDigitsFacet xsdTotalDigitsFacet = xsdSimpleTypeDefinition.getEffectiveTotalDigitsFacet();
                    if (xsdTotalDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdTotalDigitsFacet.getValue());
                    if (xsdTotalDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            if (xsdSimpleTypeDefinition.getValidFacets().contains("fractionDigits")) {
                // $NON-NLS-1$
                // $NON-NLS-1$
                validFacets.append("fractionDigits<br>\n");
                if (xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet() != null) {
                    XSDFractionDigitsFacet xsdFractionDigitsFacet = xsdSimpleTypeDefinition.getEffectiveFractionDigitsFacet();
                    if (xsdFractionDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("<b>");
                    }
                    effectiveFacetValues.append(xsdFractionDigitsFacet.getValue());
                    if (xsdFractionDigitsFacet.isFixed()) {
                        // $NON-NLS-1$
                        effectiveFacetValues.append("</b>");
                    }
                }
                // $NON-NLS-1$
                effectiveFacetValues.append("<br>\n");
            }
            // $NON-NLS-1$
            System.out.println("<td>");
            System.out.print(validFacets);
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.print("<td>");
            System.out.println(effectiveFacetValues);
            // $NON-NLS-1$
            System.out.println("</td>");
            // $NON-NLS-1$
            System.out.println("</tr>");
        }
    }
    // $NON-NLS-1$
    System.out.println("</table>");
    // $NON-NLS-1$
    String appendixContentHeaderDocumentation = getContentDocumentation("appendix-header");
    if (appendixContentHeaderDocumentation != null) {
        System.out.println(appendixContentHeaderDocumentation);
    }
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDFactory(org.eclipse.xsd.XSDFactory) XSDMinInclusiveFacet(org.eclipse.xsd.XSDMinInclusiveFacet) HashMap(java.util.HashMap) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) ArrayList(java.util.ArrayList) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) XSDLengthFacet(org.eclipse.xsd.XSDLengthFacet) XSDEnumerationFacet(org.eclipse.xsd.XSDEnumerationFacet) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDMinExclusiveFacet(org.eclipse.xsd.XSDMinExclusiveFacet) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XSDFractionDigitsFacet(org.eclipse.xsd.XSDFractionDigitsFacet) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDWhiteSpaceFacet(org.eclipse.xsd.XSDWhiteSpaceFacet) XSDResourceImpl(org.eclipse.xsd.util.XSDResourceImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XSDMaxExclusiveFacet(org.eclipse.xsd.XSDMaxExclusiveFacet) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDTotalDigitsFacet(org.eclipse.xsd.XSDTotalDigitsFacet) XSDMinLengthFacet(org.eclipse.xsd.XSDMinLengthFacet) XSDMaxLengthFacet(org.eclipse.xsd.XSDMaxLengthFacet) XSDMaxInclusiveFacet(org.eclipse.xsd.XSDMaxInclusiveFacet) Map(java.util.Map) HashMap(java.util.HashMap) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 2 with XSDAttributeUse

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

the class XSDDeleteConceptWrapAction method doAction.

@Override
public IStatus doAction() {
    List<IStatus> results = new ArrayList<IStatus>();
    try {
        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
        if (delObjs.isEmpty()) {
            return Status.CANCEL_STATUS;
        } else {
            boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass());
            String deleteLabel = Messages.DelLabel1;
            String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText();
            // $NON-NLS-1$
            int backPos = elemDesc.indexOf(" ");
            if (delObjs.size() > 1) {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1));
                if (deleteLabel.endsWith("y")) {
                    // $NON-NLS-1$
                    deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3;
                } else {
                    deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4;
                }
            } else {
                deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1));
            }
            if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) {
                return Status.CANCEL_STATUS;
            }
        }
        for (Iterator iterator = delObjs.iterator(); iterator.hasNext(); ) {
            Object toDel = iterator.next();
            UndoAction delExecute = null;
            boolean isElem = true;
            if (toDel instanceof XSDElementDeclaration) {
                XSDElementDeclaration decl = (XSDElementDeclaration) toDel;
                EList l = decl.getIdentityConstraintDefinitions();
                for (Iterator iter = l.iterator(); iter.hasNext(); ) {
                    XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
                    if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                        isElem = false;
                        break;
                    }
                }
            }
            if (toDel instanceof XSDXPathDefinition) {
                XSDXPathDefinition xpath = (XSDXPathDefinition) toDel;
                if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
                    continue;
                }
            }
            delExecute = clsAction.get(toDel.getClass());
            if (isElem && toDel instanceof XSDElementDeclaration) {
                delExecute = clsAction.get(null);
            }
            if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) {
                ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel);
            } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) {
                ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel);
            } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) {
                ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) {
                ((XSDDeleteIdentityConstraintAction) delExecute).setXSDTODel((XSDIdentityConstraintDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) {
                ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel);
            } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) {
                ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel);
            } else {
                return Status.CANCEL_STATUS;
            }
            results.add(delExecute.execute());
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage()));
        return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
    }
    return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Action(org.eclipse.jface.action.Action) XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Iterator(java.util.Iterator) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration)

Example 3 with XSDAttributeUse

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

the class DataModelMainPage method fillContextMenu.

protected void fillContextMenu(IMenuManager manager, boolean isType) {
    IStructuredSelection selection;
    if (!isType) {
        selection = ((IStructuredSelection) viewer.getSelection());
    } else {
        selection = ((IStructuredSelection) typesViewer.getSelection());
    }
    Object[] selectedObjs = selection.toArray();
    Object obj = selection.getFirstElement();
    if (!isType) {
        manager.add(newConceptAction);
    } else {
        manager.add(newComplexTypeAction);
        manager.add(newSimpleTypeAction);
        // add by ymli; fix the bug:0012228. Made the multiple types can be deleted.
        XSDDeleteTypeDefinition deleteTypeDefinition1;
        if (selectedObjs.length > 1) {
            deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, true);
        } else {
            deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, false);
        }
        if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs)) {
            manager.add(deleteTypeDefinition1);
        }
        deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
        if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
            deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
        }
        if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
            manager.add(deleteConceptWrapAction.outPutDeleteActions());
            if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs)) {
                manager.add(newBrowseItemAction);
            }
        }
        if (exAdapter != null && obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
            exAdapter.fillContextMenu(manager);
        }
    }
    manager.add(new Separator());
    if (!isType && ((selection == null) || (selection.getFirstElement() == null))) {
        if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 0) {
            manager.add(new Separator(ADDITIONMENUID));
            // add by ymli, fix bug 0009770
            // $NON-NLS-1$
            String title = "";
            if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
                title = Messages.PasteEntityText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
                title = Messages.PasteEntitiesText;
            }
            XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
            if (pasteConceptAction.checkInPasteType()) {
                manager.add(new Separator());
                manager.add(pasteConceptAction);
            }
        }
        return;
    }
    // Element Declaration
    if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
        // check if concept or "just" element
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        boolean isConcept = Util.checkConcept(decl);
        if (!Util.IsAImporedElement(decl, xsdSchema)) {
            if (isConcept) {
                manager.add(editConceptAction);
                manager.add(deleteConceptAction);
                manager.add(newBrowseItemAction);
            } else {
                manager.add(editElementAction);
                manager.add(deleteElementAction);
            }
            // add by ymli. fix bug 0009770 add the copy of concepts
            copyConceptAction.setText(Messages.CopyEntityText);
            if (Util.checkInCopy(selectedObjs)) {
                manager.add(new Separator());
                manager.add(copyConceptAction);
            }
            /*
                 * boolean isMulti = false; if(WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size()>1)
                 * isMulti = true;
                 */
            // $NON-NLS-1$
            String title = "";
            if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
                title = Messages.PasteEntitiesText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
                title = Messages.PasteEntityText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1) {
                title = Messages.PasteElementsText;
            } else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1) {
                title = Messages.PasteElement;
            }
            XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
            if (pasteConceptAction.checkInPasteType()) {
                manager.add(pasteConceptAction);
            }
            manager.add(new Separator());
            manager.add(newElementAction);
            manager.add(new Separator());
            manager.add(changeToComplexTypeAction);
            manager.add(changeToSimpleTypeAction);
            // add by fliu, see bugID:0009157
            if (((XSDElementDeclaration) obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                manager.add(setFacetMsgAction);
                manager.add(setAnnotationDisplayFomatAction);
            }
            manager.add(new Separator());
            manager.add(newIdentityConstraintAction);
        } else {
            if (isConcept) {
                manager.add(newBrowseItemAction);
            }
            manager.add(newElementAction);
        }
        // Annotations
        if (!Util.IsAImporedElement(decl, xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(), xsdSchema)) {
            setAnnotationActions2(obj, manager);
        }
    }
    // add by rhou.fix bug 0012073: Enable to create element from sub element group
    if (obj instanceof XSDModelGroup) {
        manager.add(new Separator());
        manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
        manager.add(new Separator());
        manager.add(changeSubElementGroupAction);
        manager.add(new Separator());
        manager.add(setAnnotationLabelAction);
        addPasteElementAction(manager);
    }
    if (obj instanceof XSDAttributeUse && selectedObjs.length == 1) {
        manager.add(deleteAttributeAction);
    }
    if (obj instanceof XSDAttributeDeclaration && selectedObjs.length == 1) {
        manager.add(deleteAttributeAction);
    }
    if (obj instanceof XSDParticle && selectedObjs.length == 1) {
        XSDTerm term = ((XSDParticle) obj).getTerm();
        if (!(term instanceof XSDWildcard)) {
            if (term instanceof XSDElementDeclaration) {
                manager.add(editParticleAction);
                if (!Util.IsAImporedElement(term, xsdSchema) || term.getContainer() instanceof XSDSchema) {
                    manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
                    if (term instanceof XSDModelGroup) {
                        manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
                        manager.add(newGroupFromTypeAction);
                    }
                    manager.add(deleteParticleAction);
                    // edit by ymli. fix the bug:0011523
                    copyConceptAction.setText(Messages.CopyElementText);
                    manager.add(copyConceptAction);
                    if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
                        addPasteElementAction(manager);
                    }
                    manager.add(new Separator());
                    manager.add(changeToComplexTypeAction);
                    manager.add(changeToSimpleTypeAction);
                    // add by fliu, see bugID:0009157
                    manager.add(new Separator());
                    // Annotations
                    XSDTypeDefinition type = ((XSDElementDeclaration) term).getTypeDefinition();
                    setAnnotationActions(obj, manager);
                    if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
                        manager.add(setFacetMsgAction);
                        manager.add(setAnnotationDisplayFomatAction);
                    }
                    // Xpath
                    manager.add(new Separator());
                    manager.add(getXPathAction);
                }
            }
        }
    }
    if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition) obj).getTargetNamespace() == null) {
        if (!isType && !Util.IsAImporedElement((XSDParticle) obj, xsdSchema)) {
            manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
            manager.add(newGroupFromTypeAction);
        }
        if (!Util.IsAImporedElement((XSDComplexTypeDefinition) obj, xsdSchema)) {
            // add by rhou.fix bug 0012073: Enable to create element from sub element group
            manager.add(new Separator());
            manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
            manager.add(new Separator());
            manager.add(editComplexTypeAction);
        }
        manager.add(setAnnotationLabelAction);
        addPasteElementAction(manager);
    }
    if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition) obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition) obj, xsdSchema)) {
        manager.add(deleteIdentityConstraintAction);
        manager.add(new Separator());
        manager.add(newXPathAction);
    }
    if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition) obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDXPathDefinition) obj, xsdSchema)) {
        manager.add(editXPathAction);
        manager.add(newXPathAction);
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            manager.add(deleteXPathAction);
        }
    }
    // for the anonymous simpleType
    if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition) obj, xsdSchema) || ((XSDSimpleTypeDefinition) obj).getName() == null)) {
        XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) obj;
        manager.add(changeBaseTypeAction);
        manager.add(new Separator());
        if (typedef.getBaseTypeDefinition() != null) {
            EList list = typedef.getBaseTypeDefinition().getValidFacets();
            for (Iterator iter = list.iterator(); iter.hasNext(); ) {
                String element = (String) iter.next();
                manager.add(new XSDEditFacetAction(this, element));
            }
        }
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
        deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
        manager.add(newBrowseItemAction);
    }
    if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
        if (!isType) {
            manager.add(deleteConceptWrapAction.outPutDeleteActions());
        }
        // $NON-NLS-1$
        String title = "";
        if (Util.checkInCopyTypeElement(selectedObjs)) {
            title = Messages.CopyEntitiesText;
        } else if (Util.checkInCOpyTypeParticle(selectedObjs)) {
            title = Messages.CopyElements;
        }
        copyConceptAction.setText(title);
        if (Util.checkInCopy(selectedObjs)) {
            manager.add(copyConceptAction);
        }
        // add by ymli; fix bug:0016645
        if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
            manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
        }
    }
    if (exAdapter != null) {
        exAdapter.fillContextMenu(manager, selectedObjs);
    }
    // available models
    java.util.List<IAvailableModel> availablemodels = AvailableModelUtil.getAvailableModels(isLocalInput());
    for (int i = 0; i < availablemodels.size(); i++) {
        IAvailableModel model = availablemodels.get(i);
        model.fillContextMenu(obj, manager, this, dataModelName);
        if (i == 1) {
            manager.add(new Separator());
        }
    }
    // 
    manager.add(new Separator());
    drillDownAdapter.addNavigationActions(manager);
    // Other plug-ins can contribute there actions here
    manager.add(new Separator(ADDITIONMENUID));
    deleteConceptWrapAction.clearExtraClassToDel();
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) IAvailableModel(com.amalto.workbench.availablemodel.IAvailableModel) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDPasteConceptAction(com.amalto.workbench.actions.XSDPasteConceptAction) XSDWildcard(org.eclipse.xsd.XSDWildcard) EList(org.eclipse.emf.common.util.EList) XSDEditFacetAction(com.amalto.workbench.actions.XSDEditFacetAction) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject) XSDDeleteTypeDefinition(com.amalto.workbench.actions.XSDDeleteTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) Separator(org.eclipse.jface.action.Separator)

Example 4 with XSDAttributeUse

use of org.eclipse.xsd.XSDAttributeUse 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 5 with XSDAttributeUse

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

the class TypesLabelProvider method getImage.

@Override
public Image getImage(Object obj) {
    if (obj instanceof XSDElementDeclaration) {
        // top declaration
        XSDElementDeclaration decl = (XSDElementDeclaration) obj;
        // check if concept or "just" element
        boolean isConcept = false;
        EList l = decl.getIdentityConstraintDefinitions();
        for (Iterator iter = l.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                isConcept = true;
                break;
            }
        }
        // display approprite image
        if (isConcept) {
            return ImageCache.getCreatedImage(EImage.CONCEPT.getPath());
        } else {
            return ImageCache.getCreatedImage(EImage.ELEMENT_ONLY.getPath());
        /*
                 * if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) return
                 * PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_FOLDER); else
                 * return ImageCache.getCreatedImage( "icons/elements_obj_+.gif");
                 */
        }
    }
    if (obj instanceof XSDParticle) {
        XSDParticle xsdParticle = (XSDParticle) obj;
        XSDTerm xsdTerm = xsdParticle.getTerm();
        if (xsdTerm instanceof XSDElementDeclaration) {
            // get Type of Parent Group
            // if (Util.getKeyInfo(xsdTerm) != null && Util.getKeyInfo(xsdTerm).size() > 0) {
            // return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
            // }
            XSDConcreteComponent xsdConcreteComponent = xsdParticle.getContainer();
            if (XSDUtil.hasFKInfo((XSDElementDeclaration) xsdTerm)) {
                return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
            }
            if (xsdConcreteComponent instanceof XSDModelGroup) {
                return ImageCache.getCreatedImage(EImage.SCHEMAELEMENT.getPath());
            }
        /*
                 * if(((XSDElementDeclaration) xsdTerm).getAnonymousTypeDefinition() instanceof
                 * XSDComplexTypeDefinition) return ImageCache.getCreatedImage( EImage.COMPLEXTYPE.getPath()); else
                 * return ImageCache.getCreatedImage( EImage.SIMPLETYPE.getPath());
                 */
        } else if (xsdTerm instanceof XSDModelGroup) {
            int type = ((XSDModelGroup) xsdTerm).getCompositor().getValue();
            switch(type) {
                case XSDCompositor.ALL:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                case XSDCompositor.CHOICE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                case XSDCompositor.SEQUENCE:
                    return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
            }
        } else if (xsdTerm instanceof XSDWildcard) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/wildcard.gif");
        } else {
            log.info(Messages.TypesLabelProvider_16 + xsdTerm.getClass().getName());
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDSimpleTypeDefinition) {
        return ImageCache.getCreatedImage(EImage.SIMPLETYPE.getPath());
    }
    if (obj instanceof XSDComplexTypeDefinition) {
        XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) obj;
        XSDComplexTypeContent ctc = ctd.getContent();
        if (ctc instanceof XSDParticle) {
            if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) {
                int type = ((XSDModelGroup) ((XSDParticle) ctc).getTerm()).getCompositor().getValue();
                switch(type) {
                    case XSDCompositor.ALL:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
                    case XSDCompositor.CHOICE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
                    case XSDCompositor.SEQUENCE:
                        return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
                }
            }
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/error.gif");
        }
    }
    if (obj instanceof XSDModelGroup) {
        int type = ((XSDModelGroup) obj).getCompositor().getValue();
        switch(type) {
            case XSDCompositor.ALL:
                return ImageCache.getCreatedImage(EImage.COMPLEX_ALL.getPath());
            case XSDCompositor.CHOICE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_CHOICE.getPath());
            case XSDCompositor.SEQUENCE:
                return ImageCache.getCreatedImage(EImage.COMPLEX_SEQUENCE.getPath());
        }
    }
    if (obj instanceof XSDFacet) {
        return ImageCache.getCreatedImage(EImage.FACET.getPath());
    }
    if (obj instanceof XSDIdentityConstraintDefinition) {
        XSDIdentityConstraintDefinition identity = (XSDIdentityConstraintDefinition) obj;
        if (identity.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
            return ImageCache.getCreatedImage(EImage.KEYS.getPath());
        }
        return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());
    }
    if (obj instanceof XSDXPathDefinition) {
        XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
        if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/field.gif");
        }
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/selector.gif");
    }
    if (obj instanceof XSDAttributeGroupDefinition) {
        // $NON-NLS-1$
        return ImageCache.getCreatedImage("icons/attribute_group.gif");
    }
    if (obj instanceof XSDAttributeUse) {
        XSDAttributeUse att = (XSDAttributeUse) obj;
        if ("xmlns".equals(att.getAttributeDeclaration().getTargetNamespace())) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
        }
        if (att.getUse().equals(XSDAttributeUseCategory.REQUIRED_LITERAL)) {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute_mandatory.gif");
        } else {
            // $NON-NLS-1$
            return ImageCache.getCreatedImage("icons/attribute.gif");
        }
    }
    if (obj instanceof XSDAnnotation) {
        return ImageCache.getCreatedImage(EImage.ANNOTATION.getPath());
    }
    if (obj instanceof Element) {
        try {
            Element e = (Element) obj;
            if (e.getLocalName().equals("documentation")) {
                // $NON-NLS-1$
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            } 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 ImageCache.getCreatedImage(EImage.LABEL.getPath());
                    } else if (source.equals("X_ForeignKey")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.FK_OBJ.getPath());
                    } else if (source.equals("X_ForeignKeyInfo")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_FKIntegrity_Override")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());
                    } else if (source.equals("X_SourceSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());
                    } else if (source.equals("X_TargetSystem")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());
                    } else if (source.startsWith("X_Description_")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    } else if (source.equals("X_Write")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Hide")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_Create")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_LogicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_Deny_PhysicalDelete")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());
                    } else if (source.equals("X_AutoExpand")) {
                        // $NON-NLS-1$
                        return ImageCache.getCreatedImage(EImage.DEFAULT.getPath());
                    } else {
                        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                    }
                } else {
                    return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
                }
            } else {
                return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    // $NON-NLS-1$
    return ImageCache.getCreatedImage("icons/tree_object.gif");
// return PlatformUI.getWorkbench().getSharedImages().getCreatedImage(ISharedImages.IMG_OBJ_ELEMENT);
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDConcreteComponent(org.eclipse.xsd.XSDConcreteComponent) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) XSDComplexTypeContent(org.eclipse.xsd.XSDComplexTypeContent) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) Element(org.w3c.dom.Element) XSDWildcard(org.eclipse.xsd.XSDWildcard) XSDAttributeGroupDefinition(org.eclipse.xsd.XSDAttributeGroupDefinition) XSDFacet(org.eclipse.xsd.XSDFacet) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Aggregations

XSDAttributeUse (org.eclipse.xsd.XSDAttributeUse)28 Iterator (java.util.Iterator)17 XSDAttributeGroupDefinition (org.eclipse.xsd.XSDAttributeGroupDefinition)17 XSDAttributeDeclaration (org.eclipse.xsd.XSDAttributeDeclaration)14 XSDComplexTypeDefinition (org.eclipse.xsd.XSDComplexTypeDefinition)14 XSDParticle (org.eclipse.xsd.XSDParticle)12 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)11 XSDSimpleTypeDefinition (org.eclipse.xsd.XSDSimpleTypeDefinition)11 XSDModelGroup (org.eclipse.xsd.XSDModelGroup)10 XSDConcreteComponent (org.eclipse.xsd.XSDConcreteComponent)9 XSDSchema (org.eclipse.xsd.XSDSchema)9 List (java.util.List)8 XSDWildcard (org.eclipse.xsd.XSDWildcard)8 ArrayList (java.util.ArrayList)7 EList (org.eclipse.emf.common.util.EList)7 Element (org.w3c.dom.Element)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)6 XSDTypeDefinition (org.eclipse.xsd.XSDTypeDefinition)6 XSDXPathDefinition (org.eclipse.xsd.XSDXPathDefinition)6