// Set the cell contents of the current cell to be
//the name of the of an autotext group
xCellText.setString ( aGroupNames[i] );
// Access the autotext group with this name
XAutoTextGroup xGroup = (XAutoTextGroup)
UnoRuntime.queryInterface (XAutoTextGroup.class,
xContainer.getByName(aGroupNames[i]));
// Get the titles of each autotext block in this group
String [] aBlockNames = xGroup.getTitles();
// Make sure that the autotext group contains at least one block
if ( aBlockNames.length > 0 )
{
// Split the current cell vertically into two seperate cells
xTableCursor.splitRange ( (short) 1, false );
// Put the cursor in the newly created right hand cell
// and select it
xTableCursor.goRight ( (short) 1, false );
// Split this cell horizontally to make a seperate cell
// for each Autotext block
if ( ( aBlockNames.length -1 ) > 0 )
xTableCursor.splitRange (
(short) (aBlockNames.length - 1), true );
// loop over the block names
for ( int j = 0 ; j < aBlockNames.length ; j ++ )
{
// Get the XText interface of the current cell
xCellText = (XText) UnoRuntime.queryInterface (
XText.class, xTable.getCellByName (
xTableCursor.getRangeName() ) );
// Set the text contents of the current cell to the
// title of an Autotext block
xCellText.setString ( aBlockNames[j] );
// Move the cursor down one cell
xTableCursor.goDown( (short)1, false);
}
}
// Go back to the cell we originally split
xTableCursor.gotoCellByName ( sCellName, false );
// Go down one cell
xTableCursor.goDown( (short)1, false);
}
XAutoTextGroup xGroup;
String [] aBlockNames;
// Add a depth so that we only generate 200 numbers before giving up
// on finding a random autotext group that contains autotext blocks
int nDepth = 0;
do
{
// Generate a random, positive number which is lower than
// the number of autotext groups
int nRandom = Math.abs ( maRandom.nextInt() %
aGroupNames.length );
// Get the autotext group at this name
xGroup = ( XAutoTextGroup ) UnoRuntime.queryInterface (
XAutoTextGroup.class, xContainer.getByName (
aGroupNames[ nRandom ] ) );
// Fill our string array with the names of all the blocks in
// this group
aBlockNames = xGroup.getElementNames();
// increment our depth counter
++nDepth;
}
while ( nDepth < 200 && aBlockNames.length == 0 );
// If we managed to find a group containg blocks...
if ( aBlockNames.length > 0 )
{
// Pick a random block in this group and get it's
// XAutoTextEntry interface
int nRandom = Math.abs ( maRandom.nextInt()
% aBlockNames.length );
XAutoTextEntry xEntry = ( XAutoTextEntry )
UnoRuntime.queryInterface (
XAutoTextEntry.class, xGroup.getByName (
aBlockNames[ nRandom ] ) );
// insert the modified autotext block at the end of the document
xEntry.applyTo ( mxDocCursor );
// Get the titles of all text blocks in this AutoText group
String [] aBlockTitles = xGroup.getTitles();
// Get the XNamed interface of the autotext group
XNamed xGroupNamed = ( XNamed ) UnoRuntime.queryInterface (
XNamed.class, xGroup );