Search in sources :

Example 6 with ICSSDocument

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

the class StyleSheetTest method testImportFromParentDirectory.

/**
 * Tests for the import of a stylesheet in a parent directory
 * @throws Exception
 */
public void testImportFromParentDirectory() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/style/sub.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 1 rule.", list.getLength() == 1);
                CSSRule rule = list.item(0);
                assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                assertEquals("Stylesheet reference is different than expected.", ((CSSStyleRule) rule).getSelectorText(), "#content");
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 7 with ICSSDocument

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

the class StyleSheetTest method testImportCycle.

/**
 * Tests for cycles in imports. If a cycle is encountered, we should not get stuck
 * in a loop or re-import the stylesheet.
 * @throws Exception
 */
public void testImportCycle() throws Exception {
    String filePath = "/" + PROJECT_NAME + "/WebContent/cycle0.css";
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
    assertTrue("File doesn't exist: " + filePath, file.exists());
    IStructuredModel model = null;
    try {
        model = StructuredModelManager.getModelManager().getModelForRead(file);
        if (model instanceof ICSSModel) {
            ICSSDocument document = ((ICSSModel) model).getDocument();
            if (document instanceof ICSSStyleSheet) {
                CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
                assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == 3);
                for (int i = 0; i < list.getLength(); i++) {
                    CSSRule rule = list.item(i);
                    assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
                    // Check that the rules are imported, it would start with the last imported stylesheet's rules and move up
                    assertEquals("Style rules are not equal.", ((CSSStyleRule) rule).getSelectorText(), "#cycle" + (2 - i));
                }
            }
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) CSSRule(org.w3c.dom.css.CSSRule) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) CSSRuleList(org.w3c.dom.css.CSSRuleList)

Example 8 with ICSSDocument

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

the class CSSNodeImpl method notifyChildReplaced.

protected void notifyChildReplaced(CSSNodeImpl newChild, CSSNodeImpl oldChild) {
    // for model
    ICSSDocument doc = getContainerDocument();
    if (doc == null)
        return;
    CSSModelImpl model = (CSSModelImpl) doc.getModel();
    if (model == null)
        return;
    model.childReplaced(this, newChild, oldChild);
    // for adapters
    int type = CHANGE;
    if (newChild == null)
        type = REMOVE;
    else if (oldChild == null)
        type = ADD;
    notify(type, oldChild, oldChild, newChild, getStartOffset());
}
Also used : ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Example 9 with ICSSDocument

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

the class CleanupProcessorCSS method cleanupModel.

public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
    CSSFormatUtil formatUtil = CSSFormatUtil.getInstance();
    if (structuredModel instanceof ICSSModel) {
        ICSSDocument doc = ((ICSSModel) structuredModel).getDocument();
        CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) doc);
        StringBuffer buf = formatter.cleanup(doc);
        if (buf != null) {
            int startOffset = ((IndexedRegion) doc).getStartOffset();
            int endOffset = ((IndexedRegion) doc).getEndOffset();
            formatUtil.replaceSource(doc.getModel(), startOffset, endOffset - startOffset, buf.toString());
        }
    } else if (structuredModel instanceof IDOMModel) {
        List cssnodes = formatUtil.collectCSSNodes(structuredModel, start, length);
        if (cssnodes != null && !cssnodes.isEmpty()) {
            ICSSModel model = null;
            for (int i = 0; i < cssnodes.size(); i++) {
                ICSSNode node = (ICSSNode) cssnodes.get(i);
                CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) node);
                StringBuffer buf = formatter.cleanup(node);
                if (buf != null) {
                    int startOffset = ((IndexedRegion) node).getStartOffset();
                    int endOffset = ((IndexedRegion) node).getEndOffset();
                    if (model == null) {
                        model = node.getOwnerDocument().getModel();
                    }
                    formatUtil.replaceSource(model, startOffset, endOffset - startOffset, buf.toString());
                }
            }
        }
    }
}
Also used : CSSSourceFormatter(org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter) CSSFormatUtil(org.eclipse.wst.css.core.internal.formatter.CSSFormatUtil) ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) List(java.util.List) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 10 with ICSSDocument

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

the class JFaceNodeContentProviderCSS method addElements.

/**
 * @deprecated
 */
protected 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)

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