Buffer-related questions (when opened from plugin)

Hi, When opening a buffer from within a plugin (using Workspace.open()), is there any way to 1/ attach a specific value to the buffer (kind of a buffer-scoped variable, in my case just a boolean flag) and 2/ to specify a method to be called before closing the buffer (kind of a buffer listener, so I can do some treatment before closing it)? Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/

Hi Florent, You could implement a HashMap in your WorkspaceAccessPluginExtension which would keep that flag for a certain URL for which you wanted the open operation to work. Is that boolean flag somewhat related to whether the URL was opened for editing or read-only by the user? If so you might consider adding a parameter to the URL string like:
protocol://host/path/to/resource.xml?read-only=true
In this way the information would be saved in the URL itself and if you have a custom URLHandler the information would get also passed to the handler because it will be able to read the parameter from the URL. You can add more than one parameter to specify different choices that the user made when opening the URL, this is a good method to pass parameters to the URLHandler. As for this question:
2/ to specify a method to be called before closing the buffer (kind of a buffer listener, so I can do some treatment before closing it)?
So you want some kind of a listener to notify you before an opened editor is closed, right? You have this API method:
ro.sync.exml.workspace.api.PluginWorkspace.addEditorChangeListener(WSEditorChangeListener, int)
and the listener has these interesting methods which can be overridden:
ro.sync.exml.workspace.api.listeners.WSEditorChangeListener.editorAboutToBeClosed(URL)
This method would actually allow you to reject the close if some condition is not fulfilled (if the user did not save or did not check in for example). and:
ro.sync.exml.workspace.api.listeners.WSEditorChangeListener.editorClosed(URL)
Regards, Radu Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 6/14/2012 4:45 PM, Florent Georges wrote:
Hi,
When opening a buffer from within a plugin (using Workspace.open()), is there any way to 1/ attach a specific value to the buffer (kind of a buffer-scoped variable, in my case just a boolean flag) and 2/ to specify a method to be called before closing the buffer (kind of a buffer listener, so I can do some treatment before closing it)?
Regards,

You could implement a HashMap in your WorkspaceAccessPluginExtension which would keep that flag for a certain URL for which you wanted the open operation to work. Interesting idea... Actually, that's just to keep track of the buffers opened by the plugin. So probably the best is to use a set
Oxygen XML Editor Support wrote: Hi, Thank you for your detailed answer! based on object identities, with the WSEditor objects. Do we have the guarantee that the WSEditor object does not change between the moment a file is open and when it is closed? Object identity looks like more robust to me than URI comparison, isn't it? BTW, shouldn't a WSEditor object be returned by Workspace.open()?
Is that boolean flag somewhat related to whether the URL was opened for editing or read-only by the user? No, but that's also a requirement ;-) Is there any way to open a file in read-only using the API? Other than creating a dedicated WSEditorChangeListener of course.
2/ to specify a method to be called before closing the buffer (kind of a buffer listener, so I can do some treatment before closing it)? So you want some kind of a listener to notify you before an opened editor is closed, right? Precisely. WSEditorChangeListener.editorAboutToBeClosed(URL) WSEditorChangeListener.editorClosed(URL) Perfect! Thank you, regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/

