use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter 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.INodeAdapter 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.INodeAdapter in project webtools.sourceediting by eclipse.
the class ModelReconcileAdapter method notifyListeners.
protected void notifyListeners(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
List list = new ArrayList(listeners);
for (Iterator i = list.iterator(); i.hasNext(); ) {
INodeAdapter adapter = (INodeAdapter) i.next();
adapter.notifyChanged(notifier, eventType, changedFeature, oldValue, newValue, pos);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class CSSContentAssistProcessor method getCSSModel.
/**
* Get CSSModel for an indexed node
*
* @param indexedNode
* @return IStructuredModel
*/
// private IStructuredModel getCSSModel(IndexedRegion indexedNode) {
// if (indexedNode == null) return null;
// Node node = (Node)indexedNode;
// INodeNotifier notifier = (INodeNotifier)node.getParentNode();
// if (notifier == null) return null;
// INodeAdapter adapter =
// StyleAdapterFactory.getInstance().adapt(notifier);
// if (adapter == null || !(adapter instanceof CSSModelAdapter)) return
// null;
// CSSModelAdapter modelAdapter = (CSSModelAdapter)adapter;
// return modelAdapter.getModel();
// }
/**
* Returns the CSSmodel for a given XML node.
*
* @param element
* @return IStructuredModel
*/
private IStructuredModel getCSSModel(IDOMNode element) {
if (element == null)
return null;
INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt(element);
if ((adapter == null) || !(adapter instanceof ICSSModelAdapter))
return null;
ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
return modelAdapter.getModel();
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class JSPTranslatorPersistenceTest method testCreateTranslationAdapter.
/**
* <p>This test case follows the general pattern of how a translation is created, then can be
* externalized when the workspace is closed, then reloaded when its opened again.</p>
*
* @throws Exception
*/
public void testCreateTranslationAdapter() throws Exception {
String outFileName = "testCreateTranslationAdapter.obj";
IStructuredModel structModel = null;
try {
structModel = getModelForRead("Test1.jsp");
// verify there is not already an existing translation adapter
IDOMDocument domDoc = ((IDOMModel) structModel).getDocument();
INodeAdapter existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
assertNull("There should be no existing adapter for IJSPTranslation", existingAdapter);
// create a translator and externalize it, then load the externalized translator
JSPTranslator originalTranslator = writeTranslator(structModel, outFileName);
JSPTranslator externalizedTranslator = (JSPTranslator) readObject(outFileName);
// create an adaptr from the loaded externalized translator and add it to the doc
JSPTranslationAdapter restoredAdapter = new JSPTranslationAdapter((IDOMModel) structModel, externalizedTranslator);
domDoc.addAdapter(restoredAdapter);
// verify we can retrieve the adapter we just set
existingAdapter = domDoc.getAdapterFor(IJSPTranslation.class);
assertNotNull("There should now be an existing adapter for IJSPTranslation", existingAdapter);
assertTrue("Expected " + existingAdapter + " to be an instance of JSPTranslationAdapter", existingAdapter instanceof JSPTranslationAdapter);
JSPTranslationAdapter retrievedAdapter = (JSPTranslationAdapter) existingAdapter;
JSPTranslationExtension jspTranslationExtension = retrievedAdapter.getJSPTranslation();
/* verify that the original translation is equal to that of the
* retrieved adapter created from the previously externalized translator
*/
assertEquals("The original translation should be the same as the restored externalized translation", originalTranslator.getTranslation().toString(), jspTranslationExtension.getJavaText());
} finally {
if (structModel != null) {
structModel.releaseFromRead();
}
}
}
Aggregations