Search in sources :

Example 46 with ICSSNode

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

the class CSSProposalGeneratorForDeclarationValue method addImportant.

private void addImportant(List candidates) {
    ICSSNode targetNode = fContext.getTargetNode();
    while (targetNode instanceof ICSSPrimitiveValue) {
        targetNode = targetNode.getParentNode();
    }
    if (!(targetNode instanceof ICSSStyleDeclItem)) {
        return;
    }
    // 1. has no priority region
    // 2. cursor position is after of last child
    // 3. normal isMatch method
    String priority = ((ICSSStyleDeclItem) targetNode).getPriority();
    if (priority == null || priority.length() == 0) {
        ICSSNode lastChild = targetNode.getLastChild();
        if (lastChild instanceof IndexedRegion) {
            int startOffset = ((IndexedRegion) lastChild).getStartOffset();
            // int endOffset = ((IndexedRegion)lastChild).getEndOffset();
            if (startOffset < fContext.getCursorPos() && isMatch(IMPORTANT)) {
                CSSCACandidate item = new CSSCACandidate();
                item.setReplacementString(IMPORTANT);
                item.setCursorPosition(IMPORTANT.length());
                item.setDisplayString(IMPORTANT);
                item.setImageType(CSSImageType.VALUE_STRING);
                appendSemiColon(item);
                candidates.add(item);
            }
        }
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 47 with ICSSNode

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

the class CSSNodeAdapter method getMediaText.

private String getMediaText(CSSRule rule) {
    // $NON-NLS-1$
    String result = "";
    ICSSNode child = (rule != null) ? ((ICSSNode) rule).getFirstChild() : null;
    while (child != null) {
        if (child.getNodeType() == ICSSNode.MEDIALIST_NODE) {
            result = ((MediaList) child).getMediaText();
            break;
        }
        child = child.getNextSibling();
    }
    return result;
}
Also used : ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 48 with ICSSNode

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

the class CSSNodeAdapter method notifyChanged.

/**
 * Called by the object being adapter (the notifier) when something has
 * changed.
 */
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
    if (notifyQueue == null)
        notifyQueue = new Vector();
    // exec
    if (notifier instanceof ICSSNode) {
        Collection listeners = ((JFaceNodeAdapterFactoryCSS) adapterFactory).getListeners();
        Iterator iterator = listeners.iterator();
        while (iterator.hasNext()) {
            Object listener = iterator.next();
            // INodeNotifier.CHANGE && changedFeature == null))) {
            if ((listener instanceof StructuredViewer) && ((eventType == INodeNotifier.STRUCTURE_CHANGED) || (eventType == INodeNotifier.CONTENT_CHANGED) || (eventType == INodeNotifier.CHANGE || (eventType == INodeNotifier.ADD) || (eventType == INodeNotifier.REMOVE)))) {
                if (DEBUG) {
                    // $NON-NLS-1$
                    System.out.println("JFaceNodeAdapter notified on event type > " + eventType);
                }
                // refresh on structural and "unknown" changes
                StructuredViewer structuredViewer = (StructuredViewer) listener;
                // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=5230
                if (structuredViewer.getControl() != null) {
                    getRefreshJob().refresh(structuredViewer, (ICSSNode) notifier);
                }
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) Collection(java.util.Collection) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) Vector(java.util.Vector)

Example 49 with ICSSNode

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

the class CSSNodeAdapter method getChildren.

/**
 * Returns an enumeration containing all child nodes of the given element,
 * which represents a node in a tree. The difference to
 * <code>IStructuredContentProvider.getElements(Object)</code> is as
 * follows: <code>getElements</code> is called to obtain the tree
 * viewer's root elements. Method <code>getChildren</code> is used to
 * obtain the children of a given node in the tree, which can can be a
 * root node, too.
 */
public Object[] getChildren(Object object) {
    if (object instanceof ICSSNode) {
        ICSSNode node = (ICSSNode) object;
        short nodeType = node.getNodeType();
        if (nodeType == ICSSNode.STYLERULE_NODE || nodeType == ICSSNode.PAGERULE_NODE || nodeType == ICSSNode.FONTFACERULE_NODE) {
            for (node = node.getFirstChild(); node != null && !(node instanceof ICSSStyleDeclaration); node.getNextSibling()) {
            // nop
            }
        }
        List children = new ArrayList();
        ICSSNode child = (node != null) ? node.getFirstChild() : null;
        while (child != null) {
            if (!(child instanceof ICSSPrimitiveValue) && !(child instanceof MediaList)) {
                children.add(child);
            }
            /*
				 * Required to correctly connect the refreshing behavior to
				 * the tree
				 */
            if (child instanceof INodeNotifier) {
                ((INodeNotifier) child).getAdapterFor(IJFaceNodeAdapter.class);
            }
            child = child.getNextSibling();
        }
        return children.toArray();
    }
    return new Object[0];
}
Also used : MediaList(org.w3c.dom.stylesheets.MediaList) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) MediaList(org.w3c.dom.stylesheets.MediaList) List(java.util.List) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Example 50 with ICSSNode

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

the class CSSNodeAdapter method addElements.

private 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

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