Helpful error messages for Actions

Are you missing a feature? Request its implementation here.
dcramer
Posts: 161
Joined: Sat Aug 28, 2010 1:23 am

Helpful error messages for Actions

Post 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
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Helpful error messages for Actions

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply