Search in sources :

Example 86 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class XMLFoldingStrategy method calcNewFoldPosition.

/**
 * @see org.eclipse.wst.sse.ui.internal.projection.AbstractFoldingStrategy#calcNewFoldPosition(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
 */
protected Position calcNewFoldPosition(IndexedRegion indexedRegion) {
    Position retPos = null;
    // only want to fold regions of the valid type and with a valid range
    if (indexedRegion.getStartOffset() >= 0 && indexedRegion.getLength() >= 0) {
        IDOMNode node = (IDOMNode) indexedRegion;
        IStructuredDocumentRegion startRegion = node.getStartStructuredDocumentRegion();
        IStructuredDocumentRegion endRegion = node.getEndStructuredDocumentRegion();
        // else if the region is only an open tag or an open/close tag then don't fold it
        if (startRegion != null && endRegion != null) {
            if (endRegion.getEndOffset() >= startRegion.getStartOffset())
                retPos = new XMLElementFoldingPosition(startRegion, endRegion);
        } else if (startRegion != null && indexedRegion instanceof CommentImpl) {
            retPos = new XMLCommentFoldingPosition(startRegion);
        }
    }
    return retPos;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Position(org.eclipse.jface.text.Position) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CommentImpl(org.eclipse.wst.xml.core.internal.document.CommentImpl)

Example 87 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class XSDCommonUIUtils method formatChild.

public static void formatChild(Node child) {
    if (child instanceof IDOMNode) {
        IDOMModel model = ((IDOMNode) child).getModel();
        try {
            // tell the model that we are about to make a big model change
            model.aboutToChangeModel();
            IStructuredFormatProcessor formatProcessor = new FormatProcessorXML();
            formatProcessor.formatNode(child);
        } finally {
            // tell the model that we are done with the big model change
            model.changedModel();
        }
    }
}
Also used : IStructuredFormatProcessor(org.eclipse.wst.sse.core.internal.format.IStructuredFormatProcessor) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 88 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class AbstractModelTest method calculateErrorsAndWarnings.

private Map<Integer, String> calculateErrorsAndWarnings(IFile file) throws XPathExpressionException, IOException, CoreException {
    Map<Integer, String> expectedErrors = new HashMap<Integer, String>();
    IStructuredModel smodel = null;
    try {
        smodel = StructuredModelManager.getModelManager().getModelForRead(file);
        if (smodel != null && smodel instanceof IDOMModel) {
            IDOMModel model = (IDOMModel) smodel;
            XPathExpression xp = XPathFactory.newInstance().newXPath().compile("//comment()");
            NodeList nodeSet = (NodeList) xp.evaluate(model.getDocument(), XPathConstants.NODESET);
            for (int i = 0; i < nodeSet.getLength(); i++) {
                Node commentNode = nodeSet.item(i);
                String comment = commentNode.getNodeValue().trim();
                if (comment.startsWith("ERROR") || comment.startsWith("WARN")) {
                    IDOMNode parent = (IDOMNode) commentNode.getParentNode();
                    int line = model.getStructuredDocument().getLineOfOffset(parent.getStartOffset()) + 1;
                    expectedErrors.put(line, comment);
                }
            }
        }
    } finally {
        if (smodel != null)
            smodel.releaseFromRead();
    }
    return expectedErrors;
}
Also used : XPathExpression(javax.xml.xpath.XPathExpression) HashMap(java.util.HashMap) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 89 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class AbstractXSLContentAssistProcessor method getCompletionRegion.

/**
 * Return the region whose content's require completion. This is something
 * of a misnomer as sometimes the user wants to be prompted for contents of
 * a non-existent ITextRegion, such as for enumerated attribute values
 * following an '=' sign.
 *
 * Copied from AbstractContentAssist Processor.
 */
protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) {
    if (domnode == null) {
        return null;
    }
    ITextRegion region = null;
    int offset = documentPosition;
    IStructuredDocumentRegion flatNode = null;
    IDOMNode node = (IDOMNode) domnode;
    if (node.getNodeType() == Node.DOCUMENT_NODE) {
        if (node.getStructuredDocument().getLength() == 0) {
            return null;
        }
        ITextRegion result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
        while (result == null) {
            offset--;
            result = node.getStructuredDocument().getRegionAtCharacterOffset(offset).getRegionAtCharacterOffset(offset);
        }
        return result;
    }
    IStructuredDocumentRegion startTag = node.getStartStructuredDocumentRegion();
    IStructuredDocumentRegion endTag = node.getEndStructuredDocumentRegion();
    if ((startTag != null) && (startTag.getStartOffset() <= offset) && (offset < startTag.getStartOffset() + startTag.getLength())) {
        flatNode = startTag;
    } else if ((endTag != null) && (endTag.getStartOffset() <= offset) && (offset < endTag.getStartOffset() + endTag.getLength())) {
        flatNode = endTag;
    }
    if (flatNode != null) {
        region = getCompletionRegion(offset, flatNode);
    } else {
        flatNode = node.getStructuredDocument().getRegionAtCharacterOffset(offset);
        if ((flatNode.getStartOffset() <= documentPosition) && (flatNode.getEndOffset() >= documentPosition)) {
            if ((offset == flatNode.getStartOffset()) && (flatNode.getPrevious() != null) && (((flatNode.getRegionAtCharacterOffset(documentPosition) != null) && (flatNode.getRegionAtCharacterOffset(documentPosition).getType() != DOMRegionContext.XML_CONTENT)) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_TAG_OPEN) || (flatNode.getPrevious().getLastRegion().getType() == DOMRegionContext.XML_END_TAG_OPEN))) {
                region = flatNode.getPrevious().getLastRegion();
            } else if (flatNode.getEndOffset() == documentPosition) {
                region = flatNode.getLastRegion();
            } else {
                region = flatNode.getFirstRegion();
            }
        } else {
            region = flatNode.getLastRegion();
        }
    }
    return region;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 90 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.

the class XMLTableTreeContentProvider method inputChanged.

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    // remove our listeners to the old state
    if (oldInput != null) {
        Document domDoc = (Document) oldInput;
        ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
        if (mq != null) {
            documentManager = mq.getCMDocumentManager();
            if (documentManager != null) {
                documentManager.removeListener(this);
            }
        }
    }
    if ((oldInput != null) && (oldInput instanceof IDOMNode)) {
        IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) oldInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
        if (factory != null) {
            factory.removeListener(viewer);
        }
    }
    if (viewer instanceof StructuredViewer) {
        fViewer = null;
    } else {
        fViewer = (StructuredViewer) viewer;
    }
    if ((newInput != null) && (newInput instanceof IDOMNode)) {
        IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) newInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
        if (factory != null) {
            factory.addListener(viewer);
        }
    }
    if (newInput != null) {
        Document domDoc = (Document) newInput;
        ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
        if (mq != null) {
            documentManager = mq.getCMDocumentManager();
            if (documentManager != null) {
                documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
                documentManager.addListener(this);
            }
        }
    }
}
Also used : IJFaceNodeAdapterFactory(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Document(org.w3c.dom.Document) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IJFaceNodeAdapter(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18