Search in sources :

Example 21 with INodeAdapter

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();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 22 with INodeAdapter

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();
    }
}
Also used : StructuredDocumentEvent(org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent) INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) RegionChangedEvent(org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) NullInputStream(org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)

Example 23 with INodeAdapter

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);
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with INodeAdapter

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();
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ICSSModelAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter)

Example 25 with INodeAdapter

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();
        }
    }
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Aggregations

INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)51 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)31 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)25 Node (org.w3c.dom.Node)22 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)20 Document (org.w3c.dom.Document)19 NullInputStream (org.eclipse.wst.sse.core.internal.encoding.util.NullInputStream)18 RegionChangedEvent (org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent)18 StructuredDocumentEvent (org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentEvent)18 Iterator (java.util.Iterator)10 Collection (java.util.Collection)7 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)7 Element (org.w3c.dom.Element)5 List (java.util.List)4 ICSSStyleListener (org.eclipse.wst.css.core.internal.event.ICSSStyleListener)4 IStyleSheetAdapter (org.eclipse.wst.css.core.internal.provisional.adapters.IStyleSheetAdapter)4 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)4 EObject (org.eclipse.emf.ecore.EObject)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 ISelection (org.eclipse.jface.viewers.ISelection)3