use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getIndent.
/**
*/
protected String getIndent(ICSSNode node) {
if (node == null)
// $NON-NLS-1$
return "";
ICSSNode parent = node.getParentNode();
if (node instanceof ICSSAttr)
parent = ((ICSSAttr) node).getOwnerCSSNode();
if (parent == null)
// $NON-NLS-1$
return "";
if (node instanceof org.w3c.dom.css.CSSStyleDeclaration)
parent = parent.getParentNode();
if (parent == null)
// $NON-NLS-1$
return "";
String parentIndent = getIndent(parent);
if (parent instanceof org.w3c.dom.css.CSSRule)
return parentIndent + getIndentString();
if (node.getParentNode() instanceof ICSSStyleDeclaration)
return parentIndent + getIndentString();
return parentIndent;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration in project webtools.sourceediting by eclipse.
the class CSSStyleDeclarationFactory method createStyleDeclaration.
/**
* @return org.eclipse.wst.css.core.model.interfaces.ICSSStyleDeclaration
* @param decl
* org.eclipse.wst.css.core.model.interfaces.ICSSStyleDeclaration
*/
public ICSSStyleDeclaration createStyleDeclaration(ICSSStyleDeclaration decl) {
if (decl == null) {
return null;
}
ICSSStyleDeclaration newNode = createStyleDeclaration();
if (newNode == null) {
return null;
}
fOwnerDocument = newNode;
cloneChildNodes(decl, newNode);
return newNode;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration in project webtools.sourceediting by eclipse.
the class CSSMetaModelUtil method getMetaModelNodeFor.
public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
if (node instanceof ICSSStyleDeclaration) {
node = node.getParentNode();
}
if (node instanceof ICSSStyleDeclItem) {
ICSSNode parent = node.getParentNode();
if (parent != null) {
parent = parent.getParentNode();
}
if (parent instanceof ICSSStyleRule) {
return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
} else if (parent instanceof CSSFontFaceRule) {
return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
}
}
if (node == null) {
return null;
}
if (fTypeMap == null) {
fTypeMap = new HashMap();
fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
}
String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
if (nodeType == null) {
return null;
}
Iterator iNodes = collectNodesByType(nodeType);
if (iNodes.hasNext()) {
CSSMMNode targetNode = (CSSMMNode) iNodes.next();
if (!iNodes.hasNext()) {
// it's only one
return targetNode;
}
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration in project webtools.sourceediting by eclipse.
the class CSSNodeAdapter method internalActionPerformed.
/**
* Insert the method's description here.
*/
protected void internalActionPerformed() {
if (notifyQueue == null) {
return;
}
boolean refresh_all = false;
boolean refresh_rule = false;
int pos_all = 0;
List targets = new ArrayList();
for (int i = 0; i < notifyQueue.size(); i++) {
NotifyContext context = (NotifyContext) notifyQueue.get(i);
if (context.notifier instanceof ICSSStyleSheet) {
refresh_all = true;
pos_all = i;
}
if (context.notifier instanceof ICSSStyleDeclaration) {
refresh_rule = true;
targets.add(context);
// pos_rule = i;
}
// ((NotifyContext) notifyQueue.get(i)).fire();
}
if (refresh_all) {
((NotifyContext) notifyQueue.get(pos_all)).fire();
} else if (refresh_rule) {
Iterator i = targets.iterator();
while (i.hasNext()) {
((NotifyContext) i.next()).fire();
}
// else if (refresh_rule) internalRefreshAll();
} else {
for (int i = 0; i < notifyQueue.size(); i++) {
((NotifyContext) notifyQueue.get(i)).fire();
}
}
notifyQueue.clear();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration in project webtools.sourceediting by eclipse.
the class TestCSSDecl method testInsertPropertyInExistingRule.
/**
* To test https://bugs.eclipse.org/298111
*/
public void testInsertPropertyInExistingRule() {
ICSSModel model = FileUtil.createModel();
try {
String originalDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "}";
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.set(originalDocument);
IndexedRegion indexedRegion = model.getIndexedRegion(28);
assertTrue("Indexed region should be an ICSSStyleRule", indexedRegion instanceof ICSSStyleRule);
ICSSStyleRule rule = (ICSSStyleRule) indexedRegion;
ICSSStyleDeclaration declaration = (ICSSStyleDeclaration) rule.getStyle();
declaration.setProperty("color", "#008040", null);
CSSPropertyContext context = new CSSPropertyContext(declaration);
context.applyModified(declaration);
String newDocument = structuredDocument.get();
String expectedNewDocument = "@CHARSET \"ISO-8859-1\";\r\n" + ".test {\r\n" + "\tcolor: #008040\r\n" + "}";
assertEquals("The updated CSS document does not equal the expected", expectedNewDocument, newDocument);
} finally {
if (model != null) {
model.releaseFromEdit();
}
}
}
Aggregations