// Getting the text cursor
XTextCursor xtextcursor = xsimpletext.createTextCursor();
// Querying for the interface XTextRange
XTextRange xtextrange = ( XTextRange )
UnoRuntime.queryInterface( XTextRange.class, xtextcursor );
// Getting the bug ID from the cell
String sBugID = xtextrange.getString();
if ( !sBugID.startsWith(
"http://www.openoffice.org/issues/show_bug.cgi?id=") ) {
String sBugIDLink =
"http://www.openoffice.org/issues/show_bug.cgi?id=" + sBugID;
// Querying for the interface XMultiServiceFactory
XMultiServiceFactory xMSFTextField =
(XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, aInstance );
// Creating an instance of the text field URL
Object objectTextField =
xMSFTextField.createInstance(
"com.sun.star.text.TextField.URL" );
// Querying for the interface XTextField
XTextField xtextfield = ( XTextField )
UnoRuntime.queryInterface( XTextField.class,
objectTextField );
// Querying for the interface XPropertySet
XPropertySet xpropertysetTextField = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class,
xtextfield );
// Setting the URL
xpropertysetTextField.setPropertyValue( "URL",
sBugIDLink );
// Setting the representation of the URL
xpropertysetTextField.setPropertyValue( "Representation",
sBugID );
// Querying for the interface XText
XText xtext = ( XText )UnoRuntime.queryInterface(
XText.class, xcell );
// Delete cell content
xtextrange.setString( "" );
// Inserting the text field URL to the cell
xtext.insertTextContent( xtextrange, xtextfield, false );
}
}