use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method contentChanged.
/**
* Apply changes from HTML model to CSS sub-model
*/
private void contentChanged() {
Element element = getElement();
if (element == null)
return;
ICSSModel model = getExistingModel();
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
String data = null;
Node child = element.getFirstChild();
if (child != null && child.getNodeType() == Node.TEXT_NODE && child.getNextSibling() == null) {
data = child.getNodeValue();
}
if (data == null)
// $NON-NLS-1$
data = "";
// minimize replace range
int start = 0, end = 0;
String oldData = structuredDocument.get();
if (oldData == null)
// $NON-NLS-1$
oldData = "";
// search differenct character position from first
for (; start < oldData.length() && start < data.length(); start++) if (oldData.charAt(start) != data.charAt(start))
break;
if (start == oldData.length() && start == data.length())
// no change
return;
else if (start == oldData.length()) {
// append text to last
structuredDocument.replaceText(getRequesterH2C(), start, 0, data.substring(start));
} else if (start == data.length()) {
// remove text of last //$NON-NLS-1$
structuredDocument.replaceText(getRequesterH2C(), start, oldData.length() - start, "");
} else {
// search differenct character position from last
for (; start < oldData.length() - end && start < data.length() - end; end++) {
if (oldData.charAt(oldData.length() - end - 1) != data.charAt(data.length() - end - 1))
break;
}
structuredDocument.replaceText(getRequesterH2C(), start, oldData.length() - end - start, data.substring(start, data.length() - end));
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method setModel.
/**
*/
protected void setModel(ICSSModel model, boolean setupListener) {
ICSSModel oldModel = getExistingModel();
if (model == oldModel)
return;
super.setModel(model);
if (!setupListener)
return;
if (oldModel != null)
oldModel.removeStyleListener(this);
if (model != null)
model.addStyleListener(this);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel 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.ICSSModel in project webtools.sourceediting by eclipse.
the class ElementNodeCleanupHandler method getCSSValue.
/**
*/
private String getCSSValue(Attr attr) {
ICSSModel model = getCSSModel(attr);
if (model == null)
return null;
ICSSNode document = model.getDocument();
if (document == null)
return null;
INodeNotifier notifier = (INodeNotifier) document;
CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
// try another way to get formatter
if (formatter == null)
formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
if (formatter == null)
return null;
StringBuffer buffer = formatter.cleanup(document);
if (buffer == null)
return null;
return buffer.toString();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel 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