use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class TestAttributesOrder method ensureDocumentHasGrammar.
/**
* Reusable test to make sure the XML model for the given file has a grammar.
*
* @param file
* the file containing the XML document.
*/
private void ensureDocumentHasGrammar(IFile file) throws IOException, CoreException {
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", cmElementDeclaration);
assertNotNull("No content assist available for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", modelQuery.getAvailableContent(documentElement, cmElementDeclaration, ModelQuery.INCLUDE_CHILD_NODES));
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class TestCyclicGroupReferences method testCyclicGroupReferences.
/**
* Test CMVisitor for cyclic group references.
*/
public void testCyclicGroupReferences() {
// $NON-NLS-1$
IFile file = getFile("Test.xml");
CMVisitor cmVisitor = new CMVisitor();
IStructuredModel model = null;
try {
IModelManager modelManager = StructuredModelManager.getModelManager();
model = modelManager.getModelForRead(file);
// $NON-NLS-1$
assertNotNull("failure loading model", model);
IDOMModel domModel = (IDOMModel) model;
IDOMDocument document = domModel.getDocument();
// $NON-NLS-1$
assertNotNull("failure getting document", document);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(model);
// $NON-NLS-1$
assertNotNull("ModelQuery is missing", modelQuery);
IDOMElement documentElement = (IDOMElement) document.getDocumentElement();
// $NON-NLS-1$
assertNotNull("missing document element", documentElement);
CMElementDeclaration cmElementDeclaration = modelQuery.getCMElementDeclaration(documentElement);
assertNotNull("No element declaration for" + documentElement.getNodeName() + " (" + documentElement.getNamespaceURI() + ")", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
cmElementDeclaration);
cmVisitor.visitCMElementDeclaration(cmElementDeclaration);
} catch (Throwable th) {
fail("Test failed :" + th.getClass().getName());
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class AbstractXMLModelQueryCompletionProposalComputer method isXMLNode.
/**
* Similar to the call in HTMLContentAssistProcessor. Pass in a node, it
* tells you if the document is XML type.
*
* @param node
*/
private boolean isXMLNode(Node node) {
if (node == null) {
return false;
}
Document doc = null;
doc = (node.getNodeType() != Node.DOCUMENT_NODE) ? node.getOwnerDocument() : ((Document) node);
return (doc instanceof IDOMDocument) && ((IDOMDocument) doc).isXMLType();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class XSDModelAdapter method clear.
public void clear() {
if (schema != null) {
Document doc = schema.getDocument();
if (doc instanceof IDOMDocument) {
IDOMDocument domDocument = (IDOMDocument) doc;
domDocument.getModel().removeModelStateListener(getModelReconcileAdapter());
domDocument.removeAdapter(getModelReconcileAdapter());
domDocument.removeAdapter(this);
}
schema = null;
}
resourceSet = null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.
the class NamespaceSelectionAdapter method widgetSelected.
@Override
public void widgetSelected(SelectionEvent e) {
IEditorPart activeEditor = Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IFile file = (IFile) activeEditor.getEditorInput().getAdapter(IFile.class);
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMModel model = null;
try {
model = (IDOMModel) modelManager.getModelForRead(file);
IDOMDocument document = model.getDocument();
if (document != null) {
List<NamespaceInfo> info = createNamespaceInfo(document);
IPathEditorInput editorInput = (IPathEditorInput) activeEditor.getEditorInput();
EditNamespacePrefixDialog dlg = new EditNamespacePrefixDialog(activeEditor.getSite().getShell(), editorInput.getPath());
dlg.setNamespaceInfoList(info);
if (SWT.OK == dlg.open()) {
// Apply changes
}
}
} catch (Exception ex) {
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
Aggregations