Search in sources :

Example 41 with ModelQuery

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

the class AbstractContentAssistProcessor method computeEntityReferenceProposals.

/**
 * return all possible EntityReferenceProposals (according to current
 * position in doc)
 */
protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, IDOMNode treeNode) {
    // only handle XML content for now
    // ICompletionProposals
    Vector proposals = new Vector();
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    if ((completionRegion != null) && (completionRegion.getType() == DOMRegionContext.XML_CONTENT)) {
        int nodeOffset = documentPosition - sdRegion.getStartOffset(completionRegion);
        String regionText = sdRegion.getFullText(completionRegion);
        // the previous region...there might be a better way to do this
        if ((regionText != null) && regionText.trim().equals("") && (documentPosition > 0)) {
            // $NON-NLS-1$
            IStructuredDocumentRegion prev = treeNode.getStructuredDocument().getRegionAtCharacterOffset(documentPosition - 1);
            if ((prev != null) && prev.getText().equals("&")) {
                // $NON-NLS-1$
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=206680
                // examine previous region
                sdRegion = prev;
                completionRegion = prev.getLastRegion();
                regionText = prev.getFullText();
                nodeOffset = 1;
            }
        }
        // string must start w/ &
        if ((regionText != null) && regionText.startsWith("&")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String key = (nodeOffset > 0) ? regionText.substring(1, nodeOffset) : "";
            // get entity proposals, passing in the appropriate start
            // string
            ModelQuery mq = ModelQueryUtil.getModelQuery(((Node) treeNode).getOwnerDocument());
            if (mq != null) {
                CMDocument xmlDoc = mq.getCorrespondingCMDocument(treeNode);
                CMNamedNodeMap cmmap = null;
                Properties entities = null;
                if (xmlDoc != null) {
                    cmmap = xmlDoc.getEntities();
                }
                if (cmmap != null) {
                    entities = mapToProperties(cmmap);
                } else // 224787 in absence of content model, just use
                // minimal 5 entities
                {
                    entities = new Properties();
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("quot", "\"");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("apos", "'");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("amp", "&");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("lt", "<");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("gt", ">");
                    // $NON-NLS-1$ //$NON-NLS-2$
                    entities.put("nbsp", " ");
                }
                addEntityProposals(proposals, entities, key, nodeOffset, sdRegion, completionRegion);
            }
        }
    }
    return (ICompletionProposal[]) ((proposals.size() > 0) ? proposals.toArray(new ICompletionProposal[proposals.size()]) : null);
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) Properties(java.util.Properties) Vector(java.util.Vector)

Example 42 with ModelQuery

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

the class XMLTableTreePropertyDescriptorFactory method createTextPropertyDescriptor.

public IPropertyDescriptor createTextPropertyDescriptor(Text text) {
    IPropertyDescriptor result = null;
    Node parentNode = text.getParentNode();
    if ((parentNode != null) && (parentNode.getNodeType() == Node.ELEMENT_NODE)) {
        Element parentElement = (Element) parentNode;
        ModelQuery mq = ModelQueryUtil.getModelQuery(text.getOwnerDocument());
        CMElementDeclaration ed = null;
        if (mq != null) {
            ed = mq.getCMElementDeclaration(parentElement);
        }
        if (ed != null) {
            result = createPropertyDescriptorHelper(HACK, parentElement, ed);
        } else {
            result = createDefaultPropertyDescriptor(parentElement.getNodeName());
        }
    }
    if (result == null) {
        result = new TextPropertyDescriptor(HACK, HACK);
    }
    return result;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Element(org.w3c.dom.Element) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Example 43 with ModelQuery

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

the class XMLTreeExtension method getElementValueHelper.

public String getElementValueHelper(Element element) {
    String result = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if ((result == null) && (mq != null)) {
        CMElementDeclaration ed = mq.getCMElementDeclaration(element);
        if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
            // $NON-NLS-1$
            result = decriptionBuilder.buildDescription(ed);
        }
    }
    // $NON-NLS-1$
    return result != null ? result : "";
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 44 with ModelQuery

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

the class DOMObserver method invokeCMDocumentLoad.

public void invokeCMDocumentLoad() {
    if (fIsDisabled)
        return;
    try {
        fIsLoading = true;
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(fDocument);
        if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) {
            CMDocumentLoader loader = isGrammarInferenceEnabled ? new InferredGrammarBuildingCMDocumentLoader(fDocument, modelQuery) : new CMDocumentLoader(fDocument, modelQuery);
            loader.loadCMDocuments();
        }
    } finally {
        fIsLoading = false;
    }
}
Also used : InferredGrammarBuildingCMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader) CMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader) InferredGrammarBuildingCMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 45 with ModelQuery

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

the class XMLTableTreeContentProvider method getElementValueHelper.

private String getElementValueHelper(Element element) {
    String result = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    if ((result == null) && (mq != null)) {
        CMElementDeclaration ed = mq.getCMElementDeclaration(element);
        if ((ed != null) && !Boolean.TRUE.equals(ed.getProperty("isInferred"))) {
            // $NON-NLS-1$
            result = descriptionBuilder.buildDescription(ed);
        }
    }
    // $NON-NLS-1$
    return result != null ? result : "";
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) 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