use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class StyleSheetTest method testImportFromParentDirectory.
/**
* Tests for the import of a stylesheet in a parent directory
* @throws Exception
*/
public void testImportFromParentDirectory() throws Exception {
String filePath = "/" + PROJECT_NAME + "/WebContent/style/sub.css";
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
assertTrue("File doesn't exist: " + filePath, file.exists());
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(file);
if (model instanceof ICSSModel) {
ICSSDocument document = ((ICSSModel) model).getDocument();
if (document instanceof ICSSStyleSheet) {
CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
assertTrue("There should be a total of 1 rule.", list.getLength() == 1);
CSSRule rule = list.item(0);
assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
assertEquals("Stylesheet reference is different than expected.", ((CSSStyleRule) rule).getSelectorText(), "#content");
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class StyleSheetTest method testImportCycle.
/**
* Tests for cycles in imports. If a cycle is encountered, we should not get stuck
* in a loop or re-import the stylesheet.
* @throws Exception
*/
public void testImportCycle() throws Exception {
String filePath = "/" + PROJECT_NAME + "/WebContent/cycle0.css";
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath));
assertTrue("File doesn't exist: " + filePath, file.exists());
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getModelForRead(file);
if (model instanceof ICSSModel) {
ICSSDocument document = ((ICSSModel) model).getDocument();
if (document instanceof ICSSStyleSheet) {
CSSRuleList list = ((ICSSStyleSheet) document).getCssRules(true);
assertTrue("There should be a total of 3 rules supplied stylesheet.", list.getLength() == 3);
for (int i = 0; i < list.getLength(); i++) {
CSSRule rule = list.item(i);
assertTrue("Rule should be a style rule. rule.getType() == " + rule.getType(), rule.getType() == ICSSNode.STYLERULE_NODE);
// Check that the rules are imported, it would start with the last imported stylesheet's rules and move up
assertEquals("Style rules are not equal.", ((CSSStyleRule) rule).getSelectorText(), "#cycle" + (2 - i));
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class CSSNodeImpl method notifyChildReplaced.
protected void notifyChildReplaced(CSSNodeImpl newChild, CSSNodeImpl oldChild) {
// for model
ICSSDocument doc = getContainerDocument();
if (doc == null)
return;
CSSModelImpl model = (CSSModelImpl) doc.getModel();
if (model == null)
return;
model.childReplaced(this, newChild, oldChild);
// for adapters
int type = CHANGE;
if (newChild == null)
type = REMOVE;
else if (oldChild == null)
type = ADD;
notify(type, oldChild, oldChild, newChild, getStartOffset());
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class CleanupProcessorCSS method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel, int start, int length) {
CSSFormatUtil formatUtil = CSSFormatUtil.getInstance();
if (structuredModel instanceof ICSSModel) {
ICSSDocument doc = ((ICSSModel) structuredModel).getDocument();
CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) doc);
StringBuffer buf = formatter.cleanup(doc);
if (buf != null) {
int startOffset = ((IndexedRegion) doc).getStartOffset();
int endOffset = ((IndexedRegion) doc).getEndOffset();
formatUtil.replaceSource(doc.getModel(), startOffset, endOffset - startOffset, buf.toString());
}
} else if (structuredModel instanceof IDOMModel) {
List cssnodes = formatUtil.collectCSSNodes(structuredModel, start, length);
if (cssnodes != null && !cssnodes.isEmpty()) {
ICSSModel model = null;
for (int i = 0; i < cssnodes.size(); i++) {
ICSSNode node = (ICSSNode) cssnodes.get(i);
CSSSourceFormatter formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) node);
StringBuffer buf = formatter.cleanup(node);
if (buf != null) {
int startOffset = ((IndexedRegion) node).getStartOffset();
int endOffset = ((IndexedRegion) node).getEndOffset();
if (model == null) {
model = node.getOwnerDocument().getModel();
}
formatUtil.replaceSource(model, startOffset, endOffset - startOffset, buf.toString());
}
}
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSDocument in project webtools.sourceediting by eclipse.
the class JFaceNodeContentProviderCSS method addElements.
/**
* @deprecated
*/
protected 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();
}
}
Aggregations