Search in sources :

Example 96 with ITextRegionList

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

the class ContextRegionContainer method getRegionAtCharacterOffset.

/**
 * The parameter offset refers to the overall offset in the document.
 */
public ITextRegion getRegionAtCharacterOffset(int offset) {
    ITextRegion result = null;
    if (regions != null) {
        int thisStartOffset = getStartOffset();
        if (offset < thisStartOffset)
            return null;
        int thisEndOffset = getStartOffset() + getLength();
        if (offset > thisEndOffset)
            return null;
        // transform the requested offset to the "scale" that
        // regions are stored in, which are all relative to the
        // start point.
        // int transformedOffset = offset - getStartOffset();
        // 
        ITextRegionList regions = getRegions();
        int length = regions.size();
        int low = 0;
        int high = length;
        int mid = 0;
        // Binary search for the region
        while (low < high) {
            mid = low + ((high - low) >> 1);
            ITextRegion region = regions.get(mid);
            if (org.eclipse.wst.sse.core.internal.util.Debug.debugStructuredDocument) {
                // $NON-NLS-1$
                System.out.println("region(s) in IStructuredDocumentRegion::getRegionAtCharacterOffset: " + region);
                // $NON-NLS-1$
                System.out.println("       midpoint of search:" + mid);
                // $NON-NLS-1$
                System.out.println("       requested offset: " + offset);
                // System.out.println(" transformedOffset: " +
                // transformedOffset); //$NON-NLS-1$
                // $NON-NLS-1$
                System.out.println("       region start: " + region.getStart());
                // $NON-NLS-1$
                System.out.println("       region end: " + region.getEnd());
                // $NON-NLS-1$
                System.out.println("       region type: " + region.getType());
                // $NON-NLS-1$
                System.out.println("       region class: " + region.getClass());
            }
            // Region is before this one
            if (offset < region.getStart() + thisStartOffset)
                high = mid;
            else if (offset > (region.getEnd() + thisStartOffset - 1))
                low = mid + 1;
            else
                return region;
        }
        return null;
    }
    return result;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 97 with ITextRegionList

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

the class XMLSyntaxColoringPage method applyStyles.

/**
 * Color the text in the sample area according to the current preferences
 */
void applyStyles() {
    if (fText == null || fText.isDisposed())
        return;
    IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
    while (documentRegion != null) {
        ITextRegionList regions = documentRegion.getRegions();
        for (int i = 0; i < regions.size(); i++) {
            ITextRegion currentRegion = regions.get(i);
            // lookup the local coloring type and apply it
            String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType());
            if (namedStyle == null)
                continue;
            TextAttribute attribute = getAttributeFor(namedStyle);
            if (attribute == null)
                continue;
            StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
            style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
            style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0;
            fText.setStyleRange(style);
        }
        documentRegion = documentRegion.getNext();
    }
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TextAttribute(org.eclipse.jface.text.TextAttribute) StyleRange(org.eclipse.swt.custom.StyleRange)

Example 98 with ITextRegionList

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

the class JSPActionValidator method getStartTagName.

private String getStartTagName(IStructuredDocumentRegion sdr) {
    String name = new String();
    ITextRegionList subRegions = sdr.getRegions();
    if (subRegions.size() > 2) {
        ITextRegion subRegion = subRegions.get(0);
        if (subRegion.getType() == DOMRegionContext.XML_TAG_OPEN) {
            subRegion = subRegions.get(1);
            if (subRegion.getType() == DOMRegionContext.XML_TAG_NAME) {
                name = sdr.getText(subRegion);
            }
        }
    }
    return name;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 99 with ITextRegionList

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

the class JSPActionValidator method hasJSPRegion.

private boolean hasJSPRegion(ITextRegion container) {
    if (!(container instanceof ITextRegionContainer))
        return false;
    ITextRegionList regions = ((ITextRegionContainer) container).getRegions();
    if (regions == null)
        return false;
    Iterator e = regions.iterator();
    while (e.hasNext()) {
        ITextRegion region = (ITextRegion) e.next();
        if (region == null)
            continue;
        String regionType = region.getType();
        if (regionType == DOMRegionContext.XML_TAG_OPEN || (isNestedTagName(regionType)))
            return true;
    }
    return false;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)

Example 100 with ITextRegionList

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

the class JSPValidator method getDirectiveName.

/**
 * @param collection
 * @return the jsp directive name
 */
protected String getDirectiveName(ITextRegionCollection collection) {
    // $NON-NLS-1$
    String name = "";
    ITextRegionList subRegions = collection.getRegions();
    for (int j = 0; j < subRegions.size(); j++) {
        ITextRegion subRegion = subRegions.get(j);
        if (subRegion.getType() == DOMJSPRegionContexts.JSP_DIRECTIVE_NAME) {
            name = collection.getText(subRegion);
            break;
        }
    }
    return name;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)193 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)171 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)74 Iterator (java.util.Iterator)46 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)27 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)24 ArrayList (java.util.ArrayList)21 List (java.util.List)18 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)16 StyleRange (org.eclipse.swt.custom.StyleRange)13 TextAttribute (org.eclipse.jface.text.TextAttribute)12 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)12 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)9 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)8 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)8 DOMException (org.w3c.dom.DOMException)8 BadLocationException (org.eclipse.jface.text.BadLocationException)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)7