use of org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent in project webtools.sourceediting by eclipse.
the class AttributeValueRegion method updateRegion.
public StructuredDocumentEvent updateRegion(Object requester, IStructuredDocumentRegion parent, String changes, int requestStart, int lengthToReplace) {
RegionChangedEvent result = null;
// always follow this pattern.)
if (Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("\t\tContextRegion::updateModel");
// $NON-NLS-1$
System.out.println("\t\t\tregion type is " + fType);
}
boolean canHandle = false;
// on one region.
if ((changes == null) || (changes.length() == 0)) {
// involving whitespace.
if ((fStart >= getTextEnd()) || (Math.abs(lengthToReplace) >= getTextEnd() - getStart())) {
canHandle = false;
} else {
canHandle = true;
}
} else {
if ((RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) || RegionUpdateRule.canHandleAsLetterOrDigit(this, parent, changes, requestStart, lengthToReplace)) {
canHandle = true;
} else {
canHandle = false;
}
}
if (canHandle) {
// updating the text store and down stream flatnodes.
if (Debug.debugStructuredDocument) {
// $NON-NLS-1$
System.out.println("change handled by region");
}
int lengthDifference = Utilities.calculateLengthDifference(changes, lengthToReplace);
// the total length is changing.
if (!RegionUpdateRule.canHandleAsWhiteSpace(this, parent, changes, requestStart, lengthToReplace)) {
fTextLength += lengthDifference;
}
// update length (and end) after above check for white space,
// since
// it looks to determine if at end of region.
fLength += lengthDifference;
result = new RegionChangedEvent(parent.getParentDocument(), requester, parent, 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 RegionChangedAdapterNotificationTests method testReplaceTrailingSpaceofEqualSignWithTwoSpaces.
public void testReplaceTrailingSpaceofEqualSignWithTwoSpaces() 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, 5, 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 testAppendWhitespaceToEqualSign.
public void testAppendWhitespaceToEqualSign() 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, 5, 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 testRemoveTrailingSpaceFromAttributeName.
public void testRemoveTrailingSpaceFromAttributeName() 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, 4, 1, "");
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 testRemoveTrailingSpaceFromEqualSign.
public void testRemoveTrailingSpaceFromEqualSign() 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, 5, 1, "");
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();
}
}
Aggregations