Search in sources :

Example 1 with ICSSPageRule

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

the class CSSProposalGeneratorForPseudoSelector method getSelectorTags.

/**
 */
List getSelectorTags() {
    List tagList = new ArrayList();
    ICSSNode targetNode = fContext.getTargetNode();
    String rootType = (targetNode instanceof ICSSPageRule) ? CSSMMNode.TYPE_PAGE_RULE : CSSMMNode.TYPE_STYLE_RULE;
    CSSMMTypeCollector collector = new CSSMMTypeCollector();
    collector.collectNestedType(false);
    collector.apply(fContext.getMetaModel(), rootType);
    Iterator i;
    i = collector.getNodes();
    if (!i.hasNext()) {
        return tagList;
    }
    CSSMMNode node = (CSSMMNode) i.next();
    i = node.getChildNodes();
    while (i.hasNext()) {
        CSSMMNode child = (CSSMMNode) i.next();
        if (child.getType() == CSSMMNode.TYPE_SELECTOR) {
            String selType = ((CSSMMSelector) child).getSelectorType();
            if (selType == CSSMMSelector.TYPE_PSEUDO_CLASS || selType == CSSMMSelector.TYPE_PSEUDO_ELEMENT) {
                tagList.add(child);
            }
        }
    }
    return tagList;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) CSSMMTypeCollector(org.eclipse.wst.css.core.internal.metamodel.util.CSSMMTypeCollector) CSSMMSelector(org.eclipse.wst.css.core.internal.metamodel.CSSMMSelector) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 2 with ICSSPageRule

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

the class CSSProposalGeneratorForPseudoSelector method getCandidates.

/**
 * getCandidates method comment.
 */
protected Iterator getCandidates() {
    List candidates = new ArrayList();
    boolean hasLeadingColon = checkLeadingColon();
    String textToReplace = fContext.getTextToReplace();
    if (!hasLeadingColon && 0 < textToReplace.length() && !textToReplace.equals(fContext.getTextToCompare())) {
        // cursor placed midpoint of the region
        return candidates.iterator();
    }
    ITextRegion region = fContext.getTargetRegion();
    if (region != null) {
        String type = region.getType();
        if (type != CSSRegionContexts.CSS_S && !CSSRegionUtil.isSelectorBegginingType(type)) {
            return candidates.iterator();
        }
    }
    boolean useUpperCase = CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER;
    List tags = getSelectorTags();
    Collections.sort(tags, new Comparator() {

        /* (non-Javadoc)
			 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
			 */
        public int compare(Object o1, Object o2) {
            return clean(((CSSMMSelector) o1).getName()).compareTo(clean(((CSSMMSelector) o2).getName()));
        }

        private String clean(String str) {
            int length = str.length();
            for (int i = 0; i < length; i++) {
                if (str.charAt(i) != ':') {
                    return str.substring(i);
                }
            }
            return str;
        }
    });
    Iterator i = tags.iterator();
    while (i.hasNext()) {
        CSSMMSelector selector = (CSSMMSelector) i.next();
        String text = selector.getSelectorString();
        if (hasLeadingColon && !isMatch(text)) {
            continue;
        }
        text = (useUpperCase) ? text.toUpperCase() : text.toLowerCase();
        int cursorPos = 0;
        StringBuffer buf = new StringBuffer();
        if (!hasLeadingColon)
            buf.append(textToReplace);
        buf.append(text);
        cursorPos += buf.length();
        if (0 < buf.length()) {
            // Pseudoclass/element takes arguments
            if (buf.charAt(buf.length() - 1) == ')') {
                --cursorPos;
            }
            boolean inRule = (fContext.getTargetNode() instanceof ICSSStyleRule || fContext.getTargetNode() instanceof ICSSPageRule);
            if (!inRule || (textToReplace.length() == 0 && !hasLeadingColon)) {
                // $NON-NLS-1$
                buf.append(" ");
                cursorPos += 1;
            }
            if (!inRule) {
                StringAndOffset sao = generateBraces();
                buf.append(sao.fString);
                cursorPos += sao.fOffset;
            }
            CSSCACandidate item = new CSSCACandidate();
            item.setReplacementString(buf.toString());
            item.setCursorPosition(cursorPos);
            item.setDisplayString(text);
            item.setImageType(CSSImageType.SELECTOR_PSEUDO);
            item.setMMNode(selector);
            candidates.add(item);
        }
    }
    return candidates.iterator();
}
Also used : ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) CSSMMSelector(org.eclipse.wst.css.core.internal.metamodel.CSSMMSelector) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ICSSPageRule

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

the class CSSProposalArranger method buildProposals.

/**
 */
void buildProposals() {
    fProposals.clear();
    /*
		 * String text; ICompletionProposal item; text = "---- Test
		 * Information ----"; item = new CompletionProposal("",
		 * fContext.getReplaceBegin(), 0, 0, null, text, null, null);
		 * fProposals.add(item);
		 * 
		 * text = "Target: \"" + fContext.getRegionText() + "\"";
		 * 
		 * item = new CompletionProposal("", fContext.getReplaceBegin(), 0, 0,
		 * null, text, null, null); fProposals.add(item);
		 * 
		 * text = fContext.getTargetNode().getClass().toString(); int
		 * lastPeriodPos = text.lastIndexOf('.'); text = "Node: " +
		 * text.substring(lastPeriodPos + 1); item = new
		 * CompletionProposal("", fContext.getReplaceBegin(), 0, 0, null,
		 * text, null, null); fProposals.add(item);
		 */
    ICSSNode targetNode = fContext.getTargetNode();
    // int targetPos = fContext.getTargetPos();
    if (targetNode instanceof ICSSStyleSheet) {
        buildProposalsForAnyRule();
    } else if ((targetNode instanceof ICSSMediaRule && fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_LBRACE)) || (targetNode instanceof ICSSStyleRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForAnyRule();
    // buildProposalsForStyleRule();
    } else if ((targetNode instanceof ICSSPageRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForPageRulePseudoClass();
    } else if ((targetNode instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule || targetNode instanceof ICSSPageRule || targetNode instanceof ICSSStyleDeclaration) && (targetNode.getOwnerDocument() instanceof ICSSStyleDeclaration || fContext.targetFollows(CSSRegionContexts.CSS_DECLARATION_DELIMITER) || fContext.targetFollows(CSSRegionContexts.CSS_LBRACE))) {
        buildProposalsForDeclarationName();
    } else if (targetNode instanceof ICSSStyleDeclItem) {
        if (fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
            buildProposalsForDeclarationValue();
        } else {
            buildProposalsForDeclarationName();
        }
    } else if (targetNode instanceof ICSSPrimitiveValue) {
        buildProposalsForDeclarationValue();
    }
/*
		 * else if (targetNode instanceof ICSSPrimitiveValue || ((targetNode
		 * instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule ||
		 * targetNode instanceof ICSSStyleDeclaration || targetNode instanceof
		 * ICSSStyleDeclItem) &&
		 * fContext.isTargetPosAfterOf(CSSRegionContexts.COLON))) {
		 * buildProposalsForDeclarationValue(); }
		 */
// for Test
}
Also used : ICSSMediaRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleSheet(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 4 with ICSSPageRule

use of org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule 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)

Aggregations

ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)4 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)3 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 CSSMMSelector (org.eclipse.wst.css.core.internal.metamodel.CSSMMSelector)2 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)2 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)2 Comparator (java.util.Comparator)1 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)1 CSSMMTypeCollector (org.eclipse.wst.css.core.internal.metamodel.util.CSSMMTypeCollector)1 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)1 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)1 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)1 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1