use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method createModel.
/**
*/
protected ICSSModel createModel(boolean addListener) {
if (!isValidAttribute()) {
return null;
}
ICSSModel model = super.createModel(addListener);
if (!addListener)
return model;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return null;
structuredDocument.addDocumentChangedListener(this);
return model;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method getModel.
/**
*/
public ICSSModel getModel() {
ICSSModel model = getExistingModel();
if (this.replaceModel) {
ICSSModel oldModel = model;
model = createModel(false);
// need to set before contentChanged()
setModel(model, false);
contentChanged();
// from super.createModel()
// get ModelProvideAdapter
IModelProvideAdapter modelProvideAdapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
// notify adapter
if (modelProvideAdapter != null)
modelProvideAdapter.modelProvided(model);
// from createModel()
IStructuredDocument structuredDocument = null;
if (model != null)
structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return null;
structuredDocument.addDocumentChangedListener(this);
// from setModel()
if (oldModel != null)
oldModel.removeStyleListener(this);
if (model != null)
model.addStyleListener(this);
if (oldModel != null) {
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
if (adapter != null) {
adapter.modelRemoved(oldModel);
}
}
this.replaceModel = false;
}
return model;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleElementAdapter method changeStructuredDocumentRegion.
/**
* Preparation of applying changes from CSS sub-model to HTML model
*/
private void changeStructuredDocumentRegion(IStructuredDocumentRegion flatNode) {
if (flatNode == null)
return;
Element element = getElement();
if (element == null)
return;
ICSSModel model = getExistingModel();
if (model == null)
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
return;
// get old content length
Node child = element.getFirstChild();
if (child == null || child.getNodeType() != Node.TEXT_NODE)
return;
IDOMNode content = (IDOMNode) child;
int oldLength = content.getEndOffset() - content.getStartOffset();
// get new content length
int newLength = 0;
IStructuredDocumentRegionList flatNodes = structuredDocument.getRegionList();
if (flatNodes != null) {
int count = flatNodes.getLength();
if (count > 0) {
IStructuredDocumentRegion last = flatNodes.item(count - 1);
if (last != null)
newLength = last.getEnd();
}
}
int offset = flatNode.getStart();
int end = flatNode.getEnd();
int diff = oldLength - newLength;
int length = end - offset + diff;
String data = flatNode.getText();
replaceData(offset, length, data);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class AbstractStyleSheetAdapter method released.
/**
*/
public void released() {
ICSSModel currentModel = getModel();
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(IModelProvideAdapter.class);
setElement(null);
setModel(null);
if (adapter != null)
adapter.modelReleased(currentModel);
if (currentModel != null)
currentModel.releaseFromRead();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class EmbeddedCSSFormatter method getCSSContent.
/**
*/
private String getCSSContent(IDOMNode text) {
ICSSModel model = getCSSModel(text);
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.format(document);
if (buffer == null)
return null;
return buffer.toString();
}
Aggregations