use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument 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.ICSSDocument in project webtools.sourceediting by eclipse.
the class CSSNodeAdapter method addElements.
private void addElements(Object element, ArrayList v) {
ICSSNode node;
if (element instanceof ICSSModel) {
ICSSModel model = (ICSSModel) element;
ICSSDocument doc = model.getDocument();
node = doc.getFirstChild();
} else if (element instanceof ICSSNode) {
node = ((ICSSNode) element).getFirstChild();
} else
return;
while (node != null) {
if (node instanceof CSSRule) {
v.add(node);
}
node = node.getNextSibling();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class RefreshStructureJob method contains.
/**
* Simple hierarchical containment relationship. Note, this method returns
* "false" if the two nodes are equal!
*
* @param root
* @param possible
* @return if the root is parent of possible, return true, otherwise
* return false
*/
private boolean contains(ICSSNode root, ICSSNode possible) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("==============================================================================================================");
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("recursive call w/ root: " + root + " and possible: " + possible);
// $NON-NLS-1$
System.out.println("--------------------------------------------------------------------------------------------------------------");
}
// can't contain the child if it's null
if (root == null) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: root is null");
}
return false;
}
// nothing can be parent of Document node
if (possible instanceof ICSSDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning false: possible is Document node");
}
return false;
}
// document contains everything
if (root instanceof ICSSDocument) {
if (DEBUG) {
// $NON-NLS-1$
System.out.println("returning true: root is Document node");
}
return true;
}
// check parentage
ICSSNode current = possible;
// loop parents
while ((current != null) && (current.getNodeType() != ICSSNode.STYLESHEET_NODE || current.getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
// found it
if (root.equals(current)) {
if (DEBUG) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println(" !!! found: " + possible + " in subelement of: " + root);
}
return true;
}
current = current.getParentNode();
}
// never found it
return false;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForAtmarkRule method getCandidateCharsetRule.
/**
*/
private CSSCACandidate getCandidateCharsetRule() {
// check content model
CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
if (!util.collectNodesByType(CSSMMNode.TYPE_CHARSET_RULE).hasNext()) {
return null;
}
// check if embedded or not
if (fContext.getModel().getStyleSheetType() == ICSSModel.EMBEDDED) {
return null;
}
// check if caret precede all other rules.
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)) {
return null;
}
}
}
int cursorPos = 0;
String ident = (fUseUpperCase) ? CHARSET.toUpperCase() : CHARSET.toLowerCase();
StringBuffer buf = new StringBuffer();
buf.append(ident);
// $NON-NLS-1$
buf.append(" ");
cursorPos = buf.length();
StringAndOffset sao;
sao = generateQuotes();
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(text);
item.setCursorPosition(cursorPos);
item.setDisplayString(ident);
item.setImageType(CSSImageType.RULE_CHARSET);
return item;
} else {
return null;
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument 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