Search in sources :

Example 1 with CSSMetaModelUtil

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

the class CSSPropertySource method getPropertyDescriptors.

/**
 * Returns the current collection of property descriptors.
 *
 * @return a vector containing all descriptors.
 */
public IPropertyDescriptor[] getPropertyDescriptors() {
    time0 = System.currentTimeMillis();
    CSSMetaModel metamodel = CSSMetaModelFinder.getInstance().findMetaModelFor(fNode);
    Iterator iProperties = Collections.EMPTY_LIST.iterator();
    switch(fNode.getNodeType()) {
        case ICSSNode.STYLERULE_NODE:
        case ICSSNode.FONTFACERULE_NODE:
        case ICSSNode.PAGERULE_NODE:
        case ICSSNode.STYLEDECLARATION_NODE:
            CSSMMNode mmParent = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
            if (mmParent != null) {
                iProperties = mmParent.getChildNodes();
            }
            break;
        case ICSSNode.STYLEDECLITEM_NODE:
            CSSMMNode mmNode = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
            if (mmNode != null) {
                iProperties = Collections.singletonList(mmNode).iterator();
            }
            break;
        default:
            break;
    }
    // setup categories
    Map categories = new HashMap();
    Iterator iCategories = metamodel.getCategories();
    while (iCategories.hasNext()) {
        CSSMMCategory category = (CSSMMCategory) iCategories.next();
        categories.put(category.getName(), category.getCaption());
    }
    // collect property names
    Set declaredProperties = new HashSet();
    if (iProperties.hasNext()) {
        CSSStyleDeclaration declaration = getDeclarationNode();
        if (declaration != null) {
            ICSSNodeList nodeList = ((ICSSNode) declaration).getChildNodes();
            int nProps = (nodeList != null) ? nodeList.getLength() : 0;
            for (int i = 0; i < nProps; i++) {
                ICSSNode node = nodeList.item(i);
                if (node instanceof ICSSStyleDeclItem) {
                    String name = ((ICSSStyleDeclItem) node).getPropertyName();
                    if (name != null && 0 < name.length()) {
                        declaredProperties.add(name.toLowerCase());
                    }
                }
            }
        }
    }
    List descriptors = new ArrayList();
    // first: properties from content model
    while (iProperties.hasNext()) {
        CSSMMNode node = (CSSMMNode) iProperties.next();
        if (node.getType() == CSSMMNode.TYPE_PROPERTY || node.getType() == CSSMMNode.TYPE_DESCRIPTOR) {
            // $NON-NLS-1$
            String category = (String) categories.get(node.getAttribute("category"));
            String name = node.getName().toLowerCase();
            if (declaredProperties.contains(name)) {
                declaredProperties.remove(name);
            }
            IPropertyDescriptor descriptor = createPropertyDescriptor(name, category);
            if (descriptor != null) {
                descriptors.add(descriptor);
            }
        }
    }
    // second: existing properties but not in content model
    Iterator iRemains = declaredProperties.iterator();
    while (iRemains.hasNext()) {
        IPropertyDescriptor descriptor = createPropertyDescriptor((String) iRemains.next(), null);
        if (descriptor != null) {
            descriptors.add(descriptor);
        }
    }
    IPropertyDescriptor[] resultArray = new IPropertyDescriptor[descriptors.size()];
    if (PERF_GETDESCRIPTORS) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println(getClass().getName() + ".getPropertyDescriptors: " + (System.currentTimeMillis() - time0) + "ms");
    }
    return (IPropertyDescriptor[]) descriptors.toArray(resultArray);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) HashMap(java.util.HashMap) CSSMetaModel(org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel) ArrayList(java.util.ArrayList) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSNodeList(org.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList) CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) CSSMMCategory(org.eclipse.wst.css.core.internal.metamodel.CSSMMCategory) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) Iterator(java.util.Iterator) ICSSNodeList(org.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList) ArrayList(java.util.ArrayList) List(java.util.List) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with CSSMetaModelUtil

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

the class CSSProposalGeneratorForAtmarkRule method getCandidateMediaRule.

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

Example 3 with CSSMetaModelUtil

use of org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil 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 4 with CSSMetaModelUtil

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

the class CSSMetaModelTest method testDisplayPropertyValues2r1.

public void testDisplayPropertyValues2r1() {
    CSSMetaModel model = CSSProfileRegistry.getInstance().getDefaultProfile().getMetaModel();
    if (model != null) {
        CSSMetaModelUtil util = new CSSMetaModelUtil(model);
        CSSMMProperty property = util.getProperty(PropCMProperty.P_DISPLAY);
        Iterator it = property.getValues();
        Set set = new HashSet(1);
        set.add(IValID.V_INLINE_BLOCK);
        while (it.hasNext()) {
            CSSMMNode node = (CSSMMNode) it.next();
            if (set.contains(node.getName())) {
                assertEquals("Property should be a keyword", CSSMMNode.TYPE_KEYWORD, node.getType());
                set.remove(node.getName());
            }
        }
        assertTrue("The content property is missing values added for CSS 2 revision 1.", set.isEmpty());
    }
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) HashSet(java.util.HashSet) Set(java.util.Set) CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) CSSMMProperty(org.eclipse.wst.css.core.internal.metamodel.CSSMMProperty) CSSMetaModel(org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 5 with CSSMetaModelUtil

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

the class CSSMetaModelTest method testWhitespacePropertyValues2r1.

public void testWhitespacePropertyValues2r1() {
    CSSMetaModel model = CSSProfileRegistry.getInstance().getDefaultProfile().getMetaModel();
    if (model != null) {
        CSSMetaModelUtil util = new CSSMetaModelUtil(model);
        CSSMMProperty property = util.getProperty(PropCMProperty.P_WHITE_SPACE);
        Iterator it = property.getValues();
        Set set = new HashSet(1);
        set.add(IValID.V_PRE_LINE);
        set.add(IValID.V_PRE_WRAP);
        while (it.hasNext()) {
            CSSMMNode node = (CSSMMNode) it.next();
            if (set.contains(node.getName())) {
                assertEquals("Property should be a keyword", CSSMMNode.TYPE_KEYWORD, node.getType());
                set.remove(node.getName());
            }
        }
        assertTrue("The content property is missing values added for CSS 2 revision 1.", set.isEmpty());
    }
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) HashSet(java.util.HashSet) Set(java.util.Set) CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) CSSMMProperty(org.eclipse.wst.css.core.internal.metamodel.CSSMMProperty) CSSMetaModel(org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

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