Search in sources :

Example 31 with IStructuredDocumentRegion

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

the class FMUtil method getSegment.

/**
 */
public static final Segment getSegment(IDOMNode target, int segType) {
    if (target == null)
        return new Segment(0, 0);
    Segment seg = null;
    IStructuredDocumentRegion startTag = null;
    IStructuredDocumentRegion endTag = null;
    switch(segType) {
        case SEG_WHOLE_TAG:
            startTag = target.getFirstStructuredDocumentRegion();
            if (startTag != null) {
                endTag = target.getLastStructuredDocumentRegion();
                seg = new Segment(startTag, endTag);
            } else {
                int startOffset = target.getStartOffset();
                int endOffset = target.getEndOffset();
                seg = new Segment(startOffset, endOffset - startOffset);
            }
            break;
        case SEG_START_TAG:
            startTag = target.getStartStructuredDocumentRegion();
            if (startTag != null) {
                seg = new Segment(startTag);
            } else {
                seg = new Segment(target.getStartOffset(), 1);
            }
            break;
        case SEG_END_TAG:
            endTag = target.getEndStructuredDocumentRegion();
            if (endTag != null) {
                seg = new Segment(endTag);
            } else {
                seg = new Segment(target.getEndOffset(), 1);
            }
            break;
        case SEG_START_TAG_NAME:
            startTag = target.getStartStructuredDocumentRegion();
            if (startTag != null) {
                ITextRegion nameRegion = getNameRegion(startTag);
                if (nameRegion != null) {
                    seg = new Segment(startTag.getStartOffset(nameRegion), nameRegion.getTextLength());
                }
            }
            if (seg == null) {
                seg = getSegment(target, SEG_START_TAG);
            }
            break;
        case SEG_END_TAG_NAME:
            endTag = target.getEndStructuredDocumentRegion();
            if (endTag != null) {
                ITextRegion nameRegion = getNameRegion(endTag);
                if (nameRegion != null) {
                    seg = new Segment(endTag.getStartOffset(nameRegion), nameRegion.getTextLength());
                }
            }
            if (seg == null) {
                seg = getSegment(target, SEG_END_TAG);
            }
            break;
        case SEG_NONE:
        default:
            return new Segment(0, 0);
    }
    return seg;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 32 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion 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 33 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion 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 34 with IStructuredDocumentRegion

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

the class AbstractStructuredFoldingStrategy method getIndexedRegions.

/**
 * <p>Gets all of the {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the given
 * {@link IStructuredDocumentRegion}s.</p>
 *
 * @param model the {@link IStructuredModel} used to get the {@link IndexedRegion}s
 * @param structRegions get the {@link IndexedRegion}s spanned by these {@link IStructuredDocumentRegion}s
 * @return the {@link Set} of {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the
 * given {@link IStructuredDocumentRegion}s.
 */
private Set getIndexedRegions(IStructuredModel model, IStructuredDocumentRegion[] structRegions) {
    Set indexedRegions = new HashSet(structRegions.length);
    // for each text region in each structured document region find the indexed region it spans/is in
    for (int structRegionIndex = 0; structRegionIndex < structRegions.length && fProjectionAnnotationModel != null; ++structRegionIndex) {
        IStructuredDocumentRegion structuredDocumentRegion = structRegions[structRegionIndex];
        int offset = structuredDocumentRegion.getStartOffset();
        IndexedRegion indexedRegion = model.getIndexedRegion(offset);
        indexedRegions.add(indexedRegion);
        if (structuredDocumentRegion.getEndOffset() <= indexedRegion.getEndOffset())
            continue;
        ITextRegionList textRegions = structuredDocumentRegion.getRegions();
        int textRegionCount = textRegions.size();
        for (int textRegionIndex = 1; textRegionIndex < textRegionCount; ++textRegionIndex) {
            offset = structuredDocumentRegion.getStartOffset(textRegions.get(textRegionIndex));
            indexedRegion = model.getIndexedRegion(offset);
            indexedRegions.add(indexedRegion);
        }
    }
    return indexedRegions;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) HashSet(java.util.HashSet) Set(java.util.Set) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) HashSet(java.util.HashSet)

Example 35 with IStructuredDocumentRegion

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

the class StructuredDocumentWalker method getPrevNode.

/**
 * Old Nodes: --[O1]--[O2]--[O3]--- : / \ Current Nodes:
 * ---[C1]-----[C2]-----[C3]-----[C4]---
 *
 * Input: O1 -> Output: C1 Input: O2 -> Output: O1 Input: O3 -> Output: O2
 * Input: Cn -> Output: Cn-1
 */
public IStructuredDocumentRegion getPrevNode(IStructuredDocumentRegion node) {
    IStructuredDocumentRegion prevNode = null;
    if (node != null) {
        prevNode = node.getPrevious();
        if (prevNode == null) {
            if (isOldNode(node)) {
                // this may be the start of old flatnodes
                int newEnd = node.getStart() - 1;
                prevNode = fStructuredDocument.getRegionAtCharacterOffset(newEnd);
            }
        }
    }
    return prevNode;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13