Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsHow to best open a schema-backed XML model for an external file without UI?
https://www.eclipse.org/forums/index.php/mv/msg/164474/520836/#msg_520836
please ignore my ignorance, but I can't find an obvious way to open a schema-backed XML model for an external file without any UI plug-ins necessarily being available (this IMO removes the choice for the IStructuredDocument API, because its provided by StructuredTextEditor).
My best choice currently is IModelManager.getModelForEdit(String, InputStream, URIResolver), but at least the last parameter is obsoleted already.
Is this really the best match, assuming this API is going to last? Or are there better choices? Note, that I would need to get the same model instance as StructuredTextEditor gets for the external file via the IStructuredDocument API, as I need to be in sync with it.
Any help highly appreciated!
Thanks a lot in advance,
Walter Brunauer
]]>Walter Brunauer2010-03-15T14:37:52-00:00Re: How to best open a schema-backed XML model for an external file without UI?
https://www.eclipse.org/forums/index.php/mv/msg/164474/520978/#msg_520978
> please ignore my ignorance, but I can't find an obvious way to open a
> schema-backed XML model for an external file without any UI plug-ins
> necessarily being available (this IMO removes the choice for the
> IStructuredDocument API, because its provided by StructuredTextEditor).
>
> My best choice currently is IModelManager.getModelForEdit(String,
> InputStream, URIResolver), but at least the last parameter is obsoleted
> already.
>
> Is this really the best match, assuming this API is going to last? Or
> are there better choices? Note, that I would need to get the same model
> instance as StructuredTextEditor gets for the external file via the
> IStructuredDocument API, as I need to be in sync with it.
>
> Any help highly appreciated!
>
> Thanks a lot in advance,
It's not ignorance nor surprising considering that interface is nearing
a decade of age and predates the platform's headless means of doing
this: File Buffers (in the org.eclipse.core.filebuffers bundle). The
SSE Model Manager was updated shortly before WTP came into existence to
make use of File Buffers, as that mechanism supports files in and
outside of the workspace, hence the deprecation of many of the access
methods. The correct flow is to connect to a text file buffer using
org.eclipse.core.filebuffers.IFileBufferManager#connect(IPat h,
LocationKind.LOCATION, IProgressMonitor), get the ITextFileBuffer for
the same path and location kind using
org.eclipse.core.filebuffers.IFileBufferManager#getFileBuffe r(IPath,
LocationKind), and then use the text document with
org.eclipse.wst.sse.core.internal.provisional.IModelManager# getModelFor[Read|Edit](IStructuredDocument)--type
casting is required in this case. This is actually what the
StructuredTextEditor does (in
org.eclipse.wst.sse.ui.StructuredTextEditor#doSetInput(IEdit orInput) if
that's useful) except the file buffer is handled by the
TextFileDocumentProvider. The underlying infrastructure supports the
same for files in the workspace, but you can still use the older
shortcuts on IModelManager that deal with IFiles directly. Don't forget
to release the model when you're done with it and disconnect from the
file buffer after that. This is as permanent an interface as we can
make it, short of moving it into a correctly public package and removing
everything that's deprecated--which would cause massive binary breakage,
so far stopping us from doing so even though we begin almost every
release with the intention of finally cleaning it up. That and I
haven't come up with a way to let you cleanly share models created from
a stream through a consistent API while having only the first client
supply the input stream. It's a bit of a conundrum.
--
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational]]>Nitin Dahyabhai2010-03-16T02:43:02-00:00Re: How to best open a schema-backed XML model for an external file without UI?
https://www.eclipse.org/forums/index.php/mv/msg/164474/521488/#msg_521488
Ok, so I did as you told me, it works fine and I get the very same model instance as the StructuredTextEditor, as long as the path is representing an IFile. See the simplified code snippet below how I get my model:
But if the path is representing an external location (file == null), the StructuredTextEditor gets the following backtrace on trying to do auto-completion:
java.lang.IllegalStateException: problem getting model
at org.eclipse.wst.xml.ui.internal.contentassist.AbstractConten tAssistProcessor.computeCompletionProposals(AbstractContentA ssistProcessor.java:1388)
at org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssi stProcessor.computeCompletionProposals(XMLContentAssistProce ssor.java:120)
at org.eclipse.wst.sse.ui.internal.contentassist.CompoundConten tAssistProcessor.computeCompletionProposals(CompoundContentA ssistProcessor.java:303)
<snip>
This IMHO is because the AbstractContentAssistProcessor always uses IModelManager.getExistingModelForRead(IDocument) directly, which assumes the document really needs to be the very same instance, and not only one fulfilling the equal() clauses.
Once again, I cannot use any UI classes (like the StructuredTextEditor itself does with TextFileDocumentProvider.getDocument(Object)) to get the same document, as I need the model also in a headless application.
Any idea how to overcome this?
Thanks again,
Walter
]]>Walter Brunauer2010-03-17T18:24:08-00:00Re: How to best open a schema-backed XML model for an external file without UI?
https://www.eclipse.org/forums/index.php/mv/msg/164474/521815/#msg_521815
So if this NPE is happening, who made sure that the model was created beforehand? And how is it that with a headless requirement you're running into an NPE from a UI class?]]>Nitin Dahyabhai2010-03-18T19:20:57-00:00Re: How to best open a schema-backed XML model for an external file without UI?
https://www.eclipse.org/forums/index.php/mv/msg/164474/521957/#msg_521957
Having said this, I got it working now with the following change in my implementation, and thought it might be interesting for others to know as well:
Note, that I now handle external files the same way as TextFileDocumentProvider does, and use TextFileBufferManager.connectFileStore(IFileStore, IProgressMonitor) to register the external file.
Anyway, thanks for your help,
Walter
]]>Walter Brunauer2010-03-19T12:54:51-00:00