Reload Editor Contents from Workspace Plugin

Post here questions and problems related to oXygen frameworks/document types.
ankitr
Posts: 11

Reload Editor Contents from Workspace Plugin

Wed Jan 24, 2018 9:20 am

Hi,

I am creating a CMS plugin. I have implemented my plugin as a WorkspaceAccess plugin with a custom protocol handler implementation.
Now, I need to give the user an option of reloading the contents of their editor (discarding any local changes) from the original source (the custom protocol URL). I found the following 2 methods in the SDK documentation:

1) WSEditor.reloadContent(Reader) -- Reloads from provided reader.
2) ro.sync.ecss.extensions.commons.operations.ReloadContentOperation.doOperation(AuthorAccess, ArgumentsMap) -- Reloads from the original source.

I am currently using the first (1) method, but it doesn't quite fit my requirement as it marks the file dirty. While all I want is to just tell the editor that the file has been modified from outside, and just reload from the original source and mark it not dirty instead.

The second method seems perfect for my use case, just that I could not find a way to obtain an instance of AuthorAccess in a WorkspaceAccess plugin.

I want to know if there is a better way of achieving what I'm trying to do? Or how to obtain the AuthorAccess instance so that I can call ReloadContentOperation.

Thanks,
Ankit
mihaela
Posts: 185

Re: Reload Editor Contents from Workspace Plugin

Wed Jan 24, 2018 4:46 pm

Hi,

To obtain the AuthorAccess in a WorkspaceAccess plugin you have to add an editor changed listener that allows you to get access to the editor page:

Code: Select all

    @Override
    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);
          WSEditorPage edPage = editorAccess.getCurrentPage();
          if(edPage instanceof WSAuthorEditorPage){
            // Get the author access
            AuthorAccess authorAccess = ((WSAuthorEditorPage)edPage).getAuthorAccess();
            // Your code here...
          }
        }
      }, PluginWorkspace.MAIN_EDITING_AREA);
    }


Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
ankitr
Posts: 11

Re: Reload Editor Contents from Workspace Plugin

Wed Apr 25, 2018 10:14 pm

Hi Mihaela,

Thanks for your reply.

I am using the ReloadContentOperation class for this purpose. The doOperation() method takes 2 parameters. I checked the documentation (https://www.oxygenxml.com/InstData/Editor/SDK/javadoc/ro/sync/ecss/extensions/commons/operations/ReloadContentOperation.html) but couldn't figure out what I'm supposed to pass in the second parameter: ArgumentsMap. I tried passing null to this and it seems to work. Although, I am not very sure of any unintended side effects. Could you help me with this?

My usage of this API is as below. Could you please confirm if this is correct:

Code: Select all

URL url = /* get a url instance */
WSEditor editor = Globals.workspaceAccess.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
           
            if (editor != null) {
                WSEditorPage edPage = editor.getCurrentPage();
                if (edPage instanceof WSAuthorEditorPage) {
                    AuthorAccess authAccess = ((WSAuthorEditorPage) edPage).getAuthorAccess();
                    ReloadContentOperation operation = new ReloadContentOperation();
                   
                    operation.doOperation(authAccess, null);
                }
            }


Regards,
Ankit
mihaela
Posts: 185

Re: Reload Editor Contents from Workspace Plugin

Thu Apr 26, 2018 11:26 am

Hi,

The ReloadContentOperation accepts a single argument named "markAsNotModified" that can be used to prevent the editor from showing as modified after reload. The default value is "false", so you must explicitly set it to "true" if you want the file not being marked as dirty.

In general, to find what arguments are available for a specific operation you can:
  • Check the "Author Mode Default Operations" documentaton page [1] (the ReloadContentOperation is not yet included, but we will add it in a near future)
  • Invoke the getArguments() method on the operation and list the arguments names
  • Create an action in the Oxygen XML Editor that uses this operation [2] and check the arguments listed in the "Action" dialog [3]

[1] https://www.oxygenxml.com/doc/ug-editor/topics/dg-default-author-operations.html
[2] https://www.oxygenxml.com/doc/ug-editor/topics/the-actions-sub-tab.html
[3] https://www.oxygenxml.com/doc/ug-editor/topics/the-action-dialog.html#the-action-dialog

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 1 guest