Tobias Krais wrote:

> Hi together again,
> 
> I implemented a protocol handler for the CommandURL .Judas:PrintTrays.
> The target of this new protocol is to print a document on different
> printer trays (page one on tray with letter paper, the others on the
> tray with normal paper). After sending the print command via API I added
> a PrintJobListener:
> -----%<-----
> // Querying for the interface XPrintable on the loaded document
> XPrintable xPrintable = (XPrintable)
>                 UnoRuntime.queryInterface(XPrintable.class,
>                       this.xComponent);
> 
> // Adding a print job listener
> XPrintJobBroadcaster selection = (XPrintJobBroadcaster)
>                       UnoRuntime.queryInterface(XPrintJobBroadcaster.class,
>                       xPrintable);
> OOPrintJobListener ooPrintJobListener = new OOPrintJobListener();
> ooPrintJobListener.setDebug(debug);
> selection.addPrintJobListener(ooPrintJobListener);
> 
> // Setting the property "Pages" so that only the desired pages
> // will be printed.
> PropertyValue[] printOpts = new PropertyValue[1];
> printOpts[0] = new PropertyValue();
> printOpts[0].Name = "Pages";
> printOpts[0].Value = myPages;
> 
> try {
>       xPrintable.print(printOpts);
> } catch (IllegalArgumentException e) {}
> 
> // Watch print process and continue if done.
> // TODO: see OO Bug id 72240; don't print a non-existing page, other-
> // wise here is a loop.
> while (ooPrintJobListener.getStatus() == null ||
>            ooPrintJobListener.getStatus() == PrintableState.JOB_STARTED)
> {
>       try {
>               Thread.sleep(2000);
>       }
>       catch (InterruptedException e) {}
> }
> -----%<-----
> 
> In the line where I wait send the Thread sleeping, I send the whole OO
> sleeping and my protocol handler throws an exception. Is this a bug or a
> feature?

At least it's the expected behavior. The event notification happens
synchronously (as the listener should be able to e.g. modify the
document before it gets printed) so it must happen in OOo's main thread.
Stopping this thread will deadlock the whole application.

> I solved this problem by creating another thread printing my document.
> Then it works. But this other thread won't show my dialog if the print
> failes. How can I show the dialog if my print failes from an other thread?

Why do you want to "sleep" in your listener? Perhaps you can avoid that.
Without understanding what you are trying to achieve it's hard to give
any useful hints.
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 "[EMAIL PROTECTED]".
I use it for the OOo lists and only rarely read other mails sent to it.

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

Reply via email to