use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class AdapterFactoryProviderForXSL method addContentBasedFactories.
@Override
protected void addContentBasedFactories(IStructuredModel structuredModel) {
FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry();
Assert.isNotNull(factoryRegistry, // $NON-NLS-1$
"Program Error: client caller must ensure model has factory registry");
INodeAdapterFactory factory = null;
factory = factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
if (factory == null) {
factory = new JFaceNodeAdapterFactory();
factoryRegistry.addFactory(factory);
}
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(structuredModel);
if (modelQuery != null) {
CMDocumentManager documentManager = modelQuery.getCMDocumentManager();
if (documentManager != null) {
IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore();
boolean useInferredGrammar = (store != null) ? store.getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR) : true;
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false);
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true);
DOMObserver domObserver = new DOMObserver(structuredModel);
domObserver.setGrammarInferenceEnabled(useInferredGrammar);
domObserver.init();
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class StyleAdapterFactory method isTagAvailable.
private static boolean isTagAvailable(Document document, String elementName) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
if (modelQuery != null) {
CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
CMNamedNodeMap map = cmdoc.getElements();
if ((CMElementDeclaration) map.getNamedItem(elementName) != null) {
return true;
}
}
return false;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class HTMLFormatter method getElementDeclaration.
/**
*/
protected CMElementDeclaration getElementDeclaration(Element element) {
if (element == null)
return null;
Document document = element.getOwnerDocument();
if (document == null)
return null;
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
if (modelQuery == null)
return null;
return modelQuery.getCMElementDeclaration(element);
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class HTMLContentAssistProcessor method getHTMLTagProposal.
/**
* @return ICompletionProposal
*/
private ICompletionProposal getHTMLTagProposal(ITextViewer viewer, int documentPosition) {
IModelManager mm = StructuredModelManager.getModelManager();
IStructuredModel model = null;
ICompletionProposal result = null;
try {
if (mm != null) {
model = mm.getExistingModelForRead(viewer.getDocument());
if (model != null) {
IDOMDocument doc = ((IDOMModel) model).getDocument();
ModelQuery mq = ModelQueryUtil.getModelQuery(doc);
if (mq != null) {
// XHTML requires lowercase tagname for lookup
CMDocument correspondingCMDocument = mq.getCorrespondingCMDocument(doc);
if (correspondingCMDocument != null) {
CMElementDeclaration htmlDecl = (CMElementDeclaration) correspondingCMDocument.getElements().getNamedItem(HTML40Namespace.ElementName.HTML.toLowerCase());
if (htmlDecl != null) {
StringBuffer proposedTextBuffer = new StringBuffer();
getContentGenerator().generateTag(doc, htmlDecl, proposedTextBuffer);
String proposedText = proposedTextBuffer.toString();
String requiredName = getContentGenerator().getRequiredName(doc, htmlDecl);
CustomCompletionProposal proposal = new CustomCompletionProposal(proposedText, documentPosition, /* start pos */
0, /* replace length */
requiredName.length() + 2, /*
* cursor position
* after
* (relavtive to
* start)
*/
HTMLEditorPluginImageHelper.getInstance().getImage(HTMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), requiredName, null, null, XMLRelevanceConstants.R_TAG_NAME);
result = proposal;
}
}
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class ModelQueryAdapterFactoryForHTML method createAdapter.
/**
* createAdapter method comment.
*
* XXX: we must make this method more independent of 'location' (at least
* provide some fall-back method).
*/
protected INodeAdapter createAdapter(INodeNotifier target) {
if (Debug.displayInfo) {
// $NON-NLS-1$
Logger.log(Logger.INFO_DEBUG, "-----------------------ModelQueryAdapterFactoryForHTML.createAdapter" + target);
}
if (modelQueryAdapter == null) {
if (target instanceof IDOMNode) {
IDOMNode xmlNode = (IDOMNode) target;
modelStateNotifier = xmlNode.getModel();
modelStateNotifier.addModelStateListener(getInternalModelStateListener());
IStructuredModel model = xmlNode.getModel();
org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
if (Debug.displayInfo)
// $NON-NLS-1$
System.out.println("----------------ModelQueryAdapterFactoryForHTML... baseLocation : " + resolver.getFileBaseLocation());
/**
* XMLCatalogIdResolver currently requires a filesystem
* location string. Customarily this will be what is in the
* deprecated SSE URIResolver and required by the Common URI
* Resolver.
*/
URIResolver idResolver = null;
if (resolver != null) {
idResolver = new XMLCatalogIdResolver(resolver.getFileBaseLocation(), resolver);
} else {
/*
* 203649 - this block may be necessary due to ordering of
* setting the resolver into the model
*/
String baseLocation = null;
String modelsBaseLocation = model.getBaseLocation();
if (modelsBaseLocation != null) {
File file = new Path(modelsBaseLocation).toFile();
if (file.exists()) {
baseLocation = file.getAbsolutePath();
} else {
IPath basePath = new Path(model.getBaseLocation());
IResource derivedResource = null;
if (basePath.segmentCount() > 1)
derivedResource = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
else
derivedResource = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0));
IPath derivedPath = derivedResource.getLocation();
if (derivedPath != null) {
baseLocation = derivedPath.toString();
} else {
URI uri = derivedResource.getLocationURI();
if (uri != null) {
baseLocation = uri.toString();
}
}
}
if (baseLocation == null) {
baseLocation = modelsBaseLocation;
}
}
idResolver = new XMLCatalogIdResolver(baseLocation, null);
}
CMDocumentCache documentCache = new CMDocumentCache();
ModelQuery modelQuery = new HTMLModelQueryImpl(documentCache, idResolver);
modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
modelQueryAdapter = new ModelQueryAdapterImpl(documentCache, modelQuery, idResolver);
}
}
return modelQueryAdapter;
}
Aggregations