Hi,
        I have a list of  XText, I need to group them and I need to clear 
them.

I am able to group these Text Items but I am unable to clear these Text 
contents

For grouping I use the following code

//Get the ShapeCollection Object
XMultiServiceFactory xServiceFactory = unoUtility.getServiceFactory();
Object xObj = xServiceFactory.createInstance( 
"com.sun.star.drawing.ShapeCollection" );
XShapes xShapesCollection = (XShapes)UnoRuntime.queryInterface( XShapes.
class, xObj );

//Get all the Shapes from the page
for (all the shapes in the Page){
        XShape myXShape = UNOUtility.getShapeByName(shapeName, xModel);
        XText xMyText = (XText)UnoRuntime.queryInterface(XText.class, 
myXShape);
   }
//Add these Shapes into XShapes Object
xShapesCollection.add((XShape)UnoRuntime.queryInterface(XShape.class, 
myXShape));

//Grouping

XShapeGrouper xShapeGrouper = (XShapeGrouper) UnoRuntime.queryInterface( 
XShapeGrouper.class, xDrawPage );
XShapeGroup xShapeGroup = xShapeGrouper.group( xShapesCollection );

Now I need to clear these Text Shapes and here is the code for the same

        // unoObject is of type --> com.sun.star.drawing.GroupShape
        XShapeGroup xShapeGrp = (XShapeGroup)UnoRuntime.queryInterface
(XShapeGroup.class, unoObject);
        xShapeGrp.enterGroup();
        XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class
, xShapeGrp);
        XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.
queryInterface(XIndexAccess.class, xShapes);
// so I iterate the XShapes, get each XShape and then get XText and clear 
the contents

for(int m = 0 ; m < xIndexAccess.getCount(); m ++){
        Object tempObj = xIndexAccess.getByIndex(m) ;
        xShape = (XShape)UnoRuntime.queryInterface(XShape.class, tempObj);
        XText xText1 = (XText)UnoRuntime.queryInterface(XText.class, 
tempObj);
        System.out.println("xText1.getString() = "+xText1.getString());
        System.out.println("xText1.getText() = "+xText1.getText());
        XTextCursor xTextCursor = xText.createTextCursor();
                if (xTextCursor != null) {
                        xTextCursor.gotoEnd(false);
                        xTextCursor.setString(" ");
                        xTextCursor.goLeft((short)1, false);
                        xTextCursor.gotoStart(true);
                        xTextCursor.setString("");

}
Above code doesn't clear the data from Text.
This is what I get when I print the contents of
 xText1.getText() = 
[Proxy:1771334036,b7ecef8;msci[0];9120d905d911df9cfefedcba987654,Type[com.sun.star.text.XText]]
and     xText1.getString() =   is blank

Can some one please advise?  Thanks in advance.

Thanks and Regards

Mahesh Reddy N
Email: mahesh.re...@in.ibm.com

Reply via email to