Page 1 of 1

Helpful error messages for Actions

Posted: Fri Jan 28, 2011 6:49 am
by dcramer
Hi there,
Actions are very flexible and useful and I'm creating bunches of them. I do sometimes find myself wanting to be able to specify a helpful error message sometimes. E.g. Say I write the xpath such that a PI can only be the child of an entry (because this PI controls the rotation of text in table cells). I'd like to be able to specify a message like "These PIs must be the direct children of table cells." Which would be more helpful than "The Action...is not available in the current context"

Thanks,
David

Re: Helpful error messages for Actions

Posted: Fri Jan 28, 2011 12:18 pm
by Radu
Hi David,

The solution for this would be to use a very permissive XPath for your operation (like true()) which will mean that your operation is always called.

Then on the

Code: Select all

 /**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
implementation you can check for yourself if the caret position is inside a valid XML element.
The ro.sync.ecss.extensions.api.AuthorDocumentController has methods which can be used to evaluate an XPath at the caret position.
Then you have full control over the error message to report either by throwing an AuthorOperationException or by showing the error message yourself:

Code: Select all

authorAccess.getWorkspaceAccess().showErrorMessage(message)
Regards,
Radu