Search in sources :

Example 41 with ITextRegion

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

the class HTMLSyntaxColoringPage method getNamedStyleAtOffset.

private String getNamedStyleAtOffset(int offset) {
    // ensure the offset is clean
    if (offset >= fDocument.getLength())
        return getNamedStyleAtOffset(fDocument.getLength() - 1);
    else if (offset < 0)
        return getNamedStyleAtOffset(0);
    IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
    while (documentRegion != null && !documentRegion.containsOffset(offset)) {
        documentRegion = documentRegion.getNext();
    }
    if (documentRegion != null) {
        // find the ITextRegion's Context at this offset
        ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset);
        if (interest == null)
            return null;
        if (offset > documentRegion.getTextEndOffset(interest))
            return null;
        String regionContext = interest.getType();
        if (regionContext == null)
            return null;
        // find the named style (internal/selectable name) for that
        // context
        String namedStyle = (String) fContextToStyleMap.get(regionContext);
        if (namedStyle != null) {
            return namedStyle;
        }
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 42 with ITextRegion

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

the class Attribute method setType.

public void setType(Object requestor, String type) {
    String oldType = getType();
    if (!type.equals(oldType)) {
        boolean wasEnumeration = oldType.equals(ENUMERATED_NAME) || oldType.equals(ENUMERATED_NOTATION);
        boolean isEnumeration = type.equals(ENUMERATED_NAME) || type.equals(ENUMERATED_NOTATION);
        // $NON-NLS-1$
        String newText = "";
        int startOffset = 0;
        int endOffset = 0;
        if (wasEnumeration && !isEnumeration) {
            // get rid of the old enumlist
            AttributeEnumList enumList = getEnumList();
            if (enumList != null) {
                startOffset = enumList.getStartOffset();
                endOffset = enumList.getEndOffset();
            }
        }
        ITextRegion region = getTypeRegion();
        if (region != null) {
            startOffset = getStructuredDTDDocumentRegion().getStartOffset(region);
            if (endOffset == 0) {
                endOffset = getStructuredDTDDocumentRegion().getEndOffset(region);
            }
        } else if (startOffset == 0) {
            ITextRegion nameRegion = getNameRegion();
            // $NON-NLS-1$
            newText += " ";
            endOffset = startOffset = getStructuredDTDDocumentRegion().getEndOffset(nameRegion);
        }
        String newTypeWord = (String) typeHash.get(type);
        if (newTypeWord == null) {
            // then this must be a parm entity being used in the type
            // use the type text directly
            newTypeWord = type;
        }
        newText += newTypeWord;
        if (isEnumeration && !wasEnumeration) {
            // put in a new numlist
            boolean isSpaceNeeded = !type.equals(ENUMERATED_NAME);
            // $NON-NLS-1$ //$NON-NLS-2$
            newText += isSpaceNeeded ? " " : "";
            // $NON-NLS-1$
            newText += "()";
        }
        replaceText(requestor, startOffset, endOffset - startOffset, newText);
        if (newTypeWord.equals("") && !type.equals(ENUMERATED_NAME)) {
            // $NON-NLS-1$
            // the set the defaultkind to ""
            // setDefaultKind(requestor, "");
            // $NON-NLS-1$
            setDefaultValue(requestor, "", false);
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 43 with ITextRegion

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

the class Attribute method setDefaultKind.

public void setDefaultKind(Object requestor, String kind) {
    ITextRegion defaultKindRegion = getDefaultKindRegion();
    // $NON-NLS-1$
    String oldDefaultKind = defaultKindRegion == null ? "" : getStructuredDTDDocumentRegion().getText(defaultKindRegion);
    if (!kind.equals(oldDefaultKind)) {
        String newText = kind;
        int startOffset = 0;
        int length = 0;
        if (defaultKindRegion != null) {
            startOffset = getStructuredDTDDocumentRegion().getStartOffset(defaultKindRegion);
            length = getStructuredDTDDocumentRegion().getEndOffset(defaultKindRegion) - startOffset;
        } else {
            startOffset = getOffsetAfterType();
            // $NON-NLS-1$
            newText = " " + newText;
        }
        ITextRegion defaultValue = getNextQuotedLiteral(iterator());
        if (kind.equals(Attribute.FIXED) || kind.equals("")) {
            // $NON-NLS-1$
            if (defaultValue == null) {
                // we are changing to fixed and wehave no quoted region.
                // put in an empty value
                // $NON-NLS-1$
                newText += " \"\"";
            }
        } else {
            if (defaultValue != null) {
                length = getStructuredDTDDocumentRegion().getEndOffset(defaultValue) - startOffset;
            }
        }
        replaceText(requestor, startOffset, length, newText);
    // do something if there is no "kind" region
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 44 with ITextRegion

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

the class AttributeList method addAttribute.

public void addAttribute(String name) {
    // $NON-NLS-1$
    beginRecording(this, DTDCoreMessages._UI_LABEL_ATTR_LIST_ADD);
    DTDNode lastAttribute = (DTDNode) getLastChild();
    if (lastAttribute != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        replaceText(this, lastAttribute.getEndOffset(), 0, "\n\t" + name + " CDATA #IMPLIED");
    } else {
        ITextRegion nameRegion = getNameRegion();
        if (nameRegion != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            replaceText(this, getStructuredDTDDocumentRegion().getEndOffset(nameRegion), 0, "\n\t" + name + " CDATA #IMPLIED");
        }
    }
    endRecording(this);
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 45 with ITextRegion

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

the class TestRegionChangedEvent method testGetStructuredDocumentRegion.

public void testGetStructuredDocumentRegion() {
    RegionChangedEvent event = getBasicEvent();
    ITextRegion region = event.getRegion();
    assertEquals(null, region);
}
Also used : RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)447 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)179 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)174 Iterator (java.util.Iterator)75 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)58 ArrayList (java.util.ArrayList)40 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)39 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)35 List (java.util.List)33 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)31 BadLocationException (org.eclipse.jface.text.BadLocationException)30 RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)19 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)16 Node (org.w3c.dom.Node)16 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)15 IOException (java.io.IOException)13 IRegion (org.eclipse.jface.text.IRegion)13 StyleRange (org.eclipse.swt.custom.StyleRange)13