Hi Frank,

Frank Schönheit - Sun Microsystems Germany escribió:
Hi Ariel,

you can find a Scripting Framework example using a Java "macro" to test
in DatabaseDocument/s. You have to unzip and store the folder inside
your OOo user dir. user/Scripts/java and restart OOo to deploy it.
Inside this folder you will also find an ODB with the JAR embedded.

interesting, you picked the least-obvious "scripting language" to test,
given that Java is the only one which has no UI for editing the "scripts".
That's a good thing, actually :)

NOOOO! I was too lazy ;-)
Have you seen that awful GUI that pops up when you edit a Javascript/BeanShell "macro"? No code completion, debugging is awful also, etc... So working with the NetBeans IDE is easier. (with Python I didn't even try: the IDLE is from the stone-age)

DataSourceBrowser:

(note to myself: play more with the DataSourceBrowser in a Writer/Calc
document, this was not on my list so far. note to Ariel: thanks for the
hint.)

1. open the table "names"
2. from it, open the dialog Tools - Macros - Run macro - Macro selector
3.1.  if you run the Java method globalHello in user's
       Script/java/HelloODB
       XScriptContext.getDocument() returns NULL, so I use
       XScriptContext.getDesktop().getCurrentFrame() to identify
       the module, and the result is css.sdb.DataSourceBrowser
3.2.  if you run the Java method localHello embedded in the ODB
       XScriptContext.getDocument() returns an XModel reference
       to the css.sdb.OfficeDatabaseDocument (the dialog will be
       executed with the app. main container window as parent
       because the XModel is not null and so I instantiate the
       DialogProvider  with it as argument -- I could avoid this,
       but I wanted to stress how the Scripting Framework's
       XScriptContext.getDocument() works like ThisDatabaseDocument
       even if invoked from the DSBrowser)

In fact, XScriptContext.getDocument() and ThisDatabaseDocument are
mapped to the same: the document containing the macros.

XScriptContext.getInvocationContext() and ThisComponent are mapped to
the component from where the macro was called.

FormDesign:
here this begin to get more complicated, and it makes really a
difference the OS, and if you are debugging or just running the Java macro.
For example, I left an exception I got only on Windows without
debugging, to see if other's can reproduce it.
Anyway exceptions are caught an the stack trace printed on a JPanel.


I still didn't have the time to test it deeply, but at first sight some
thing seems issues (for example, invoking from toolbars is impossible).

Okay, I need to find time to play with it. If you're faster with
describing what you mean with "impossible", I might spare it :)

I will do it tonight an d then tell you, for now I can say that a message is prompted:


A Scripting Framework error ocurred while running the Java script HelloODB.localHello

Message: ScriptResolver.getProxy: Can't find method:

localHello:HelloODB.localHello(com.sun.star.script.provider.XScriptContext, java.lang.Short)



As you see, the methods get invoked with an extra argument (strange, because there exist (as far as I know) only to ways to invoke them:

* passing only an XScriptContext
* passing an XScriptContext, and an Object[] (this is the Java-bridge when passing args. to the method, Object[0] is the EventObject; in other languages they have a global Object[] variable named ARGUMENTS http://api.openoffice.org/docs/DevelopersGuide/ScriptingFramework/ScriptingFramework.xhtml#1_3_3_Handling_arguments_passed_to_macros)

Regards
Ariel.


--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[EMAIL PROTECTED]

http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.

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

Reply via email to