Search in sources :

Example 26 with ICSSNode

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

the class CSSHyperlinkDetector method getHyperlinkRegion.

private IRegion getHyperlinkRegion(ICSSNode node, String href) {
    CSSRegionContainer uriRegion = null;
    switch(node.getNodeType()) {
        case ICSSNode.PRIMITIVEVALUE_NODE:
            uriRegion = (CSSRegionContainer) node;
            break;
        case ICSSNode.IMPORTRULE_NODE:
            // $NON-NLS-1$
            ICSSNode attribute = node.getAttributes().getNamedItem("href");
            if (attribute instanceof CSSRegionContainer) {
                uriRegion = (CSSRegionContainer) attribute;
            }
            break;
    }
    if (uriRegion != null) {
        final int start = uriRegion.getStartOffset();
        final int end = uriRegion.getEndOffset();
        if (end > start)
            return new Region(start, end - start);
    }
    return null;
}
Also used : Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSRegionContainer(org.eclipse.wst.css.core.internal.document.CSSRegionContainer)

Example 27 with ICSSNode

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

the class CSSContentOutlineConfiguration method getFilteredNode.

private Object getFilteredNode(Object o) {
    ICSSNode node = null;
    if (o instanceof ICSSNode) {
        node = (ICSSNode) o;
        short nodeType = node.getNodeType();
        if (node instanceof ICSSValue) {
            while (node != null && !(node instanceof ICSSStyleDeclItem)) {
                node = node.getParentNode();
            }
        } else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
            node = node.getParentNode();
        } else if (nodeType == ICSSNode.MEDIALIST_NODE) {
            node = node.getParentNode();
        }
    }
    return node;
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 28 with ICSSNode

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

the class CSSProposalGeneratorForAtmarkRule method getCandidateImportRule.

/**
 */
private CSSCACandidate getCandidateImportRule() {
    // check content model
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_IMPORT_RULE).hasNext()) {
        return null;
    }
    // charset and import can precede import rule.
    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 || obj instanceof ICSSCharsetRule || obj instanceof ICSSImportRule)) {
                return null;
            }
        }
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? IMPORT.toUpperCase() : IMPORT.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateURI();
    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(buf.toString());
        item.setCursorPosition(cursorPos);
        item.setDisplayString(ident);
        item.setImageType(CSSImageType.RULE_IMPORT);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) ICSSCharsetRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSCharsetRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument) Iterator(java.util.Iterator) SelectionCollector(org.eclipse.wst.css.core.internal.util.SelectionCollector) ICSSImportRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule)

Example 29 with ICSSNode

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

the class StructuredSelectPreviousCSSActionDelegate 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.getPreviousSibling();
            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(newIndexedRegion.getStartOffset(), currentEndOffset - newIndexedRegion.getStartOffset());
                }
            }
        } 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 30 with ICSSNode

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

the class JSPedCSSPropertySheetConfiguration method getInputSelection.

public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
    // remove UI refresh adapters
    if (fSelectedNotifiers != null) {
        for (int i = 0; i < fSelectedNotifiers.length; i++) {
            fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
        }
        fSelectedNotifiers = null;
    }
    ISelection preferredSelection = super.getInputSelection(selectingPart, selection);
    if (preferredSelection instanceof IStructuredSelection) {
        Object[] selectedObjects = new Object[((IStructuredSelection) selection).size()];
        System.arraycopy(((IStructuredSelection) selection).toArray(), 0, selectedObjects, 0, selectedObjects.length);
        for (int i = 0; i < selectedObjects.length; i++) {
            if (selectedObjects[i] instanceof ICSSNode) {
                ICSSNode node = (ICSSNode) selectedObjects[i];
                while (node.getNodeType() == ICSSNode.PRIMITIVEVALUE_NODE || node.getNodeType() == ICSSNode.STYLEDECLITEM_NODE) {
                    node = node.getParentNode();
                    selectedObjects[i] = node;
                }
            }
        }
        /*
			 * Add UI refresh adapters and remember notifiers for later
			 * removal
			 */
        if (selectedObjects.length > 0) {
            List selectedNotifiers = new ArrayList(1);
            for (int i = 0; i < selectedObjects.length; i++) {
                if (selectedObjects[i] instanceof INodeNotifier) {
                    selectedNotifiers.add(selectedObjects[i]);
                    ((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
                }
            }
            fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
        }
        preferredSelection = new StructuredSelection(selectedObjects);
    }
    return preferredSelection;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

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