I've tried what you recommended but couldn't get it to work. The
dispatch seems to work and I don't get any errors or exceptions but the
Macro doesn't get called somehow...
My java class implements XDispatchProvider and XDispatch.
Inside my dispatch(...) I call the macro if the user has clicked on the
corresponding button. I guess I'm doing something wrong here but can't
fiddle out what! I also tried with a simple macro that doesn't need any
macros, but it failed as well.
java.class:
...inside the dispatch(..)...
String[] filterNames = { "Test" };
String defaultName = "test";
String defaultDir = "file:///";
PropertyValue[] propertyvalue = new PropertyValue [4];
propertyvalue[0] = new PropertyValue();
propertyvalue[0].Value = xTextDocument;
propertyvalue[1] = new PropertyValue();
propertyvalue[1].Value = filterNames;
propertyvalue[2] = new PropertyValue();
propertyvalue[2].Value = defaultName;
propertyvalue[3] = new PropertyValue();
propertyvalue[3].Value = defaultDir;
com.sun.star.util.URL[] URL = new
com.sun.star.util.URL[1];
URL[0] = new URL();
URL[0].Complete =
"vnd.sun.star.script:Tools.ModuleControls.StoreDocument?language=Basic&location=application";
XURLTransformer xParser =
(XURLTransformer)UnoRuntime.queryInterface(XURLTransformer.class,
xMCF.createInstanceWithContext("com.sun.star.util.URLTransformer",
xComponentContext));
xParser.parseStrict(URL);
URL aURL = URL[0];
dispatch(aURL, propertyvalue);
Carsten Driesner schrieb:
Jimmy wrote:
How can I dispatch a macro Url from my Java Add-on?
I'd like to dispatch the following function in the
Tools/ModuleControles Library:
StoreDocument(oDocument as Object, FilterNames() as String,
DefaultName as String, DisplayDirectory as String, Optional
iAddProcedure as Integer)
I'd like to call this function from my add-on. It would be best if I
could call this function from my Addons.xcu but this leads to a crash
since I don't know how to set the oDocument parameter in the xcu file.
Is there any other chance to call the macro? I can catch the dispatch
for the corresponding button but don't know how to go any further..
Hi Jimmy,
It's not possible to create a script URL with complex parameters like
Object (argument 1) or a sequence (argument 2). Therefore you have to
create your own DispatchProvider and forward the call to your script
via dispatch API.
Thanks
public void dispatch(URL arg0, PropertyValue[] arg1) {
if (arg0.Protocol.compareTo("org.openoffice.addon.MyAddon:")
== 0) {
if (arg0.Path.compareTo("FuncExport") == 0) {
try {
Iterator iterOn = frames.iterator();
while (iterOn.hasNext()) {
FrameInfo actFrameInfo = (FrameInfo)
iterOn.next();
if (actFrameInfo.getXComp() == ElementController
.getXComponent()) {
convertElml = actFrameInfo.getXmlConverter();
break;
}
}
// NOW CALL THE MACRO
} catch (java.lang.Exception e) {
e.printStackTrace();
}
}
}
}
You should read the following Developer's Guide chapter 18.6.1
Scripting Framework URI Specification.
You have to dispatch a "vnd.sun.star.script:"-URL which refers to your
Basic macro. The arguments for your script function have to be passed
within the ::com::sun::star::uno::Sequence<
::com::sun::star::beans::PropertyValue > argument. The first entry
should match your first argument.
So your code would look like that (pseudo code):
Sequence< OUString > aSeqFilterNames(1):
Sequence< PropertyValue > aSeqArgs(4);
OUString aDefaultName;
OUString aDirectory;
...
aSeqArgs[0].Value = makeAny( xMyDocument );
aSeqArgs[1].Value = makeAny( aSeqFilterNames );
aSeqArgs[2].Value = makeAny( aDefaultName );
aSeqArgs[3].Value = makeAny( aDirectory );
com::sun::star::util::URL aURL;
aURL.Complete = OUString(
"vnd.sun.star.script:Library.Module.StoreDocument?language=Basic&location=application"
);
xDispatch->dispatch( aURL, aSeqArgs );
Regards,
Carsten
---------------------------------------------------------------------
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]