use of org.eclipse.wst.css.core.internal.formatter.CSSSourceGenerator in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method valueChanged.
/**
*/
void valueChanged(CSSNodeImpl node, String oldValue) {
if (!(node instanceof CSSRegionContainer)) {
CSSUtil.debugOut(// $NON-NLS-1$
"Too Bad.." + // $NON-NLS-1$
((node == null) ? "null" : node.getClass().toString()));
return;
}
int start = node.getStartOffset();
if (node.getNodeType() == ICSSNode.ATTR_NODE) {
ICSSAttr attr = (ICSSAttr) node;
CSSSourceGenerator formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) attr.getOwnerCSSNode());
if (formatter != null)
start = formatter.getAttrInsertPos(attr.getOwnerCSSNode(), attr.getName());
}
int oldLength = (oldValue == null) ? 0 : oldValue.length();
// flash old IStructuredDocumentRegion/ITextRegion
if (node instanceof CSSStructuredDocumentRegionContainer) {
((CSSStructuredDocumentRegionContainer) node).setFirstStructuredDocumentRegion(null);
((CSSStructuredDocumentRegionContainer) node).setLastStructuredDocumentRegion(null);
} else if (node instanceof CSSRegionContainer) {
((CSSRegionContainer) node).setRangeRegion(null, null, null);
}
// generate new source
String newValue = node.generateSource();
ICSSNode parent;
if (node.getNodeType() == ICSSNode.ATTR_NODE) {
parent = ((ICSSAttr) node).getOwnerCSSNode();
} else {
parent = node.getParentNode();
}
fParser.setupUpdateContext(CSSModelUpdateContext.UPDATE_CHANGE_RCONTAINER, parent, node);
insertText(start, oldLength, newValue);
fParser.cleanupUpdateContext();
}
use of org.eclipse.wst.css.core.internal.formatter.CSSSourceGenerator in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method getSpaceBefore.
/**
* @return java.lang.String
* @param parentNode
* org.eclipse.wst.css.core.model.CSSNodeImpl
* @param node
* org.eclipse.wst.css.core.model.CSSNodeImpl
*/
private String getSpaceBefore(ICSSNode parentNode, ICSSNode node, ICSSNode toRemove) {
CSSSourceGenerator formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) parentNode);
if (formatter != null) {
org.eclipse.jface.text.IRegion exceptFor = null;
if (toRemove != null) {
CSSNodeImpl remove = (CSSNodeImpl) toRemove;
exceptFor = new org.eclipse.jface.text.Region(remove.getStartOffset(), remove.getEndOffset() - remove.getStartOffset());
}
return formatter.formatBefore(parentNode, node, exceptFor).toString();
} else
// $NON-NLS-1$
return "";
}
use of org.eclipse.wst.css.core.internal.formatter.CSSSourceGenerator in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method attrInserted.
/**
* @param parentNode
* org.eclipse.wst.css.core.model.CSSNodeImpl
* @param node
* org.eclipse.wst.css.core.model.CSSNodeImpl
*/
private void attrInserted(CSSNodeImpl parentNode, CSSAttrImpl attr) {
CSSSourceGenerator formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(parentNode);
if (formatter == null) {
// $NON-NLS-1$
CSSUtil.debugOut("Cannot get format adapter : " + parentNode.getClass().toString());
return;
}
short updateMode = CSSModelUpdateContext.UPDATE_INSERT_RCONTAINER;
fParser.setupUpdateContext(updateMode, parentNode, attr);
// get formatted info
AttrChangeContext region = new AttrChangeContext();
String text = new String(formatter.formatAttrChanged(parentNode, attr, true, region));
// set text
insertText(region.start, region.end - region.start, text);
fParser.cleanupUpdateContext();
}
use of org.eclipse.wst.css.core.internal.formatter.CSSSourceGenerator in project webtools.sourceediting by eclipse.
the class CSSModelUpdater method attrRemoved.
/**
* @param parentNode
* org.eclipse.wst.css.core.model.CSSNodeImpl
* @param node
* org.eclipse.wst.css.core.model.CSSNodeImpl
*/
private void attrRemoved(CSSNodeImpl parentNode, CSSAttrImpl attr) {
CSSSourceGenerator formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(parentNode);
if (formatter == null) {
// $NON-NLS-1$
CSSUtil.debugOut("Cannot get format adapter : " + parentNode.getClass().toString());
return;
}
short updateMode = CSSModelUpdateContext.UPDATE_REMOVE_RCONTAINER;
fParser.setupUpdateContext(updateMode, parentNode, attr);
// get formatted info
AttrChangeContext region = new AttrChangeContext();
String text = new String(formatter.formatAttrChanged(parentNode, attr, false, region));
// set text
insertText(region.start, region.end - region.start, text);
fParser.cleanupUpdateContext();
}
Aggregations