To implement your own handler for actions such as typing, deleting, or pasting, provide an implementation of ro.sync.ecss.extensions.api.AuthorSchemaAwareEditingHandler. For this handler to be called, the Schema Aware Editing option must be set to On,or Custom. The handler can either resolve a specific case, let the default implementation take place, or reject the edit entirely by throwing an InvalidEditException.
package simple.documentation.framework.extensions;
/**
* Specific editing support for SDF documents.
* Handles typing and paste events inside section and tables.
*/
public class SDFSchemaAwareEditingHandler implements AuthorSchemaAwareEditingHandler {
Typing events can be handled using the handleTyping method. For example, the SDFSchemaAwareEditingHandler checks if the schema is not a learned one, was loaded successfully, and if Smart Paste is active. If these conditions are met, the event will be handled.
/** * @see ro.sync.ecss.extensions.api.AuthorSchemaAwareEditingHandler#handleTyping(int, char, ro.sync.ecss.extensions.api.AuthorAccess) */ public boolean handleTyping(int offset, char ch, AuthorAccess authorAccess) throws InvalidEditException { boolean handleTyping = false; AuthorSchemaManager authorSchemaManager = authorAccess.getDocumentController().getAuthorSchemaManager(); if (!authorSchemaManager.isLearnSchema() && !authorSchemaManager.hasLoadingErrors() && authorSchemaManager.getAuthorSchemaAwareOptions().isEnableSmartTyping()) { try { AuthorDocumentFragment characterFragment = authorAccess.getDocumentController().createNewDocumentTextFragment(String.valueOf(ch)); handleTyping = handleInsertionEvent(offset, new AuthorDocumentFragment[] {characterFragment}, authorAccess); } catch (AuthorOperationException e) { throw new InvalidEditException(e.getMessage(), "Invalid typing event: " + e.getMessage(), e, false); } } return handleTyping; }
Implementing the AuthorSchemaAwareEditingHandler makes it possible to handle other events, such as the keyboard delete event at the given offset (using Delete or Backspace keys), delete element tags, delete selection, join elements, or paste fragment.