Search in sources :

Example 6 with ICSSStyleDeclaration

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

the class BUG124835SetStyleAttributeValueTest method setInlineStyle.

private void setInlineStyle(Element element, String name, String value) {
    ICSSStyleDeclaration decl = null;
    try {
        decl = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) element).getStyle();
    } catch (ClassCastException ex) {
    // do nothing
    }
    if (decl != null) {
        String priority = decl.getPropertyPriority(name);
        decl.setProperty(name, value, priority);
    }
}
Also used : ElementCSSInlineStyle(org.w3c.dom.css.ElementCSSInlineStyle) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)

Example 7 with ICSSStyleDeclaration

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

the class BUG124835SetStyleAttributeValueTest method getInlineStyle.

private String getInlineStyle(Element element, String name) {
    String value = null;
    ICSSStyleDeclaration decl = null;
    try {
        decl = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) element).getStyle();
    } catch (ClassCastException ex) {
    // do nothing
    }
    if (decl != null) {
        value = decl.getPropertyValue(name);
    }
    return value;
}
Also used : ElementCSSInlineStyle(org.w3c.dom.css.ElementCSSInlineStyle) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)

Example 8 with ICSSStyleDeclaration

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

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

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

ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)11 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)5 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3 List (java.util.List)3 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)2 ICSSPrimitiveValue (org.eclipse.wst.css.core.internal.provisional.document.ICSSPrimitiveValue)2 ICSSStyleSheet (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet)2 CSSPropertyContext (org.eclipse.wst.css.core.internal.util.declaration.CSSPropertyContext)2 CSSFontFaceRule (org.w3c.dom.css.CSSFontFaceRule)2 ElementCSSInlineStyle (org.w3c.dom.css.ElementCSSInlineStyle)2 MediaList (org.w3c.dom.stylesheets.MediaList)2 HashMap (java.util.HashMap)1 Preferences (org.eclipse.core.runtime.Preferences)1 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)1 ICSSAttr (org.eclipse.wst.css.core.internal.provisional.document.ICSSAttr)1 ICSSMediaRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSMediaRule)1 ICSSModel (org.eclipse.wst.css.core.internal.provisional.document.ICSSModel)1