Search in sources :

Example 6 with ICSSPrimitiveValue

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

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

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

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

the class PrimitiveValueFormatter method formatPre.

/**
 */
protected void formatPre(ICSSNode node, StringBuffer source) {
    int start = ((IndexedRegion) node).getStartOffset();
    int end = ((IndexedRegion) node).getEndOffset();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    CSSCleanupStrategy stgy = getCleanupStrategy(node);
    if (end > 0) {
        // format source
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        boolean appendQuote = regions.length > 1 && node.getParentNode() instanceof ICSSStyleDeclItem && isCleanup() && getCleanupStrategy(node).isQuoteValues() && (((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT_FAMILY) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_VOICE_FAMILY));
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        StringBuffer strBuf = new StringBuffer();
        boolean skipSpace = false;
        for (int i = 0; i < regions.length; i++) {
            if (i != 0 && !skipSpace)
                appendSpaceBefore(node, regions[i], strBuf);
            skipSpace = false;
            strBuf.append(decoratedPropValueRegion(regions[i], stgy));
            if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
                skipSpace = true;
        }
        if (appendQuote) {
            source.append(quote);
            String str = strBuf.toString();
            str = str.replace('\'', ' ');
            str = str.replace('\"', ' ');
            str = str.trim();
            source.append(str);
            source.append(quote);
        } else {
            source.append(strBuf);
        }
    } else {
        // generate source
        ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
        short type = value.getPrimitiveType();
        String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
        String str = null;
        switch(type) {
            case CSSPrimitiveValue.CSS_NUMBER:
            case CSSPrimitiveValue.CSS_PERCENTAGE:
            case CSSPrimitiveValue.CSS_EMS:
            case CSSPrimitiveValue.CSS_EXS:
            case CSSPrimitiveValue.CSS_PX:
            case CSSPrimitiveValue.CSS_CM:
            case CSSPrimitiveValue.CSS_MM:
            case CSSPrimitiveValue.CSS_IN:
            case CSSPrimitiveValue.CSS_PT:
            case CSSPrimitiveValue.CSS_PC:
            case CSSPrimitiveValue.CSS_DEG:
            case CSSPrimitiveValue.CSS_RAD:
            case CSSPrimitiveValue.CSS_GRAD:
            case CSSPrimitiveValue.CSS_MS:
            case CSSPrimitiveValue.CSS_S:
            case CSSPrimitiveValue.CSS_HZ:
            case CSSPrimitiveValue.CSS_KHZ:
            case CSSPrimitiveValue.CSS_DIMENSION:
            case ICSSPrimitiveValue.CSS_INTEGER:
                if (value.getFloatValue(type) == ((int) value.getFloatValue(type))) {
                    str = Integer.toString((int) value.getFloatValue(type));
                } else {
                    str = Float.toString(value.getFloatValue(type));
                }
                break;
            case CSSPrimitiveValue.CSS_IDENT:
            case ICSSPrimitiveValue.CSS_HASH:
            case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
                str = value.getStringValue();
                if (str != null) {
                    if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
                        str = str.toUpperCase();
                    else
                        str.toLowerCase();
                }
                break;
            case CSSPrimitiveValue.CSS_STRING:
            case CSSPrimitiveValue.CSS_URI:
            case CSSPrimitiveValue.CSS_ATTR:
            case ICSSPrimitiveValue.CSS_URANGE:
            case ICSSPrimitiveValue.CSS_FORMAT:
            case ICSSPrimitiveValue.CSS_LOCAL:
            case ICSSPrimitiveValue.CSS_COMMA:
            case ICSSPrimitiveValue.CSS_SLASH:
                str = value.getStringValue();
        }
        String preStr = null, postStr = null;
        switch(type) {
            case CSSPrimitiveValue.CSS_ATTR:
                // $NON-NLS-1$
                preStr = "attr(";
                // $NON-NLS-1$
                postStr = ")";
                break;
            case CSSPrimitiveValue.CSS_CM:
                // $NON-NLS-1$
                postStr = "cm";
                break;
            // case ICSSPrimitiveValue.CSS_COUNTER:
            case CSSPrimitiveValue.CSS_DEG:
                // $NON-NLS-1$
                postStr = "deg";
                break;
            case CSSPrimitiveValue.CSS_EMS:
                // $NON-NLS-1$
                postStr = "em";
                break;
            case CSSPrimitiveValue.CSS_EXS:
                // $NON-NLS-1$
                postStr = "ex";
                break;
            case CSSPrimitiveValue.CSS_GRAD:
                // $NON-NLS-1$
                postStr = "grad";
                break;
            case CSSPrimitiveValue.CSS_HZ:
                // $NON-NLS-1$
                postStr = "Hz";
                break;
            case CSSPrimitiveValue.CSS_IN:
                // $NON-NLS-1$
                postStr = "in";
                break;
            case CSSPrimitiveValue.CSS_KHZ:
                // $NON-NLS-1$
                postStr = "kHz";
                break;
            case CSSPrimitiveValue.CSS_MM:
                // $NON-NLS-1$
                postStr = "mm";
                break;
            case CSSPrimitiveValue.CSS_MS:
                // $NON-NLS-1$
                postStr = "ms";
                break;
            case CSSPrimitiveValue.CSS_PC:
                // $NON-NLS-1$
                postStr = "pc";
                break;
            case CSSPrimitiveValue.CSS_PERCENTAGE:
                // $NON-NLS-1$
                postStr = "%";
                break;
            case CSSPrimitiveValue.CSS_PT:
                // $NON-NLS-1$
                postStr = "pt";
                break;
            case CSSPrimitiveValue.CSS_PX:
                // $NON-NLS-1$
                postStr = "px";
                break;
            case CSSPrimitiveValue.CSS_RAD:
                // $NON-NLS-1$
                postStr = "rad";
                break;
            // case ICSSPrimitiveValue.CSS_RGBCOLOR:
            case CSSPrimitiveValue.CSS_S:
                // $NON-NLS-1$
                postStr = "s";
                break;
            case CSSPrimitiveValue.CSS_STRING:
                quote = CSSUtil.detectQuote(str, quote);
                preStr = quote;
                postStr = quote;
                break;
            case CSSPrimitiveValue.CSS_URI:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "url(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
            // the followings are original primitive values
            case CSSPrimitiveValue.CSS_IDENT:
            case CSSPrimitiveValue.CSS_UNKNOWN:
            // use str
            case ICSSPrimitiveValue.CSS_INTEGER:
            case ICSSPrimitiveValue.CSS_HASH:
            case ICSSPrimitiveValue.CSS_SLASH:
            case ICSSPrimitiveValue.CSS_COMMA:
            case CSSPrimitiveValue.CSS_DIMENSION:
            case CSSPrimitiveValue.CSS_NUMBER:
            case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
                break;
            case ICSSPrimitiveValue.CSS_URANGE:
                // $NON-NLS-1$
                preStr = "U+";
                break;
            case ICSSPrimitiveValue.CSS_FORMAT:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "format(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
            case ICSSPrimitiveValue.CSS_LOCAL:
                quote = CSSUtil.detectQuote(str, quote);
                // $NON-NLS-1$
                preStr = "local(" + quote;
                // $NON-NLS-1$
                postStr = quote + ")";
                break;
        }
        if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
            if (preStr != null)
                preStr = preStr.toUpperCase();
            if (postStr != null)
                postStr = postStr.toUpperCase();
        }
        if (preStr != null)
            source.append(preStr);
        if (str != null)
            source.append(str);
        if (postStr != null)
            source.append(postStr);
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Preferences(org.eclipse.core.runtime.Preferences)

Example 10 with ICSSPrimitiveValue

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

the class StyleDeclItemFormatter method formatBefore.

/**
 */
protected void formatBefore(ICSSNode node, ICSSNode child, String toAppend, StringBuffer source, IRegion exceptFor) {
    ICSSNode prev = (child != null) ? child.getPreviousSibling() : node.getLastChild();
    int start = (prev != null) ? ((IndexedRegion) prev).getEndOffset() : 0;
    int end = (child != null) ? ((IndexedRegion) child).getStartOffset() : 0;
    if (start > 0 && start < end) {
        CSSCleanupStrategy stgy = getCleanupStrategy(node);
        IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
        // get meaning regions
        CompoundRegion[] regions = null;
        if (exceptFor == null)
            regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
        else {
            regions = getRegions(structuredDocument, new FormatRegion(start, end - start), exceptFor, null);
        }
        // generate source
        for (int i = 0; i < regions.length; i++) {
            appendSpaceBefore(node, regions[i], source);
            // must
            source.append(decoratedRegion(regions[i], 2, stgy));
        // be
        // comments
        }
    }
    if (child != null) {
        boolean append = true;
        if (child instanceof ICSSPrimitiveValue) {
            if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_COMMA)
                // $NON-NLS-1$
                toAppend = ",";
            else if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
                // $NON-NLS-1$
                toAppend = "/";
            ICSSNode prevSibling = child.getPreviousSibling();
            if (prevSibling instanceof ICSSPrimitiveValue) {
                if (((ICSSPrimitiveValue) prevSibling).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
                    append = false;
                if (prevSibling instanceof CSSRegionContainer) {
                    // If the previous region was unknown, don't append whitespace
                    final ITextRegion region = ((CSSRegionContainer) prevSibling).getFirstRegion();
                    if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
                        append = false;
                }
            }
        }
        if (child instanceof CSSRegionContainer) {
            final ITextRegion region = ((CSSRegionContainer) child).getFirstRegion();
            // If the current region is unknown, don't append whitespace
            if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
                append = false;
        }
        if (toAppend != null && !toAppend.equals(",") && !toAppend.equals("/") && !toAppend.equals(")") && append) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            appendSpaceBefore(node, toAppend, source);
        }
    }
}
Also used : ICSSPrimitiveValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) CSSRegionContainer(org.eclipse.wst.css.core.internal.document.CSSRegionContainer) CSSCleanupStrategy(org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)

Aggregations

ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)11 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)6 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)2 PropCMProperty (org.eclipse.wst.css.core.internal.contentmodel.PropCMProperty)2 CSSTextParser (org.eclipse.wst.css.core.internal.parserz.CSSTextParser)2 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)2 ICSSValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSValue)2 ICSSValueList (org.eclipse.wst.css.core.internal.provisional.document.ICSSValueList)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSRegionContainer (org.eclipse.wst.css.core.internal.document.CSSRegionContainer)1 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)1 ICSSPageRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule)1 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)1 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)1