use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class ForeignRegion method updateRegion.
public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion flatnode, String changes, int requestStart, int lengthToReplace) {
org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent result = null;
int lengthDifference = org.eclipse.wst.sse.core.internal.util.Utilities.calculateLengthDifference(changes, lengthToReplace);
fLength += lengthDifference;
fTextLength += lengthDifference;
result = new RegionChangedEvent(flatnode.getParentDocument(), requester, flatnode, this, changes, requestStart, lengthToReplace);
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class BasicStructuredDocumentRegion method updateRegion.
public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion structuredDocumentRegion, String changes, int requestStart, int lengthToReplace) {
StructuredDocumentEvent result = null;
int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
// Get the region pointed to by the requestStart postion, and give
// that region a chance to effect
// the update.
ITextRegion region = getRegionAtCharacterOffset(requestStart);
// the
if ((region == null) && (lengthToReplace == 0)) {
region = _getRegions().get(_getRegions().size() - 1);
// make sure the region is contiguous
if (getEndOffset(region) == requestStart) {
result = region.updateRegion(requester, this, changes, requestStart, lengthToReplace);
}
} else {
if (region != null) {
// we don't give the region a chance to update.
if ((containsOffset(region, requestStart)) && (containsOffset(region, requestStart + lengthToReplace))) {
result = region.updateRegion(requester, this, changes, requestStart, lengthToReplace);
}
}
}
// (i.e. more than one region, but no change to the node itself)
if (result != null) {
// That is, a region decided it could handle the change and
// created
// a region changed event.
// $NON-NLS-1$
Assert.isTrue(result instanceof RegionChangedEvent, "Program Error");
updateDownStreamRegions(((RegionChangedEvent) result).getRegion(), lengthDifference);
// PLUS, we need to update our own node end point (length)
setLength(getLength() + lengthDifference);
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testAppendWhitespaceToAttributeValue.
public void testAppendWhitespaceToAttributeValue() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) before).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 7, 0, " ");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertEquals("Node replaced", before, after);
assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
assertEquals("unexpected document content", "<a b= c ></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testChangeTagName2.
public void testChangeTagName2() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) document).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 2, 0, "d");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertNotSame("DOM Node not replaced", before, after);
assertEquals("Structure Changed notification not sent to adapter " + changed[0] + " to parent " + structuredDocument.get(), INodeNotifier.STRUCTURE_CHANGED, changed[0]);
assertEquals("unexpected document content", "<ad b= c></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testChangeTagName1.
public void testChangeTagName1() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) document).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 1, 0, "d");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertNotSame("DOM Node not replaced", before, after);
assertEquals("Structure Changed notification not sent to adapter " + changed[0] + " to parent " + structuredDocument.get(), INodeNotifier.STRUCTURE_CHANGED, changed[0]);
assertEquals("unexpected document content", "<da b= c></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
Aggregations