You can implement your own handler for actions like typing, delete or paste by providing an implementation of ro.sync.ecss.extensions.api.AuthorSchemaAwareEditingHandler. The Schema Aware Editing must be On or Custom in order for this handler to be called. 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 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 gives the possibility to handle other events like: the keyboard delete event at the given offset (using Delete or Backspace keys), delete element tags, delete selection, join elements or paste fragment.