How to reload current opened document via API

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to reload current opened document via API

Benjamin Vollmer
Hello,

I work on an extension where in some cases the opened document is
updated externally. So I have to reload my document.

In a snippet I found this way:

PropertyValue[] aLoadProps = new PropertyValue[0];

// reload current document
xComponentLoader.loadComponentFromURL(this.xFrame.getController().getModel().getURL(),
"_self", 0, aLoadProps);

But in my context this snippet doesn't work. Under Ubuntu nothing
happens when the code is executed, under Windows there occurs an UNO
Runtime Error. At the moment I reload the file manually over File ->
Reload. This works but it is not really a solution.

What is the right way to reload a document via API?

regards
Benjamin



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Mathias Bauer
Benjamin Vollmer wrote:

> Hello,
>
> I work on an extension where in some cases the opened document is
> updated externally. So I have to reload my document.
>
> In a snippet I found this way:
>
> PropertyValue[] aLoadProps = new PropertyValue[0];
>
> // reload current document
> xComponentLoader.loadComponentFromURL(this.xFrame.getController().getModel().getURL(),
> "_self", 0, aLoadProps);
>
> But in my context this snippet doesn't work. Under Ubuntu nothing
> happens when the code is executed, under Windows there occurs an UNO
> Runtime Error. At the moment I reload the file manually over File ->
> Reload. This works but it is not really a solution.
>
> What is the right way to reload a document via API?

You can use the Dispatch API to achieve that. The command you have to
dispatch at the documents' frame is ".uno:Reload".

Regards,
Mathias

--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[hidden email]".
I use it for the OOo lists and only rarely read other mails sent to it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Benjamin Vollmer
Quoting Mathias Bauer <[hidden email]>:

> Benjamin Vollmer wrote:
>
>> Hello,
>>
>> I work on an extension where in some cases the opened document is
>> updated externally. So I have to reload my document.
>>
>> In a snippet I found this way:
>>
>> PropertyValue[] aLoadProps = new PropertyValue[0];
>>
>> // reload current document
>> xComponentLoader.loadComponentFromURL(this.xFrame.getController().getModel().getURL(),
>> "_self", 0, aLoadProps);
>>
>> But in my context this snippet doesn't work. Under Ubuntu nothing
>> happens when the code is executed, under Windows there occurs an UNO
>> Runtime Error. At the moment I reload the file manually over File ->
>> Reload. This works but it is not really a solution.
>>
>> What is the right way to reload a document via API?
>
> You can use the Dispatch API to achieve that. The command you have to
> dispatch at the documents' frame is ".uno:Reload".

Unfortunately the solution with ".uno:Reload" does not work anymore  
since OO.org 3.1 was released. Under Windows I cannot update the  
opened document externally because it is locked. I need a workaround  
with close and then reopen the document. Is there also a Dispatch API  
command for close? I found ".uno:CloseDoc", but it doesn't work as  
aspected. Nothing happens when I use ".uno:CloseDoc" instead of  
".uno:Reload".

