Search in sources :

Example 31 with INodeNotifier

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();
    }
}
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 32 with INodeNotifier

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();
    }
}
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 33 with INodeNotifier

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

Example 34 with INodeNotifier

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;
}
Also used : Document(org.w3c.dom.Document) DocumentTypeAdapter(org.eclipse.wst.xml.core.internal.document.DocumentTypeAdapter) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 35 with INodeNotifier

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 : "";
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Aggregations

INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)71 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)35 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)31 Node (org.w3c.dom.Node)29 Document (org.w3c.dom.Document)26 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)24 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 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 Iterator (java.util.Iterator)9 List (java.util.List)8 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)8 ModelQueryAdapter (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter)8 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)7 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 Element (org.w3c.dom.Element)7 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6