Set prolog revised date on save?

Post here questions and problems related to editing and publishing DITA content.
sanGeoff
Posts: 42
Joined: Mon Aug 18, 2014 11:50 pm

Set prolog revised date on save?

Post by sanGeoff »

Is it possible to get Oxygen to update the revised date on a DITA document when it's saved? I tried updating the attribute during a editorAboutToBeSavedVeto(), EditorListener event, but it throws a java.lang.Error: Fire should be on the AWT thread. error.
Radu
Posts: 9446
Joined: Fri Jul 09, 2004 5:18 pm

Re: Set prolog revised date on save?

Post by Radu »

Hi,

The save action is called on a thread in order not to block the entire application if the content will be saved on a remote server for example.
All modifications to the internal Author editing mode model must be done on the AWT thread so you should call:

Code: Select all

		SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
//YOUR CODE HERE
}
});
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sanGeoff
Posts: 42
Joined: Mon Aug 18, 2014 11:50 pm

Re: Set prolog revised date on save?

Post by sanGeoff »

Ah,, exactly what I needed, thank you so much. I see that now in the the FAQ of the Developer Guide, should have looked harder first. Looks like I need it both ways though, since closing the application or closing the file seems to trigger the save action on the AWT thread.

Code: Select all


if(! SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
//CODE;
}
});
} else
//CODE;


Looks like I might need to find another way though, the editorAboutToBeSavedVeto event triggers before the save-"Yes, No, Cancel" dialog comes up. So if a user presses No or cancel the editor was not actually about to be saved. Humm... I guess I will try the AuthorListener and update the revised date when any change occurs to the document. Or is there a way to recorder the WSEditorListener so my listener is only called after a yes confirm Save on editor close?
Radu
Posts: 9446
Joined: Fri Jul 09, 2004 5:18 pm

Re: Set prolog revised date on save?

Post by Radu »

Hi,
Looks like I need it both ways though, since closing the application or closing the file seems to trigger the save action on the AWT thread.
Exactly, you can probably create an utility method like:

Code: Select all

  /**
* Invokes a runnable synchronously on the AWT thread. The current thread
* may be AWT or not. Returns after the runnable is run.
*
* @param runnable The runnable to be run.
*/
public static void invokeSynchronously(final Runnable runnable) {
if (SwingUtilities.isEventDispatchThread()) {
runnable.run();
} else {
try {
SwingUtilities.invokeAndWait(runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
and call it with a Runnable which contains your code.
Looks like I might need to find another way though, the editorAboutToBeSavedVeto event triggers before the save-"Yes, No, Cancel" dialog comes up. So if a user presses No or cancel the editor was not actually about to be saved. Humm... I guess I will try the AuthorListener and update the revised date when any change occurs to the document. Or is there a way to recorder the WSEditorListener so my listener is only called after a yes confirm Save on editor close?
Yes, the API is called before the dialog is shown. We considered this callback is a good way for the developer to reject the save operation completely (by returning "false") and thus there will be situations when the Save dialog shown by Oxygen can be prohibited to appear.
But it probably does not matter much for your particular situation, you can modify the document and set the revised date even if the user eventually rejects the save on close operation.
The AuthorListener is called quite often (for each small modification) and I would not see it a good place from where to make changes in the XML content.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sanGeoff
Posts: 42
Joined: Mon Aug 18, 2014 11:50 pm

Re: Set prolog revised date on save?

Post by sanGeoff »

Thanks for the reply, that makes sense now that you explain it. Yeah I figured the AuthorListener would be called often. If I did that, I would have had an if(!setOnce) or something so it only sets it once.
Post Reply