use of org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule 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;
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule 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.ICSSImportRule in project webtools.sourceediting by eclipse.
the class CSSImportRuleTest method testCreateRule.
public void testCreateRule() {
ICSSStyleSheet sheet = getStyleSheet();
ICSSDocument doc = sheet;
ICSSImportRule newRule = doc.createCSSImportRule();
newRule.setHref("dummy.css");
MediaList newList = newRule.getMedia();
newList.appendMedium("media1");
newList.appendMedium("media2");
sheet.insertRuleBefore(newRule, null);
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule = ruleList.item(0);
assertTrue(rule instanceof CSSImportRule);
CSSImportRule importRule = (CSSImportRule) rule;
assertEquals("dummy.css", importRule.getHref());
MediaList mediaList = importRule.getMedia();
assertEquals(2, mediaList.getLength());
assertEquals("media1", mediaList.item(0));
assertEquals("media2", mediaList.item(1));
assertEquals("@import url(\"dummy.css\") media1, media2;", importRule.getCssText());
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule in project webtools.sourceediting by eclipse.
the class AbstractCssTraverser method traverse.
private final short traverse(ICSSNode node) {
if (node == null)
return TRAV_CONT;
travStack.push(node);
// pre-action
short ret = preNode(node);
if (ret == TRAV_CONT) {
if (fTraverseImported && (node.getNodeType() == ICSSNode.IMPORTRULE_NODE)) {
ICSSImportRule rule = (ICSSImportRule) node;
// traverse external style-sheet
ICSSStyleSheet sheet = (ICSSStyleSheet) rule.getStyleSheet();
if (sheet != null && !traversedSheets.contains(sheet)) {
// prevent
// loop
traversedSheets.add(sheet);
short retExt = traverse(sheet);
if (retExt == TRAV_STOP) {
travStack.pop();
return retExt;
}
}
}
// collect children
ArrayList children = new ArrayList();
ICSSNode child = node.getFirstChild();
if (fTraverseImportFirst) {
ArrayList others = new ArrayList();
while (child != null) {
if (child.getNodeType() == ICSSNode.IMPORTRULE_NODE)
children.add(child);
else
others.add(child);
child = child.getNextSibling();
}
children.addAll(others);
} else {
while (child != null) {
children.add(child);
child = child.getNextSibling();
}
}
// traverse children
for (int i = 0; i < children.size(); i++) {
child = (ICSSNode) children.get(i);
short retChild = traverse(child);
if (retChild == TRAV_STOP) {
travStack.pop();
return retChild;
}
}
} else if (ret == TRAV_STOP) {
travStack.pop();
return ret;
}
// post-action
ret = postNode(node);
travStack.pop();
return (ret == TRAV_PRUNE) ? TRAV_CONT : ret;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSImportRule in project webtools.sourceediting by eclipse.
the class CSSStyleSheetImpl method getRules.
private void getRules(CSSRuleListImpl list, ICSSStyleSheet sheet, Stack refs) {
String href = sheet.getHref();
if (href != null) {
// Avoid circular @imports
if (refs.contains(href))
return;
refs.push(href);
}
boolean acceptImports = true;
for (ICSSNode node = sheet.getFirstChild(); node != null; node = node.getNextSibling()) {
// @import rules must precede all other rules, according to the spec
if (node.getNodeType() == ICSSNode.IMPORTRULE_NODE && acceptImports) {
CSSStyleSheet importSheet = ((ICSSImportRule) node).getStyleSheet();
if (importSheet instanceof ICSSStyleSheet)
getRules(list, (ICSSStyleSheet) importSheet, refs);
else
list.appendNode(node);
} else // Add the rule to the list
if (node instanceof CSSRule) {
list.appendNode(node);
if (node.getNodeType() != ICSSNode.CHARSETRULE_NODE)
acceptImports = false;
}
}
if (href != null)
refs.pop();
}
Aggregations