use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.
the class CSSModelImpl method valueChanged.
void valueChanged(CSSNodeImpl node, String oldValue) {
if (!fStructuredDocumentUpdate) {
CSSModelUpdater updater = getUpdater();
updater.valueChanged(node, oldValue);
}
ICSSSelector[] removed = null, added = null;
if (node != null) {
if (node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSStyleRule.SELECTOR)) {
CSSAttrImpl attr = (CSSAttrImpl) node;
// collect changed selector
ICSSSelectorList list = new CSSSelectorListImpl(attr.getValue());
added = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
// get old value
list = new CSSSelectorListImpl(oldValue);
removed = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) removed[i] = list.getSelector(i);
} else if (node instanceof ICSSValue) {
ICSSNode rule = node;
while (rule != null) {
if (rule instanceof ICSSStyleRule)
break;
rule = rule.getParentNode();
}
if (rule != null) {
ICSSSelectorList list = ((ICSSStyleRule) rule).getSelectors();
added = new ICSSSelector[list.getLength()];
for (int i = 0; i < list.getLength(); i++) added[i] = list.getSelector(i);
}
}
}
if (removed != null || added != null || getDocument().getNodeType() == ICSSNode.STYLEDECLARATION_NODE) {
// send selector changed event
getStyleNotifier().fire(removed, added, null);
}
// for href attribute
if (getStyleListeners() != null && getStyleListeners().size() > 0) {
if (node != null && node.getNodeType() == ICSSNode.ATTR_NODE && ((CSSAttrImpl) node).getName().equals(ICSSImportRule.HREF)) {
((ICSSImportRule) ((ICSSAttr) node).getOwnerCSSNode()).getStyleSheet();
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.
the class CSSPropertyContext method applyFull.
/**
* This function exports all property/value pairs to 'decl' declaration
*/
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);
String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
if (value == null || value.length() <= 0)
decl.removeProperty(key.toString());
else
// $NON-NLS-2$//$NON-NLS-1$
decl.setProperty(key.toString(), value.trim(), (val instanceof ValueData && ((ValueData) val).important) ? "!important" : "");
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSValue in project webtools.sourceediting by eclipse.
the class CSSFontFamilyTest method testValueModification.
public void testValueModification() throws IOException {
ICSSModel model = getModel();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(FileUtil.createString("src/org/eclipse/wst/css/core/tests/testfiles", "CSSFontFamilyTest.css"));
CSSStyleSheet sheet = (CSSStyleSheet) model.getDocument();
CSSRuleList rules = sheet.getCssRules();
assertEquals(4, rules.getLength());
// Rule 1: No whitespace
CSSRule rule;
CSSStyleDeclaration declaration;
CSSValue value;
// Rule 1: No whitespace
rule = rules.item(0);
assertEquals(CSSRule.STYLE_RULE, rule.getType());
assertTrue(rule instanceof CSSStyleRule);
declaration = ((CSSStyleRule) rule).getStyle();
value = declaration.getPropertyCSSValue(FONT_FAMILY);
checkPrimitiveString(value, new PrimitiveString(CSSPrimitiveValue.CSS_IDENT, "Courier"));
declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times, serif", "");
value = declaration.getPropertyCSSValue(FONT_FAMILY);
assertTrue(value instanceof ICSSValue);
assertEquals("\"Times New Roman\", Times, serif", ((ICSSValue) value).getCSSValueText());
declaration.setProperty(FONT_FAMILY, "\"Times New Roman\", Times", "");
value = declaration.getPropertyCSSValue(FONT_FAMILY);
assertTrue(value instanceof ICSSValue);
assertEquals("\"Times New Roman\", Times", ((ICSSValue) value).getCSSValueText());
}
Aggregations