Hello Florent,
So probably the best is to use a set based on object identities, with the WSEditor objects. Do we have the guarantee that the WSEditor object does not change between the moment a file is open and when it is closed? Object identity looks like more robust to me than URI comparison, isn't it?
No, actually the method "ro.sync.exml.workspace.api.PluginWorkspace.getCurrentEditorAccess(int)" returns each time a new wrapper object over our internal implementation so you should use the URL as the key which identifies an opened editor. Then you can use the method "ro.sync.exml.workspace.api.PluginWorkspace.getEditorAccess(URL, int)" each time you need the WSEditorAccess.
BTW, shouldn't a WSEditor object be returned by Workspace.open()?
Yes, good idea, too bad we did not think of it then. We try to keep the API as backward compatible as possible so the current method cannot be changed anymore. But the workaround to obtain a WSEditor is simple.
No, but that's also a requirement Is there any way to open a file in read-only using the API? Other than creating a dedicated WSEditorChangeListener of course.
There are two ways I think: 1) We have an interface called "ro.sync.exml.plugin.urlstreamhandler.URLHandlerReadOnlyCheckerExtension" which can be implemented in the "URLStreamHandlerPluginExtension", there is a sample for it in the Plugins SDK. 2) On the "WSEditorChangeListener.editorOpened(URL)" callback after a WSEditor is opened you can gain access to its current page "ro.sync.exml.workspace.api.editor.WSEditor.getCurrentPage()" and if it is an instance of WSTextBasedEditorPage use this method: "WSTextBasedEditorPage.setEditable(boolean)" Regards, Radu Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 6/15/2012 2:47 PM, Florent Georges wrote:
Oxygen XML Editor Support wrote:
Hi,
Thank you for your detailed answer!
You could implement a HashMap in your WorkspaceAccessPluginExtension which would keep that flag for a certain URL for which you wanted the open operation to work.
Interesting idea... Actually, that's just to keep track of the buffers opened by the plugin. So probably the best is to use a set based on object identities, with the WSEditor objects. Do we have the guarantee that the WSEditor object does not change between the moment a file is open and when it is closed? Object identity looks like more robust to me than URI comparison, isn't it?
BTW, shouldn't a WSEditor object be returned by Workspace.open()?
Is that boolean flag somewhat related to whether the URL was opened for editing or read-only by the user?
No, but that's also a requirement ;-) Is there any way to open a file in read-only using the API? Other than creating a dedicated WSEditorChangeListener of course.
2/ to specify a method to be called before closing the buffer (kind of a buffer listener, so I can do some treatment before closing it)?
So you want some kind of a listener to notify you before an opened editor is closed, right?
Precisely.
WSEditorChangeListener.editorAboutToBeClosed(URL) WSEditorChangeListener.editorClosed(URL)
Perfect!
Thank you, regards,

Oxygen XML Editor Support
"PluginWorkspace.getCurrentEditorAccess(int)" returns each time a new wrapper object over our internal implementation
Ok I see, thanks!
Is there any way to open a file in read-only using the API? Other than creating a dedicated WSEditorChangeListener of course.
There are two ways I think:
1) We have an interface called "URLHandlerReadOnlyCheckerExtension" which can be implemented in the "URLStreamHandlerPluginExtension", there is a sample for it in the Plugins SDK.
Which is not usable if I don't implement a Targeted URL Stream Handler Plugin, is it?
2) On the "WSEditorChangeListener.editorOpened(URL)" callback after a WSEditor is opened you can gain access to its current page "WSEditor.getCurrentPage()" and if it is an instance of WSTextBasedEditorPage use this method: "setEditable(boolean)"
Interesting. Does that mean that this can't prevent editing when the user is using the Grid view? Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/

Hi Florent,
Which is not usable if I don't implement a Targeted URL Stream Handler Plugin, is it?
Right, you would need to implement a special protocol handler plugin extension.
Interesting. Does that mean that this can't prevent editing when the user is using the Grid view?
You are right, we do not have API for accessing the Grid page (it is not very used for customizations). The Grid page does not make much sense for being used by a technical writer. But, a WSEditor has a method "changePage" and the possibility to add a listener to it via "addEditorListener" so if the user switches to the Grid page you could automatically switch to some other page (Text or Author) and thus avoid having the user modify a read-only content. Another approach would be to let the user modify the content and then throw an error when the user attempts to save. You also have methods like: "WSEditorBase.setEditorTabText(String)" which would allow you to add a "(read-only)" status showing in the editor's tab. Regards, Radu Radu Coravu <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com On 6/15/2012 5:13 PM, Florent Georges wrote:
Oxygen XML Editor Support
"PluginWorkspace.getCurrentEditorAccess(int)" returns each time a new wrapper object over our internal implementation
Ok I see, thanks!
Is there any way to open a file in read-only using the API? Other than creating a dedicated WSEditorChangeListener of course.
There are two ways I think:
1) We have an interface called "URLHandlerReadOnlyCheckerExtension" which can be implemented in the "URLStreamHandlerPluginExtension", there is a sample for it in the Plugins SDK.
Which is not usable if I don't implement a Targeted URL Stream Handler Plugin, is it?
2) On the "WSEditorChangeListener.editorOpened(URL)" callback after a WSEditor is opened you can gain access to its current page "WSEditor.getCurrentPage()" and if it is an instance of WSTextBasedEditorPage use this method: "setEditable(boolean)"
Interesting. Does that mean that this can't prevent editing when the user is using the Grid view?
Regards,
-- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/
participants (2)
-
Florent Georges
-
Oxygen XML Editor Support