use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testRemoveTrailingSpaceFromAttributeValue.
public void testRemoveTrailingSpaceFromAttributeValue() 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, 8, 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.INodeNotifier in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testPrependSpaceToAttributeValue.
public void testPrependSpaceToAttributeValue() 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, 6, 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.INodeNotifier in project webtools.sourceediting by eclipse.
the class XSDModelAdapter method lookupOrCreateModelAdapter.
public static XSDModelAdapter lookupOrCreateModelAdapter(Document document) {
XSDModelAdapter adapter = null;
if (document instanceof INodeNotifier) {
INodeNotifier notifier = (INodeNotifier) document;
adapter = (XSDModelAdapter) notifier.getAdapterFor(XSDModelAdapter.class);
if (adapter == null) {
adapter = new XSDModelAdapter();
notifier.addAdapter(adapter);
}
}
return adapter;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class XMLPropertySource method getDocTypeFromDOMNode.
/**
* by "internal spec" the DOCTYPE adapter is only available from Document
* Node
*
* @return {@link DocumentTypeAdapter}
*/
private DocumentTypeAdapter getDocTypeFromDOMNode(Node node) {
DocumentTypeAdapter adapter = null;
Document ownerDocument = node.getOwnerDocument();
if (ownerDocument == null) {
// ... but, maybe a separate issue).
if (node instanceof Document) {
ownerDocument = (Document) node;
}
}
if (ownerDocument != null) {
adapter = (DocumentTypeAdapter) ((INodeNotifier) ownerDocument).getAdapterFor(DocumentTypeAdapter.class);
}
return adapter;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class XMLTableTreeContentProvider method getText.
public String getText(Object object) {
if (object instanceof INodeNotifier) {
((INodeNotifier) object).getAdapterFor(IJFaceNodeAdapter.class);
}
String result = null;
if (object instanceof Node) {
Node node = (Node) object;
switch(node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
{
result = node.getNodeName();
break;
}
case Node.DOCUMENT_TYPE_NODE:
{
// $NON-NLS-1$
result = "DOCTYPE";
break;
}
case Node.ELEMENT_NODE:
{
result = node.getNodeName();
break;
}
case Node.PROCESSING_INSTRUCTION_NODE:
{
result = ((ProcessingInstruction) node).getTarget();
break;
}
}
}
result = TextProcessor.process(result);
// $NON-NLS-1$
return result != null ? result : "";
}
Aggregations