file close listener with extension bundle
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 17
- Joined: Thu Sep 17, 2015 3:39 pm
file close listener with extension bundle
Hi!
I am trying to implement a file save listener and a file close listener. For the file save listener, i found this solution:
For the file close listener there seems to be an equivalent solution using an EditorChangeListener, but this can only be added to a PluginWorkspace. Is there a way to do this with an extension bundle without a plugin?
Thanks and Regards,
Julia
I am trying to implement a file save listener and a file close listener. For the file save listener, i found this solution:
Code: Select all
authorAccess.getWorkspaceAccess().getEditorAccess(authorAccess.getEditorAccess().getEditorLocation()).addEditorListener(new WSEditorListener() {
@Override
public void editorSaved(int arg0) {
super.editorSaved(arg0);
logger.info("File saved!");
}
});
Thanks and Regards,
Julia
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: file close listener with extension bundle
Hi Julia,
Just to see if I understand the use case, you want to do a specific thing when the current opened XML file is closed, right?
Could you elaborate on what you want to do? I could consider adding some more API for this.
Anyway, in any place of the code you can use static access to the entire workspace like:
but ideally if you add a listener from an opened editor, when the XML editor is closed you should remove the listener, otherwise the main plugin workspace will keep a reference to the listener which will keep a reference to the opened editor, so when you will close the editor the Java garbage collector will no longer de-allocate the memory used by it.
Something like:
Or you can create a plugin for Oxygen (a Workspace Access plugin) which adds the editor listener and does various things. And the end user would need to install both the plugin and the custom framework.
Regards,
Radu
Just to see if I understand the use case, you want to do a specific thing when the current opened XML file is closed, right?
Could you elaborate on what you want to do? I could consider adding some more API for this.
Anyway, in any place of the code you can use static access to the entire workspace like:
Code: Select all
PluginWorkspaceProvider.getPluginWorkspace().addEditorChangeListener(....., PluginWorkspace.MAIN_EDITING_AREA);
Something like:
Code: Select all
WSEditorChangeListener editorListener = null;
private addTheListener() {
editorListener = new WSEditorChangeListener(){
/**
* @see ro.sync.exml.workspace.api.listeners.WSEditorChangeListener#editorClosed(java.net.URL)
*/
@Override
public void editorClosed(URL editorLocation) {
//Do something here...
//And remove the listener
PluginWorkspaceProvider.getPluginWorkspace().removeEditorChangeListener(editorListener, PluginWorkspace.MAIN_EDITING_AREA);
}
};
PluginWorkspaceProvider.getPluginWorkspace().addEditorChangeListener(editorListener, PluginWorkspace.MAIN_EDITING_AREA);
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 17
- Joined: Thu Sep 17, 2015 3:39 pm
Re: file close listener with extension bundle
Hi Radu!
Thanks for your reply, this should work for me. I am caching some information for every open file and I would like to clear the cache if the file is closed, just as I refresh the cache when the file is saved.
Regards,
Julia
Thanks for your reply, this should work for me. I am caching some information for every open file and I would like to clear the cache if the file is closed, just as I refresh the cache when the file is saved.
Regards,
Julia
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: file close listener with extension bundle
Hi Julia,
Thanks for the details, I added an issue on our side, maybe in a future version we can add an "editorClosed" callback API directly in the listener WSEditorListener that you were originally trying to use for this purpose.
Regards,
Radu
Thanks for the details, I added an issue on our side, maybe in a future version we can add an "editorClosed" callback API directly in the listener WSEditorListener that you were originally trying to use for this purpose.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 17
- Joined: Thu Sep 17, 2015 3:39 pm
Re: file close listener with extension bundle
Hi Radu,
I am currently facing one problem with this file save listener. The EditorListener only works for files opened in author mode, since it needs the AuthorAccess, right? But I often open, edit and then save files in text mode and I would like to have my functionality for that case, too.
How can I achieve this through my extension bundle?
Regards,
Julia
I am currently facing one problem with this file save listener. The EditorListener only works for files opened in author mode, since it needs the AuthorAccess, right? But I often open, edit and then save files in text mode and I would like to have my functionality for that case, too.
How can I achieve this through my extension bundle?
Regards,
Julia
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: file close listener with extension bundle
Post by alex_jitianu »
Hi Julia,
My colleague Radu has a few days off so I will help you while he's away. The plugin-level API works for the Text page as well. Have you decided to create an WorkspaceAccess plugin or are you still using this API from the framework-level API, meaning the ExtensionsBundle? If you are still using the ExtensionsBundle then I guess you are adding the listener from an AuthorExtensionStateListener? If that's the case then, indeed this AuthorExtensionStateListener is only notified when an editor is opened in the AuthorPage.
An WorkspaceAccess plugin is activated automatically on Oxygen's startup and in it you can listen for any editor open event (in any page it might be):
So the bottom line is that if you create such a plugin you will definitely not miss any events.
Best regards,
Alex
My colleague Radu has a few days off so I will help you while he's away. The plugin-level API works for the Text page as well. Have you decided to create an WorkspaceAccess plugin or are you still using this API from the framework-level API, meaning the ExtensionsBundle? If you are still using the ExtensionsBundle then I guess you are adding the listener from an AuthorExtensionStateListener? If that's the case then, indeed this AuthorExtensionStateListener is only notified when an editor is opened in the AuthorPage.
An WorkspaceAccess plugin is activated automatically on Oxygen's startup and in it you can listen for any editor open event (in any page it might be):
Code: Select all
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
@Override
public void editorOpened(URL editorLocation) {
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
editorAccess.addEditorListener(new WSEditorListener() {
@Override
public void editorSaved(int operationType) {
// TODO Save event.
}
});
}
@Override
public void editorClosed(URL editorLocation) {
// TODO Save event.
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA);
}
}, PluginWorkspace.MAIN_EDITING_AREA);
Best regards,
Alex
-
- Posts: 417
- Joined: Mon May 09, 2016 9:37 am
Re: file close listener with extension bundle
Post by sorin_carbunaru »
Hello there,
Just wanted to announce that oXygen 19.1 is out and our API now has a method that gets notified when an editor in the stand-alone application is about to be closed. See ro.sync.exml.workspace.api.listeners.WSEditorListener.editorAboutToBeClosedVeto(URL).
All the best wishes,
Sorin Carbunaru
oXygen XML
Just wanted to announce that oXygen 19.1 is out and our API now has a method that gets notified when an editor in the stand-alone application is about to be closed. See ro.sync.exml.workspace.api.listeners.WSEditorListener.editorAboutToBeClosedVeto(URL).
All the best wishes,
Sorin Carbunaru
oXygen XML
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service