Refresh KeyDefinitionInfo values

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Refresh KeyDefinitionInfo values

Post by Konstantin »

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
Joined: Tue Oct 27, 2015 11:49 am

Re: Refresh KeyDefinitionInfo values

Post by Konstantin »

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
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: Refresh KeyDefinitionInfo values

Post by Gabriel Titerlea »

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
Joined: Tue Oct 27, 2015 11:49 am

Re: Refresh KeyDefinitionInfo values

Post by Konstantin »

Ok, thanks
aleh.haidash
Posts: 32
Joined: Tue May 26, 2015 10:28 am

Re: Refresh KeyDefinitionInfo values

Post by aleh.haidash »

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
Site Admin
Posts: 95
Joined: Thu Jun 09, 2016 2:01 pm

Re: Refresh KeyDefinitionInfo values

Post by Gabriel Titerlea »

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: 32
Joined: Tue May 26, 2015 10:28 am

Re: Refresh KeyDefinitionInfo values

Post by aleh.haidash »

Thanks, It works.
Best Regards,
Aleh
Post Reply