use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet 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.ICSSStyleSheet 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
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet 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.ICSSStyleSheet in project webtools.sourceediting by eclipse.
the class TestForNPEInCSSCreation method testCSSModel.
public void testCSSModel() {
IDOMModel model = FileUtil.createHTMLModel();
try {
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(getHTMLDocumentText());
IDOMDocument doc = model.getDocument();
// get head tag
NodeList list = doc.getElementsByTagName(HTML40Namespace.ElementName.HEAD);
Element head = (Element) list.item(0);
// create and append style element
Element ele = doc.createElement(HTML40Namespace.ElementName.STYLE);
ele.setAttribute(HTML40Namespace.ATTR_NAME_TYPE, "text/css");
String delim = model.getStructuredDocument().getLineDelimiter();
if (delim == null)
// $NON-NLS-1$
delim = "\n";
StringBuffer buffer = new StringBuffer(delim);
// $NON-NLS-1$
buffer.append("<!--");
buffer.append(delim);
// $NON-NLS-1$
buffer.append("-->");
buffer.append(delim);
Text text = doc.createTextNode(buffer.toString());
ele.appendChild(text);
head.insertBefore(ele, null);
// get adapter for StyleSheet
ICSSStyleSheet sheet = (ICSSStyleSheet) ((IStyleSheetAdapter) ((INodeNotifier) ele).getAdapterFor(IStyleSheetAdapter.class)).getSheet();
// create style declaration
ICSSStyleRule rule = sheet.createCSSStyleRule();
rule.getStyle().setProperty("background-color", "lime", "");
rule.getStyle().setProperty("background-color", "blue", "");
rule.getStyle().setProperty("background-color", "#0080ff", "");
// model.save();
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleSheet in project webtools.sourceediting by eclipse.
the class CSSCharsetRuleTest method testCreateRule.
public void testCreateRule() {
ICSSStyleSheet sheet = getStyleSheet();
ICSSDocument doc = sheet;
CSSCharsetRule newRule = doc.createCSSCharsetRule();
newRule.setEncoding("iso-8859-1");
sheet.insertRuleBefore(newRule, null);
CSSRuleList ruleList = sheet.getCssRules();
CSSRule rule = ruleList.item(0);
assertTrue(rule instanceof CSSCharsetRule);
CSSCharsetRule charsetRule = (CSSCharsetRule) rule;
assertEquals("iso-8859-1", charsetRule.getEncoding());
assertEquals(RULE, charsetRule.getCssText());
}
Aggregations