Node selection listener

Oxygen general issues.
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

Node selection listener

Post by maxim.kovalev »

Hi all
Tell me whether there is a listener that is triggered by Oxygen on the node selection?

thanks
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Node selection listener

Post by mihaela »

Hi Maxim,

You can add an AuthorCaretListener to the Author Editor Access and find the selected node when the caret position is updated:

Code: Select all

authorAccess.getEditorAccess().addAuthorCaretListener(caretListener);
To find if there is a selection in the Author page:

Code: Select all

boolean hasSelection = authorAccess.getEditorAccess().hasSelection();
To find the node which is perfectly surrounded by the current selection in the Author editor, you can call the following method (available in Author Editor Access):

Code: Select all

AuthorNode getFullySelectedNode()
This method was introduced in oXygen version 13.1.

For older oXygen versions, here is a sample of how you can get the fully selected node:

Code: Select all


boolean hasSelection = authorAccess.getEditorAccess().hasSelection();
if (hasSelection) {
// Find the selection start offset
int selStart = authorAccess.getEditorAccess().getSelectionStart();
// Find the selection end offset
int selEnd = authorAccess.getEditorAccess().getSelectionEnd();
// Find if an Author node starts at selection start offset
OffsetInformation info = authorAccess.getDocumentController().getContentInformationAtOffset(selStart);
if (info.getPositionType() == OffsetInformation.ON_START_MARKER) {
// Find if an this node ends at selection end offset
if (info.getNodeForMarkerOffset().getEndOffset() == selEnd - 1) {
// This is the the fully selected node
System.out.println("Fully selected node: " + info.getNodeForMarkerOffset().getName());
}
}
}
This is the link to the online Author SDK Javadoc:
http://www.oxygenxml.com/InstData/Edito ... index.html

Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

Re: Node selection listener

Post by maxim.kovalev »

Hi Mihaela

boolean hasSelection = authorAccess.getEditorAccess().hasSelection();
I for some reason always returns false
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

Re: Node selection listener

Post by maxim.kovalev »

boolean hasSelection = authorAccess.getEditorAccess().hasSelection();
only works when you select a node on the top panel, and I wanted to get in contact with the cursor contents
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: Node selection listener

Post by mihaela »

Hi Maxim,

If you just want to find the node at caret position:

Code: Select all


int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode nodeAtCaret = authorAccess.getDocumentController().
getNodeAtOffset(caretOffset);
Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

Re: Node selection listener

Post by maxim.kovalev »

sorry =)
the relevant information can be obtained from
authorAccess.getEditorAccess (). addAuthorCaretListener (caretListener);
AuthorCaretEvent arg0.getNode

большое спасибо =)
Post Reply