Search in sources :

Example 16 with ModelQuery

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

the class DocumentImpl method getCMAttributes.

/**
 * Provides an element's attribute declarations
 * @param element the element to retrieve the attribute map of
 * @return a <code>CMNamedNodeMap</code> of attributes if the declaration exists; null otherwise.
 */
CMNamedNodeMap getCMAttributes(Element element) {
    CMNamedNodeMap map = (CMNamedNodeMap) fCMCache.get(element);
    if (map == null) {
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(this);
        CMElementDeclaration decl = modelQuery != null ? modelQuery.getCMElementDeclaration(element) : null;
        if (decl != null) {
            map = decl.getAttributes();
            fCMCache.put(element, map);
        }
    }
    return map;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 17 with ModelQuery

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

the class AbstractContentAssistProcessor method getPossibleDataTypeValues.

/**
 * Retrieves all of the possible valid values for this attribute
 * declaration
 */
protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) {
    List list = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String[] dataTypeValues = null;
        // The ModelQuery may not be available if the corresponding
        // adapter
        // is absent
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
        if (modelQuery != null) {
            dataTypeValues = modelQuery.getPossibleDataTypeValues(element, ad);
        } else {
            if (ad.getAttrType() != null) {
                dataTypeValues = ad.getAttrType().getEnumeratedValues();
            }
        }
        if (dataTypeValues != null) {
            list = new ArrayList(dataTypeValues.length);
            for (int i = 0; i < dataTypeValues.length; i++) {
                list.add(dataTypeValues[i]);
            }
        }
    }
    if (list == null) {
        list = new ArrayList(0);
    }
    return list;
}
Also used : Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 18 with ModelQuery

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

the class AbstractContentAssistProcessor method getAvailableChildrenAtIndex.

// returns a list of ModelQueryActions
protected List getAvailableChildrenAtIndex(Element parent, int index, int validityChecking) {
    List list = new ArrayList();
    CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
    if (parentDecl != null) {
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
        // taken from ActionManagers
        // int editMode = modelQuery.getEditMode();
        int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
        int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES;
        modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list);
    }
    return list;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 19 with ModelQuery

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

the class XMLQuickAssistProcessor method getRequiredAttrs.

private List getRequiredAttrs(Node node) {
    List result = new ArrayList();
    ModelQuery modelQuery = getModelQuery(node);
    if (modelQuery != null) {
        CMElementDeclaration elementDecl = modelQuery.getCMElementDeclaration((Element) node);
        if (elementDecl != null) {
            CMNamedNodeMap attrMap = elementDecl.getAttributes();
            CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attrMap);
            List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, elementDecl, ModelQuery.INCLUDE_ATTRIBUTES);
            for (int k = 0; k < nodes.size(); k++) {
                CMNode cmnode = (CMNode) nodes.get(k);
                if (cmnode.getNodeType() == CMNode.ATTRIBUTE_DECLARATION) {
                    allAttributes.put(cmnode);
                }
            }
            attrMap = allAttributes;
            Iterator it = attrMap.iterator();
            CMAttributeDeclaration attr = null;
            while (it.hasNext()) {
                attr = (CMAttributeDeclaration) it.next();
                if (attr.getUsage() == CMAttributeDeclaration.REQUIRED) {
                    result.add(attr);
                }
            }
        }
    }
    return result;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 20 with ModelQuery

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

the class ContentModelWorkbenchAdapter method getChildren.

public Object[] getChildren(Object o) {
    if (o instanceof Element) {
        Element node = (Element) o;
        ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
        if (mq != null) {
            CMElementDeclaration decl = mq.getCMElementDeclaration(node);
            CMListWorkbenchAdapter adapter = new CMListWorkbenchAdapter(decl);
            return new Object[] { adapter };
        }
    }
    return EMPTY;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Aggregations

ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)76 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)38 List (java.util.List)22 ArrayList (java.util.ArrayList)19 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)18 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)16 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)15 Element (org.w3c.dom.Element)15 Document (org.w3c.dom.Document)14 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)13 Node (org.w3c.dom.Node)12 Iterator (java.util.Iterator)10 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 NodeList (org.w3c.dom.NodeList)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6