Hi Marco

Marco Castillo escribió:
Dear list:
I'm inserting textfields into a Text Document. At this point I can create a Text Field and I can insert one text field into a Write Document.
[...]
Now I have a couple of issues. When I try to insert the created field into the 
document again
[...]
I get the following exception raised:
[...]
So my first issue is, how can I insert a recently created text field into a 
Document more than one time?

you can NOT. Once you create an instance of ANY text context (not only
TextField) and insert it, you can not then insert it again by keeping a
reference. The XTextContent you inserted now belongs to the XText where
you inserted it, and it is not allowed to insert it again (not even if
the XText is the same, for example the text body or the text of the same
text frame)

Do I have to use another method than insertTextContent().

no, you must create ANOTHER instance of the TextField. You can do this
programatically by writing a method that returns an instance of the text
filed you want, passing some args (you pass the same args == you get
another instance of the same text field)

The Developer Guide states that the preferred method to insert a text field is insertTextContent().

This is the only method for inserting every text content.

So why am I getting this Exception when
I try to insert the field more than one time?

because this is not allowed! You must create another instance

The second issue is about the cursor position. I need to insert the field in the current cursor position. The method insertTextContent() takes three arguments. The first is a XTextRange that indicates the place within the document where the text field is going to be inserted. How can I get a XTextRange value that belongs to the current cursor position within the text document?

There are mainly two kinds of cursor: modal cursor and the view cursor.
When you say "the current cursor position" you are talking about the
view cursor. View cursor and modal cursor export different interfaces,
but you can create a text cursor for the view cursor using
createTextCursorByRange().

Please see my version of the viewCursorExample() in TextDocuments.java,
you can find it

http://www.ArielConstenlaHaile.com.ar/ooo/temp/TextDocuments_java.zip

and read the Developer's Guide
http://api.openoffice.org/docs/DevelopersGuide/Text/Text.xhtml#1_3_3_1_Cursors
and related documentation.


Regards
Ariel.


--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[EMAIL PROTECTED]

http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to