Re: Is this a UNO API bug?

2012-08-23 Thread Andrew Douglas Pitonyak


I assumed that a page number was a document property... Suppose I was 
wrong then.


On 08/23/2012 01:06 AM, dongjun zong wrote:

I already read this document. But the update is not effect for Page Number
field.

The method update() of the interface
com.sun.star.util.XUpdatablehttp://api.openoffice.org/docs/common/ref/com/sun/star/util/XUpdatable.htmlaffects
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().




2012/8/23 Andrew Douglas Pitonyak and...@pitonyak.org


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_Fieldshttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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();
//}

   

Re: Is this a UNO API bug?

2012-08-22 Thread dongjun zong
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 and...@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 and...@pitonyak.org mailto:
 and...@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 and...@pitonyak.org
 mailto:and...@pitonyak.org


 OK, I had 

Re: Is this a UNO API bug?

2012-08-22 Thread Andrew Douglas Pitonyak


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 and...@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, 

Re: Is this a UNO API bug?

2012-08-22 Thread dongjun zong
I already read this document. But the update is not effect for Page Number
field.

The method update() of the interface
com.sun.star.util.XUpdatablehttp://api.openoffice.org/docs/common/ref/com/sun/star/util/XUpdatable.htmlaffects
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().




2012/8/23 Andrew Douglas Pitonyak and...@pitonyak.org


 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_Fieldshttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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.htmlhttp://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 

Re: Is this a UNO API bug?

2012-08-21 Thread Andrew Douglas Pitonyak


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
Info:  http://www.pitonyak.org/oo.php



Re: Is this a UNO API bug?

2012-08-21 Thread Andrew Douglas Pitonyak


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
Info:  http://www.pitonyak.org/oo.php



Re: Is this a UNO API bug?

2012-08-21 Thread dongjun zong
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 and...@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.odthttp://www.pitonyak.org/AndrewMacro.odt
 Info:  http://www.pitonyak.org/oo.php




Re: Is this a UNO API bug?

2012-08-21 Thread Oliver Brinzing
 The strange thing is this API can works fine for doc sample file.

the following code works for me with a new doc, output is: Hello 1 World!!!

public class TextfieldProblem {
public void setTextfield(XComponent component) {
XMultiServiceFactory serviceFactory = UnoRuntime.queryInterface(
XMultiServiceFactory.class, component);
XTextField pageNumberFiled = null;
try {
pageNumberFiled = UnoRuntime
.queryInterface(
XTextField.class,
serviceFactory

.createInstance(com.sun.star.text.textfield.PageNumber));
XPropertySet props = 
UnoRuntime.queryInterface(XPropertySet.class,
pageNumberFiled);
props.setPropertyValue(NumberingType,

com.sun.star.style.NumberingType.ARABIC);
props.setPropertyValue(SubType,

com.sun.star.text.PageNumberType.CURRENT);
} catch (Exception e) {
e.printStackTrace();
}
XTextDocument document = 
UnoRuntime.queryInterface(XTextDocument.class,
component);
try {

document.getText().insertString(document.getText().getStart(),
Hello , true);

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

document.getText().insertString(document.getText().getEnd(),
 World!!!, true);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
getTextfield(document);
}

public void getTextfield(XComponent xComponent) {
XTextDocument document = 
UnoRuntime.queryInterface(XTextDocument.class,
xComponent);
String documentString = document.getText().getString();
System.out.println(documentString);
}
}



Regards

Oliver
-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: Is this a UNO API bug?

2012-08-21 Thread dongjun zong
Oliver,
I found that if page is more than 2, it will has problem. Would you pls
help try a 3 page exist odt sample for this issue?

2012/8/21 Oliver Brinzing oliver.brinz...@gmx.de

  The strange thing is this API can works fine for doc sample file.

 the following code works for me with a new doc, output is: Hello 1 World!!!

 public class TextfieldProblem {
 public void setTextfield(XComponent component) {
 XMultiServiceFactory serviceFactory =
 UnoRuntime.queryInterface(
 XMultiServiceFactory.class, component);
 XTextField pageNumberFiled = null;
 try {
 pageNumberFiled = UnoRuntime
 .queryInterface(
 XTextField.class,
 serviceFactory

 .createInstance(com.sun.star.text.textfield.PageNumber));
 XPropertySet props =
 UnoRuntime.queryInterface(XPropertySet.class,
 pageNumberFiled);
 props.setPropertyValue(NumberingType,

 com.sun.star.style.NumberingType.ARABIC);
 props.setPropertyValue(SubType,

 com.sun.star.text.PageNumberType.CURRENT);
 } catch (Exception e) {
 e.printStackTrace();
 }
 XTextDocument document =
 UnoRuntime.queryInterface(XTextDocument.class,
 component);
 try {

 document.getText().insertString(document.getText().getStart(),
 Hello , true);

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

 document.getText().insertString(document.getText().getEnd(),
  World!!!, true);
 } catch (IllegalArgumentException e) {
 e.printStackTrace();
 }
 getTextfield(document);
 }

