use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class HTMLElementFormatter 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.format(document);
if (buffer == null)
return null;
return buffer.toString();
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class HTMLElementFormatter method getCSSModel.
/**
*/
private ICSSModel getCSSModel(Attr attr) {
if (attr == null)
return null;
INodeNotifier notifier = (INodeNotifier) attr.getOwnerElement();
if (notifier == null)
return null;
INodeAdapter adapter = notifier.getAdapterFor(IStyleDeclarationAdapter.class);
if (adapter == null)
return null;
if (!(adapter instanceof IStyleDeclarationAdapter))
return null;
IStyleDeclarationAdapter styleAdapter = (IStyleDeclarationAdapter) adapter;
return styleAdapter.getModel();
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class TestModelClone method getEmbeddedModelQuery.
private ModelQuery getEmbeddedModelQuery(Node node) {
ModelQuery embeddedModelQuery = null;
if (node instanceof INodeNotifier) {
Node ownerNode = node.getOwnerDocument();
if (ownerNode == null) {
// then must be the document itself
ownerNode = node;
}
PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) ((INodeNotifier) ownerNode).getAdapterFor(PageDirectiveAdapter.class);
if (pageDirectiveAdapter != null) {
String effectiveContentType = null;
ModelQuery potentialModelQueryObject = null;
String familyId = pageDirectiveAdapter.getEmbeddedType().getFamilyId();
// if (ContentTypeFamilyForHTML.HTML_FAMILY.equals(familyId)) {
if ("org.eclipse.wst.html.core.contentfamily.html".equals(familyId)) {
effectiveContentType = "text/html";
} else {
effectiveContentType = pageDirectiveAdapter.getContentType();
}
potentialModelQueryObject = (ModelQuery) embeddedModelQueries.get(effectiveContentType);
if (potentialModelQueryObject == null) {
ModelQueryAdapter embeddedAdapter = (ModelQueryAdapter) pageDirectiveAdapter.adapt((INodeNotifier) node, ModelQueryAdapter.class);
if (embeddedAdapter != null) {
// we will cache one model query per content type
embeddedModelQuery = embeddedAdapter.getModelQuery();
embeddedModelQueries.put(effectiveContentType, embeddedModelQuery);
}
} else {
embeddedModelQuery = potentialModelQueryObject;
}
}
}
return embeddedModelQuery;
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class XSLModelLoader method preLoadAdapt.
@Override
protected void preLoadAdapt(IStructuredModel structuredModel) {
super.preLoadAdapt(structuredModel);
IDOMModel domModel = (IDOMModel) structuredModel;
// if there is a model in the adapter, this will adapt it to
// first node. After that the PropagatingAdater spreads over the
// children being
// created. Each time that happends, a side effect is to
// also "spread" sprecific registered adapters,
// they two can propigate is needed.
((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
if (Debug.debugNotificationAndEvents) {
PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) domModel.getDocument()).getAdapterFor(PropagatingAdapter.class);
propagatingAdapter.addAdaptOnCreateFactory(new DebugAdapterFactory());
}
}
use of org.eclipse.wst.sse.core.internal.provisional.INodeNotifier in project webtools.sourceediting by eclipse.
the class RegionChangedAdapterNotificationTests method testAppendWhitespaceToAttributeValue.
public void testAppendWhitespaceToAttributeValue() throws IOException {
IDOMModel model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(getName() + ".xml", new NullInputStream(), null);
try {
Document document = model.getDocument();
IStructuredDocument structuredDocument = model.getStructuredDocument();
structuredDocument.setText(this, "<a b= c></a>");
Node before = document.getFirstChild();
final int[] changed = new int[] { -1 };
INodeAdapter adapter = new INodeAdapter() {
public boolean isAdapterForType(Object type) {
return type.equals(RegionChangedAdapterNotificationTests.class);
}
public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) {
changed[0] = eventType;
}
};
((INodeNotifier) before).addAdapter(adapter);
Object[] originalRegions = structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray();
StructuredDocumentEvent fmEvent = structuredDocument.replaceText(null, 7, 0, " ");
assertTrue("Region instances changed", Arrays.equals(originalRegions, structuredDocument.getFirstStructuredDocumentRegion().getRegions().toArray()));
assertTrue(fmEvent instanceof RegionChangedEvent);
Node after = document.getFirstChild();
assertEquals("Node replaced", before, after);
assertEquals("unexpected adapter notification event sent " + structuredDocument.get(), -1, changed[0]);
assertEquals("unexpected document content", "<a b= c ></a>", structuredDocument.get());
} finally {
model.releaseFromEdit();
}
}
Aggregations