use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter in project webtools.sourceediting by eclipse.
the class CSSFormatUtil method findCSS.
private void findCSS(List cssNodes, IDOMNode node) {
ICSSModelAdapter adapter;
adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleSheetAdapter.class);
if (adapter != null) {
ICSSModel model = adapter.getModel();
if (model != null && model.getStyleSheetType() == ICSSModel.EMBEDDED) {
cssNodes.add(model.getDocument());
}
} else {
adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleDeclarationAdapter.class);
if (adapter != null) {
ICSSModel model = adapter.getModel();
if (model != null && model.getStyleSheetType() == ICSSModel.INLINE) {
cssNodes.add(model.getDocument());
}
}
}
for (IDOMNode child = (IDOMNode) node.getFirstChild(); child != null; child = (IDOMNode) child.getNextSibling()) {
findCSS(cssNodes, child);
}
}
use of org.eclipse.wst.css.core.internal.provisional.adapters.ICSSModelAdapter in project webtools.sourceediting by eclipse.
the class CSSCompletionProposalComputer method getCSSModel.
/**
* Returns the CSSmodel for a given XML node.
*
* @param element
* @return IStructuredModel
*/
private static 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.css.core.internal.provisional.adapters.ICSSModelAdapter 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.css.core.internal.provisional.adapters.ICSSModelAdapter 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.css.core.internal.provisional.adapters.ICSSModelAdapter 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();
}
}
Aggregations