Search in sources :

Example 11 with ICSSDocument

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument 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 12 with ICSSDocument

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.

the class CSSNodeAdapter method addElements.

private void addElements(Object element, ArrayList v) {
    ICSSNode node;
    if (element instanceof ICSSModel) {
        ICSSModel model = (ICSSModel) element;
        ICSSDocument doc = model.getDocument();
        node = doc.getFirstChild();
    } else if (element instanceof ICSSNode) {
        node = ((ICSSNode) element).getFirstChild();
    } else
        return;
    while (node != null) {
        if (node instanceof CSSRule) {
            v.add(node);
        }
        node = node.getNextSibling();
    }
}
Also used : CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Example 13 with ICSSDocument

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.

the class RefreshStructureJob method contains.

/**
 * Simple hierarchical containment relationship. Note, this method returns
 * "false" if the two nodes are equal!
 *
 * @param root
 * @param possible
 * @return if the root is parent of possible, return true, otherwise
 *         return false
 */
private boolean contains(ICSSNode root, ICSSNode possible) {
    if (DEBUG) {
        // $NON-NLS-1$
        System.out.println("==============================================================================================================");
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println("recursive call w/ root: " + root + " and possible: " + possible);
        // $NON-NLS-1$
        System.out.println("--------------------------------------------------------------------------------------------------------------");
    }
    // can't contain the child if it's null
    if (root == null) {
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("returning false: root is null");
        }
        return false;
    }
    // nothing can be parent of Document node
    if (possible instanceof ICSSDocument) {
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("returning false: possible is Document node");
        }
        return false;
    }
    // document contains everything
    if (root instanceof ICSSDocument) {
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("returning true: root is Document node");
        }
        return true;
    }
    // check parentage
    ICSSNode current = possible;
    // loop parents
    while ((current != null) && (current.getNodeType() != ICSSNode.STYLESHEET_NODE || current.getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
        // found it
        if (root.equals(current)) {
            if (DEBUG) {
                // $NON-NLS-1$ //$NON-NLS-2$
                System.out.println("   !!! found: " + possible + " in subelement of: " + root);
            }
            return true;
        }
        current = current.getParentNode();
    }
    // never found it
    return false;
}
Also used : ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 14 with ICSSDocument

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForAtmarkRule method getCandidateCharsetRule.

/**
 */
private CSSCACandidate getCandidateCharsetRule() {
    // check content model
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_CHARSET_RULE).hasNext()) {
        return null;
    }
    // check if embedded or not
    if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
        return null;
    }
    // check if caret precede all other rules.
    int offset = fContext.getCursorPos();
    if (0 < offset) {
        SelectionCollector trav = new SelectionCollector();
        trav.setRegion(0, offset - 1);
        trav.apply(fContext.getModel().getDocument());
        Iterator i = trav.getSelectedNodes().iterator();
        while (i.hasNext()) {
            Object obj = i.next();
            if (obj instanceof ICSSNode && !(obj instanceof ICSSDocument)) {
                return null;
            }
        }
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? CHARSET.toUpperCase() : CHARSET.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateQuotes();
    buf.append(sao.fString);
    cursorPos += sao.fOffset;
    sao = generateSemicolon();
    buf.append(sao.fString);
    String text = buf.toString();
    if (isMatch(text)) {
        CSSCACandidate item = new CSSCACandidate();
        item.setReplacementString(text);
        item.setCursorPosition(cursorPos);
        item.setDisplayString(ident);
        item.setImageType(CSSImageType.RULE_CHARSET);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) Iterator(java.util.Iterator) SelectionCollector(org.eclipse.wst.css.core.internal.util.SelectionCollector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Example 15 with ICSSDocument

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.

the class CSSCharsetRuleTest method testCreateRule.

public void testCreateRule() {
    ICSSStyleSheet sheet = getStyleSheet();
    ICSSDocument doc = sheet;
    CSSCharsetRule newRule = doc.createCSSCharsetRule();
    newRule.setEncoding("iso-8859-1");
    sheet.insertRuleBefore(newRule, null);
    CSSRuleList ruleList = sheet.getCssRules();
    CSSRule rule = ruleList.item(0);
    assertTrue(rule instanceof CSSCharsetRule);
    CSSCharsetRule charsetRule = (CSSCharsetRule) rule;
    assertEquals("iso-8859-1", charsetRule.getEncoding());
    assertEquals(RULE, charsetRule.getCssText());
}
Also used : CSSCharsetRule(org.w3c.dom.css.CSSCharsetRule) CSSRule(org.w3c.dom.css.CSSRule) 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)

Aggregations

ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)23 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)12 CSSRule (org.w3c.dom.css.CSSRule)10 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)9 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)8 CSSRuleList (org.w3c.dom.css.CSSRuleList)8 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)7 IFile (org.eclipse.core.resources.IFile)5 Path (org.eclipse.core.runtime.Path)5 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)4 Iterator (java.util.Iterator)2 List (java.util.List)2 ITextSelection (org.eclipse.jface.text.ITextSelection)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 CSSFormatUtil (org.eclipse.wst.css.core.internal.formatter.CSSFormatUtil)2 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)2 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)2 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)2 SelectionCollector (org.eclipse.wst.css.core.internal.util.SelectionCollector)2 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)2