use of org.w3c.dom.stylesheets.MediaList in project webtools.sourceediting by eclipse.
the class MediaRuleFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
ICSSNode child = node.getFirstChild();
if (child != null && (child instanceof MediaList) && ((MediaList) child).getLength() == 0) {
if (child.getNextSibling() != null)
end = ((IndexedRegion) child.getNextSibling()).getStartOffset();
else
end = -1;
}
if (end > 0) {
// source formatting
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else {
// source generation
String str = MEDIA;
if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
str = MEDIA.toUpperCase();
source.append(str);
}
if (child != null && (child instanceof MediaList) && ((MediaList) child).getLength() > 0) {
// $NON-NLS-1$
appendSpaceBefore(node, "", source);
}
}
use of org.w3c.dom.stylesheets.MediaList in project webtools.sourceediting by eclipse.
the class MediaListFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
int start = ((IndexedRegion) node).getStartOffset();
int end = ((IndexedRegion) node).getEndOffset();
if (end > 0) {
// format source
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedIdentRegion(regions[i], stgy));
}
} else {
// generate source
MediaList list = (MediaList) node;
int n = list.getLength();
for (int i = 0; i < n; i++) {
String medium = list.item(i);
if (CSSCorePlugin.getDefault().getPluginPreferences().getInt(CSSCorePreferenceNames.CASE_IDENTIFIER) == CSSCorePreferenceNames.UPPER)
medium = medium.toUpperCase();
else
medium = medium.toLowerCase();
if (i != 0) {
// $NON-NLS-1$
source.append(",");
appendSpaceBefore(node, medium, source);
}
source.append(medium);
}
}
}
use of org.w3c.dom.stylesheets.MediaList in project webtools.sourceediting by eclipse.
the class CSSMediaRuleTest method testCreateRule.
public void testCreateRule() {
ICSSStyleSheet sheet = getStyleSheet();
ICSSDocument doc = sheet;
ICSSMediaRule newRule = doc.createCSSMediaRule();
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 CSSMediaRule);
CSSMediaRule mediaRule = (CSSMediaRule) rule;
MediaList mediaList = mediaRule.getMedia();
assertEquals(2, mediaList.getLength());
assertEquals("media1", mediaList.item(0));
assertEquals("media2", mediaList.item(1));
assertEquals("@media media1, media2 {" + FileUtil.commonEOL + "}", mediaRule.getCssText());
}
use of org.w3c.dom.stylesheets.MediaList 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.w3c.dom.stylesheets.MediaList 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];
}
Aggregations