Search in sources :

Example 11 with CMDataType

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.

the class BaseNodeActionManager method contributeTextNodeActions.

protected void contributeTextNodeActions(IMenuManager menu, Element parentElement, CMElementDeclaration parentEd, int index) {
    if ((parentEd == null) || isTextAllowed(parentEd)) {
        CMDataType dataType = parentEd != null ? parentEd.getDataType() : null;
        contributeAction(menu, createAddPCDataAction(parentElement, dataType, index));
        contributeAction(menu, createAddCDataSectionAction(parentElement, index));
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)

Example 12 with CMDataType

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.

the class XSLContentModelGenerator method generateRequiredAttribute.

/**
 * @param ownerNode
 * @param attrDecl
 * @param buffer
 */
public void generateRequiredAttribute(Node ownerNode, CMAttributeDeclaration attrDecl, StringBuffer buffer) {
    if ((attrDecl == null) || (buffer == null)) {
        return;
    }
    // attribute name
    String attributeName = getRequiredName(ownerNode, attrDecl);
    CMDataType attrType = attrDecl.getAttrType();
    String defaultValue = null;
    // = sign
    // $NON-NLS-1$
    buffer.append(attributeName + "=");
    // attribute value
    if (attrType != null) {
        // insert any value that is implied
        if ((attrType.getImpliedValueKind() != CMDataType.IMPLIED_VALUE_NONE) && (attrType.getImpliedValue() != null)) {
            defaultValue = attrType.getImpliedValue();
        } else // first value
        if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
            defaultValue = attrType.getEnumeratedValues()[0];
        }
    }
    char attrQuote = '\"';
    // Found a double quote, wrap the attribute in single quotes
    if (defaultValue != null && defaultValue.indexOf(attrQuote) >= 0) {
        attrQuote = '\'';
    }
    buffer.append(attrQuote);
    // $NON-NLS-1$
    buffer.append(((defaultValue != null) ? defaultValue : ""));
    buffer.append(attrQuote);
    return;
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)

Example 13 with CMDataType

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.

the class CMPrinter method visitCMElementDeclaration.

public void visitCMElementDeclaration(CMElementDeclaration ed) {
    if (!visitedElements.contains(ed)) {
        visitedElements.add(ed);
        // $NON-NLS-1$
        fStringBuffer.append(indent + "<CMElementDeclaration");
        printAttributes(fStringBuffer, ed);
        // $NON-NLS-1$
        fStringBuffer.append(">\n");
        incrementIndent();
        printProperties(fStringBuffer, ed);
        CMNamedNodeMap nodeMap = ed.getAttributes();
        int size = nodeMap.getLength();
        for (int i = 0; i < size; i++) {
            visitCMNode(nodeMap.item(i));
        }
        visitCMNode(ed.getContent());
        CMDataType dataType = ed.getDataType();
        if (dataType != null)
            visitCMNode(dataType);
        decrementIndent();
        // $NON-NLS-1$
        fStringBuffer.append(indent + "</CMElementDeclaration>\n");
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 14 with CMDataType

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.

the class XMLPropertySource method getValidValues.

private String[] getValidValues(CMAttributeDeclaration attrDecl) {
    if (attrDecl == null) {
        return new String[0];
    }
    String[] validValues = null;
    CMDataType attrType = attrDecl.getAttrType();
    if (attrType != null) {
        validValues = _getValidStrings(attrDecl, attrType);
        if (fSortEnumeratedValues) {
            Arrays.sort(validValues);
        }
    }
    if (validValues == null) {
        validValues = new String[0];
    }
    return validValues;
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)

Example 15 with CMDataType

use of org.eclipse.wst.xml.core.internal.contentmodel.CMDataType in project webtools.sourceediting by eclipse.

the class XMLPropertySource method createPropertyDescriptor.

protected IPropertyDescriptor createPropertyDescriptor(CMAttributeDeclaration attrDecl, Attr attr) {
    IPropertyDescriptor descriptor = null;
    CMDataType attrType = attrDecl.getAttrType();
    if (attrType != null) {
        // handle declarations that provide FIXED/ENUMERATED values
        if ((attrType.getEnumeratedValues() != null) && (attrType.getEnumeratedValues().length > 0)) {
            descriptor = createEnumeratedPropertyDescriptor(attrDecl, attrType, attr);
        } else if (((attrDecl.getUsage() == CMAttributeDeclaration.FIXED) || (attrType.getImpliedValueKind() == CMDataType.IMPLIED_VALUE_FIXED)) && (attrType.getImpliedValue() != null)) {
            descriptor = createFixedPropertyDescriptor(attrDecl, attrType, attr);
        } else {
            // plain text
            descriptor = createTextPropertyDescriptor(attrDecl, attr);
        }
    } else {
        // no extra information given
        descriptor = createTextPropertyDescriptor(attrDecl, attr);
    }
    return descriptor;
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Aggregations

CMDataType (org.eclipse.wst.xml.core.internal.contentmodel.CMDataType)26 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)12 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)9 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)7 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)7 List (java.util.List)6 Element (org.w3c.dom.Element)6 ArrayList (java.util.ArrayList)5 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)5 Node (org.w3c.dom.Node)5 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)4 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)4 Iterator (java.util.Iterator)3 Vector (java.util.Vector)3 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)3 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)3 NodeList (org.w3c.dom.NodeList)3 Image (org.eclipse.swt.graphics.Image)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)2