Page 1 of 1
Node selection listener
Posted: Wed Nov 23, 2011 9:49 am
by maxim.kovalev
Hi all
Tell me whether there is a listener that is triggered by Oxygen on the node selection?
thanks
Re: Node selection listener
Posted: Wed Nov 23, 2011 2:13 pm
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):
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
Re: Node selection listener
Posted: Wed Nov 23, 2011 5:39 pm
by maxim.kovalev
Hi Mihaela
boolean hasSelection = authorAccess.getEditorAccess().hasSelection();
I for some reason always returns false
Re: Node selection listener
Posted: Wed Nov 23, 2011 5:53 pm
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
Re: Node selection listener
Posted: Wed Nov 23, 2011 6:03 pm
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
Re: Node selection listener
Posted: Wed Nov 23, 2011 6:05 pm
by maxim.kovalev
sorry =)
the relevant information can be obtained from
authorAccess.getEditorAccess (). addAuthorCaretListener (caretListener);
AuthorCaretEvent arg0.getNode
большое спасибо =)