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