Listen for changes on specific element / node

Oxygen general issues.
cditcher
Posts: 29
Joined: Thu Jun 21, 2012 6:47 pm
Location: Victoria BC, Canada

Listen for changes on specific element / node

Post by cditcher »

I have a situation where if a user deletes a node from the document, I want to capture the event and ensure that the entire containing fragment is deleted. For example, the following:

Code: Select all


 <heading>
<text>My Heading</text>
</heading>
If the user deletes the <text> (element)node I would like to check if the parent is a <heading> and if so delete the entire <heading><text>...</text></heading>. My initial approach was to create an extension bundle and register it with my framework, override createAuthorExtensionStateListener() and my implementation of AuthorExtensionStateListener sets a document filter on the controller.

Code: Select all

@Override
public void activated(AuthorAccess aa) {
aa.getDocumentController().setDocumentFilter(new MyAuthorDocumentFilter());
}
MyAuthorDocumentFilter overrides deleteNode and delete functions from superclass but these methods do not appear to be called when a user deletes anything from the document. Do filter methods only get called through the api or does internal Oxygen code call them as well?

I have also tried registering my own implementation of AuthorListener which does respond to deleted nodes, text etc but assumed that a filter might be a better approach.

Am I on the right track or is there an easier way to capture and react to changes to specific nodes? Thanks.
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Listen for changes on specific element / node

Post by Radu »

Hi,

The ro.sync.ecss.extensions.api.AuthorDocumentFilter.deleteNode(AuthorDocumentFilterBypass, AuthorNode) is usually called from actions specialized in moving or deleting entire nodes, for example if you delete a node from the Outline view, this action gets called.
If the user presses DEL or BACKSPACE in the editor then usually this callback gets called:

Code: Select all

ro.sync.ecss.extensions.api.AuthorDocumentFilter.delete(AuthorDocumentFilterBypass, int, int, boolean)
Then you would need to use the "ro.sync.ecss.extensions.api.AuthorDocumentController" API to see what exact XML code will be deleted. The user can press DEL or BACKSP either when he has a selection or when there is no selection so the start and end offsets may differ because of this.

Another workaround for you as you have already overwritten the "ExtensionsBundle" base would be to overwrite this method:

Code: Select all

ro.sync.ecss.extensions.api.ExtensionsBundle.getAuthorSchemaAwareEditingHandler()
The Author SDK should contain the Java sources for ro.sync.ecss.extensions.docbook.DocbookSchemaAwareEditingHandler. And you could try to overwrite this method:

Code: Select all

ro.sync.ecss.extensions.api.AuthorSchemaAwareEditingHandlerAdapter#handleDelete(int, int, ro.sync.ecss.extensions.api.AuthorAccess, boolean)
which deals explicitly with various deletions in the Author mode without any prior selection.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
cditcher
Posts: 29
Joined: Thu Jun 21, 2012 6:47 pm
Location: Victoria BC, Canada

Re: Listen for changes on specific element / node

Post by cditcher »

Thanks Radu, I will try the filter approach you mentioned. I have obtained the sdk and it appears classes in the ro.sync.ecss.extensions.docbook package are obfuscated.

Thanks,
Chris
cditcher
Posts: 29
Joined: Thu Jun 21, 2012 6:47 pm
Location: Victoria BC, Canada

Re: Listen for changes on specific element / node

Post by cditcher »

Update: I was able to implement AuthorSchemaAwareHandlingAdapter. I just had to go over the documentation a bit more carefully. Thanks.
Radu
Posts: 9053
Joined: Fri Jul 09, 2004 5:18 pm

Re: Listen for changes on specific element / node

Post by Radu »

Hi Chris,

All the Java sources for the Java extensions implemented for the predefined document types (Docbook, DITA, TEI, XHTML) should be found in the folder oxygenAuthorSDK\samples\Oxygen Default Frameworks.
If you have any suggestions how we could improve the SDK or documentation in order to give developers a better start, please tell us.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply