use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode 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.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method refreshSheet.
/**
*/
public void refreshSheet() {
if (!replaceModel) {
removed();
replaceModel = true;
IDOMNode node = (IDOMNode) getElement();
if (node != null) {
node.notify(INodeNotifier.CHANGE, getElement().getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_HREF), null, null, node.getStartOffset());
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method retrieveModel.
/**
*/
private ICSSModel retrieveModel() {
if (!isValidAttribute()) {
return null;
}
// null,attr check is done in isValidAttribute()
Element element = getElement();
// $NON-NLS-1$
String href = element.getAttribute("href");
IDOMModel baseModel = ((IDOMNode) element).getModel();
if (baseModel == null)
return null;
Object id = baseModel.getId();
if (!(id instanceof String))
return null;
// String base = (String)id;
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
URLModelProvider provider = new URLModelProvider();
try {
IStructuredModel newModel = provider.getModelForRead(baseModel, href);
if (newModel == null)
return null;
if (!(newModel instanceof ICSSModel)) {
newModel.releaseFromRead();
return null;
}
// notify adapter
if (adapter != null)
adapter.modelProvided(newModel);
return (ICSSModel) newModel;
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method createModel.
protected ICSSModel createModel() {
// create phantom(broken link) external CSS model
if (getElement() == null)
return null;
IStructuredModel baseModel = ((IDOMNode) getElement()).getModel();
ICSSModel newModel = (ICSSModel) baseModel.getModelManager().createUnManagedStructuredModelFor(CSS_ID);
// calculate base location and set
// get resolver in Model
URIResolver resolver = baseModel.getResolver();
// resolve to absolute url : this need not exact location of css file. It is important that absurl is not null.
String ref = getElement().getAttribute(HTML40Namespace.ATTR_NAME_HREF);
String absurl = (resolver != null && ref != null && ref.length() > 0) ? resolver.getLocationByURI(ref, true) : null;
if ((absurl == null) || (absurl.length() == 0)) {
IPath basePath = new Path(baseModel.getBaseLocation());
URLHelper helper = new URLHelper(basePath.removeLastSegments(1).toString());
// $NON-NLS-1$
absurl = helper.toAbsolute(ref == null ? "" : ref);
}
if ((absurl == null) || (absurl.length() == 0)) {
absurl = ref;
}
if (absurl == null) {
// $NON-NLS-1$
absurl = "";
}
newModel.setBaseLocation(absurl);
// set style listener
newModel.addStyleListener(this);
return newModel;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class StyleAttrAdapter method setValue.
/**
*/
private void setValue() {
Element element = getElement();
if (element == null)
return;
ICSSModel model = getExistingModel();
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
String value = null;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes != null) {
int count = flatNodes.getLength();
if (count > 0) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < count; i++) {
IStructuredDocumentRegion flatNode = flatNodes.item(i);
if (flatNode == null)
continue;
buffer.append(flatNode.getText());
}
value = buffer.toString();
}
}
this.ignoreNotification = true;
if (value == null || value.length() == 0) {
element.removeAttribute(STYLE);
} else {
Attr attr = element.getAttributeNode(STYLE);
if (attr != null) {
((IDOMNode) attr).setValueSource(value);
} else {
Document document = element.getOwnerDocument();
attr = document.createAttribute(STYLE);
((IDOMNode) attr).setValueSource(value);
element.setAttributeNode(attr);
}
}
this.ignoreNotification = false;
notifyStyleChanged(element);
}
Aggregations