Search in sources :

Example 81 with CMNode

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

the class CMImageUtil method getDeclaration.

public static CMNode getDeclaration(Node node) {
    CMNode decl = null;
    ModelQuery mq = null;
    switch(node.getNodeType()) {
        case Node.ATTRIBUTE_NODE:
            {
                mq = ModelQueryUtil.getModelQuery(((Attr) node).getOwnerDocument());
                decl = mq.getCMAttributeDeclaration((Attr) node);
            }
            break;
        case Node.ELEMENT_NODE:
            {
                mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
                decl = mq.getCMElementDeclaration((Element) node);
            }
            break;
    }
    return decl;
}
Also used : CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 82 with CMNode

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

the class XMLAnnotationsView method selectionChanged.

public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    IEditorPart edPart = getSite().getPage().getActiveEditor();
    if (part.equals(edPart)) {
        if (selection instanceof IStructuredSelection) {
            currentSelection = (IStructuredSelection) selection;
            if (!selection.isEmpty() && (currentSelection.getFirstElement() instanceof Node)) {
                Node node = (Node) currentSelection.getFirstElement();
                ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
                if (mq != null) {
                    cmNode = mq.getCMNode(node);
                    MarkupTagInfoProvider tagInfo = new MarkupTagInfoProvider();
                    xmlDoc = tagInfo.getInfo(cmNode);
                } else {
                    xmlDoc = XMLUIMessages.Documentation_view_default_msg;
                }
                doStyledTextInput();
            }
        }
    }
}
Also used : Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) MarkupTagInfoProvider(org.eclipse.wst.xml.ui.internal.taginfo.MarkupTagInfoProvider) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 83 with CMNode

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

the class HTML5ContentModelTest method checkAttrValues.

private void checkAttrValues(String documentKey, String elementName, String attrName, String[] attrValues) {
    CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    final CMNode node = attributes.getNamedItem(attrName);
    assertNotNull("No attribute [" + attrName + "]", node);
    final String[] actualValues = ((HTMLAttributeDeclaration) node).getAttrType().getEnumeratedValues();
    assertEquals(attrValues.length, actualValues.length);
    Set valueSet = new HashSet(actualValues.length);
    for (int i = 0; i < actualValues.length; i++) {
        valueSet.add(actualValues[i]);
    }
    for (int i = 0; i < attrValues.length; i++) {
        if (!valueSet.remove(attrValues[i]))
            fail("Type did not contain attribute value [" + attrValues[i] + "]");
    }
    assertTrue("Type had unexpected attribute values", valueSet.isEmpty());
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Set(java.util.Set) HashSet(java.util.HashSet) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) HashSet(java.util.HashSet)

Example 84 with CMNode

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

the class HTML5ContentModelTest method checkAttrNames.

/**
 * @param cm_doc_type
 * @param elementName
 * @param attrNameImport
 */
private void checkAttrNames(String documentKey, String elementName, String[] attrNames) {
    CMDocument document = HTMLCMDocumentFactory.getCMDocument(documentKey);
    CMNode elementDeclaration = document.getElements().getNamedItem(elementName);
    assertEquals("not an element declaration:" + elementDeclaration, CMNode.ELEMENT_DECLARATION, elementDeclaration.getNodeType());
    assertNotNull("missing element declaration:" + elementName, elementDeclaration);
    CMNamedNodeMap attributes = ((CMElementDeclaration) elementDeclaration).getAttributes();
    for (int i = 0; i < attrNames.length; i++) {
        assertNotNull("missing attribute declaration:" + attrNames[i] + " for element: " + elementName, attributes.getNamedItem(attrNames[i]));
    }
    assertEquals("Attributes defined in content model that are not expected by the test for element: " + elementName, attributes.getLength(), attrNames.length);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)

Example 85 with CMNode

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

the class ModelQueryImpl method getOrigin.

public CMNode getOrigin(Node node) {
    CMNode result = null;
    // todo... make sure parent is right
    // 
    Node parentNode = getParentOrOwnerNode(node);
    if (parentNode != null && parentNode.getNodeType() == Node.ELEMENT_NODE) {
        Element parentElement = (Element) parentNode;
        CMNode[] array = getOriginArray(parentElement);
        if (array != null) {
            int index = getIndexOfNode(parentElement.getChildNodes(), node);
            if (index < array.length) {
                result = array[index];
            }
        }
    }
    return result;
}
Also used : Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMAnyElement(org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement) Element(org.w3c.dom.Element) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode)

Aggregations

CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)133 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)37 List (java.util.List)36 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)35 ArrayList (java.util.ArrayList)28 Iterator (java.util.Iterator)23 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)20 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)17 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)17 Element (org.w3c.dom.Element)16 NodeList (org.w3c.dom.NodeList)15 CMNamedNodeMapImpl (org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl)14 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)13 Node (org.w3c.dom.Node)13 NamedNodeMap (org.w3c.dom.NamedNodeMap)10 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)9 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)9 Image (org.eclipse.swt.graphics.Image)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8