Get multiple selected AuthorNodes
Post here questions and problems related to oXygen frameworks/document types.
Get multiple selected AuthorNodes
Hi I am attempting to get multiple selected nodes (something like List<AuthorNode>) from AuthorAccess object in our custom framework. Consider the scenario of multiple cells selected in a table (we are using oasis:table). You can see from the attached screenshot the user has selected 4 cells across 2 columns and see the corresponding selected elements in the outline view to the left.
I have attempted the following test code:
The log output shows that only the trow parent elements are selected by this:
I am trying to get a List<AuthorNode> of the selected (in this case) <oasis:entry/> elements. Any thoughts?
I have attempted the following test code:
Code: Select all
List<ContentInterval> selections = aa.getEditorAccess().getAuthorSelectionModel().getSelectionIntervals();
for (ContentInterval contentInterval : selections) {
log.debug(aa.getDocumentController().getNodeAtOffset(contentInterval.getStartOffset()).getDisplayName());
}
Code: Select all
7004548 DEBUG[ AWT-EventQueue-0 ] ca.bc.gov.qp.civix.municipal.action.TableOperation - oasis:trow
7005643 DEBUG [ AWT-EventQueue-0 ] ca.bc.gov.qp.civix.municipal.action.TableOperation - oasis:trow
Re: Get multiple selected AuthorNodes
Hi,
The internal hierarchy of AuthorNode nodes looks like the one in this image:
https://www.oxygenxml.com/InstData/Edit ... gment.html
Each node has an inclusive start offset and an inclusive end offset.
When you are calling this method:
the API considers that the offset represents a caret position, so the actual node which will be returned will not be the node containing the start offset but the node which is its parent. So in this case asking for the node at "contentInterval.getStartOffset() + 1" would return what you expected.
Also the problem is a little bit more complicated, a single selection interval may contain one or more consecutive nodes, so if you look only for the node containing the start of the selection interval, you may not take into consideration nodes which are fully engulfed in the selection.
There is a special API which you could also call for each selection interval:
and the merge all returned nodes in a list/set.
Regards,
Radu
The internal hierarchy of AuthorNode nodes looks like the one in this image:
https://www.oxygenxml.com/InstData/Edit ... gment.html
Each node has an inclusive start offset and an inclusive end offset.
When you are calling this method:
Code: Select all
aa.getDocumentController().getNodeAtOffset(contentInterval.getStartOffset())
Also the problem is a little bit more complicated, a single selection interval may contain one or more consecutive nodes, so if you look only for the node containing the start of the selection interval, you may not take into consideration nodes which are fully engulfed in the selection.
There is a special API which you could also call for each selection interval:
Code: Select all
ro.sync.ecss.extensions.api.AuthorDocumentController.getNodesToSelect(int, int)
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Re: Get multiple selected AuthorNodes
After looking at your answer it seems I was almost there. Combining the .getNodesToSelect() method with results returned from .getSelectionIntervals() gave me what i was looking for. The following code snippet works, even when there is no selection:
Thanks again for your help, Radu!
Code: Select all
List<ContentInterval> selections = aa.getEditorAccess().getAuthorSelectionModel().getSelectionIntervals();
for (ContentInterval contentInterval : selections) {
List<AuthorNode> selected = aa.getDocumentController().getNodesToSelect(
contentInterval.getStartOffset(),
contentInterval.getEndOffset()
);
for (AuthorNode authorNode : selected) {
log.info(authorNode.getDisplayName());
}
}
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service