Search in sources :

Example 41 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class EMF2DOMSSEAdapter method primGetExistingAdapter.

protected EMF2DOMAdapter primGetExistingAdapter(Node aNode, Translator childMap) {
    INodeNotifier sseNode = (INodeNotifier) aNode;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            Object adapterTarget = e2DAdapter.getTarget();
            // Handle the cases where either adapter's target is null
            if ((getTarget() == null) || (adapterTarget == null))
                if (resourceClass != null && resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // Check if target is an EMF resource
            if (getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (adapterTarget != null && adapterTarget == getTarget()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                EObject myTarget = (EObject) getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget != null && ((EObject) adapterTarget).eResource() == myTarget.eResource()) {
                    return e2DAdapter;
                }
            }
            if (adapterTarget instanceof EObject) {
                if (((EObject) e2DAdapter.getTarget()).eResource() == null && e2DAdapter.fTranslator == childMap) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 42 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class EMF2DOMSSEAdapter method primGetExistingAdapter.

protected EMF2DOMAdapter primGetExistingAdapter(Node aNode) {
    INodeNotifier sseNode = (INodeNotifier) aNode;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            Object adapterTarget = e2DAdapter.getTarget();
            // Handle the cases where either adapter's target is null
            if ((getTarget() == null) || (adapterTarget == null))
                if (resourceClass != null && resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // Check if target is an EMF resource
            if (getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (adapterTarget != null && adapterTarget == getTarget()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                EObject myTarget = (EObject) getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget != null && ((EObject) adapterTarget).eResource() == myTarget.eResource()) {
                    return e2DAdapter;
                }
            }
            if (adapterTarget instanceof EObject) {
                if (((EObject) e2DAdapter.getTarget()).eResource() == null) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 43 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class EMF2DOMSSERenderer method getExistingDOMAdapter.

public EMF2DOMAdapter getExistingDOMAdapter(Node node) {
    // IDOMNode xNode = (IDOMNode) node;
    // return (EMF2DOMSSEAdapter) xNode.getAdapterFor(EMF2DOMAdapter.ADAPTER_CLASS);
    INodeNotifier sseNode = (INodeNotifier) node;
    Collection adapters = sseNode.getAdapters();
    for (Iterator iterator = adapters.iterator(); iterator.hasNext(); ) {
        INodeAdapter adapter = (INodeAdapter) iterator.next();
        // First Check if it's an EMF2DOMAdapter
        if (adapter != null && adapter.isAdapterForType(EMF2DOMAdapter.ADAPTER_CLASS)) {
            // Cast to EMF2DOMSSEAdapter
            EMF2DOMSSEAdapter e2DAdapter = (EMF2DOMSSEAdapter) adapter;
            // Use the resourceClass to make sure the resource type is identical
            if (getResource() == null || e2DAdapter.getTarget() == null)
                if (resourceClass.equals(e2DAdapter.getResourceClass()))
                    return e2DAdapter;
                else
                    continue;
            // First check if targets are resources
            if (e2DAdapter.getTarget() instanceof Resource) {
                /*
					 * Now check if it's the right one (Multiple resources
					 * could be attached)
					 */
                if (e2DAdapter.getTarget() == getResource()) {
                    return e2DAdapter;
                }
            } else {
                // Check if targets are EObjects with the same resources
                TranslatorResource myTarget = getResource();
                EObject adapterTarget = (EObject) e2DAdapter.getTarget();
                /*
					 * Now check if it's the right one (Multiple resources could
					 * be attached)
					 */
                if (adapterTarget.eResource() == myTarget || adapterTarget.eResource() == null) {
                    return e2DAdapter;
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Resource(org.eclipse.emf.ecore.resource.Resource) TranslatorResource(org.eclipse.wst.common.internal.emf.resource.TranslatorResource) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 44 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class CSSPropertySheetConfiguration method getInputSelection.

public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
    // remove UI refresh adapters
    if (fSelectedNotifiers != null) {
        for (int i = 0; i < fSelectedNotifiers.length; i++) {
            fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
        }
        fSelectedNotifiers = null;
    }
    ISelection preferredSelection = super.getInputSelection(selectingPart, selection);
    if (preferredSelection instanceof IStructuredSelection) {
        Object[] selectedObjects = new Object[((IStructuredSelection) selection).size()];
        System.arraycopy(((IStructuredSelection) selection).toArray(), 0, selectedObjects, 0, selectedObjects.length);
        for (int i = 0; i < selectedObjects.length; i++) {
            if (selectedObjects[i] instanceof ICSSNode) {
                ICSSNode node = (ICSSNode) selectedObjects[i];
                while (node.getNodeType() == ICSSNode.PRIMITIVEVALUE_NODE || node.getNodeType() == ICSSNode.STYLEDECLITEM_NODE) {
                    node = node.getParentNode();
                    selectedObjects[i] = node;
                }
            }
        }
        /*
			 * Add UI refresh adapters and remember notifiers for later
			 * removal
			 */
        if (selectedObjects.length > 0) {
            List selectedNotifiers = new ArrayList(1);
            for (int i = 0; i < selectedObjects.length; i++) {
                if (selectedObjects[i] instanceof INodeNotifier) {
                    selectedNotifiers.add(selectedObjects[i]);
                    ((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
                }
            }
            fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
        }
        preferredSelection = new StructuredSelection(selectedObjects);
    }
    return preferredSelection;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 45 with INodeNotifier

use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.

the class CSSTextNodeCleanupHandler method getCSSContent.

/**
 */
private String getCSSContent(Node text) {
    ICSSModel model = getCSSModel(text);
    if (model == null)
        return null;
    ICSSNode document = model.getDocument();
    if (document == null)
        return null;
    INodeNotifier notifier = (INodeNotifier) document;
    CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
    // try another way to get formatter
    if (formatter == null)
        formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
    if (formatter == null)
        return null;
    StringBuffer buffer = formatter.cleanup(document);
    if (buffer == null)
        return null;
    return buffer.toString();
}
Also used : CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

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