incubator-ooo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Douglas Pitonyak <and...@pitonyak.org>
Subject Re: Is this a UNO API bug?
Date Thu, 23 Aug 2012 04:18:34 GMT

Is the page number field? Hmmm, I inspected one and it supports 
update(), not refresh(). So no, I don't think that I mean refresh().

Can you insert the field and then, since you still have a copy of the 
field, call update()?

This is supported by  com.sun.star.util.XUpdatable

Read this:

http://wiki.openoffice.org/wiki/Documentation/DevGuide/Text/Text_Fields

And I quote:::::::::::::::::::::::::::::::

All fields support the interfaces com.sun.star.text.XTextField 
<http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextField.html>, 
com.sun.star.util.XUpdatable 
<http://api.openoffice.org/docs/common/ref/com/sun/star/util/XUpdatable.html>, 
com.sun.star.text.XDependentTextField 
<http://api.openoffice.org/docs/common/ref/com/sun/star/text/XDependentTextField.html>

and the service com.sun.star.text.TextContent 
<http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextContent.html>. 


The method |getPresentation()| of the interface 
com.sun.star.text.XTextField 
<http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextField.html> 
returns the textual representation of the result of the text field 
operation, such as a date, time, variable value, or the command, such as 
CHAPTER, TIME (fixed) depending on the boolean parameter.

The method |update()| of the interface com.sun.star.util.XUpdatable 
<http://api.openoffice.org/docs/common/ref/com/sun/star/util/XUpdatable.html> 
affects only the following field types:

  * Date and time fields are set to the current date and time.
  * The |ExtendedUser| fields that show parts of the user data set for
    OpenOffice.org, such as the Name, City, Phone No. and the Author
    fields that are set to the current values.
  * The |FileName| fields are updated with the current name of the file.
  * The |DocInfo.XXX| fields are updated with the current document info
    of the document.

All other fields ignore calls to |update()|.

::::::::::::::::::::::::::::::::::::::::

I hope that this helps some!

On 08/22/2012 03:30 AM, dongjun zong wrote:
> You mentioned force update, do you mean use refresh() method ? I have tried
> by below code, still can't work.
>
> public void createPageNumber(XComponent component) {
>          XMultiServiceFactory sevriceFactory = (XMultiServiceFactory)
> UnoRuntime.queryInterface(XMultiServiceFactory.class, component);
>          XTextField pageNumberFiled;
>          try {
>              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",
> NumberingType.ARABIC);//Set page number display as Arabic
>              props.setPropertyValue("SubType", PageNumberType.CURRENT);
>
>
>
>   document.getText().insertTextContent(document.getText().getEnd(),
>                       pageNumberFiled, true);
>               XTextFieldsSupplier fieldsSupplier =
> UnoRuntime.queryInterface(XTextFieldsSupplier.class, document);
>               XEnumerationAccess xEnumeratedFields =
> fieldsSupplier.getTextFields();
>
>              XRefreshable refeshable =
> UnoRuntime.queryInterface(XRefreshable.class, xEnumeratedFields);
>              refeshable.refresh();
>
>
>
> //             try {
> //                Thread.sleep(1000);
> //            } catch (InterruptedException e) {
> //                e.printStackTrace();
> //            }
>
>               System.out.println(document.getText().getString());
>
>          } catch (com.sun.star.uno.Exception e) {
>              e.printStackTrace();
>          }
>
> 2012/8/22 Andrew Douglas Pitonyak <andrew@pitonyak.org>
>
>> 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 <andrew@pitonyak.org <mailto:
>>> andrew@pitonyak.org>>
>>>
>>>
>>>      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 <andrew@pitonyak.org
>>>          <mailto:andrew@pitonyak.org>>
>>>
>>>
>>>              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>
>>> <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<http://www.pitonyak.org/AndrewMacro.odt>
>>>      Info: http://www.pitonyak.org/oo.php
>>>
>>>
>>>
>> --
>> 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


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message