Search in sources :

Example 6 with ICSSStyleDeclItem

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

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

the class CSSPropertySource method getPropertyValue.

/**
 * Returns the current value for the named property.
 *
 * @param name
 *            the name of the property as named by its property descriptor
 * @return the current value of the property
 */
public Object getPropertyValue(Object name) {
    if (name == null) {
        // $NON-NLS-1$
        return "";
    }
    String valueString = null;
    String nameString = name.toString();
    CSSStyleDeclaration declaration = null;
    switch(fNode.getNodeType()) {
        case ICSSNode.STYLEDECLITEM_NODE:
            valueString = ((ICSSStyleDeclItem) fNode).getCSSValueText();
            break;
        case ICSSNode.STYLERULE_NODE:
        case ICSSNode.FONTFACERULE_NODE:
        case ICSSNode.PAGERULE_NODE:
            declaration = (CSSStyleDeclaration) fNode.getFirstChild();
            if (declaration != null) {
                valueString = declaration.getPropertyValue(nameString);
            }
            break;
        case ICSSNode.STYLEDECLARATION_NODE:
            valueString = ((CSSStyleDeclaration) fNode).getPropertyValue(nameString);
            break;
        case ICSSNode.PRIMITIVEVALUE_NODE:
            ICSSNode parent = fNode;
            while (parent != null && !(parent instanceof ICSSStyleDeclItem)) {
                parent = parent.getParentNode();
            }
            if (parent != null) {
                valueString = ((ICSSStyleDeclItem) parent).getCSSValueText();
            }
            break;
        default:
            break;
    }
    if (valueString == null) {
        // $NON-NLS-1$
        valueString = "";
    }
    return valueString;
}
Also used : ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 8 with ICSSStyleDeclItem

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

the class CSSContentOutlineConfiguration method getFilteredNode.

private Object getFilteredNode(Object o) {
    ICSSNode node = null;
    if (o instanceof ICSSNode) {
        node = (ICSSNode) o;
        short nodeType = node.getNodeType();
        if (node instanceof ICSSValue) {
            while (node != null && !(node instanceof ICSSStyleDeclItem)) {
                node = node.getParentNode();
            }
        } else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
            node = node.getParentNode();
        } else if (nodeType == ICSSNode.MEDIALIST_NODE) {
            node = node.getParentNode();
        }
    }
    return node;
}
Also used : ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Example 9 with ICSSStyleDeclItem

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

the class CSSQueryContext method applyFull.

/**
 */
public void applyFull(ICSSStyleDeclaration decl) {
    if (decl == null)
        return;
    Enumeration keys = fProperties.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Object val = fProperties.get(key);
        if (val instanceof CSSQueryDeclarationData) {
            ICSSStyleDeclItem declItem = ((CSSQueryDeclarationData) val).getDeclItem();
            if (declItem.getLength() <= 0) {
                ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
                if (itemToRemove != null) {
                    decl.removeDeclItemNode(itemToRemove);
                }
            } else {
                decl.setDeclItemNode(declItem);
            }
        } else {
            String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
            if (value == null || value.length() <= 0) {
                ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
                if (itemToRemove != null) {
                    decl.removeDeclItemNode(itemToRemove);
                }
            } else {
                decl.setProperty(key.toString(), value, null);
            }
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ICSSValue(org.eclipse.wst.css.core.internal.provisional.document.ICSSValue) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)

Example 10 with ICSSStyleDeclItem

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

the class CSSProposalGeneratorForDeclarationValue method addSemiColon.

/**
 */
private void addSemiColon(List candidates) {
    ICSSNode targetNode = fContext.getTargetNode();
    if (targetNode instanceof ICSSStyleDeclItem) {
        ICSSNode firstChild = targetNode.getFirstChild();
        if (firstChild == null) {
            return;
        }
        if (firstChild instanceof IndexedRegion) {
            int startOffset = ((IndexedRegion) firstChild).getStartOffset();
            if (fContext.getCursorPos() <= startOffset) {
                return;
            }
        }
    }
    boolean bAddCloser = false;
    ITextRegion targetRegion = fContext.getTargetRegion();
    if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        // find trailing ":" or ";"
        // if ":" before ";" is found, add ";"
        RegionIterator iterator = fContext.getRegionIterator();
        IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion();
        while (iterator.hasNext()) {
            ITextRegion region = iterator.next();
            if (iterator.getStructuredDocumentRegion() != container) {
                break;
            }
            if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
                bAddCloser = true;
                break;
            }
        }
        if (!bAddCloser) {
            // second chance:
            // leading IStructuredDocumentRegion is not ";"
            IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container);
            if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
                bAddCloser = true;
            }
        }
    }
    if (bAddCloser) {
        CSSCACandidate item = new CSSCACandidate();
        // $NON-NLS-1$
        String text = fContext.getTextToReplace() + ";";
        item.setReplacementString(text);
        item.setCursorPosition(text.length());
        // $NON-NLS-1$
        item.setDisplayString(";");
        item.setImageType(null);
        candidates.add(item);
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Aggregations

ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)18 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)11 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)6 Preferences (org.eclipse.core.runtime.Preferences)4 Iterator (java.util.Iterator)3 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)3 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)3 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)3 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)3 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)3 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)3 ArrayList (java.util.ArrayList)2 Enumeration (java.util.Enumeration)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2