List Info

Thread: Re: Some Calc Java Macro Issues:




Re: Some Calc Java Macro Issues:
user name
2007-07-18 10:49:50
Hi Denis,

Denis Camargo wrote:
> I would like to thank everyone for the hints and tips
and code
> supplied. I have deployed a new version of my Java
macro, and its
> performance has improved by staggering 3,500%. The
class in my last
> post is working fine, I am able to activate the
autofilters now
> easily.
> 
> I would like to suggest adding that class to the code
snippets
> project. How can I do it?

you can find infos on the main site 
http://codesnippets.services.openoffice.org/index.xml.
there you will 
find also a link to Paolo's useful SnippetCreator
extension.

Juergen

> 
> <code>
> import com.sun.star.beans.PropertyValue;
> import com.sun.star.frame.XDispatchHelper;
> import com.sun.star.frame.XDispatchProvider;
> import com.sun.star.frame.XFrame;
> import com.sun.star.frame.XModel;
> import com.sun.star.lang.XMultiComponentFactory;
> import com.sun.star.script.provider.XScriptContext;
> import com.sun.star.uno.UnoRuntime;
> import com.sun.star.uno.XComponentContext;
> 
> 
> /** This class might work within OpenOffice.org Java /
BeanShell 
> Macros.<br>
> * it has  static methods only (so no object creation is
required by
> the caller)<br>
> * OOo makes available a XSriptContext object called
XSCRIPTCONTEXT in
> the macro.<br>
> * This object is the starting point for the method
calls.<br>
> *Please note that the <a
> href="http://api.openoffice
.org/docs/common/ref/com/sun/star/frame/XDispatchHelper.html
"> 
> 
> * interface XDispatchHelper</a> has a return
value. If that is of any
> interest to you, change the return values.
> *<br><br>Disclaimer:<br>
> *<p> This class is provided as is (no warranties
of any kind), and
> contains draft code.
> *It was not tested and probably is ripe with all kinds
of bugs. <br>
> *It is meant as an <strong>example</strong>
on how to work your way
> into the XDispatchHelper
> 
> *interface and execute a UNO dispatch in a Java /
BeanShell macro 
> context. </p>
> 
> */
> public class DispatchUNOCommand {
> 
> /** Creates a new instance of DispatchUNOCommand
<br>
>  * There is no need to do it, since everything is
static anyway.
>  */
> private DispatchUNOCommand() { }
> 
> /** Executes a dispatch, taking the same params the
interface
>  * <a 
> href="http://api.openoffice
.org/docs/common/ref/com/sun/star/frame/XDispatchHelper.html
"> 
> 
>  * interface XDispatchHelper</a>.
>  *
>  *param xsc a XScriptContext object. In OOo macros,
there is
> always one available called XSCRIPTCONTEXT.
>  *param unoUrl describes the feature which should be
supported by
> internally used dispatch object
>  *param targetFrame specifies the frame which should be
the target
> for this request
>  *param searchFlags optional search parameter for
finding the
> frame if no special TargetFrameName was used
>  *param arguments optional arguments for this request.
They depend
> on the real implementation of the dispatch object.
>  */
> public static void execute(XScriptContext xsc, String
unoUrl,
> String targetFrame,
>       int searchFlags, PropertyValue[] arguments)
throws
> com.sun.star.uno.Exception {
> 
>    // get the model and frame from the script context.
No need to
> go to the desktop.
>    XModel xm = xsc.getDocument();
>    final XFrame xf =
xm.getCurrentController().getFrame();
> 
>    // we could nest these two below in the
"helper" creation below.
> 
>    XComponentContext xcc = xsc.getComponentContext();
>    XMultiComponentFactory xmcf =
xcc.getServiceManager();
> 
>    final Object helper =
xmcf.createInstanceWithContext
>         
("com.sun.star.frame.DispatchHelper", xcc);
> 
> 
>    XDispatchHelper xdh =
(XDispatchHelper)UnoRuntime.queryInterface
>          (XDispatchHelper.class, helper);
> 
> 
>    XDispatchProvider xdp =
(XDispatchProvider)UnoRuntime.queryInterface
> 
>          (XDispatchProvider.class, xf);
> 
>    xdh.executeDispatch(xdp, unoUrl, targetFrame,
searchFlags , arguments);
> }
> 
> /** Executes a dispatch taking only the URL param of
>  * <a 
> href="http://api.openoffice
.org/docs/common/ref/com/sun/star/frame/XDispatchHelper.html
"> 
> 
>  * interface XDispatchHelper</a> . <br>
>  * The call assumes targetFrame = "",
searchFlags = 0 and empty arguments.
>  *param xsc a XScriptContext object. In OOo macros,
there is
> always one available called XSCRIPTCONTEXT.
>  *param unoUrl describes the feature which should be
supported by
> internally used dispatch object
>  */
> public static void execute(XScriptContext xsc, String
unoUrl)
> throws com.sun.star.uno.Exception {
>    execute(xsc, unoUrl, "", 0, new
PropertyValue[0]);
> }
> }
> </code>
> 
>
------------------------------------------------------------
---------
> To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
> For additional commands, e-mail: dev-helpapi.openoffice.org
> 

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Some Calc Java Macro Issues:
user name
2007-07-18 11:46:24
Hi,

Alle 17:49, mercoledì 18 luglio 2007, Juergen Schmidt ha
scritto:
> Hi Denis,
>
> Denis Camargo wrote:
> > I would like to thank everyone for the hints and
tips and code
> > supplied. I have deployed a new version of my Java
macro, and its
> > performance has improved by staggering 3,500%. The
class in my last
> > post is working fine, I am able to activate the
autofilters now
> > easily.
> >
> > I would like to suggest adding that class to the
code snippets
> > project. How can I do it?
>
> you can find infos on the main site
> http://codesnippets.services.openoffice.org/index.xml.
there you will
> find also a link to Paolo's useful SnippetCreator
extension.

I've just seen that in that page there are 2 links, but one
of them points to 
an old version of the snippet-creator. However, the latest
version is here:

http://www.paolo-mantovani.org/downloads/SnippetCreator/


Also installation instructions are a bit outdated (based on
the old pkgchk 
tool) 

regards
Paolo Mantovani

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )