Verified Owner
Top Description Fields Constructors Methods
org.jabref.model.openoffice.uno

public Class UnoSelection

extends Object
Class Inheritance
Imports
java.util.Optional, com.sun.star.frame.XController, com.sun.star.lang.XServiceInfo, com.sun.star.text.XTextDocument, com.sun.star.view.XSelectionSupplier, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

Selection in the document.

Field Summary

Modifier and TypeField and Description
private static final Logger

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Optional<com.sun.star.lang.XServiceInfo>
getSelectionAsXServiceInfo(@NonNull com.sun.star.text.XTextDocument doc)

Returns: may be Optional.empty(), or some type supporting XServiceInfo So far it seems the first thing we have to do with a selection is to decide what do we have.

private static Optional<com.sun.star.view.XSelectionSupplier>
getSelectionSupplier(com.sun.star.text.XTextDocument doc)

public static void
select(@NonNull com.sun.star.text.XTextDocument doc, Object newSelection)

Select the object represented by newSelection if it is known and selectable in this XSelectionSupplier object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

UnoSelectionback to summary
private UnoSelection()

Method Detail

getSelectionAsXServiceInfoback to summary
public static Optional<com.sun.star.lang.XServiceInfo> getSelectionAsXServiceInfo(@NonNull com.sun.star.text.XTextDocument doc)
Returns:Optional<com.sun.star.lang.XServiceInfo>

may be Optional.empty(), or some type supporting XServiceInfo So far it seems the first thing we have to do with a selection is to decide what do we have.

One way to do that is accessing its XServiceInfo interface.

Experiments using printServiceInfo with cursor in various positions in the document:

With cursor within the frame, in text: *** xserviceinfo.getImplementationName: "SwXTextRanges" "com.sun.star.text.TextRanges"

With cursor somewhere else in text: *** xserviceinfo.getImplementationName: "SwXTextRanges" "com.sun.star.text.TextRanges"

With cursor in comment (also known as "annotation"): *** XSelectionSupplier is OK *** Object initialSelection is null *** xserviceinfo is null

With frame selected: *** xserviceinfo.getImplementationName: "SwXTextFrame" "com.sun.star.text.BaseFrame" "com.sun.star.text.TextContent" "com.sun.star.document.LinkTarget" "com.sun.star.text.TextFrame" "com.sun.star.text.Text"

With cursor selecting an inserted image: *** XSelectionSupplier is OK *** Object initialSelection is OK *** xserviceinfo is OK *** xserviceinfo.getImplementationName: "SwXTextGraphicObject" "com.sun.star.text.BaseFrame" "com.sun.star.text.TextContent" "com.sun.star.document.LinkTarget" "com.sun.star.text.TextGraphicObject"

getSelectionSupplierback to summary
private static Optional<com.sun.star.view.XSelectionSupplier> getSelectionSupplier(com.sun.star.text.XTextDocument doc)
selectback to summary
public static void select(@NonNull com.sun.star.text.XTextDocument doc, Object newSelection)

Select the object represented by newSelection if it is known and selectable in this XSelectionSupplier object.

Presumably result from XSelectionSupplier.getSelection() is usually OK. It also accepted XTextRange newSelection = doc.getText().getStart();