Set Actions Enable/Disable from Java

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

Set Actions Enable/Disable from Java

Post by Konstantin »

Hi !!!
1. Do you have API in AuthorDocumentModel to get access to Actions (to do they Enable/Disable) ?
2. Do you have API to invoke JS methods from Java ?
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: Set Actions Enable/Disable from Java

Post by cristi_talau »

Hello,
1. Do you have API in AuthorDocumentModel to get access to Actions (to do they Enable/Disable) ?
Unfortunately, no. Depending on the the type and location of the action, we have JS API to mark them enabled/disabled and to refresh the toolbar rendering to reflect the state of the action [1].
2. Do you have API to invoke JS methods from Java ?
Unfortunately, no again. Web Author is designed to respond to user editing actions with JS handlers that in turn call Java services.
So far, this model worked for us, so we are trying to understand your use-case. It would be great if you could offer us some insights about what you are trying to achieve:
1. What JS code would you like to invoke?
2. I am also curious about the Java code that is supposed to call into JS. When is it executed? In response to which user action? Or is it some background task?

Best,
Cristian

[1] http://www.oxygenxml.com/webapp-demo-aw ... sample.xml
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: Set Actions Enable/Disable from Java

Post by Konstantin »

We work generally with Java, in JS I only created actions.
We use Webapp as part of our application inside Iframe and we can open some Editors in different tabs.
We have big functionality which cant be implemented in JS.
We communicate between Webapp and our application thru GET/POST queries and servlets.
So all handlers of my actions implemented in Java.

So for example case:
1) I open new document.
2) Make new changes. In Java I need know that document isDirty for change actions status (action Save - Enable)
3) I click Save. IF save was succesfull I need change Save to Disasble.
4) Then I close Tab with editor in our appication and I need know that is editor has changes to offer to user save them

So in this moment very important for us have API in Java:
1) isDirty editor. We use it very often but you don't have normal API for that.
I use this, but it works bad as I wrote he topic13355.html#p39181:

Code: Select all

goog.events.listen(editor, sync.api.Editor.EventTypes.DIRTY_STATUS_CHANGED, function(e) {		
setDirty(e, editor, function() { });
});

function setDirty(event, editor, callback) {
new sync.ops.ServerOperation("webapp.extention.action.DirtyAction", editor.controller).doOperation(callback, {
"url": editor.options.url,
"isDirty": event.isDirty
}, null);
}
2) action.setEnable(true) Important for upper case. And I need make normal ReadOnly mode with disabled actions

3) Insert and refresh content which came from out application inside editor. As I wrote here topic13372.html#p39242
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: Set Actions Enable/Disable from Java

Post by cristi_talau »

Hello,
We communicate between Webapp and our application thru GET/POST queries and servlets.
So all handlers of my actions implemented in Java.
This is exactly what we do ourselves for the builtin actions.


It seems that you try to implement your version of the builtin Save action. Right?
I can share how we solved these problems with the builtin version of the Save action.
1) I open new document.
2) Make new changes. In Java I need know that document isDirty for change actions status (action Save - Enable)
In the JS code we listen for the "DIRTY_STATUS_CHANGED" event. When the document is not dirty, the JS Save action "isEnabled" method returns false. Moreover, we refresh the toolbar rendering of the Save action using ActionsManager#refreshActions.
3) I click Save. IF save was succesfull I need change Save to Disasble.
The Save action is a AJAX call. Its response message contains the success state of the Save action. Based on that we set/reset the dirty flag.
4) Then I close Tab with editor in our appication and I need know that is editor has changes to offer to user save them
You should listen for the "DIRTY_STATUS_CHANGED" event and add a "unload" listener in JS to prevent the user from leaving the page.

1) isDirty editor. We use it very often but you don't have normal API for that.
I guess the above explanations address this question. Please let me know if the suggestions above are not applicable in your case.
2) action.setEnable(true) Important for upper case. And I need make normal ReadOnly mode with disabled actions
I understand that you have an action that turns a selection in "uppercase" letters and you want to disable it once the letters are made uppercase. Does it insert an XML element, or it just changes the text? Is it an action defined in the framework, or it is added by the plugin?

You can use the AbstractAction#isEnabled and ActionsManager#refreshActionsStatus to enable/disable the action. We currently miss JS API to retrieve the selected text, but that can be added in the upcoming release.
3) Insert and refresh content which came from out application inside editor. As I wrote here topic13372.html#p39242
I understand that the user changes the content of the XML file outside the oXygen editor and you want to force the editor to reload the content. Right?

Assuming this is the case, you need:
1. make the JS code aware that the document content was changed
- One option is that you know in the JS code that embeds the iframe that the content was refreshed. In this case you can use window.postMessage.
- Another option is to have the JS code check whether the document was changed from time to time and on every window focus.
- Another option is to use websockets to provide real-time updates to the JS code. Beware that replacing the editor content while the user is editing may not be desirable.
2. reload the content
- You can invoke an AuthorOperation to reload the content of the document. We have Java API that we use for example when switching back from the text-mode editor: ro.sync.ecss.common.WebappAccess.setTextModeState(AuthorDocumentModel, WebappTextModeState).

Please let me know if I made false assumptions about your situation.

Best,
Cristian
Konstantin
Posts: 61
Joined: Tue Oct 27, 2015 11:49 am

Re: Set Actions Enable/Disable from Java

Post by Konstantin »

I understand that you have an action that turns a selection in "uppercase" letters
I meant case which i explained before. Disable action Save after save...

Can I get callback or response from Java when use :

Code: Select all

   
new sync.ops.ServerOperation("webapp.extention.action.DirtyAction", editor.controller).doOperation(callback, {
"url": editor.options.url,
"isDirty": event.isDirty
}, null);
or

Code: Select all


editor.getActionsManager().invokeOperation( 'ro.sync.ecss.extensions.commons.operations.ChangeAttributeOperation',  {
'name': 'conkeyref',
'value': 'chunk_xxx/p_topic_body_p_5_1'
}
);
cristi_talau
Posts: 495
Joined: Thu Sep 04, 2014 4:22 pm

Re: Set Actions Enable/Disable from Java

Post by cristi_talau »

Hello,

Internally we have a method to get some results from invoking a Java AuthorOperation. I will add API for this in the next version (18.1).

Best,
Cristian
Post Reply