Search in sources :

Example 1 with ICSSStyleDeclaration

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

the class AbstractCSSSourceFormatter method getIndent.

/**
 */
protected String getIndent(ICSSNode node) {
    if (node == null)
        // $NON-NLS-1$
        return "";
    ICSSNode parent = node.getParentNode();
    if (node instanceof ICSSAttr)
        parent = ((ICSSAttr) node).getOwnerCSSNode();
    if (parent == null)
        // $NON-NLS-1$
        return "";
    if (node instanceof org.w3c.dom.css.CSSStyleDeclaration)
        parent = parent.getParentNode();
    if (parent == null)
        // $NON-NLS-1$
        return "";
    String parentIndent = getIndent(parent);
    if (parent instanceof org.w3c.dom.css.CSSRule)
        return parentIndent + getIndentString();
    if (node.getParentNode() instanceof ICSSStyleDeclaration)
        return parentIndent + getIndentString();
    return parentIndent;
}
Also used : ICSSAttr(org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)

Example 2 with ICSSStyleDeclaration

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

the class CSSStyleDeclarationFactory method createStyleDeclaration.

/**
 * @return org.eclipse.wst.css.core.model.interfaces.ICSSStyleDeclaration
 * @param decl
 *            org.eclipse.wst.css.core.model.interfaces.ICSSStyleDeclaration
 */
public ICSSStyleDeclaration createStyleDeclaration(ICSSStyleDeclaration decl) {
    if (decl == null) {
        return null;
    }
    ICSSStyleDeclaration newNode = createStyleDeclaration();
    if (newNode == null) {
        return null;
    }
    fOwnerDocument = newNode;
    cloneChildNodes(decl, newNode);
    return newNode;
}
Also used : ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)

Example 3 with ICSSStyleDeclaration

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

the class CSSMetaModelUtil method getMetaModelNodeFor.

public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
    if (node instanceof ICSSStyleDeclaration) {
        node = node.getParentNode();
    }
    if (node instanceof ICSSStyleDeclItem) {
        ICSSNode parent = node.getParentNode();
        if (parent != null) {
            parent = parent.getParentNode();
        }
        if (parent instanceof ICSSStyleRule) {
            return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
        } else if (parent instanceof CSSFontFaceRule) {
            return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
        }
    }
    if (node == null) {
        return null;
    }
    if (fTypeMap == null) {
        fTypeMap = new HashMap();
        fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
        fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
        fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
    }
    String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
    if (nodeType == null) {
        return null;
    }
    Iterator iNodes = collectNodesByType(nodeType);
    if (iNodes.hasNext()) {
        CSSMMNode targetNode = (CSSMMNode) iNodes.next();
        if (!iNodes.hasNext()) {
            // it's only one
            return targetNode;
        }
    }
    return null;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) HashMap(java.util.HashMap) Iterator(java.util.Iterator) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 4 with ICSSStyleDeclaration

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

the class CSSNodeAdapter method internalActionPerformed.

/**
 * Insert the method's description here.
 */
protected void internalActionPerformed() {
    if (notifyQueue == null) {
        return;
    }
    boolean refresh_all = false;
    boolean refresh_rule = false;
    int pos_all = 0;
    List targets = new ArrayList();
    for (int i = 0; i < notifyQueue.size(); i++) {
        NotifyContext context = (NotifyContext) notifyQueue.get(i);
        if (context.notifier instanceof ICSSStyleSheet) {
            refresh_all = true;
            pos_all = i;
        }
        if (context.notifier instanceof ICSSStyleDeclaration) {
            refresh_rule = true;
            targets.add(context);
        // pos_rule = i;
        }
    // ((NotifyContext) notifyQueue.get(i)).fire();
    }
    if (refresh_all) {
        ((NotifyContext) notifyQueue.get(pos_all)).fire();
    } else if (refresh_rule) {
        Iterator i = targets.iterator();
        while (i.hasNext()) {
            ((NotifyContext) i.next()).fire();
        }
    // else if (refresh_rule) internalRefreshAll();
    } else {
        for (int i = 0; i < notifyQueue.size(); i++) {
            ((NotifyContext) notifyQueue.get(i)).fire();
        }
    }
    notifyQueue.clear();
}
Also used : ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) MediaList(org.w3c.dom.stylesheets.MediaList) List(java.util.List) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)

Example 5 with ICSSStyleDeclaration

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

the class TestCSSDecl method testInsertPropertyInExistingRule.

/**
 * To test https://bugs.eclipse.org/298111
 */
public void testInsertPropertyInExistingRule() {
    ICSSModel model = FileUtil.createModel();
    try {
        String originalDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "}";
        IStructuredDocument structuredDocument = model.getStructuredDocument();
        structuredDocument.set(originalDocument);
        IndexedRegion indexedRegion = model.getIndexedRegion(28);
        assertTrue("Indexed region should be an ICSSStyleRule", indexedRegion instanceof ICSSStyleRule);
        ICSSStyleRule rule = (ICSSStyleRule) indexedRegion;
        ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) rule.getStyle();
        declaration.setProperty("color", "#008040", null);
        CSSPropertyContext context = new CSSPropertyContext(declaration);
        context.applyModified(declaration);
        String newDocument = structuredDocument.get();
        String expectedNewDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "\tcolor: #008040\r\n" + "}";
        assertEquals("The updated CSS document does not equal the expected", expectedNewDocument, newDocument);
    } finally {
        if (model != null) {
            model.releaseFromEdit();
        }
    }
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) CSSPropertyContext(org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)

Aggregations

ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)11 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)5 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 CSSPropertyContext (org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)2 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)2 ElementCSSInlineStyle (org.w3c.dom.css.ElementCSSInlineStyle)2 MediaList (org.w3c.dom.stylesheets.MediaList)2 HashMap (java.util.HashMap)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)1 ICSSAttr (org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr)1 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)1 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1