Search in sources :

Example 6 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForDeclarationValue method getCandidates.

/**
 * getCandidates method comment.
 */
protected Iterator getCandidates() {
    List candidates = new ArrayList();
    // check should add semi-colon or not
    checkSemiColon();
    String name = getPropertyName();
    if (name != null) {
        CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
        Iterator i = Collections.EMPTY_LIST.iterator();
        if (isFontFaceRule()) {
            CSSMMDescriptor desc = util.getDescriptor(name);
            if (desc != null) {
                i = desc.getValues();
            }
        } else {
            CSSMMProperty prop = util.getProperty(name);
            if (prop != null) {
                i = prop.getValues();
            }
        }
        while (i.hasNext()) {
            CSSMMNode val = (CSSMMNode) i.next();
            String valueType = val.getType();
            if (valueType == CSSMMNode.TYPE_KEYWORD) {
                addString(candidates, val.toString());
            } else if (valueType == CSSMMNode.TYPE_NUMBER) {
                addNumber(candidates, (CSSMMNumber) val);
            } else if (valueType == CSSMMNode.TYPE_FUNCTION) {
                addFunction(candidates, (CSSMMFunction) val);
            }
        }
    }
    addImportant(candidates);
    addSemiColon(candidates);
    return candidates.iterator();
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) CSSMMProperty(org.eclipse.wst.css.core.internal.metamodel.CSSMMProperty) ArrayList(java.util.ArrayList) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) CSSMMDescriptor(org.eclipse.wst.css.core.internal.metamodel.CSSMMDescriptor) CSSMMNumber(org.eclipse.wst.css.core.internal.metamodel.CSSMMNumber)

Example 7 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForAtmarkRule method getCandidateFontFaceRule.

/**
 */
private CSSCACandidate getCandidateFontFaceRule() {
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_FONT_FACE_RULE).hasNext()) {
        return null;
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? FONT_FACE.toUpperCase() : FONT_FACE.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateBraces();
    buf.append(sao.fString);
    cursorPos += sao.fOffset;
    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_FONTFACE);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)

Example 8 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForAtmarkRule method getCandidateCharsetRule.

/**
 */
private CSSCACandidate getCandidateCharsetRule() {
    // check content model
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_CHARSET_RULE).hasNext()) {
        return null;
    }
    // check if embedded or not
    if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
        return null;
    }
    // check if caret precede all other rules.
    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)) {
                return null;
            }
        }
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? CHARSET.toUpperCase() : CHARSET.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateQuotes();
    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(text);
        item.setCursorPosition(cursorPos);
        item.setDisplayString(ident);
        item.setImageType(CSSImageType.RULE_CHARSET);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) Iterator(java.util.Iterator) SelectionCollector(org.eclipse.wst.css.core.internal.util.SelectionCollector) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSDocument(org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)

Example 9 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForAtmarkRule method getCandidatePageRule.

/**
 */
private CSSCACandidate getCandidatePageRule() {
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    if (!util.collectNodesByType(CSSMMNode.TYPE_PAGE_RULE).hasNext()) {
        return null;
    }
    int cursorPos = 0;
    String ident = (fUseUpperCase) ? PAGE.toUpperCase() : PAGE.toLowerCase();
    StringBuffer buf = new StringBuffer();
    buf.append(ident);
    // $NON-NLS-1$
    buf.append(" ");
    cursorPos = buf.length();
    StringAndOffset sao;
    sao = generateBraces();
    buf.append(sao.fString);
    cursorPos += sao.fOffset;
    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_PAGE);
        return item;
    } else {
        return null;
    }
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)

Example 10 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForDeclarationName method getCandidates.

/**
 * getCandidates method comment.
 */
protected Iterator getCandidates() {
    List candidates = new ArrayList();
    Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
    // $NON-NLS-1$
    String preDelim = "";
    for (int i = 0; i < preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM); i++) {
        // $NON-NLS-1$
        preDelim += ' ';
    }
    // $NON-NLS-1$
    String postDelim = "";
    for (int i = 0; i < preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_POST_DELIM); i++) {
        // $NON-NLS-1$
        postDelim += ' ';
    }
    ICSSNode targetNode = fContext.getTargetNode();
    boolean bFontRule = false;
    for (ICSSNode node = targetNode; node != null; node = node.getParentNode()) {
        if (node instanceof org.w3c.dom.css.CSSFontFaceRule) {
            bFontRule = true;
            break;
        }
    }
    List names = new ArrayList();
    CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
    Iterator iNames = util.collectNodesByType((bFontRule) ? CSSMMNode.TYPE_DESCRIPTOR : CSSMMNode.TYPE_PROPERTY);
    while (iNames.hasNext()) {
        CSSMMNode node = (CSSMMNode) iNames.next();
        names.add(node);
    }
    sortNames(names);
    // Collections.sort(names);
    boolean bAddColon = true;
    if ((targetNode instanceof ICSSStyleRule || targetNode instanceof ICSSStyleDeclItem || targetNode instanceof ICSSStyleDeclaration) && fContext.targetHas(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
        bAddColon = false;
    }
    Iterator i = names.iterator();
    while (i.hasNext()) {
        CSSMMNode node = (CSSMMNode) i.next();
        String text = node.getName();
        text = (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER) ? text.toUpperCase() : text.toLowerCase();
        if (!isMatch(text)) {
            continue;
        }
        int cursorPos = 0;
        StringBuffer buf = new StringBuffer();
        buf.append(text);
        buf.append(preDelim);
        cursorPos = buf.length();
        if (bAddColon) {
            // $NON-NLS-1$
            buf.append(':');
            buf.append(postDelim);
            cursorPos += 1 + postDelim.length();
        }
        // if (! (targetNode instanceof ICSSStyleDeclItem)) {
        // buf.append(';');//$NON-NLS-1$
        // }
        CSSCACandidate item = new CSSCACandidate();
        item.setReplacementString(buf.toString());
        item.setCursorPosition(cursorPos);
        item.setDisplayString(text);
        item.setMMNode(node);
        item.setImageType(getCategoryImageType(node));
        candidates.add(item);
    }
    return candidates.iterator();
}
Also used : CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ArrayList(java.util.ArrayList) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule) CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Preferences(org.eclipse.core.runtime.Preferences)

Aggregations

CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)13 Iterator (java.util.Iterator)10 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)8 HashSet (java.util.HashSet)6 Set (java.util.Set)6 CSSMMProperty (org.eclipse.wst.css.core.internal.metamodel.CSSMMProperty)6 CSSMetaModel (org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel)6 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ICSSDocument (org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument)2 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)2 SelectionCollector (org.eclipse.wst.css.core.internal.util.SelectionCollector)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Preferences (org.eclipse.core.runtime.Preferences)1 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)1 CSSMMCategory (org.eclipse.wst.css.core.internal.metamodel.CSSMMCategory)1 CSSMMDescriptor (org.eclipse.wst.css.core.internal.metamodel.CSSMMDescriptor)1 CSSMMNumber (org.eclipse.wst.css.core.internal.metamodel.CSSMMNumber)1