Package ro.sync.ecss.extensions.api
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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ro.sync.ecss.extensions.api.AuthorActionEventHandler
AuthorActionEventHandler.AuthorActionEventType
-
-
Constructor Summary
Constructors Constructor Description DefaultAuthorActionEventHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
areCompatibleLists(AuthorNode node1, AuthorNode node2)
Check if two given nodes are compatible lists (i.e.boolean
canHandleEvent(AuthorAccess authorAccess, AuthorActionEventHandler.AuthorActionEventType type)
Check if an Author action event can be handled.java.util.List<IAuthorExtensionAction>
getContentCompletionActions(AuthorAccess authorAccess, int caretOffset)
Intercepts action events in the Author mode and provides them in the content completion lists.java.lang.String
getDescription()
protected java.lang.String
getParagraphElement(AuthorAccess authorAccess)
Get the preferred XML element content to be inserted.protected java.lang.String
getPreferredXMLElementContent(AuthorAccess authorAccess)
Get the preferred XML element content to be inserted.boolean
handleEvent(AuthorAccess authorAccess, AuthorActionEventHandler.AuthorActionEventType eventType)
An event was generated.protected boolean
isList(AuthorNode node)
Check if the given node is a list.protected boolean
isMovableListItem(AuthorAccess authorAccess, AuthorNode candidate)
Checks if this node represents a list item that can be promoted/demoted.protected ContentInterval
promote(AuthorDocumentController controller, int offset, java.util.List<AuthorNode> candidates, boolean hasSelection)
Unwraps these list items from the list.protected void
promoteSubListItems(AuthorDocumentController controller, AuthorNode theDemotedCandidate, AuthorNode listElement)
Sometimes, when we demote a list item, we want it to become the sibling of its children.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ro.sync.ecss.extensions.api.AuthorActionEventHandler
canHandleEvent, getListItemAncestorToSplit
-
-
-
-
Method Detail
-
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:
AuthorActionEventHandler.handleEvent(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.AuthorActionEventHandler.AuthorActionEventType)
-
getPreferredXMLElementContent
protected java.lang.String getPreferredXMLElementContent(AuthorAccess authorAccess)
Get the preferred XML element content to be inserted. Can benull
.- Parameters:
authorAccess
- The author access.- Returns:
- the preferred XML element content to be inserted. Can be
null
-
getParagraphElement
protected java.lang.String getParagraphElement(AuthorAccess authorAccess)
Get the preferred XML element content to be inserted. Can benull
.- 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, java.util.List<AuthorNode> candidates, boolean hasSelection) throws javax.swing.text.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:
javax.swing.text.BadLocationException
AuthorOperationException
-
promoteSubListItems
protected void promoteSubListItems(AuthorDocumentController controller, AuthorNode theDemotedCandidate, AuthorNode listElement) throws javax.swing.text.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
javax.swing.text.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:
AuthorActionEventHandler.canHandleEvent(AuthorAccess, AuthorActionEventType)
-
getDescription
public java.lang.String getDescription()
- Returns:
- The description of the extension.
- See Also:
Extension.getDescription()
-
getContentCompletionActions
public java.util.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 classAuthorActionEventHandlerBase
- Parameters:
authorAccess
- The author access.caretOffset
- The caret offset.- Returns:
- The content completion actions.
-
-