Page 1 of 1

showStatusMessage

Posted: Fri Aug 17, 2012 3:49 pm
by patrick
Hi,

I try to use showStatusMessage in a for loop in a custom oxygen plugin to display the status while replacing some elements in the document. It should show the progress, e.g. "x of y nodes replaced" but the status appear only after the plugin is finished. How can I push a 'live' message to the oxygen status bar?

Thanks,
Patrick

Re: showStatusMessage

Posted: Fri Aug 17, 2012 4:22 pm
by Radu
Hello Patrick,

This is the usual behavior of swing applications.
An AuthorOperation is executed on the Java AWT thread.
As long as the AWT thread is busy (performing the operation's code) repaint is not done in the entire application as the repaint should also be made by the AWT thread.

What you could try to do would be to start a thread which performs the operation's code.
But be careful to invoke all the code which interacts with our internal model on the AWT thread using javax.swing.SwingUtilities.invokeAndWait(Runnable) because the Author model is not thread safe.

So your code could look a little like this:

Code: Select all

  /**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
@Override
public void doOperation(final AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
new Thread("modifying thread"){
public void run() {
for (int i = 0; i < 100; i++) {
authorAccess.getWorkspaceAccess().showStatusMessage("THE STATUS " + i);

//And modify some nodes
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
authorAccess.getDocumentController().setAttribute("test", new AttrValue("val"), element);
}
});
} catch (InterruptedException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}.start();
}
In this way the AWT thread would be freed at times and might be able to show the status change.

Regards,
Radu