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. I use the 
following code to get a valid text field:

private XDependentTextField createTextField(XMultiServiceFactory 
documentFactory, String fieldName, String fieldValue) {
        XDependentTextField userField = null;
        try {
            if (documentFactory != null) {            
                // Create the field...
                userField = (XDependentTextField) 
UnoRuntime.queryInterface(XDependentTextField.class, 
documentFactory.createInstance("com.sun.star.text.TextField.User"));

                // Create the field master...
                XPropertySet masterPropSet = (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class, 
documentFactory.createInstance("com.sun.star.text.FieldMaster.User"));
                
                // Set the field name and content...
                masterPropSet.setPropertyValue("Name", fieldName);
                masterPropSet.setPropertyValue("Content", fieldValue);
                
                // Attach the fieldmaster to the field...
                userField.attachTextFieldMaster(masterPropSet);
            }
        }
        catch (java.lang.Exception e) {
            e.printStackTrace();
        }
        return userField;
    }

I took the above code from the TextDocuments.java example that comes with the 
OO SDK. I use the following code to insert the field into a Document:
            // Create a field...
            XDependentTextField userField0 = 
this.createTextField(documentFactory, "field0", "hellohello");
        
            // Get the text document. Here the object document is a properly 
initialized XTextDocument object...
            XText documentText = this.getDocumentText(document);
        
            // Insert the field...
            documentText.insertTextContent(documentText.getEnd(), userField0, 
false);

The above code works like a breeze. It inserts the field field0 initialized 
with the string "hellohello" right at the end of the Document.
Now I have a couple of issues. When I try to insert the created field into the 
document again, let's say by invoking the following code:
            // Insert the field again...

            documentText.insertTextContent(documentText.getStart, userField0, 
false);


I get the following exception raised:
com.sun.star.uno.RuntimeException: 
    at 
com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:187)
    at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:153)
    at 
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:349)
    at 
com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:318)
    at 
com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:106)
    at 
com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:657)
    at 
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:159)
    at 
com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:141)
    at $Proxy24.insertTextContent(Unknown Source)

So my first issue is, how can I insert a recently created text field into a 
Document more than one time? Do I have to use another method than 
insertTextContent(). The Developer Guide states that the preferred method to 
insert a text field is insertTextContent(). So why am I getting this Exception 
when I try to insert the field more than one time? Do I have to use a different 
method to insert a field more than one time?
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?

Thank you in advance for your kind reply and for the time to read this message.

Regards

Marco







      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


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

Reply via email to