use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class ModelQueryUtil method getModelQueryAdapter.
public static ModelQueryAdapter getModelQueryAdapter(Document node) {
ModelQueryAdapter result = null;
if (node instanceof INodeNotifier) {
INodeNotifier notifier = (INodeNotifier) node;
result = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class CSSNodeAdapter method getChildren.
/**
* Returns an enumeration containing all child nodes of the given element,
* which represents a node in a tree. The difference to
* <code>IStructuredContentProvider.getElements(Object)</code> is as
* follows: <code>getElements</code> is called to obtain the tree
* viewer's root elements. Method <code>getChildren</code> is used to
* obtain the children of a given node in the tree, which can can be a
* root node, too.
*/
public Object[] getChildren(Object object) {
if (object instanceof ICSSNode) {
ICSSNode node = (ICSSNode) object;
short nodeType = node.getNodeType();
if (nodeType == ICSSNode.STYLERULE_NODE || nodeType == ICSSNode.PAGERULE_NODE || nodeType == ICSSNode.FONTFACERULE_NODE) {
for (node = node.getFirstChild(); node != null && !(node instanceof ICSSStyleDeclaration); node.getNextSibling()) {
// nop
}
}
List children = new ArrayList();
ICSSNode child = (node != null) ? node.getFirstChild() : null;
while (child != null) {
if (!(child instanceof ICSSPrimitiveValue) && !(child instanceof MediaList)) {
children.add(child);
}
/*
* Required to correctly connect the refreshing behavior to
* the tree
*/
if (child instanceof INodeNotifier) {
((INodeNotifier) child).getAdapterFor(IJFaceNodeAdapter.class);
}
child = child.getNextSibling();
}
return children.toArray();
}
return new Object[0];
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class TestPageDirective method testAdapt.
public void testAdapt() {
IDOMModel model = createUnmanagedHTMLModel();
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) model.getDocument().getAdapterFor(PageDirectiveAdapter.class);
Node ownerNode = model.getDocument();
ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) ownerNode, ModelQueryAdapter.class);
assertNotNull("could not adapt embedded adapter", embeddedAdapter);
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class TestModelsFromFiles method testClone.
private void testClone(IStructuredModel structuredModel) throws IOException {
IDOMDocument document = ((IDOMModel) structuredModel).getDocument();
INodeNotifier notifier = document;
ModelQueryAdapter modelQueryAdapter = (ModelQueryAdapter) notifier.getAdapterFor(ModelQueryAdapter.class);
assertNotNull("initial modelQueryAdapter should not be null", modelQueryAdapter);
IStructuredModel newModel = structuredModel.newInstance();
IDOMDocument newDocument = ((IDOMModel) newModel).getDocument();
INodeNotifier newNotifier = newDocument;
ModelQueryAdapter result = (ModelQueryAdapter) newNotifier.getAdapterFor(ModelQueryAdapter.class);
assertNotNull("newInstance modelQueryAdapter should not be null", result);
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class TestForNPEInCSSCreation method testCSSModel.
public void testCSSModel() {
IDOMModel model = FileUtil.createHTMLModel();
try {
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(getHTMLDocumentText());
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");
String delim = model.getStructuredDocument().getLineDelimiter();
if (delim == null)
// $NON-NLS-1$
delim = "\n";
StringBuffer buffer = new StringBuffer(delim);
// $NON-NLS-1$
buffer.append("<!--");
buffer.append(delim);
// $NON-NLS-1$
buffer.append("-->");
buffer.append(delim);
Text text = doc.createTextNode(buffer.toString());
ele.appendChild(text);
head.insertBefore(ele, null);
// get adapter for StyleSheet
ICSSStyleSheet sheet = (ICSSStyleSheet) ((IStyleSheetAdapter) ((INodeNotifier) ele).getAdapterFor(IStyleSheetAdapter.class)).getSheet();
// create style declaration
ICSSStyleRule rule = sheet.createCSSStyleRule();
rule.getStyle().setProperty("background-color", "lime", "");
rule.getStyle().setProperty("background-color", "blue", "");
rule.getStyle().setProperty("background-color", "#0080ff", "");
// model.save();
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
Aggregations