Search in sources :

Example 91 with CMElementDeclaration

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

the class AttributeContextInformationProvider method getInfoForElement.

/**
 * @param node
 */
private IContextInformation[] getInfoForElement(IDOMNode node) {
    IContextInformation[] results = EMPTY_CONTEXT_INFO;
    CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) node);
    if (decl != null) {
        CMNamedNodeMap attributes = decl.getAttributes();
        CMNamedNodeMapImpl allAttributes = new CMNamedNodeMapImpl(attributes);
        List nodes = ModelQueryUtil.getModelQuery(node.getOwnerDocument()).getAvailableContent((Element) node, decl, 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);
            }
        }
        attributes = allAttributes;
        String attrContextString = node.getNodeName();
        // $NON-NLS-1$
        StringBuffer attrInfo = new StringBuffer(" ");
        // $NON-NLS-1$
        String name = "";
        HashMap attrPosMap = new HashMap();
        int pos = 0;
        int length = 0;
        int numPerLine = 8;
        CMAttributeDeclaration[] sortedAttrs = getSortedAttributes(attributes);
        for (int i = 0; i < sortedAttrs.length; i++) {
            name = sortedAttrs[i].getAttrName();
            length = name.length();
            pos = attrInfo.length();
            attrInfo.append(name);
            if (sortedAttrs[i].getUsage() == CMAttributeDeclaration.REQUIRED) {
                // $NON-NLS-1$
                attrInfo.append("*");
                length++;
            }
            if (i < attributes.getLength() - 1) {
                // $NON-NLS-1$
                attrInfo.append(" ");
                if ((i != 0) && (i % numPerLine == 0)) {
                    // $NON-NLS-1$
                    attrInfo.append("\n ");
                }
            }
            attrPosMap.put(name, new Position(pos, length));
        }
        if (!attrInfo.toString().trim().equals("")) {
            return new IContextInformation[] { new AttributeContextInformation(attrContextString, attrInfo.toString(), attrPosMap) };
        }
    }
    return results;
}
Also used : CMNamedNodeMapImpl(org.eclipse.wst.xml.core.internal.contentmodel.basic.CMNamedNodeMapImpl) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList) List(java.util.List) 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 92 with CMElementDeclaration

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

the class AttributeContextInformationProvider method getInfoForText.

/**
 * @param node
 */
IContextInformation[] getInfoForText(IDOMNode node) {
    Node parent = node.getParentNode();
    String contextString = node.getNodeName();
    // $NON-NLS-1$
    StringBuffer info = new StringBuffer(" ");
    if ((parent != null) && (parent.getNodeType() == Node.ELEMENT_NODE)) {
        CMElementDeclaration decl = fModelUtil.getModelQuery().getCMElementDeclaration((Element) parent);
        CMContent content = decl.getContent();
        if (content instanceof CMGroup) {
            CMGroup cmGroup = (CMGroup) content;
            CMNodeList children = cmGroup.getChildNodes();
            CMNode cmNode = null;
            for (int i = 0; i < children.getLength(); i++) {
                cmNode = children.item(i);
                contextString = cmNode.getNodeName();
                if (contextString != null) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    info.append("<" + cmNode.getNodeName() + ">");
                    if (i < children.getLength() - 1) {
                        // $NON-NLS-1$
                        info.append(" ");
                    }
                }
            }
        }
    }
    if (!info.toString().trim().equals("")) {
        return new IContextInformation[] { new ContextInformation(contextString, info.toString()) };
    } else {
        return EMPTY_CONTEXT_INFO;
    }
}
Also used : CMGroup(org.eclipse.wst.xml.core.internal.contentmodel.CMGroup) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) ContextInformation(org.eclipse.jface.text.contentassist.ContextInformation) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) IContextInformation(org.eclipse.jface.text.contentassist.IContextInformation) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMContent(org.eclipse.wst.xml.core.internal.contentmodel.CMContent) CMNodeList(org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)

Example 93 with CMElementDeclaration

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

the class XMLHyperlinkDetector method getCMElementDeclaration.

/**
 * Get the CMElementDeclaration for an element
 *
 * @param element
 * @return CMElementDeclaration
 */
private CMElementDeclaration getCMElementDeclaration(Element element) {
    CMElementDeclaration ed = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if (mq != null) {
        ed = mq.getCMElementDeclaration(element);
    }
    return ed;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 94 with CMElementDeclaration

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

the class JSPModelQueryCMProvider method getCorrespondingCMDocument.

/**
 * Returns the CMDocument that corresponds to the DOM Node. or null if no
 * CMDocument is appropriate for the DOM Node.
 */
public CMDocument getCorrespondingCMDocument(Node node) {
    CMDocument jcmdoc = null;
    if (node instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) node).getModel();
        String modelPath = model.getBaseLocation();
        if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
            float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
            jcmdoc = JSPCMDocumentFactory.getCMDocument(version);
        }
    }
    if (jcmdoc == null) {
        jcmdoc = JSPCMDocumentFactory.getCMDocument();
    }
    CMDocument result = null;
    try {
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String elementName = node.getNodeName();
            // test to see if this node belongs to JSP's CMDocument (case
            // sensitive)
            CMElementDeclaration dec = (CMElementDeclaration) jcmdoc.getElements().getNamedItem(elementName);
            if (dec != null) {
                result = jcmdoc;
            }
        }
        String prefix = node.getPrefix();
        if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
            // check position dependent
            IDOMNode xmlNode = (IDOMNode) node;
            TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
            if (tldmgr != null) {
                List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
                // there shouldn't be more than one cmdocument returned
                if (documents != null && documents.size() > 0)
                    result = (CMDocument) documents.get(0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) List(java.util.List)

Example 95 with CMElementDeclaration

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

the class TagModelQueryCMProvider method getCorrespondingCMDocument.

/**
 * Returns the CMDocument that corresponds to the DOM Node. or null if no
 * CMDocument is appropriate for the DOM Node.
 */
public CMDocument getCorrespondingCMDocument(Node node) {
    CMDocument tagdoc = null;
    if (node instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) node).getModel();
        String modelPath = model.getBaseLocation();
        if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) {
            float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath));
            tagdoc = TAGCMDocumentFactory.getCMDocument(version);
        }
    }
    CMDocument result = null;
    try {
        if (node.getNodeType() == Node.ELEMENT_NODE && tagdoc != null) {
            String elementName = node.getNodeName();
            // test to see if this node belongs to JSP's CMDocument (case
            // sensitive)
            CMElementDeclaration dec = (CMElementDeclaration) tagdoc.getElements().getNamedItem(elementName);
            if (dec != null) {
                result = tagdoc;
            }
        }
        String prefix = node.getPrefix();
        if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) {
            // check position dependent
            IDOMNode xmlNode = (IDOMNode) node;
            TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument());
            if (tldmgr != null) {
                List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset());
                // there shouldn't be more than one cmdocument returned
                if (documents != null && !documents.isEmpty())
                    result = (CMDocument) documents.get(0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    // }
    return result;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) Path(org.eclipse.core.runtime.Path) TLDCMDocumentManager(org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) List(java.util.List)

Aggregations

CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)147 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)53 List (java.util.List)46 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)43 Element (org.w3c.dom.Element)41 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)38 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)37 ArrayList (java.util.ArrayList)35 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)33 Node (org.w3c.dom.Node)32 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)30 NodeList (org.w3c.dom.NodeList)28 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)24 Iterator (java.util.Iterator)19 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)17 NamedNodeMap (org.w3c.dom.NamedNodeMap)17 Image (org.eclipse.swt.graphics.Image)15 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)15