Search in sources :

Example 1 with MediaList

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

the class MediaRuleFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
    ICSSNode child = node.getFirstChild();
    if (child != null && (child instanceof MediaList) && ((MediaList) child).getLength() == 0) {
        if (child.getNextSibling() != null)
            end = ((IndexedRegion) child.getNextSibling()).getStartOffset();
        else
            end = -1;
    }
    if (end > 0) {
        // source formatting
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(decoratedIdentRegion(regions[i], stgy));
        }
    } else {
        // source generation
        String str = MEDIA;
        if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
            str = MEDIA.toUpperCase();
        source.append(str);
    }
    if (child != null && (child instanceof MediaList) && ((MediaList) child).getLength() > 0) {
        // $NON-NLS-1$
        appendSpaceBefore(node, "", source);
    }
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 2 with MediaList

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

the class MediaListFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        for (int i = 0; i < regions.length; i++) {
            if (i != 0)
                appendSpaceBefore(node, regions[i], source);
            source.append(decoratedIdentRegion(regions[i], stgy));
        }
    } else {
        // generate source
        MediaList list = (MediaList) node;
        int n = list.getLength();
        for (int i = 0; i < n; i++) {
            String medium = list.item(i);
            if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
                medium = medium.toUpperCase();
            else
                medium = medium.toLowerCase();
            if (i != 0) {
                // $NON-NLS-1$
                source.append(",");
                appendSpaceBefore(node, medium, source);
            }
            source.append(medium);
        }
    }
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Example 3 with MediaList

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

the class CSSMediaRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    ICSSMediaRule newRule = doc.createCSSMediaRule();
    MediaList newList = newRule.getMedia();
    newList.appendMedium("media1");
    newList.appendMedium("media2");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSMediaRule);
    CSSMediaRule mediaRule = (CSSMediaRule) rule;
    MediaList mediaList = mediaRule.getMedia();
    assertEquals(2, mediaList.getLength());
    assertEquals("media1", mediaList.item(0));
    assertEquals("media2", mediaList.item(1));
    assertEquals("@media media1, media2 {" + FileUtil.commonEOL + "}", mediaRule.getCssText());
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) MediaList(org.w3c.dom.stylesheets.MediaList) CSSRule(org.w3c.dom.css.CSSRule) ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) CSSMediaRule(org.w3c.dom.css.CSSMediaRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 4 with MediaList

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

the class CSSImportRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    ICSSImportRule newRule = doc.createCSSImportRule();
    newRule.setHref("dummy.css");
    MediaList newList = newRule.getMedia();
    newList.appendMedium("media1");
    newList.appendMedium("media2");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSImportRule);
    CSSImportRule importRule = (CSSImportRule) rule;
    assertEquals("dummy.css", importRule.getHref());
    MediaList mediaList = importRule.getMedia();
    assertEquals(2, mediaList.getLength());
    assertEquals("media1", mediaList.item(0));
    assertEquals("media2", mediaList.item(1));
    assertEquals("@import url(\"dummy.css\") media1, media2;", importRule.getCssText());
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) CSSRule(org.w3c.dom.css.CSSRule) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) CSSImportRule(org.w3c.dom.css.CSSImportRule) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 5 with MediaList

use of org.w3c.dom.stylesheets.MediaList 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];
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MediaList(org.w3c.dom.stylesheets.MediaList) List(java.util.List) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

MediaList (org.w3c.dom.stylesheets.MediaList)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)3 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 CSSRule (org.w3c.dom.css.CSSRule)2 CSSRuleList (org.w3c.dom.css.CSSRuleList)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)1 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)1 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)1 CSSImportRule (org.w3c.dom.css.CSSImportRule)1 CSSMediaRule (org.w3c.dom.css.CSSMediaRule)1