use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class TestCSS method testTypeFooBarStyleElementAdapter.
public void testTypeFooBarStyleElementAdapter() {
IDOMModel model = FileUtil.createHTMLModel();
try {
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(MARKUP);
IDOMDocument doc = model.getDocument();
// get head tag
NodeList list = doc.getElementsByTagName(HTML40Namespace.ElementName.HEAD);
Element head = (Element) list.item(0);
// create and append style element
Element ele = doc.createElement(HTML40Namespace.ElementName.STYLE);
ele.setAttribute(HTML40Namespace.ATTR_NAME_TYPE, "foo/bar");
head.appendChild(ele);
INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt((IDOMNode) ele);
assertNotNull("No adapter on " + ele, adapter);
assertTrue("Adapter is not an ICSSModelAdapter", adapter instanceof ICSSModelAdapter);
ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
assertNull("There should be no CSS model for the node", modelAdapter.getModel());
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class TestCSS method testStyleElementAdapter.
public void testStyleElementAdapter() {
IDOMModel model = FileUtil.createHTMLModel();
try {
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(MARKUP);
IDOMDocument doc = model.getDocument();
// get head tag
NodeList list = doc.getElementsByTagName(HTML40Namespace.ElementName.HEAD);
Element head = (Element) list.item(0);
// create and append style element
Element ele = doc.createElement(HTML40Namespace.ElementName.STYLE);
ele.setAttribute(HTML40Namespace.ATTR_NAME_TYPE, "text/css");
head.appendChild(ele);
INodeAdapter adapter = StyleAdapterFactory.getInstance().adapt((IDOMNode) ele);
assertNotNull("No adapter on " + ele, adapter);
assertTrue("Adapter is not an ICSSModelAdapter", adapter instanceof ICSSModelAdapter);
ICSSModelAdapter modelAdapter = (ICSSModelAdapter) adapter;
assertNotNull("There should be a CSS model for the node", modelAdapter.getModel());
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter 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;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter 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;
}
Aggregations