XNameAccess xContainer = (XNameAccess) UnoRuntime.queryInterface(
XNameAccess.class, mxFactory.createInstance (
"com.sun.star.text.AutoTextContainer" ) );
// Create a new table at the document factory
XTextTable xTable = (XTextTable) UnoRuntime.queryInterface(
XTextTable.class, mxDocFactory .createInstance(
"com.sun.star.text.TextTable" ) );
// Store the names of all auto text groups in an array of strings
String[] aGroupNames = xContainer.getElementNames();
// Make sure we have at least one group name
if ( aGroupNames.length > 0 )
{
// initialise the table to have a row for every autotext group
//in a single column + one
// additional row for a header
xTable.initialize( aGroupNames.length+1,1);
// Access the XPropertySet of the table
XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, xTable );
// We want a visible background
xTableProps.setPropertyValue( "BackTransparent", new Boolean(false));
// We want the background to be light blue
xTableProps.setPropertyValue( "BackColor", new Integer(13421823));
// Inser the table into the document
mxDocText.insertTextContent( mxDocCursor, xTable, false);
// Get an XIndexAccess to all table rows
XIndexAccess xRows = xTable.getRows();
// Get the first row in the table
XPropertySet xRow = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, xRows.getByIndex ( 0 ) );
// We want the background of the first row to be visible too
xRow.setPropertyValue( "BackTransparent", new Boolean(false));
// And let's make it dark blue
xRow.setPropertyValue( "BackColor", new Integer(6710932));
// Put a description of the table contents into the first cell
insertIntoCell( "A1", "AutoText Groups", xTable);
// Create a table cursor pointing at the second cell in the first column
XTextTableCursor xTableCursor = xTable.createCursorByCellName ( "A2" );
// Loop over the group names
for ( int i = 0 ; i < aGroupNames.length ; i ++ )
{
// Get the name of the current cell
String sCellName = xTableCursor.getRangeName ();
// Get the XText interface of the current cell
XText xCellText = (XText) UnoRuntime.queryInterface (
XText.class, xTable.getCellByName ( sCellName ) );
// 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 gruop 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] );