I also found the interface xClosable  
(http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Closing_Documents#XCloseable), but I had no success with the usage. Under Ubuntu OpenOffice crashes with the sample code, under Windows the code closes the document but also all other visible OpenOffice  
components.

regards
Benjamin



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Mikhail Voytenko
Hi Benjamin,

Sorry, but editing of a document is not allowed if it is already edited
by the office. I assume that you could reach it since OOo3.0.x does not
use system file locking, so the document file can be edited in parallel.
This is actually the reason why OOo3.1 supports the system file locking
as well now, to prevent such situations.

The problem with ".uno:CloseDoc" and XCloseable sounds strange. Could
you please provide more information regarding how you are using the API.

Best regards,
Mikhail.

On 06/05/09 13:06, [hidden email] wrote:

> Quoting Mathias Bauer <[hidden email]>:
>
>> Benjamin Vollmer wrote:
>>
>>> Hello,
>>>
>>> I work on an extension where in some cases the opened document is
>>> updated externally. So I have to reload my document.
>>>
>>> In a snippet I found this way:
>>>
>>> PropertyValue[] aLoadProps = new PropertyValue[0];
>>>
>>> // reload current document
>>> xComponentLoader.loadComponentFromURL(this.xFrame.getController().getModel().getURL(),
>>>
>>> "_self", 0, aLoadProps);
>>>
>>> But in my context this snippet doesn't work. Under Ubuntu nothing
>>> happens when the code is executed, under Windows there occurs an UNO
>>> Runtime Error. At the moment I reload the file manually over File ->
>>> Reload. This works but it is not really a solution.
>>>
>>> What is the right way to reload a document via API?
>>
>> You can use the Dispatch API to achieve that. The command you have to
>> dispatch at the documents' frame is ".uno:Reload".
>
> Unfortunately the solution with ".uno:Reload" does not work anymore
> since OO.org 3.1 was released. Under Windows I cannot update the
> opened document externally because it is locked. I need a workaround
> with close and then reopen the document. Is there also a Dispatch API
> command for close? I found ".uno:CloseDoc", but it doesn't work as
> aspected. Nothing happens when I use ".uno:CloseDoc" instead of
> ".uno:Reload".
>
> I also found the interface xClosable
> (http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Closing_Documents#XCloseable),
> but I had no success with the usage. Under Ubuntu OpenOffice crashes
> with the sample code, under Windows the code closes the document but
> also all other visible OpenOffice components.
>
> regards
> Benjamin
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Mathias Bauer
In reply to this post by Benjamin Vollmer
[hidden email] wrote:

> Quoting Mathias Bauer <[hidden email]>:
>
>> Benjamin Vollmer wrote:
>>
>>> Hello,
>>>
>>> I work on an extension where in some cases the opened document is
>>> updated externally. So I have to reload my document.
>>>
>>> In a snippet I found this way:
>>>
>>> PropertyValue[] aLoadProps = new PropertyValue[0];
>>>
>>> // reload current document
>>> xComponentLoader.loadComponentFromURL(this.xFrame.getController().getModel().getURL(),
>>> "_self", 0, aLoadProps);
>>>
>>> But in my context this snippet doesn't work. Under Ubuntu nothing
>>> happens when the code is executed, under Windows there occurs an UNO
>>> Runtime Error. At the moment I reload the file manually over File ->
>>> Reload. This works but it is not really a solution.
>>>
>>> What is the right way to reload a document via API?
>>
>> You can use the Dispatch API to achieve that. The command you have to
>> dispatch at the documents' frame is ".uno:Reload".
>
> Unfortunately the solution with ".uno:Reload" does not work anymore  
> since OO.org 3.1 was released. Under Windows I cannot update the  
> opened document externally because it is locked. I need a workaround  
> with close and then reopen the document. Is there also a Dispatch API  
> command for close? I found ".uno:CloseDoc", but it doesn't work as  
> aspected. Nothing happens when I use ".uno:CloseDoc" instead of  
> ".uno:Reload".

As dispatching this command does the same as choosing "Reload" from the
file menu this would mean that reloading does not work at all?! I
couldn't reproduce that on Windows.

Ciao,
Mathias

--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[hidden email]".
I use it for the OOo lists and only rarely read other mails sent to it.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Benjamin Vollmer
Quoting Mathias Bauer <[hidden email]>:

> [hidden email] wrote:
>> Unfortunately the solution with ".uno:Reload" does not work anymore
>> since OO.org 3.1 was released. Under Windows I cannot update the
>> opened document externally because it is locked. I need a workaround
>> with close and then reopen the document. Is there also a Dispatch API
>> command for close? I found ".uno:CloseDoc", but it doesn't work as
>> aspected. Nothing happens when I use ".uno:CloseDoc" instead of
>> ".uno:Reload".
>
> As dispatching this command does the same as choosing "Reload" from the
> file menu this would mean that reloading does not work at all?! I
> couldn't reproduce that on Windows.

Hi,

The ".uno:Reload" command is not the problem. The problem refers to my  
extension context. I overwrite an opened document via copy() in java  
code and then reload the document via API. With OOo 3.1 this is not  
possible anymore (on windows). So I need to find another solution for  
that. My idea was to close the doc via dispatch command and then  
reopen it again (not really a nice solution). I change the code with  
".uno:Reload" to ".uno:CloseDoc", but the document does not close.

Code:
final XMultiServiceFactory xMSF = (XMultiServiceFactory) this.
    getXInterface(XMultiServiceFactory.class, this.getXContext().
    getServiceManager().createInstanceWithContext(
      "com.sun.star.lang.MultiServiceFactory", this.getXContext()));

final XDispatchHelper xDispatchHelper = (XDispatchHelper) this.
    getXInterface(XDispatchHelper.class, xMSF.createInstance(
       "com.sun.star.frame.DispatchHelper"));

xDispatchHelper.executeDispatch((XDispatchProvider) this.
    getXInterface(XDispatchProvider.class, this.getXFrame()),
       ".uno:CloseDoc", "", 0, new com.sun.star.beans.PropertyValue[0]);

(getXInterface is a wrapper function for UnoRuntime.query())



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to reload current opened document via API

Mathias Bauer
[hidden email] wrote:

> Quoting Mathias Bauer <[hidden email]>:
>
>> [hidden email] wrote:
>>> Unfortunately the solution with ".uno:Reload" does not work anymore
>>> since OO.org 3.1 was released. Under Windows I cannot update the
>>> opened document externally because it is locked. I need a workaround
>>> with close and then reopen the document. Is there also a Dispatch API
>>> command for close? I found ".uno:CloseDoc", but it doesn't work as
>>> aspected. Nothing happens when I use ".uno:CloseDoc" instead of
>>> ".uno:Reload".
>>
>> As dispatching this command does the same as choosing "Reload" from the
>> file menu this would mean that reloading does not work at all?! I
>> couldn't reproduce that on Windows.
>
> Hi,
>
> The ".uno:Reload" command is not the problem. The problem refers to my  
> extension context. I overwrite an opened document via copy() in java  
> code and then reload the document via API. With OOo 3.1 this is not  
> possible anymore (on windows). So I need to find another solution for  
> that. My idea was to close the doc via dispatch command and then  
> reopen it again (not really a nice solution). I change the code with  
> ".uno:Reload" to ".uno:CloseDoc", but the document does not close.

I don't understand why closing doesn't work, but maybe there's a
workaround.

Obviously the lock of the document causes the problem. so perhaps
switching the document to readonly mode can help: please try to first
dispatch ".uno:EditDoc" (this should switch the document to readonly
mode) and then overwrite the document, then dispatch ".uno:Reload" and
then ".uno:EditDoc" again. If the code works as expected, switching to
readonly mode and back should not cause any further reloads, maybe some
toolbar flickering possible.

BTW: the missing lock was a bug in OOo3.0, so basically your code worked
just by luck because of this bug. In general you can't assume that an
application does not lock a file that it has opened for editing.

Regards,
Mathias

--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[hidden email]".
I use it for the OOo lists and only rarely read other mails sent to it.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]