Refresh KeyDefinitionInfo values

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Konstantin
Posts: 61

Refresh KeyDefinitionInfo values

Fri Sep 30, 2016 2:25 pm

Hello
We use Webapp 18.0.0.6

In our application we use different reuse elements like this:

Code: Select all

<ph keyref="keyword_q"/>

In one moment value of this Keyword is changed and I need refresh it in editor.

I use KeyDefinitionManager and fill KeyDefinitionInfo for this editor with.

Code: Select all

public class WorkspacePluginExtension implements WorkspaceAccessPluginExtension {

   private static WebappKeyDefinitionManager keyManager = new WebappKeyDefinitionManager();

   @Override
   public void applicationStarted(final StandalonePluginWorkspace workspace) {

      final WebappPluginWorkspace webappWorcspace = (WebappPluginWorkspace) workspace;
      webappWorcspace.setDITAKeyDefinitionManager(keyManager);
..........

Code: Select all

public class WebappKeyDefinitionManager extends KeyDefinitionManager {
....
    private void fillKeys(final URL url, final List<KeyDefinitionElement> list) {
      
      final String editorUID = Utils.getEditorUID(url.toString());
      List<KeyDefinitionInfo> keyDefinitions = keysMap.get(editorUID);

      if (keyDefinitions == null) {
         keyDefinitions = new ArrayList<>();
         keysMap.put(editorUID, keyDefinitions);
      } else {
         keyDefinitions.clear();
      }

         for (final KeyDefinitionElement element : list) {

            final KeyDefinitionInfo info = new KeyDefinitionInfo();
            final String query = url.getQuery();

            final StringBuilder dwUrl = new StringBuilder();
            ...

            final URL correct = CorrectURLUtil.correct(new URL(dwUrl.toString()));

            info.setProperty(KeyDefinitionInfo.DEFINITION_LOCATION, correct);
            info.setProperty(KeyDefinitionInfo.NAME, element.getName());
            info.setProperty(KeyDefinitionInfo.HREF, element.getLocation());

            ....

            keyDefinitions.add(info);
         }
   }

Then I need refresh editor to change values.
For this I use JS:

Code: Select all

editor.restoreContent();

but it does not help. I must get request on Servlet to take content for this reuse elements but it does not happen.

How can I update "keyref" or "conkeyref" in editor ?
Konstantin
Posts: 61

Re: Refresh KeyDefinitionInfo values

Fri Sep 30, 2016 4:03 pm

I found this answer and it works:
topic10642.html#p30978

Code: Select all

AuthorActionsProvider actionsProvider = authorAccess.getEditorAccess().getActionsProvider();
Map<String, Object> authorCommonActions = actionsProvider.getAuthorCommonActions();
Object refreshRefAction = authorCommonActions.get("Author/Refresh_references");
actionsProvider.invokeAction(refreshRefAction);

But it was for Applet low than 16 version

Maybe there is better way to do it ?
Gabriel Titerlea
Posts: 36

Re: Refresh KeyDefinitionInfo values

Mon Oct 03, 2016 10:49 am

Maybe there is better way to do it ?


Hello,

Calling:

Code: Select all

AuthorActionsProvider actionsProvider = authorAccess.getEditorAccess().getActionsProvider();
Map<String, Object> authorCommonActions = actionsProvider.getAuthorCommonActions();
Object refreshRefAction = authorCommonActions.get("Author/Refresh_references");
actionsProvider.invokeAction(refreshRefAction);

inside a ro.sync.ecss.extensions.api.AuthorOperation#doOperation method is the correct method of refreshing references values.

There is no better way.

Best,
Gabriel
Konstantin
Posts: 61

Re: Refresh KeyDefinitionInfo values

Mon Oct 03, 2016 2:29 pm

Ok, thanks
aleh.haidash
Posts: 27

Re: Refresh KeyDefinitionInfo values

Thu Nov 03, 2016 12:09 pm

Hello.

Code: Select all

AuthorActionsProvider actionsProvider = authorAccess.getEditorAccess().getActionsProvider();
Map<String, Object> authorCommonActions = actionsProvider.getAuthorCommonActions();
Object refreshRefAction = authorCommonActions.get("Author/Refresh_references");
actionsProvider.invokeAction(refreshRefAction);


Using this way for refreshing content I set dirty status to TRUE and activate Redo button. It's not well for me. How can I refresh references without setting status dirty? or maybe can I change dirty to FALSE after that operation?

Thanks.
Best Regards,
Aleh
Gabriel Titerlea
Posts: 36

Re: Refresh KeyDefinitionInfo values

Fri Nov 04, 2016 4:18 pm

aleh.haidash wrote:How can I refresh references without setting status dirty? or maybe can I change dirty to FALSE after that operation?


Hello,

What version of Web Author are you using? How is a user initiating the call to the refresh references action? I was not able to reproduce the bug where the Redo button is activated after calling the refresh actions method.

Regarding the dirty status, assuming you have defined an author operation which refreshes actions:

Code: Select all

package com.example;
public class RefreshReferences implements AuthorOperation {

  @Override
  public String getDescription() {
    return "Description";
  }

  @Override
  public void doOperation(AuthorAccess authorAccess, ArgumentsMap arg1)
      throws IllegalArgumentException, AuthorOperationException {
    AuthorActionsProvider actionsProvider = authorAccess.getEditorAccess().getActionsProvider();
    Map<String, Object> authorCommonActions = actionsProvider.getAuthorCommonActions();
    Object refreshRefAction = authorCommonActions.get("Author/Refresh_references");
    actionsProvider.invokeAction(refreshRefAction);
  }

  @Override
  public ArgumentDescriptor[] getArguments() {
    return null;
  }

}


You can call this action from javascript [1] and you can save the dirty status of the document before calling the method and set it back afterwards:

Code: Select all

JavascriptRefreshAction.prototype.actionPerformed = function(callback) {
  var wasDirty = this.editor.isDirty();
  this.editor.getActionsManager().invokeOperation(
    'com.example.RefreshReferences', {},
    function () {
      this.editor.setDirty(wasDirty);
      callback();
    }.bind(this));
};


[1] https://www.oxygenxml.com/maven/com/oxy ... ction.html

Best,
Gabriel
aleh.haidash
Posts: 27

Re: Refresh KeyDefinitionInfo values

Tue Nov 08, 2016 3:26 pm

Thanks, It works.
Best Regards,
Aleh

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 2 guests