Search in sources :

Example 16 with IDOMNode

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);
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ImportedCollector(org.eclipse.wst.css.core.internal.util.ImportedCollector) ICSSStyleListener(org.eclipse.wst.css.core.internal.event.ICSSStyleListener) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) XMLModelNotifier(org.eclipse.wst.xml.core.internal.document.XMLModelNotifier) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) DocumentStyle(org.w3c.dom.stylesheets.DocumentStyle) StyleSheet(org.w3c.dom.stylesheets.StyleSheet) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Iterator(java.util.Iterator) NodeIterator(org.w3c.dom.traversal.NodeIterator) Collection(java.util.Collection) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 17 with IDOMNode

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());
        }
    }
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)

Example 18 with IDOMNode

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;
}
Also used : IModelProvideAdapter(org.eclipse.wst.css.core.internal.provisional.adapters.IModelProvideAdapter) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IOException(java.io.IOException)

Example 19 with IDOMNode

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) URIResolver(org.eclipse.wst.sse.core.internal.util.URIResolver) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 20 with IDOMNode

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);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredDocumentRegionList(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Attr(org.w3c.dom.Attr)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18