Search in sources :

Example 51 with ICSSNode

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

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

the class RefreshStructureJob method addRefreshRequest.

private synchronized void addRefreshRequest(ICSSNode newNodeRequest) {
    /*
		 * note: the caller must NOT pass in null node request (which, since
		 * private method, we do not need to gaurd against here, as long as we
		 * gaurd against it in calling method.
		 */
    int size = fRefreshes.size();
    for (int i = 0; i < size; i++) {
        ICSSNode existingNodeRequest = (ICSSNode) fRefreshes.get(i);
        /*
			 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=157427 If we
			 * already have a request which equals the new request, discard
			 * the new request
			 */
        if (existingNodeRequest.equals(newNodeRequest)) {
            return;
        }
        /*
			 * If we already have a request which contains the new request,
			 * discard the new request
			 */
        if (contains(existingNodeRequest, newNodeRequest)) {
            return;
        }
        /*
			 * If new request contains any existing requests, replace it with
			 * new request. ISSUE: technically, we should replace ALL
			 * contained, existing requests (such as if many siblings already
			 * que'd up when their common parent is then requested, but, I'm
			 * not sure if that occurs much, in practice, or if there's an
			 * algorithm to quickly find them all. Actually, I guess we could
			 * just go through the _rest_ of the list (i+1 to size) and remove
			 * any that are contained by new request ... in future :) .
			 */
        if (contains(newNodeRequest, existingNodeRequest)) {
            fRefreshes.set(i, newNodeRequest);
            return;
        }
    }
    /*
		 * If we get to here, either from existing request list being zero
		 * length, or no exisitng requests "matched" new request, then add the
		 * new request.
		 */
    fRefreshes.add(newNodeRequest);
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 53 with ICSSNode

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

the class StructuredSelectNextHandler method getNewSelectionRegion.

protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
    Region newRegion = null;
    if (indexedRegion instanceof ICSSNode) {
        ICSSNode cursorNode = (ICSSNode) indexedRegion;
        Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
        int currentOffset = textSelection.getOffset();
        int currentEndOffset = currentOffset + textSelection.getLength();
        if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
            ICSSNode newNode = cursorNode.getNextSibling();
            if (newNode == null) {
                newNode = cursorNode.getParentNode();
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
                }
            } else {
                if (newNode instanceof IndexedRegion) {
                    IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
                    newRegion = new Region(currentOffset, newIndexedRegion.getEndOffset() - currentOffset);
                }
            }
        } else
            newRegion = cursorNodeRegion;
    }
    return newRegion;
}
Also used : Region(org.eclipse.jface.text.Region) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 54 with ICSSNode

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

the class CSSHyperlinkDetector method detectHyperlinks.

/* (non-Javadoc)
	 * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
	 */
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    if (textViewer != null && region != null) {
        final IDocument document = textViewer.getDocument();
        final ICSSNode node = getNode(document, region);
        if (node == null) {
            return null;
        }
        String href = null;
        switch(node.getNodeType()) {
            case ICSSNode.PRIMITIVEVALUE_NODE:
                if (((CSSPrimitiveValue) node).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
                    href = ((CSSPrimitiveValue) node).getStringValue();
                }
                break;
            case ICSSNode.IMPORTRULE_NODE:
                href = ((CSSImportRule) node).getHref();
                break;
        }
        if (href != null) {
            final IHyperlink hyperlink = getHyperlink(node, href);
            if (hyperlink != null) {
                return new IHyperlink[] { hyperlink };
            }
        }
    }
    return null;
}
Also used : IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IDocument(org.eclipse.jface.text.IDocument)

Example 55 with ICSSNode

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

the class CSSContentAssistContext method initializeTargetNode.

/**
 */
private void initializeTargetNode() {
    if (fCursorPos == 0) {
        fTargetNode = fModel.getDocument();
        return;
    }
    // find edge of tree node
    ICSSNode cursorNode = getNodeAt(fCursorPos);
    if (cursorNode == null) {
        // end of document
        cursorNode = fModel.getDocument();
    }
    ICSSNode node = null;
    IStructuredDocumentRegion flatNode = fStructuredDocument.getRegionAtCharacterOffset(fCursorPos - 1);
    while (flatNode != null && (node = getNodeAt(flatNode.getStartOffset())) == cursorNode && ((IndexedRegion) node).getStartOffset() != flatNode.getStartOffset()) {
        flatNode = flatNode.getPrevious();
    }
    if (flatNode == null) {
        // top of document
        fTargetNode = (node == null) ? fModel.getDocument() : node;
        return;
    }
    // BBBBBBBBBB cursorNode:A , node:B -> target is A
    if (cursorNode != null) {
        for (ICSSNode parent = cursorNode.getParentNode(); parent != null; parent = parent.getParentNode()) {
            if (parent == cursorNode) {
                fTargetNode = cursorNode;
                return;
            }
        }
    }
    // v<--|
    // AAA
    // BBBBBBBBBB cursorNode:B , node:A -> depend on A's node type
    short nodeType = node.getNodeType();
    if (nodeType == ICSSNode.STYLEDECLITEM_NODE || nodeType == ICSSNode.CHARSETRULE_NODE || nodeType == ICSSNode.IMPORTRULE_NODE) {
        String type = CSSUtil.getStructuredDocumentRegionType(flatNode);
        if (type == CSSRegionContexts.CSS_DELIMITER || type == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
            fTargetNode = node.getParentNode();
        } else {
            fTargetNode = node;
        }
    // fTargetNode = (bOverSemiColon) ? node.getParentNode() : node;
    } else if (CSSUtil.getStructuredDocumentRegionType(flatNode) == CSSRegionContexts.CSS_RBRACE) {
        fTargetNode = node.getParentNode();
    } else {
        fTargetNode = node;
    }
    return;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

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