Search in sources :

Example 1 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class CSSModelParser method getStructuredDocumentRegionList.

/**
 */
private IStructuredDocumentRegionList getStructuredDocumentRegionList(int start, int end) {
    IStructuredDocumentRegionList nodeList = null;
    if (0 <= start && start <= end) {
        ICSSModel model = fDocument.getModel();
        if (model instanceof CSSModelImpl) {
            IStructuredDocument structuredDocument = ((CSSModelImpl) model).getStructuredDocument();
            if (structuredDocument != null) {
                IStructuredDocumentRegion startNode = structuredDocument.getRegionAtCharacterOffset(start);
                IStructuredDocumentRegion endNode = structuredDocument.getRegionAtCharacterOffset(end - 1);
                if (startNode != null && endNode != null) {
                    nodeList = new CoreNodeList(startNode, endNode);
                }
            }
        }
    }
    return nodeList;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CoreNodeList(org.eclipse.wst.sse.core.internal.text.CoreNodeList)

Example 2 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class CSSModelParser method insertStructuredDocumentRegions.

/**
 */
private void insertStructuredDocumentRegions(IStructuredDocumentRegionList regionList) {
    for (Enumeration e = regionList.elements(); e.hasMoreElements(); ) {
        IStructuredDocumentRegion region = (IStructuredDocumentRegion) e.nextElement();
        if (region == null) {
            continue;
        }
        insertStructuredDocumentRegion(region);
        if (fCreationContext.isToReparse()) {
            int origStart = region.getEnd();
            int origEnd = regionList.item(regionList.getLength() - 1).getEnd();
            int newStart = fCreationContext.getReparseStart();
            int newEnd = fCreationContext.getReparseEnd();
            if (newStart < origStart || origEnd < newEnd) {
                IStructuredDocumentRegionList newNodeList = getStructuredDocumentRegionList(newStart, newEnd);
                setupCreationContext(newNodeList.item(0));
                insertStructuredDocumentRegions(newNodeList);
                return;
            } else {
                fCreationContext.resetReparseRange();
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Enumeration(java.util.Enumeration) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)

Example 3 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class StyleAttrAdapter method setValue.

/**
 */
private void setValue() {
    Element element = getElement();
    if (element == null)
        return;
    ICSSModel model = getExistingModel();
    if (model == null)
        return;
    IStructuredDocument structuredDocument = model.getStructuredDocument();
    if (structuredDocument == null)
        return;
    String value = null;
    IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
    if (flatNodes != null) {
        int count = flatNodes.getLength();
        if (count > 0) {
            StringBuffer buffer = new StringBuffer();
            for (int i = 0; i < count; i++) {
                IStructuredDocumentRegion flatNode = flatNodes.item(i);
                if (flatNode == null)
                    continue;
                buffer.append(flatNode.getText());
            }
            value = buffer.toString();
        }
    }
    this.ignoreNotification = true;
    if (value == null || value.length() == 0) {
        element.removeAttribute(STYLE);
    } else {
        Attr attr = element.getAttributeNode(STYLE);
        if (attr != null) {
            ((IDOMNode) attr).setValueSource(value);
        } else {
            Document document = element.getOwnerDocument();
            attr = document.createAttribute(STYLE);
            ((IDOMNode) attr).setValueSource(value);
            element.setAttributeNode(attr);
        }
    }
    this.ignoreNotification = false;
    notifyStyleChanged(element);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Attr(org.w3c.dom.Attr)

Example 4 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class StructuredDocumentToTextAdapter method redrawNodesReplaced.

/**
 * Request a redraw of the text range occupied by the given
 * StructuredDocumentRegionsReplacedEvent
 *
 * @param structuredDocumentEvent
 */
protected void redrawNodesReplaced(StructuredDocumentRegionsReplacedEvent structuredDocumentEvent) {
    if (isStoppedForwardingChanges())
        return;
    if (Debug.debugStructuredDocument) {
        // $NON-NLS-1$
        System.out.println("maybe redraw stuff");
    }
    // just the new stuff
    IStructuredDocumentRegionList newStructuredDocumentRegions = structuredDocumentEvent.getNewStructuredDocumentRegions();
    int nNewNodes = newStructuredDocumentRegions.getLength();
    if (nNewNodes > 0) {
        IStructuredDocumentRegion firstNode = newStructuredDocumentRegions.item(0);
        IStructuredDocumentRegion lastNode = newStructuredDocumentRegions.item(nNewNodes - 1);
        redrawRange(firstNode.getStartOffset(), lastNode.getEndOffset());
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)

Example 5 with IStructuredDocumentRegionList

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList in project webtools.sourceediting by eclipse.

the class ScannerUnitTests method testNothinginBlockJSP9.

public void testNothinginBlockJSP9() {
    String text = "<script>";
    IStructuredDocumentRegionList nodes = setUpJSP(text);
    boolean sizeCheck = checkSimpleRegionCounts(nodes, new int[] { 3 });
    assertTrue("IStructuredDocumentRegion and ITextRegion count", sizeCheck);
    boolean typeCheck = checkSimpleRegionTypes(nodes.item(0).getRegions(), new String[] { DOMRegionContext.XML_TAG_OPEN, DOMRegionContext.XML_TAG_NAME, DOMRegionContext.XML_TAG_CLOSE });
    assertTrue("region context type check", typeCheck);
    verifyLengths(0, nodes.item(0), text);
}
Also used : IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)

Aggregations

IStructuredDocumentRegionList (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList)68 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)11 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)3 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)3 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 DOMException (org.w3c.dom.DOMException)2 Element (org.w3c.dom.Element)2 NodesEvent (org.eclipse.wst.dtd.core.internal.event.NodesEvent)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 NewDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent)1 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)1 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)1 RegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent)1 StructuredDocumentRegionsReplacedEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent)1 CoreNodeList (org.eclipse.wst.sse.core.internal.text.CoreNodeList)1