news.gmane.org wrote:
Mathias Bauer ha scritto:
news.gmane.org schrieb:

Mathias Bauer ha scritto:
news.gmane.org wrote:

XModel oModel = (XModel)UnoRuntime.queryInterface(XModel.class,oEvent.Source);
        if (oModel!=null) {
            System.out.println("Document URL is: " + oModel.getURL());
        }
    }
You should be aware that getURL() will return an empty string if the
document is an untitled one and as you can have more than of untitled
document it doesn't qualify as an identifier.

You could use the document (reference) itself as a unique identifier.
You then must register as a listener so you get a notification when the
document is disposed so that you can release your reference.
The problem is: how do I get the document refernce from the EventObject?
I've tried this:

OfficeDocument oDocument = (OfficeDocument)UnoRuntime.queryInterface(OfficeDocument.class,oEvent.Source);

but I'm getting a ClassCastException.
that's natural because you can't query for OfficeDocument. You can only query for UNO interfaces. At this level you have left the Bean abstraction and have to deal with the UNO interfaces directly. The OfficeBean is only a smarter wrapper around often used API', especially to get started with documents. but later on if you want to do more, you have to deal with the real Office API directly.

Try to query for XTextDocument, i haven't test it but if the event source transport the document it should work.

Hope this helps

Juergen


OfficeDocument is not a valid type here. You have to use any interface
from our documents - I would recommend to use com.sun.star.XModel.

The problem comes to a higher level: when I'm calling oBean.loadFromUrl I don't have my document yet, what should I compare the event source to? My intention was to use the url so that I'm sure that the document being loaded is the same as the one I'm listening to. Moreover if I query the XModel interface from the EventSource and then I compare it with oBean.getController().getModel() , I get that the references are not equal.

The problem comes also on storeAsUrl(). If I create a new document and then save it, the event on the listener comes with a source URL which is an empty string, because, as you said, the new document has no URL.

I'm really in trouble with that, and I'm very sorry to bother you with this issue.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to