Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Where to construct IStructuredDocument
Where to construct IStructuredDocument [message #230190] Wed, 08 April 2009 21:04 Go to next message
Frank Du is currently offline Frank Du
Messages: 91
Registered: July 2009
Member
Dear, All,

I encountered an "unknown IStructuredDocument" error with an extended WTP
XML editor. The editor extends StructuredTextEditor, and uses
StructuredTextViewerConfigurationXML.

It works fine with XML file. But our data input is a small portion of a
large file, which feeds XML fragment to the editor as a java object. I
implemented IStorageEditorInput on the object. The editor opens up with
XML fragment, having syntax highlighting. But, when trying to run Document
Format action, I encountered the "unknown IStructuredDocument" error.

My question is: Where to construct IStructuredDocument?

I tried to do it in a FileDocumentProvider, the editor just throws
numerous errors if I set document provider.

Best Regards,
Frank

================================================
For your reference, below is the log:


!ENTRY org.eclipse.ui 4 4 2009-04-08 16:54:11.999
!MESSAGE "Format" did not complete normally. Please see the log for more
information.

!ENTRY org.eclipse.ui 4 0 2009-04-08 16:54:12.077
!MESSAGE unknown IStructuredDocument
org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocu ment @d642fd
!STACK 0
org.eclipse.wst.sse.core.internal.util.Assert$AssertionFaile dException:
unknown IStructuredDocument
org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocu ment @d642fd
at
org.eclipse.wst.sse.core.internal.util.Assert.isNotNull(Asse rt.java:124)
at
org.eclipse.wst.sse.core.internal.model.ModelManagerImpl._ge tModelFor(ModelManagerImpl.java:541)
at
org.eclipse.wst.sse.core.internal.model.ModelManagerImpl.get ModelForEdit(ModelManagerImpl.java:1292)
at
org.eclipse.wst.xml.ui.internal.XMLFormattingStrategy.format (XMLFormattingStrategy.java:58)
at
org.eclipse.jface.text.formatter.MultiPassContentFormatter.f ormatMaster(MultiPassContentFormatter.java:193)
at
org.eclipse.wst.sse.ui.StructuredTextMultiPassContentFormatt er.formatMaster(StructuredTextMultiPassContentFormatter.java :56)
at
org.eclipse.jface.text.formatter.MultiPassContentFormatter.f ormat(MultiPassContentFormatter.java:135)
at
org.eclipse.wst.sse.ui.internal.StructuredTextViewer.doOpera tion(StructuredTextViewer.java:513)
at
......
Re: Where to construct IStructuredDocument [message #230214 is a reply to message #230190] Thu, 09 April 2009 04:24 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2274
Registered: July 2009
Senior Member
Frank Du wrote:
> Dear, All,
>
> I encountered an "unknown IStructuredDocument" error with an extended
> WTP XML editor. The editor extends StructuredTextEditor, and uses
> StructuredTextViewerConfigurationXML.
> It works fine with XML file. But our data input is a small portion of a
> large file, which feeds XML fragment to the editor as a java object. I
> implemented IStorageEditorInput on the object. The editor opens up with
> XML fragment, having syntax highlighting. But, when trying to run
> Document Format action, I encountered the "unknown IStructuredDocument"
> error.
>
> My question is: Where to construct IStructuredDocument?
> I tried to do it in a FileDocumentProvider, the editor just throws
> numerous errors if I set document provider.
>
> Best Regards,
> Frank
>
> ================================================
> For your reference, below is the log:
>
>
> !ENTRY org.eclipse.ui 4 4 2009-04-08 16:54:11.999
> !MESSAGE "Format" did not complete normally. Please see the log for
> more information.
>
> !ENTRY org.eclipse.ui 4 0 2009-04-08 16:54:12.077
> !MESSAGE unknown IStructuredDocument
> org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocu ment @d642fd
> !STACK 0
> org.eclipse.wst.sse.core.internal.util.Assert$AssertionFaile dException:
> unknown IStructuredDocument
> org.eclipse.wst.sse.core.internal.text.JobSafeStructuredDocu ment @d642fd
> at
> org.eclipse.wst.sse.core.internal.util.Assert.isNotNull(Asse rt.java:124)
> at
> org.eclipse.wst.sse.core.internal.model.ModelManagerImpl._ge tModelFor(ModelManagerImpl.java:541)
>
> at
> org.eclipse.wst.sse.core.internal.model.ModelManagerImpl.get ModelForEdit(ModelManagerImpl.java:1292)
>
> at
> org.eclipse.wst.xml.ui.internal.XMLFormattingStrategy.format (XMLFormattingStrategy.java:58)
>
> at
> org.eclipse.jface.text.formatter.MultiPassContentFormatter.f ormatMaster(MultiPassContentFormatter.java:193)
>
> at
> org.eclipse.wst.sse.ui.StructuredTextMultiPassContentFormatt er.formatMaster(StructuredTextMultiPassContentFormatter.java :56)
>
> at
> org.eclipse.jface.text.formatter.MultiPassContentFormatter.f ormat(MultiPassContentFormatter.java:135)
>
> at
> org.eclipse.wst.sse.ui.internal.StructuredTextViewer.doOpera tion(StructuredTextViewer.java:513)
>
> at .....

You shouldn't need to use the FileDocumentProvider since the
TextFileDocumentProvider will already support files in the
workspace. We usually discourage subclassing StructuredTextEditor
since that's what the viewer configurations are for.

The error message is indicating that the document in the editor
isn't shared as part of an IStructuredModel in the SSE
IModelManager. The formatting functionality requires access to the
model, and in this case there's no way to pass that object through
the MultiPassContentFormatter API. The XMLFormattingStrategy has to
look it up somehow, hence the IModelManager's involvement and the
need to use a shared model. Most of the time the editor's being
opened on IFiles in the workspace or java.io.Files in the
filesystem, which are handled by the TextFileDocumentProvider, or
with an implementor of IStorageEditorInput which we then handle with
our own StorageModelProvider. The
org.eclipse.ui.editors.documentProviders extension point can be used
to map your own input type to a document provider. My own
experience is that cooking up your own document provider is usually
more trouble than it's worth (we're up to
IDocumentProviderExtension5 now), and that it's simpler instead to
create an editor input that can be used by an existing provider.

If you need to show an arbitrary bit of text in the
StructuredTextViewer_, and need it to be shared, create the model
using the IModelManager.getModelForEdit(String, InputStream,
URIResolver) method and set that model's IStructuredDocument into
the viewer. The string name you give it will be important in
helping to find the right content type and model handlers to build
the XML model. As with all shared models, be sure to release it
when you're done using it.

You're not the first one to run into this snag, as it's hit our own
committers from time to time:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=270888 . Good luck.

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Where to construct IStructuredDocument [message #230305 is a reply to message #230214] Mon, 13 April 2009 21:27 Go to previous messageGo to next message
Frank Du is currently offline Frank Du
Messages: 91
Registered: July 2009
Member
Hi Natin,

Thank you so much for the detailed reply. I consulted you at eclipsecon
about it, and have created IStorageEditorInput class now. Here is our
scenario:

1. We have a config file which contains several kinds of configuration text
2. A multi-page editor is created.
3. From the main editor page, users can open different kinds of configs in
different editors. New editors go to new editor tab pages.
4. The Properties "file" editor and text editor work fine now. I use
IDocumentProvider to sync the changes between memory objects and textual
representation.

5. For the xml editor, we can retrieve text from memory config object, and
display the xml fragment properly. But how could I save changes back to
memory objects.

I have gone through the source code, and don't have enough clues. Natin,
could you please tell me which method to override or replace, to save the
changes?

Best Regards,
Frank






Nitin Dahyabhai wrote:

> You shouldn't need to use the FileDocumentProvider since the
> TextFileDocumentProvider will already support files in the
> workspace. We usually discourage subclassing StructuredTextEditor
> since that's what the viewer configurations are for.

> The error message is indicating that the document in the editor
> isn't shared as part of an IStructuredModel in the SSE
> IModelManager. The formatting functionality requires access to the
> model, and in this case there's no way to pass that object through
> the MultiPassContentFormatter API. The XMLFormattingStrategy has to
> look it up somehow, hence the IModelManager's involvement and the
> need to use a shared model. Most of the time the editor's being
> opened on IFiles in the workspace or java.io.Files in the
> filesystem, which are handled by the TextFileDocumentProvider, or
> with an implementor of IStorageEditorInput which we then handle with
> our own StorageModelProvider. The
> org.eclipse.ui.editors.documentProviders extension point can be used
> to map your own input type to a document provider. My own
> experience is that cooking up your own document provider is usually
> more trouble than it's worth (we're up to
> IDocumentProviderExtension5 now), and that it's simpler instead to
> create an editor input that can be used by an existing provider.

> If you need to show an arbitrary bit of text in the
> StructuredTextViewer_, and need it to be shared, create the model
> using the IModelManager.getModelForEdit(String, InputStream,
> URIResolver) method and set that model's IStructuredDocument into
> the viewer. The string name you give it will be important in
> helping to find the right content type and model handlers to build
> the XML model. As with all shared models, be sure to release it
> when you're done using it.

> You're not the first one to run into this snag, as it's hit our own
> committers from time to time:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=270888 . Good luck.
Re: Where to construct IStructuredDocument [message #230364 is a reply to message #230305] Wed, 15 April 2009 03:40 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin Dahyabhai
Messages: 2274
Registered: July 2009
Senior Member
Frank Du wrote:
> Thank you so much for the detailed reply. I consulted you at eclipsecon
> about it, and have created IStorageEditorInput class now. Here is our
> scenario:
>
> 1. We have a config file which contains several kinds of configuration text
> 2. A multi-page editor is created.
> 3. From the main editor page, users can open different kinds of configs
> in different editors. New editors go to new editor tab pages.
> 4. The Properties "file" editor and text editor work fine now. I use
> IDocumentProvider to sync the changes between memory objects and textual
> representation.
>
> 5. For the xml editor, we can retrieve text from memory config object,
> and display the xml fragment properly. But how could I save changes back
> to memory objects.
>
> I have gone through the source code, and don't have enough clues. Natin,
> could you please tell me which method to override or replace, to save
> the changes?

Well, that's a hard one--offering the ability to save to something
that's not a file has not been a big use case for us. In this
situation, I think there's no choice but to subclass and override
org.eclipse.wst.sse.ui.StructuredTextEditor.setDocumentProvi der(IEditorInput)
for your source page so that it uses your own document provider for
your editor input. Although it's discouraged in the JavaDoc, the
StructuredTextEditor class isn't marked final.

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: Where to construct IStructuredDocument [message #230428 is a reply to message #230364] Wed, 15 April 2009 20:38 Go to previous messageGo to next message
Eclipse User
Originally posted by: dcarver.starstandard.org

As XML Databases become more popular, this type of non-file saving will
become more prevelant. Consider a situation where an XQuery is run to
retrieve the information, and a XQuery Update is executed to update the
information. The XML Editor may be used to view the results or you may
want to make changes directly to the xml and restore it back in the
database. In this particular case, there is no physical file per say,
as the update and retrievel could be done through API or through RESTful
web service interfaces.

Dave

Nitin Dahyabhai wrote:
> Frank Du wrote:
>> Thank you so much for the detailed reply. I consulted you at
>> eclipsecon about it, and have created IStorageEditorInput class now.
>> Here is our scenario:
>>
>> 1. We have a config file which contains several kinds of configuration
>> text
>> 2. A multi-page editor is created.
>> 3. From the main editor page, users can open different kinds of
>> configs in different editors. New editors go to new editor tab pages.
>> 4. The Properties "file" editor and text editor work fine now. I use
>> IDocumentProvider to sync the changes between memory objects and
>> textual representation.
>>
>> 5. For the xml editor, we can retrieve text from memory config object,
>> and display the xml fragment properly. But how could I save changes
>> back to memory objects.
>>
>> I have gone through the source code, and don't have enough clues.
>> Natin, could you please tell me which method to override or replace,
>> to save the changes?
>
> Well, that's a hard one--offering the ability to save to something
> that's not a file has not been a big use case for us. In this
> situation, I think there's no choice but to subclass and override
> org.eclipse.wst.sse.ui.StructuredTextEditor.setDocumentProvi der(IEditorInput)
> for your source page so that it uses your own document provider for your
> editor input. Although it's discouraged in the JavaDoc, the
> StructuredTextEditor class isn't marked final.
>
Re: Where to construct IStructuredDocument [message #230796 is a reply to message #230428] Mon, 27 April 2009 22:34 Go to previous messageGo to next message
Frank Du is currently offline Frank Du
Messages: 91
Registered: July 2009
Member
Hi David,

I agree with you. Aside from requirements from technical evolution, there
are also requirements from target users. XML is great for technicians, but
may be too verbose or cumbersome for normal software users, especially
when it grows very large. So, you wish to display a small portion of large
xml. You wish to break it into pieces and present pieces in some form UI.
That's the reason why we are doing it this way. Hope it helps to explain
the use scenarios and make WTP editors more generic for such situations.

Thank you so much, David and Nitin! I will try Nitin's suggestion soon,
and keep this thread posted.

Have a good one day!

Best Regards,
Frank Du


David Carver wrote:

> As XML Databases become more popular, this type of non-file saving will
> become more prevelant. Consider a situation where an XQuery is run to
> retrieve the information, and a XQuery Update is executed to update the
> information. The XML Editor may be used to view the results or you may
> want to make changes directly to the xml and restore it back in the
> database. In this particular case, there is no physical file per say,
> as the update and retrievel could be done through API or through RESTful
> web service interfaces.

> Dave
Re: Where to construct IStructuredDocument [message #230867 is a reply to message #230364] Tue, 28 April 2009 21:01 Go to previous message
Frank Du is currently offline Frank Du
Messages: 91
Registered: July 2009
Member
Dear Nitin & All,

I finally put up all the suggestions from several my newsgroup posts.
Woo-hoo! Finally got working code now! The steps I went through are:

1. Implement IStorage.
2. Implement IStorageEditorInput.
With the steps so far, the embedded xml editor can read the document
contents from in-memory objects.

3. Copy and modify source code of StorageModelProvider, to insert my code
to doSaveDocument(...) method. The code will update in-memory objects,
when the input is our IStorageEditorInput.
With the step 3, the embedded xml editor can save changes back to
in-memory objects.

4. In the editor class (subclass StructuredTextEditor), override the
method setDocumentProvider(IEditorInput input). When input is our storage
editor input, set it to use the modified StorageModelProvider.

With the steps above, everything works now. It just, of course, looks like
ugly code. IMH, it may be beautiful if the StructuredModelManager yields
StructuredModel and StructuredDocument not based on IFile but on
IEditorInput.

Wish the above information helps for those who run into similar issues.
Thanks so much to all of you, especially to Nitin!

Have a good one day!

Best Regards,
Frank Du



Nitin Dahyabhai wrote:

> Frank Du wrote:
>> Thank you so much for the detailed reply. I consulted you at eclipsecon
>> about it, and have created IStorageEditorInput class now. Here is our
>> scenario:
>>
>> 1. We have a config file which contains several kinds of configuration text
>> 2. A multi-page editor is created.
>> 3. From the main editor page, users can open different kinds of configs
>> in different editors. New editors go to new editor tab pages.
>> 4. The Properties "file" editor and text editor work fine now. I use
>> IDocumentProvider to sync the changes between memory objects and textual
>> representation.
>>
>> 5. For the xml editor, we can retrieve text from memory config object,
>> and display the xml fragment properly. But how could I save changes back
>> to memory objects.
>>
>> I have gone through the source code, and don't have enough clues. Natin,
>> could you please tell me which method to override or replace, to save
>> the changes?

> Well, that's a hard one--offering the ability to save to something
> that's not a file has not been a big use case for us. In this
> situation, I think there's no choice but to subclass and override
>
org.eclipse.wst.sse.ui.StructuredTextEditor.setDocumentProvi der(IEditorInput)
> for your source page so that it uses your own document provider for
> your editor input. Although it's discouraged in the JavaDoc, the
> StructuredTextEditor class isn't marked final.
Previous Topic:For the Designers among you: We need a new logo and icon
Next Topic:Advance Queues / JMS Queues
Goto Forum:
  


Current Time: Sun Sep 21 12:19:25 GMT 2014

Powered by FUDForum. Page generated in 0.06616 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software