Class DefaultAuthorActionEventHandler

java.lang.Object
ro.sync.ecss.extensions.api.AuthorActionEventHandlerBase
ro.sync.ecss.extensions.api.DefaultAuthorActionEventHandler
All Implemented Interfaces:
AuthorActionEventHandler, Extension
Direct Known Subclasses:
DITAAuthorActionEventHandler, DocbookAuthorActionEventHandler, TEIAuthorActionEventHandler, XHTMLAuthorActionEventHandler

@API(type=EXTENDABLE, src=PUBLIC) public class DefaultAuthorActionEventHandler extends AuthorActionEventHandlerBase
Intercepts TAB and SHIFT+TAB events inside a list item and promotes or demotes it.
Since:
18
  • Constructor Details

    • DefaultAuthorActionEventHandler

      public DefaultAuthorActionEventHandler()
  • Method Details

    • handleEvent

      public boolean handleEvent(AuthorAccess authorAccess, AuthorActionEventHandler.AuthorActionEventType eventType)
      Description copied from interface: AuthorActionEventHandler
      An event was generated.
      Parameters:
      authorAccess - Author access.
      eventType - The type of the generated event.
      Returns:
      true if the event was handled and the default operation should be skipped, false to let the default operation execute.
      See Also:
    • getPreferredXMLElementContent

      protected String getPreferredXMLElementContent(AuthorAccess authorAccess)
      Get the preferred XML element content to be inserted. Can be null.
      Parameters:
      authorAccess - The author access.
      Returns:
      the preferred XML element content to be inserted. Can be null
    • getParagraphElement

      protected String getParagraphElement(AuthorAccess authorAccess)
      Get the preferred XML element content to be inserted. Can be null.
      Parameters:
      authorAccess - The author access.
      Returns:
      the preferred XML element content to be inserted.
    • isMovableListItem

      protected boolean isMovableListItem(AuthorAccess authorAccess, AuthorNode candidate)
      Checks if this node represents a list item that can be promoted/demoted.
      Parameters:
      authorAccess - The Author access.
      candidate - The node that candidates for promotion/demotion.
      Returns:
      true if the list item can be promoted/demoted.
    • promote

      protected ContentInterval promote(AuthorDocumentController controller, int offset, List<AuthorNode> candidates, boolean hasSelection) throws BadLocationException, AuthorOperationException
      Unwraps these list items from the list. Moves them up one level in the hierarchy of nested lists.
      Parameters:
      controller - Author document controller.
      offset - If there is no selection, this is the offset where the action is invoked. Otherwise, this represents the end offset of the selection, needed for restoring caret position.
      candidates - The list items to promote.
      hasSelection - true if the promotion is performed on a selection.
      Returns:
      If there was no selection, return an interval from the next caret position to itself. Otherwise, if the selection was forward, return an interval from the lower offset to the higher one, or if the selection was backward, return an interval from the higher offset to the lower one. "From" means start offset and "to" means end offset.
      Throws:
      BadLocationException
      AuthorOperationException
    • promoteSubListItems

      protected void promoteSubListItems(AuthorDocumentController controller, AuthorNode theDemotedCandidate, AuthorNode listElement) throws BadLocationException, AuthorOperationException
      Sometimes, when we demote a list item, we want it to become the sibling of its children. To obtain this, after demoting the item along with its children, we promote the children. This method promotes the children.
      Parameters:
      controller - The Author document controller.
      theDemotedCandidate - The candidate which was demoted.
      listElement - The parent list of the demoted item.
      Throws:
      AuthorOperationException
      BadLocationException
    • isList

      protected boolean isList(AuthorNode node)
      Check if the given node is a list.
      Parameters:
      node - The node.
      Returns:
      true if the node is a list.
    • areCompatibleLists

      protected boolean areCompatibleLists(AuthorNode node1, AuthorNode node2)
      Check if two given nodes are compatible lists (i.e. if we accept items from one list to migrate into the other one).
      Returns:
      true if the two given nodes are compatible lists.
    • canHandleEvent

      public boolean canHandleEvent(AuthorAccess authorAccess, AuthorActionEventHandler.AuthorActionEventType type)
      Description copied from interface: AuthorActionEventHandler
      Check if an Author action event can be handled.
      Parameters:
      authorAccess - Access to the Author API.
      type - The type of event generated.
      Returns:
      true if the Author action event can be handled.
      See Also:
    • getDescription

      public String getDescription()
      Returns:
      The description of the extension.
      See Also:
    • getContentCompletionActions

      public List<IAuthorExtensionAction> getContentCompletionActions(AuthorAccess authorAccess, int caretOffset)
      Intercepts action events in the Author mode and provides them in the content completion lists.
      Overrides:
      getContentCompletionActions in class AuthorActionEventHandlerBase
      Parameters:
      authorAccess - The author access.
      caretOffset - The caret offset.
      Returns:
      The content completion actions.