On 08/21/2012 09:08 PM, dongjun zong wrote:
Andrew,
I think you are right, I add a sleep time after insert page number field before getText, the page number can get correct.
But I think it's a bug for page number update issue.

Have you tried forcing an update? If so, then you won't need to wait.

I expect that an update may be a time consuming operation (say if you insert at page number 400, and it must refresh from the start). I once saw a problem where a document would open, but the initial page numbers were wrong. It took a while for the page numbers to be updated after the document loaded. The final solution was to issue a full refresh, which took time, but made it happen. So, the trade off was to allow the user to immediately see and edit the document rather than forcing them to wait for the refresh to occur on load. With a large document, this can take time.

My guess is that it takes significantly more time to create and insert a field than to trigger the update process. When the API is used to insert, we have no context on the operation so it seems reasonable to not make an immediate update before return. If the update process takes 1000 times longer to occur (probably depends on document size and other factors, depending on what is updated), then if I want to insert 100 fields, what might have taken a fraction of a second may now take minutes.

Commands triggered from the GUI can make the reasonable assumption that the user is not likely to perform that task a 100 times, and that a user is sitting right there and probably desires an immediate response to the command, so then the triggered code (a dispatch) includes the update task as part of the process.

If you think that not updating the single field immediately is a bug, you should try inserting a Table Of Contents (TOC).

So, although you are certain that it is a bug, and you may be right, I might call it a design decision that tends to make the typical user experience more performant; which is the usual case..... but this is mostly speculation on my part.


Oliver, I have tired again, on my computer, if don't add sleep time, it has problem for exist more than 2 page sample fie. You can try this sample, add a page nubmer at end of this document. pls get this sample from attachement.



2012/8/21 Andrew Douglas Pitonyak <[email protected] <mailto:[email protected]>>

    My expectation is that this is not a bug.

    I think that this is probably a timing problem based on the speed
    of the computer, the size of the document, how busy your CPU is,
    etc. If you do not have a number, then the values have probably
    not updated yet. Remember that the data model has no idea what
    page number it really is. This value must be updated by the view
    model / current controller (or something similar). If you have a
    value, then it just so happens that the values updated
    immediately. If you insert the value using the GUI, that code is
    smart enough to then trigger the update before it returns.


    On 08/21/2012 03:23 AM, dongjun zong wrote:

        The strange thing is this API can works fine for doc sample
        file. I guess
        this is a bug.

        2012/8/21 Andrew Douglas Pitonyak <[email protected]
        <mailto:[email protected]>>

            OK, I had to  look...

            For a text field, see if you can call update. This may not
            work if the
            document has not finished repaginating. I have heard of
            cases where a
            document had not finished doing that before someone tried
            to do stuff to
            it. The solution was to tell the document to full refresh
            (probably using a
            dispatch).



            On 08/21/2012 02:30 AM, Andrew Douglas Pitonyak wrote:

                Did you successfully insert the text field? If yes,
                then after you insert
                a text field, it has probably not yet refreshed its
                value. Off hand, I
                don't remember exactly what you need to refresh
                first.... I would need to
                look it up and I really need to run but figured it
                might help you a bit and
                you can look for the various refresh items (I think
                that you can refresh
                each index and for fields I think there may be a
                single master field
                refresh but I don't remember... have not done it in a
                long time.).

                On 08/20/2012 03:32 AM, dongjun zong wrote:

                    Hi All,
                         Using UNO API I do below operation.
                    1.Launch a odt document,
                    2.Create a page number field and insert into this
                    docment
                    3.Get the document text

                    But in the step3, page number is not contained in
                    the get text. But if I
                    launch a doc document, I can get the page number
                    in step 3. I think this
                    is
                    a UNO API bug, can some body help confirm? Below
                    is my main code pieces.

                    XMultiServiceFactory sevriceFactory =
                    (XMultiServiceFactory)
                    UnoRuntime.queryInterface(**XMultiServiceFactory.class,
                    document);
                              XTextField  pageNumberFiled =
                    (XTextField)UnoRuntime.**queryInterface(XTextField.**class,
                    
sevriceFactory.createInstance(**"com.sun.star.text.textfield.**PageNumber"));


                              XPropertySet props =
                    
(XPropertySet)UnoRuntime.**queryInterface(XPropertySet.**class,
                    pageNumberFiled);
props.setPropertyValue("**NumberingType", 4);//Set
                    page number
                    display as Arabic

                              XTextCursor xTextCursor =
                    document.getText().**
                    createTextCursor();
                              xTextCursor.gotoEnd(false);

                    
document.getText().**insertTextContent(document.**getText().getEnd(),
                    pageNumberFiled, true);


                              String documentString =
                    document.getText().getString()**;
                              System.out.println(**documentString);


            --
            Andrew Pitonyak
            My Macro Document:
            
http://www.pitonyak.org/**AndrewMacro.odt<http://www.pitonyak.org/AndrewMacro.odt>
            Info: http://www.pitonyak.org/oo.php



-- Andrew Pitonyak
    My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
    Info: http://www.pitonyak.org/oo.php



--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php

Reply via email to