use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class ElementDeclarationAdapterFactory method adapt.
/**
*/
public INodeAdapter adapt(INodeNotifier notifier) {
if (notifier == null)
return null;
INodeAdapter adapter = notifier.getExistingAdapter(ElementDeclarationAdapter.class);
if (adapter != null)
return adapter;
adapter = new HTMLElementDeclarationAdapter();
notifier.addAdapter(adapter);
return adapter;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class AbstractStyleSheetAdapter method styleUpdate.
/**
* @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
*/
public void styleUpdate(ICSSModel srcModel) {
IDOMNode node = (IDOMNode) getElement();
if (node == null)
return;
IDOMModel model = node.getModel();
if (model == null)
return;
XMLModelNotifier notifier = model.getModelNotifier();
if (notifier == null)
return;
// before updating, all sub-models should be loaded!
DocumentStyle document = (DocumentStyle) model.getDocument();
StyleSheetList styles = document.getStyleSheets();
if (styles != null) {
int n = styles.getLength();
ImportedCollector trav = new ImportedCollector();
for (int i = 0; i < n; i++) {
org.w3c.dom.stylesheets.StyleSheet sheet = styles.item(i);
if (sheet instanceof ICSSNode)
trav.apply((ICSSNode) sheet);
}
}
// flash style changed events
if (styleChangedNodes != null) {
Object[] elements = styleChangedNodes.toArray();
for (int i = 0; elements != null && i < elements.length; i++) notifyStyleChanged((Element) elements[i]);
styleChangedNodes.clear();
}
// to notify GEF tree
if (document instanceof INodeNotifier) {
Collection adapters = ((INodeNotifier) document).getAdapters();
if (adapters == null)
return;
Iterator it = adapters.iterator();
if (it == null)
return;
while (it.hasNext()) {
INodeAdapter adapter = (INodeAdapter) it.next();
if (adapter instanceof ICSSStyleListener) {
((ICSSStyleListener) adapter).styleUpdate(srcModel);
}
}
}
notifier.propertyChanged(node);
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class AbstractStyleSheetAdapter method styleChanged.
/**
* @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
* @param removed com.ibm.sed.css.model.interfaces.ICSSSelector[]
* @param added com.ibm.sed.css.model.interfaces.ICSSSelector[]
* @param media java.lang.String
*/
public void styleChanged(ICSSModel srcModel, ICSSSelector[] removed, ICSSSelector[] added, String media) {
Element element = getElement();
if (element == null)
// might released
return;
Document doc = element.getOwnerDocument();
if (doc == null)
// error
return;
// to notify GEF tree
if (doc instanceof INodeNotifier) {
Collection adapters = ((INodeNotifier) doc).getAdapters();
if (adapters == null)
return;
Iterator it = adapters.iterator();
if (it == null)
return;
while (it.hasNext()) {
INodeAdapter adapter = (INodeAdapter) it.next();
if (adapter instanceof ICSSStyleListener) {
((ICSSStyleListener) adapter).styleChanged(srcModel, removed, added, media);
}
}
}
if (styleChangedNodes == null) {
styleChangedNodes = new HashSet();
}
try {
int removedSelNum = removed != null ? removed.length : 0;
int addedSelNum = added != null ? added.length : 0;
NodeIterator iter = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, null, true);
Node node;
while ((node = iter.nextNode()) != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element elm = (Element) node;
boolean match = false;
int i;
for (i = 0; i < removedSelNum && !match; i++) {
match = removed[i].match(elm, null);
}
for (i = 0; i < addedSelNum && !match; i++) {
match = added[i].match(elm, null);
}
if (match) {
if (!styleChangedNodes.contains(elm))
styleChangedNodes.add(elm);
// notifyStyleChanged(elm);
}
}
}
} catch (ClassCastException ex) {
// Document doesn't implement DocumentTraversal...
}
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter in project webtools.sourceediting by eclipse.
the class AdapterFactoryTestOnly method adapt.
/**
* Method that returns the adapter associated with the this factory and
* the given object, and "sets up" the adaptable object to use the
* adapter.
*
* The adapter may be a singleton or not ... depending on the needs of the
* INodeAdapter ... but in general it is recommended for an adapter to be
* stateless, so the efficiencies of a singleton can be gained.
*
* The implementation of this method should call addAdapter on the adapted
* object with the correct instance of the adapter.
*/
public INodeAdapter adapt(INodeNotifier target) {
// object.addAdapter(adapterInstance);
// return adapterInstance;
INodeAdapter result = null;
Iterator adaptersList = adapters.iterator();
while (adaptersList.hasNext()) {
INodeAdapter adapter = (INodeAdapter) adaptersList.next();
if (adapter.isAdapterForType(target)) {
INodeAdapter existingAdapter = target.getExistingAdapter(adapter);
if (existingAdapter == null) {
target.addAdapter(adapter);
result = adapter;
}
}
}
return result;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeAdapter 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();
}
Aggregations