Search in sources :

Example 1 with StyleSheetList

use of org.w3c.dom.stylesheets.StyleSheetList in project dbeaver by serge-rider.

the class ApplicationCSSManager method updateApplicationCSS.

static void updateApplicationCSS(Display display) {
    CSSEngine engine = WidgetElement.getEngine(display);
    if (engine == null) {
        log.error("No CSSEngine");
        return;
    }
    ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine.getDocumentCSS();
    List<StyleSheet> sheets = new ArrayList<>();
    StyleSheetList list = doc.getStyleSheets();
    for (int i = 0; i < list.getLength(); i++) {
        sheets.add(list.item(i));
    }
    try {
        Reader reader = new StringReader(EXTRA_CSS);
        sheets.add(engine.parseStyleSheet(reader));
        doc.removeAllStyleSheets();
        for (StyleSheet sheet : sheets) {
            doc.addStyleSheet(sheet);
        }
        engine.reapply();
    } catch (Exception e) {
        log.error(e);
    }
}
Also used : StyleSheet(org.w3c.dom.stylesheets.StyleSheet) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) CSSEngine(org.eclipse.e4.ui.css.core.engine.CSSEngine) StringReader(java.io.StringReader) Reader(java.io.Reader) ExtendedDocumentCSS(org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 2 with StyleSheetList

use of org.w3c.dom.stylesheets.StyleSheetList 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 3 with StyleSheetList

use of org.w3c.dom.stylesheets.StyleSheetList in project webtools.sourceediting by eclipse.

the class HTMLDocumentAdapter method getOverrideStyle.

/**
 */
public CSSStyleDeclaration getOverrideStyle(Element element, String pseudoName) {
    StyleSheetList ssl = getStyleSheets();
    int numStyles = ssl.getLength();
    CSSQueryTraverser query = new CSSQueryTraverser();
    query.setTraverseImported(true);
    query.setTraverseImportFirst(true);
    query.setElement(element, pseudoName);
    for (int i = 0; i < numStyles; i++) {
        // loop for styles (<style> and <link>)
        org.w3c.dom.stylesheets.StyleSheet ss = ssl.item(i);
        try {
            query.apply((ICSSNode) ss);
        } catch (ClassCastException ex) {
        // I can handle only CSS style
        }
    }
    return query.getDeclaration();
}
Also used : StyleSheet(org.w3c.dom.stylesheets.StyleSheet) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 4 with StyleSheetList

use of org.w3c.dom.stylesheets.StyleSheetList in project dbeaver by dbeaver.

the class ApplicationCSSManager method updateApplicationCSS.

static void updateApplicationCSS(Display display) {
    CSSEngine engine = WidgetElement.getEngine(display);
    if (engine == null) {
        log.error("No CSSEngine");
        return;
    }
    ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine.getDocumentCSS();
    List<StyleSheet> sheets = new ArrayList<>();
    StyleSheetList list = doc.getStyleSheets();
    for (int i = 0; i < list.getLength(); i++) {
        sheets.add(list.item(i));
    }
    try {
        Reader reader = new StringReader(TABBED_FOLDER_STYLE);
        sheets.add(engine.parseStyleSheet(reader));
        doc.removeAllStyleSheets();
        for (StyleSheet sheet : sheets) {
            doc.addStyleSheet(sheet);
        }
    // engine.reapply();
    } catch (Exception e) {
        log.error(e);
    }
}
Also used : StyleSheet(org.w3c.dom.stylesheets.StyleSheet) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) CSSEngine(org.eclipse.e4.ui.css.core.engine.CSSEngine) StringReader(java.io.StringReader) Reader(java.io.Reader) ExtendedDocumentCSS(org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Example 5 with StyleSheetList

use of org.w3c.dom.stylesheets.StyleSheetList in project dbeaver by dbeaver.

the class ApplicationCSSManager method updateApplicationCSS.

static void updateApplicationCSS(Display display) {
    CSSEngine engine = WidgetElement.getEngine(display);
    if (engine == null) {
        log.error("No CSSEngine");
        return;
    }
    ExtendedDocumentCSS doc = (ExtendedDocumentCSS) engine.getDocumentCSS();
    List<StyleSheet> sheets = new ArrayList<>();
    StyleSheetList list = doc.getStyleSheets();
    for (int i = 0; i < list.getLength(); i++) {
        sheets.add(list.item(i));
    }
    try {
        Reader reader = new StringReader(EXTRA_CSS);
        sheets.add(engine.parseStyleSheet(reader));
        doc.removeAllStyleSheets();
        for (StyleSheet sheet : sheets) {
            doc.addStyleSheet(sheet);
        }
        engine.reapply();
    } catch (Exception e) {
        log.error(e);
    }
}
Also used : StyleSheet(org.w3c.dom.stylesheets.StyleSheet) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) CSSEngine(org.eclipse.e4.ui.css.core.engine.CSSEngine) StringReader(java.io.StringReader) Reader(java.io.Reader) ExtendedDocumentCSS(org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS) StyleSheetList(org.w3c.dom.stylesheets.StyleSheetList)

Aggregations

StyleSheetList (org.w3c.dom.stylesheets.StyleSheetList)9 StyleSheet (org.w3c.dom.stylesheets.StyleSheet)7 ArrayList (java.util.ArrayList)5 Reader (java.io.Reader)4 StringReader (java.io.StringReader)4 ExtendedDocumentCSS (org.eclipse.e4.ui.css.core.dom.ExtendedDocumentCSS)4 CSSEngine (org.eclipse.e4.ui.css.core.engine.CSSEngine)4 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)2 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 Element (org.w3c.dom.Element)2 DocumentStyle (org.w3c.dom.stylesheets.DocumentStyle)2 Collection (java.util.Collection)1 Enumeration (java.util.Enumeration)1 Iterator (java.util.Iterator)1 ICSSStyleListener (org.eclipse.wst.css.core.internal.event.ICSSStyleListener)1 CSSClassTraverser (org.eclipse.wst.css.core.internal.util.CSSClassTraverser)1 ImportRuleCollector (org.eclipse.wst.css.core.internal.util.ImportRuleCollector)1 ImportedCollector (org.eclipse.wst.css.core.internal.util.ImportedCollector)1 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)1 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)1