 public void getTextfield(XComponent xComponent) {
 XTextDocument document =
 UnoRuntime.queryInterface(XTextDocument.class,
 xComponent);
 String documentString = document.getText().getString();
 System.out.println(documentString);
 }
 }



 Regards

 Oliver
 --

 GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45




Re: Is this a UNO API bug?

2012-08-21 Thread Oliver Brinzing
Hi,

 I found that if page is more than 2, it will has problem. Would you pls
 help try a 3 page exist odt sample for this issue?

are you sure? the following code gives me a new 6 pages document with string:

Page # 1
Page # 2
Page # 3
Page # 4
Page # 5

public class TextfieldProblem {

public static void setTextfield(final XComponent component) {

final XMultiServiceFactory serviceFactory = 
UnoRuntime.queryInterface(
XMultiServiceFactory.class, component);

final XTextDocument xDoc = UnoRuntime.queryInterface(
XTextDocument.class, component);
try {
final XText xText = xDoc.getText();
final XTextCursor xTextCursor = 
xText.createTextCursor();
xTextCursor.gotoRange(xText.getStart(), false);

for (int i = 0; i  5; i++) {
xText.insertString(xTextCursor, Page # , 
false);
xText.insertTextContent(xTextCursor,

TextfieldProblem.createTextfield(serviceFactory), false);
TextfieldProblem.insertPageBreak(xText, 
xTextCursor);
}
} catch (final IllegalArgumentException e) {
e.printStackTrace();
} catch (final UnknownPropertyException e) {
e.printStackTrace();
} catch (final PropertyVetoException e) {
e.printStackTrace();
} catch (final WrappedTargetException e) {
e.printStackTrace();
}
TextfieldProblem.getTextfield(xDoc);
}

private static XTextField createTextfield(
final XMultiServiceFactory serviceFactory) {
XTextField pageNumberFiled = null;
try {
pageNumberFiled = UnoRuntime
.queryInterface(
XTextField.class,
serviceFactory

.createInstance(com.sun.star.text.textfield.PageNumber));

final XPropertySet props = UnoRuntime.queryInterface(
XPropertySet.class, pageNumberFiled);

props.setPropertyValue(NumberingType, new Short(

com.sun.star.style.NumberingType.ARABIC));

props.setPropertyValue(SubType,

com.sun.star.text.PageNumberType.CURRENT);

} catch (final Exception e) {
e.printStackTrace();
}
return pageNumberFiled;
}

private static void insertPageBreak(final XText xText,
final XTextCursor xTextCursor) throws 
UnknownPropertyException,
PropertyVetoException, IllegalArgumentException,
WrappedTargetException {

final XPropertySet xCursorProps = UnoRuntime.queryInterface(
XPropertySet.class, xTextCursor);
xCursorProps.setPropertyValue(BreakType, 
BreakType.PAGE_AFTER);
xText.insertControlCharacter(xTextCursor,
ControlCharacter.PARAGRAPH_BREAK, false);
xTextCursor.gotoEnd(false);
}

public static void getTextfield(final XComponent xComponent) {
final XTextDocument document = UnoRuntime.queryInterface(
XTextDocument.class, xComponent);
final String documentString = document.getText().getString();
System.out.println(documentString);
}
}


Regards

Oliver

--

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45



signature.asc
Description: OpenPGP digital signature


Re: Is this a UNO API bug?

2012-08-21 Thread Andrew Douglas Pitonyak

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 and...@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.odthttp://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



Re: Is this a UNO API bug?

2012-08-21 Thread dongjun zong
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.

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 and...@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 and...@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.odthttp://www.pitonyak.org/**AndrewMacro.odt
 http://www.**pitonyak.org/AndrewMacro.odthttp://www.pitonyak.org/AndrewMacro.odt
 
 Info:  http://www.pitonyak.org/oo.php



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




PageNumberFieldTest.odt
Description: application/vnd.oasis.opendocument.text


Re: Is this a UNO API bug?

2012-08-21 Thread Andrew Douglas Pitonyak


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 and...@pitonyak.org 
mailto:and...@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 and...@pitonyak.org
mailto:and...@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