Search in sources :

Example 76 with ICSSNode

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

the class CSSModelParser method insertBraceClose.

/**
 */
private CSSNodeImpl insertBraceClose(IStructuredDocumentRegion region) {
    ICSSNode target = CSSModelUtil.findBraceContainer(fCreationContext.getTargetNode());
    if (!(target instanceof CSSStructuredDocumentRegionContainer)) {
        return null;
    }
    CSSStructuredDocumentRegionContainer parent = (CSSStructuredDocumentRegionContainer) target;
    if (CSSModelUtil.isInterruption(parent, region)) {
        ICSSNode node = parent.getParentNode();
        if (node instanceof CSSNodeImpl) {
            fCreationContext.setReparseStart(parent.getStartOffset());
            fCreationContext.setReparseEnd(parent.getEndOffset());
            ((CSSNodeImpl) node).removeChild(parent);
        }
        return null;
    }
    if (parent instanceof ICSSPageRule || parent instanceof ICSSMediaRule || parent instanceof CSSFontFaceRule || parent instanceof ICSSStyleRule) {
        CSSModelUtil.expandStructuredDocumentRegionContainer(parent, region);
        if (!CSSModelUtil.isBraceClosed(target)) {
            fCreationContext.setTargetNode(parent.getParentNode());
            fCreationContext.setNextNode(parent.getNextSibling());
            return parent;
        }
    }
    return null;
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) 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 77 with ICSSNode

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

the class CSSModelParser method getNodeAt.

/**
 */
private CSSNodeImpl getNodeAt(int offset) {
    CSSNodeImpl rootNode = fCreationContext.getRootNode();
    ICSSNode target = rootNode.getNodeAt(offset);
    if (target instanceof CSSNodeImpl) {
        return (CSSNodeImpl) target;
    } else {
        return null;
    }
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 78 with ICSSNode

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

the class CSSModelParser method cleanupLastNode.

/**
 */
boolean cleanupLastNode(IStructuredDocumentRegion lastNode, CSSStructuredDocumentRegionContainer target) {
    if (lastNode == null || target == null) {
        return false;
    }
    if (lastNode == target.getLastStructuredDocumentRegion()) {
        IStructuredDocumentRegion prevNode = fStructuredDocumentWalker.getPrevNodeInCurrent(lastNode);
        IStructuredDocumentRegion firstNode = target.getFirstStructuredDocumentRegion();
        if (firstNode == null || fStructuredDocumentWalker.isOldNode(firstNode) || prevNode == null || prevNode.getStartOffset() < firstNode.getStartOffset()) {
            target.setRangeStructuredDocumentRegion(null, null);
        } else {
            target.setLastStructuredDocumentRegion(prevNode);
        }
        ICSSNode parent = target.getParentNode();
        if (parent instanceof CSSStructuredDocumentRegionContainer) {
            cleanupLastNode(lastNode, (CSSStructuredDocumentRegionContainer) parent);
            return true;
        }
    }
    return false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 79 with ICSSNode

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

the class CSSModelParser method cleanupFirstNode.

/**
 */
boolean cleanupFirstNode(IStructuredDocumentRegion firstNode, CSSStructuredDocumentRegionContainer target) {
    if (firstNode == null || target == null) {
        return false;
    }
    if (firstNode == target.getFirstStructuredDocumentRegion()) {
        IStructuredDocumentRegion nextNode = fStructuredDocumentWalker.getNextNodeInCurrent(firstNode);
        IStructuredDocumentRegion lastNode = target.getLastStructuredDocumentRegion();
        if (lastNode == null || fStructuredDocumentWalker.isOldNode(lastNode) || nextNode == null || lastNode.getStartOffset() < nextNode.getStartOffset()) {
            target.setRangeStructuredDocumentRegion(null, null);
        } else {
            target.setFirstStructuredDocumentRegion(nextNode);
        }
        ICSSNode parent = target.getParentNode();
        if (parent instanceof CSSStructuredDocumentRegionContainer) {
            cleanupFirstNode(firstNode, (CSSStructuredDocumentRegionContainer) parent);
            return true;
        }
    }
    return false;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 80 with ICSSNode

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

the class CSSStyleDeclarationImpl method item.

/**
 * Used to retrieve the properties that have been explicitly set in this
 * declaration block. The order of the properties retrieved using this
 * method does not have to be the order in which they were set. This
 * method can be used to iterate over all properties in this declaration
 * block.
 *
 * @param index
 *            Index of the property name to retrieve.
 * @return The name of the property at this ordinal position. The empty
 *         string if no property exists at this position.
 */
public String item(int index) {
    if (index < 0)
        return null;
    int i = 0;
    ICSSNode node = getFirstChild();
    while (node != null) {
        if (node instanceof CSSStyleDeclItemImpl) {
            if (i != index)
                i++;
            else {
                CSSStyleDeclItemImpl item = (CSSStyleDeclItemImpl) node;
                return item.getPropertyName();
            }
        }
        node = node.getNextSibling();
    }
    return null;
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Aggregations

ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)95 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)21 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)13 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)12 DOMException (org.w3c.dom.DOMException)12 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)11 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)11 Iterator (java.util.Iterator)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)9 Region (org.eclipse.jface.text.Region)8 CSSSourceFormatter (org.eclipse.wst.css.core.internal.formatter.CSSSourceFormatter)6 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)6 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)5 ICSSImportRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)5 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5