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;
}
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);
}
}
}
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
}
}
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);
}
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);
}
Aggregations