Page 1 of 1
Listen for changes on specific element / node
Posted: Sat Nov 30, 2013 3:27 am
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.
Re: Listen for changes on specific element / node
Posted: Mon Dec 02, 2013 11:47 am
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
Re: Listen for changes on specific element / node
Posted: Tue Dec 03, 2013 8:52 pm
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
Re: Listen for changes on specific element / node
Posted: Wed Dec 04, 2013 12:45 am
by cditcher
Update: I was able to implement AuthorSchemaAwareHandlingAdapter. I just had to go over the documentation a bit more carefully. Thanks.
Re: Listen for changes on specific element / node
Posted: Wed Dec 04, 2013 9:39 am
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