The AuthorSchemaAwareEditingHandlerAdapter extension point allows you to handle
certain Author mode actions in various ways. For example, implementing
the AuthorSchemaAwareEditingHandlerAdapter makes it possible to handle events
such as typing, the keyboard delete event at a given offset (using Delete or Backspace keys),
delete element tags, delete selection, join elements, or paste fragment. It also makes it
possible to improve solutions that are proposed by the paste mechanism in Oxygen XML Author Eclipse plugin when pasting content (through the use of some specific methods).
For this handler to be called, the Schema-Aware Editing option must be set to On or
Custom in the Schema-Aware preferences page. The handler can either
resolve a specific case, let the default implementation take place, or reject the edit
entirely by throwing an InvalidEditException.
Typing events can be handled using the handleTyping method. For example, the
AuthorSchemaAwareEditingHandler checks if the schema is not a learned
one, was loaded successfully, and if the Smart paste and drag and drop option is selected. If
these conditions are met, the event will be handled.
public class AuthorSchemaAwareEditingHandlerAdapter
extends AuthorSchemaAwareEditingHandler {
/**
* @see 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;
}