use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLHyperlinkDetector method getCMElementDeclaration.
/**
* Get the CMElementDeclaration for an element
*
* @param element
* @return CMElementDeclaration
*/
private CMElementDeclaration getCMElementDeclaration(Element element) {
CMElementDeclaration ed = null;
ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
if (mq != null) {
ed = mq.getCMElementDeclaration(element);
}
return ed;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class ToggleEditModeHandler method updateElement.
// Handlers that need to interact with the ui that the command came from
// need to use implement this method.
public void updateElement(UIElement element, Map parameters) {
XMLUIPlugin xmluiPlugin = XMLUIPlugin.getDefault();
if (xmluiPlugin == null)
// probably shutting down
return;
IWorkbench workbench = xmluiPlugin.getWorkbench();
if (workbench == null)
return;
IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null)
return;
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
if (activePage == null)
return;
IEditorPart editor = activePage.getActiveEditor();
ITextEditor textEditor = null;
if (editor instanceof ITextEditor)
textEditor = (ITextEditor) editor;
else if (editor != null) {
Object o = editor.getAdapter(ITextEditor.class);
if (o != null)
textEditor = (ITextEditor) o;
}
if (textEditor != null) {
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
ModelQuery modelQuery;
try {
modelQuery = ModelQueryUtil.getModelQuery(model);
} finally {
model.releaseFromRead();
}
if (modelQuery != null) {
setAppearanceForEditMode(modelQuery.getEditMode(), element);
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class XMLAnnotationsView method selectionChanged.
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IEditorPart edPart = getSite().getPage().getActiveEditor();
if (part.equals(edPart)) {
if (selection instanceof IStructuredSelection) {
currentSelection = (IStructuredSelection) selection;
if (!selection.isEmpty() && (currentSelection.getFirstElement() instanceof Node)) {
Node node = (Node) currentSelection.getFirstElement();
ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
if (mq != null) {
cmNode = mq.getCMNode(node);
MarkupTagInfoProvider tagInfo = new MarkupTagInfoProvider();
xmlDoc = tagInfo.getInfo(cmNode);
} else {
xmlDoc = XMLUIMessages.Documentation_view_default_msg;
}
doStyledTextInput();
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.
the class AdapterFactoryProviderForXML method addContentBasedFactories.
protected void addContentBasedFactories(IStructuredModel structuredModel) {
FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry();
// $NON-NLS-1$
Assert.isNotNull(factoryRegistry, "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);
}
//
if (structuredModel != null) {
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 ModelQueryAdapterFactoryForJSP method createAdapter.
/**
* createAdapter method comment.
*/
protected INodeAdapter createAdapter(INodeNotifier target) {
if (Debug.displayInfo)
// $NON-NLS-1$
System.out.println("-----------------------ModelQueryAdapterFactoryForJSP.createAdapter" + target);
if (modelQueryAdapterImpl == null) {
if (target instanceof IDOMNode) {
IDOMNode xmlNode = (IDOMNode) target;
IStructuredModel model = stateNotifier = xmlNode.getModel();
if (model.getBaseLocation() != null) {
stateNotifier.addModelStateListener(this);
}
org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
if (Debug.displayInfo)
// $NON-NLS-1$
System.out.println("----------------ModelQueryAdapterFactoryForJSP... 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);
}
ModelQuery modelQuery = createModelQuery(model, idResolver);
modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
modelQueryAdapterImpl = new JSPModelQueryAdapterImpl(new CMDocumentCache(), modelQuery, idResolver);
}
}
return modelQueryAdapterImpl;
}
Aggregations