Hello Marco,

Marco Castillo escribió:
Dear Ariel:
    Thank you  for your kind reply. I hav just try the code for the view 
cursor, and it works fine!. About the user text fields, is clear now that I 
cannot insert a field twice using the same instance of the field. But I'm 
curious, you said in your last e-mail that I must create ANOTHER instance of 
the field using the same parameters for its creation. How can I create a new 
instance of the same field that is already inserted. I use the following code 
to insert the field (from my last e-mail)

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

                // Creamos el fieldmaster asociado al recientemente creado user 
field...
                XPropertySet masterPropSet = (XPropertySet) 
UnoRuntime.queryInterface(XPropertySet.class,
                                                              
documentFactory.createInstance("com.sun.star.text.FieldMaster.User"));
// Le ponemos el nombre y valor al fieldmaster...
                masterPropSet.setPropertyValue("Name", fieldName);
                masterPropSet.setPropertyValue("Content", fieldValue);
// Finalmente le insertamos el fieldmaster al user field...
                userField.attachTextFieldMaster(masterPropSet);
            }
        }
        catch (java.lang.Exception e) {
            e.printStackTrace();
        }
        return userField;
    }

In the case of creating a new field, the above code is ok. But how do I get another instance of 
the same field? Do I use the UnoRuntime.queryInterface to acomplish this?, somewhere in the 
documentation I read something about the field names, that the name of the field is something 
like "com.sun.star.text.TextField.User.<MyFieldName>", do I have to use a 
sintax like this to retrieve the new instance of the same field?
Thank you in advance for your kind reply.

the main problem with your code is that it creates the field master
while instantiating a new dependent text field. This will work *only*
*once*, but the next time you invoke this method, you will get an
exception because in the text field master collection of the document
there can be *only one* text field master with this name, for example:

com.sun.star.text.FieldMaster.User.CompanyDir
com.sun.star.text.FieldMaster.SetExpression.OOoMathFormula

So before creating a text field master it is better to check if the
field master collection of the document has already a field master with
this name.

And when you create a dependent text field, use a getter method that
creates the text field master *only* if it does not exists; if it exists, it only gets it. This way you can invoke instantiate the dependent text field any time you want.

You can find a "dummy" example of a sequential field here

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


Side comment, I think something is wrong with OOoMath formulae: I just copied and pasted code that *did* work "as is" in other versions of OOo, but now the formulae inserted via API do not adjust its size automatically as they get inserted in the document. In formers versions there was no need to set the size of the formula shape. Is this an issue?


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