ExtensionsBundle activating twice with changePage()

Post here questions and problems related to oXygen frameworks/document types.
ArbitraryName
Posts: 16
Joined: Tue Aug 05, 2014 8:36 pm

ExtensionsBundle activating twice with changePage()

Post by ArbitraryName »

I have the following code in my WorkspaceAccessPluginExtension to force the initial opening of a document into AuthorMode to ensure that some processing accomplished in the AuthorExtensionStateListener is performed. From a user perspective everything appears to function fine. When I look at the logging I see that my ExtensionsBundle is being activated as a result of my changePage() method call, but is activated again at some point after my editorOpened override is complete. This is effectively causing my AuthorExtensionStateListener activated() code to run twice, which is undesired overhead. Is there some issue with me using changePage() this way?

Code: Select all

@Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
LOGGER.debug("Application started...");

// Force the Author view when a file is initially opened.
pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {

@Override
public void editorOpened(URL editorLocation) {

LOGGER.debug("Editor opened");
WSEditor editorAccess = pluginWorkspaceAccess.getEditorAccess(editorLocation,
StandalonePluginWorkspace.MAIN_EDITING_AREA);

if (editorAccess != null && !(editorAccess.getCurrentPage() instanceof WSAuthorEditorPage)) {
LOGGER.debug("Switching to Author Mode");
editorAccess.changePage(EditorPageConstants.PAGE_AUTHOR);
LOGGER.debug("Finished switching to Author Mode");
}
}

}, StandalonePluginWorkspace.MAIN_EDITING_AREA);
LOGGER.debug("End app started block");
}
Thanks,

AN
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: ExtensionsBundle activating twice with changePage()

Post by Radu »

Hi,

Indeed it is possible that when you switch to the Author visual editing mode you get an "activated-deactivated-activated" sequence of events, we will look into this and try to avoid it if possible.

Usually the activated callback for an extension should be used to add listeners while the deactivated callback should be used to remove those listeners.
What exactly do you do when an extension gets activated? Activation/deactivation events may also occur when the editing session is in progress.
For example activation and de-activation events also occur when the user switches to the Text editing mode and back to Author or when he revers the file from disk.
What we guarantee is that you will never get two activated events one after the other, without calling "deactivate" on the extensions bundle object before the subsequent activation event is received.

If you are using the activation events to make actual one-time changes to the document, maybe you should make those changes on the editorOpened callback after switching to the Author editing mode.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
ArbitraryName
Posts: 16
Joined: Tue Aug 05, 2014 8:36 pm

Re: ExtensionsBundle activating twice with changePage()

Post by ArbitraryName »

Thanks Radu. The code in the AuthorExtensionStateListener activated is needed to run the first time every document is opened. Our documents contain some reference data which may have changed since the last time a user opened the document and this process ensures it is updated.

From what I have seen there are fundamental differences between programatically manipulating the XML in a TextEditorPage vs an AuthorEditorPage and it is highly desirable that we not have to write our functionality two different ways to accomplish the same thing. Our code is already fully implemented using the Author paradigm and we are trying to leverage that. If we were to attempt to manipulate the XML directly in an documentOpened() method we would need to be able to handle both ways, or as I have attempted, force the user into the Author page.

I have seen that the AuthorExtensionStateListener is deactivated/activated when switching between Text and Author pages, but what I am also seeing is that the ExtensionsBundle itself is loading twice. If this were not the case I believe I would have additional options to get things working the way we desire.

The way I test this is to have a document opened in a Text page, close Oxygen, re-open Oxygen. This triggers the above code which forces Author page.

Thanks,

AN
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: ExtensionsBundle activating twice with changePage()

Post by Radu »

Hi,

I was just saying that when you receive the editorOpened callback, after you make the page switch using

Code: Select all

 editorAccess.changePage(EditorPageConstants.PAGE_AUTHOR);
you can obtain the current editing page, cast it to ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPage and make changes to the internal model. The changes to the internal model need to be made on the AWT thread, while the editorOpened callback comes on another thread so all your work with the API which changes the internal model needs to be done in a runnable invoked using javax.swing.SwingUtilities.invokeAndWait(Runnable).

Again, even if you leave your processing on the activated() callback, the second time you receive the callback you can try to see if the internal XML nodes model needs updates and if it seems to be already updated do nothing.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply