Hi Andreas,
Andreas Lauschke escribió:
Ariel,
did you get my email of July 6? How do I return an array as an
array formula (the Shift+Ctrl Return thing)?
yes I recived it, so please sorry me, I have three mails of you marked
as TO-DO, but didn't find the time to give a responsible answer (the end
of the first academic semester [it ends today here in Argentina -
followed by a 2 weeks winter holidays] kept me too busy; to this add a
Patagonian trip to see the glacier tearing apart [] and a 22 nights
Krystov Kieslowski film retrospective; all this together kept me away
from hobby-things like playing with OOo API).
Anyway, remember that if you send your mail to [email protected]
you have more chances to get a faster/better answer.
In the following I quote and answer your previous questions (again,
sorry for the delay)
Can you see what is wrong with the attached .oxt file? When I
double-click it and register with OOo, my test function shows up in the
function browser in Calc, but I get an error #Null!, which means there
is an internal syntax error. It should just display a test string,
that's all, but it doesn't.
Without seeing the code, unfortunately I can't do much, other than wild
guessing... so I guess it has something to do with the type of the value
you return, and if it matches its IDL declaration. So please send me the
source code if you need a deeper look into this.
When I say deploy, I get the "number of type" error.
But when I choose debug, for some reason it works!
what do you mean by the "number of type" error?
Any way, I strongly discourage deploying ("Deploy OOo Extension" or
"Deploy and run extension in OOo") the extension in your working OOo,
even if there is no current OOo process started.
Reasons:
* by deploying once and again testing extensions in your working OOo,
you may end messing up your OOo user installation (the only solution
will be then to remove the openoffice.org2/user/uno_packages folder); so
you better keep your OOo inst. clean
* by deploying in a running installation you may get runtime exceptions
(you may want to re-install a component that was already instantiated by
the office and is in use, etc.)
* etc. ...
So the *best* choice for testing/studying is debugging, and deploying
only in the final testing step, to make sure it works.
It's the best because when debugging, the office is started with an
environment parameter that tells to create the user directory inside the
*build* folder of your NB project, keeping your real user installation
clean and safe. Every time you clean the project, this user directory is
deleted.
You can try this on your own by using the switch
-env:"UserInstallation=file:///[here goes an URL pointing to the
location where you want your user installation to be]/"
For example to deploy the extension on a new user installation anywhere
you want [in this case /home/ariel/ooo-debug/]:
/opt/openoffice.org2.4/program/unopkg gui -f
"file:///home/ariel/NetBeansProjects/ooo/Addins/DemoAddin.oxt"
-env:"UserInstallation=file:///home/ariel/ooo-debug/"
To start the office reading/writing the user setting from this dir.:
/opt/openoffice.org2.4/program/soffice -nologo -nofirststartwizard
-norestore -env:"UserInstallation=file:///home/ariel/ooo-debug/"
For extra command line arguments, type soffice -help on the command line.
It makes me go through the whole setup wizard again,
use the option -nofirststartwizard
and then I am in OOo, not Calc (I have to open Calc from within OOo),
but then my function is there, and it works!
use the option -calc
How to do this from within NetBeans? [a basic knowledge of how Ant works
is helpful - unfortunately people now, "thanks" to cool IDEs, start
coding without studying basic things like the use of GNU Make or Ant]
* go to the "Files" window (ctr-2)
* expand the tree and open the Ant build script for the UNO project:
MyProject
|-----nbproject
\----------build-uno-impl.xml
* find the target "uno-debug" (it's very easy using the "Navigator" window)
* there add the environment variables and additional arguments where it
says "<!-- start Office with debug Java and user installation -->"
<exec executable="${office.soffice}" dir="${office.program.dir}"
failonerror="true">
<arg value="-nofirststartwizard"/>
<arg value="-calc"/>
<env key="UserInstallation"
value="${office.debug.user.directory}"/>
<env key="JAVA_TOOL_OPTIONS" value=""-Xdebug"
"-Xrunjdwp:transport=dt_socket,address=${jpda.address}""/>
</exec>
Although you can customize build targets editing the
MyProject/build.xml, in this case we must manipulate directly the
build-uno-impl.xml (and notice that the OOo NB plug-in may re-generate
the build script, so you may need to do edit again).
In this case I added:
<arg value="-nofirststartwizard"/>
to disable the annoying first start wizard (but in OOo 2.4 still a
dialog pops up, this may be an issue...)
<arg value="-calc"/>
so that OOo starts directly with a spreadsheet document.
When developing/studying/debugging/etc OOo Calc Add-Ins, I find it very
useful to have a spreadsheet document with the functions already applied
to cell[ranges], and open this doc. on start up.
* create a Calc doc and add apply your function to some cell/s. The best
way is not to use the user interface name of the function ("DisplayName"
in the CalcAddIns.xcu) but to use the fully qualified service/impl. name
+ function name, for example
=ar.com.arielconstenlahaile.addindemo.DocCellAccessAddIn.rgb(D1;A1;B1;C1;TRUE())
unfortunately this can't be done manually in the GUI, because OOo Calc
will convert all letters to small-case, and then your add-in will not be
instantiated (as there will be no such service named
ar.com.arielconstenlahaile.addindemo.doccellaccessaddin to instantiate).
So you have to use setFormula() on every cell you want [you can do this
faster with OOo Basic instead of using Java]
* store this doc. as, let's say, AddinDemo.ods inside the root folder of
your NB project
* in the project's property file add the following property-value pair
sample.doc.name=AddinDemo.ods
* you can choose to manipulate the UNO project build script, or the
customizable build script [it's better to use the customizable build
script, because the UNO build script may be regenerated, but as we had
manipulated this already...]
** in build-uno-impl.xml, add to the target uno-project-init
<property name="sample.doc"
value="${project.dir}${file.separator}${sample.doc.name}"/>
** or in build.xml add
<target name="-post-init" depends="-uno-project-init">
<!-- This is added to open the test document on start-up, when
debugging -->
<property name="sample.doc"
value="${project.dir}${file.separator}${sample.doc.name}"/>
</target>
* finally, in the same place where we added <arg
value="-nofirststartwizard"/> , this time instead of <arg
value="-calc"/>, we pass an URL
<arg value="${sample.doc}"/>
So that the invocation to the office executable looks like this:
<!-- start Office with debug Java and user installation -->
<exec executable="${office.soffice}" dir="${office.program.dir}"
failonerror="true">
<arg value="-nofirststartwizard"/>
<arg value="${sample.doc}"/>
<env key="UserInstallation"
value="${office.debug.user.directory}"/>
<env key="JAVA_TOOL_OPTIONS" value=""-Xdebug"
"-Xrunjdwp:transport=dt_socket,address=${jpda.address}""/>
</exec>
(Closing it doesn't work right then. When I exit Calc I still have OOo open,
and when I kill staroffice.bin in the task manager,
NETBeans finally returns).
This does not happen under Linux, but I could reproduce this on Windows.
I don't know if this an OOo issue, or a NetBeans, or Java one.
I should also mention that if I do the sequence Clean and Build,
create oxt extension, Clean, I now get a compile error in
the .java file again. Apparently Clean removes something,
so NETBeans doesn't find the X... file anymore.
I have to redo Clean and Build in order to get it to compile.
But even then, I cannot deploy after creating the .oxt file,
I HAVE to choose debug.
I didn't understand completely what you mean, but I guess your talking
about the fact that you use the wizard to define a new interface with
methods to use as add-in functions in Calc, this generates two
Something.idl and XSomething.idl files. Then in the generated
XXXImpl.java file, you find your class that implements XSomething, but
NB underlines XSomething in read, telling it can't find the symbol...etc...
In order to understand all these, you should read the Developer's Guide,
its chapter about "Writing UNO Components", because Calc Add-Ins are UNO
components: so you must understand the process of developing a UNO
component.
In the case of Calc add-in the process can be resumed to:
1. think first what functions you want to add (this implies thinking
well about the kind of arguments and return values, etc.)
2. write the IDL specification for your functions: you must define new
interface/s with these method/s. You will have now .idl files
3. Compile the *.idl files using the compiler that comes with the SDK:
idlc. This will generate *.urd files [UNO reflection data] containing
binary type descriptions for the types [==new interface/s with new
methods] you have defined
4. merge this *.urd files into a registry database (*.rdb) using the
tool regmerge that comes with the SDK. You can check the result using
the tool regview
5. from the *.rdb [the registry database keeps a registry of the types
you have defined] generate a language dependent representation of this types
5.1 for C++, use cppumaker, that will generate a pair of headers *.hpp
*.hdl. The *.hpp files are the ones to include in your impl. files and
pass to the compiler with -Ipath/to/*.hpp ...
5.2. for Java, use javamaker, that will generate *.class files for your
types. This *.class files must be added to the class path when compiling.
As Java knows nothing about .idl nor .rdb files, the new interface you
have defined [ let's say XSomething, declared as being implemented by
your impl. class, let's say MyXSomethingImpl in MyXSomethingImpl.java]
must be known to Java at compile time in the way it understands: as
*.class files [in the NB Ide these files are build on a Java ARchive:
IDL_types.jar]; otherwise, it will generate an error: you say to
implement some interface methods, but Java can't find the symbols for
this interface.
6. at last, but not at least [missing in the Dev's Guide, this very
important step is not mentioned at all]: generate the source code for
implementing the add-in using the tool uno-skeletonmaker that comes with
the SDK. This will generate, in the case of Java, a *.java file (as the
one you find when the wizard in the NB plug-in finishes)
If you understood all this process, you may see clearly that when
cleaning the NB Project this language dependent representation of your
new IDL types is deleted, so Java will now nothing about the implemented
interface unless you rebuild the project and assure the *.class files
are on the classpath at compile time.
For the NB editor red-underlying the new interface name as an error, you
can ignore this, and in fact you can compile successfully (
IDL_types.jar will be on the classpath, of course this jar must exist!
assure this by building first).
Please try to read the "Writing UNO Components" chapter; IMO trying to
create a Calc Add-In with a plain text editor and from the command line
will be the best exercise to understand how things work.
I also found that apparently I cannot use two signatures
for the same function name? That would be really horrible,
I hope I am doing something wrong, I *WANT* to
enable different signatures for the same function name.
Quoting from Dev's Guide
[http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Defining_an_Interface]
"You can not *override* an attribute or a method inherited from a parent
interface, that would not make sense in an abstract specification
anyway. Furthermore, *overloading* is not possible. The qualified
interface identifier in conjunction with the name of the method creates
a unique method name."
When I said
sometestinteger(int test)
sometestinteger(String teststring)
NETBeans didn't compile it. But when I said
sometestinteger(int test)
sometestinteger2(String teststring)
it worked (the only difference is that the string method is called differently).
This is nuts!
there is [an elegant?!] solution taking care of the supported types for
functions arguments, as described in the service
com.sun.star.sheet.AddIn
http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/AddIn.html
Playing with them you can define *OPTIONAL* arguments [I mean of type
"[Minimum Length]" in BASE( Number; Radix; [Minimum Length] )] and
*VARIABLE* arguments [like in IMPRODUCT(complex number; complex number
1; ...)]
how do I return an array? I want the array to be from
an array formula (what you enter with Ctrl+Shift Enter).
again
http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/AddIn.html
In http://www.ArielConstenlaHaile.com.ar/ooo/temp/ArrayAddIn.zip
you'll find an example of arrays.
http://www.ArielConstenlaHaile.com.ar/ooo/temp/DocCellAccessAddIn.zip
you'll find an example of optional args.
These are two dummy add-in that do nothing (but I find that dummy
examples that do nothing useful can in fact be very useful for learning).
I'd tell you that you *must* read the chap. in the Developer's Guide
about Calc Add-Ins
[http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Spreadsheet_Add-Ins],
but it's quite from the stone age, and for a
beginner using the NB plugin will be rather confusing (it does not
explain the use of the configuration file, nor how to use the possible
types for function's args and return values, etc. ...), so I tell you
*may* read it, and if confuses you, give it up...
Regarding the deployment issue (with debugger), I found out that the
problem is the deploy function in NETBeans. If I don't use it and
double-click the .oxt directly to install it in the Extension
Manager, it works just fine. But from within NETBeans it doesn't work.
IIRC reading the NB plugin source code, the menu does nothing but
invoke the Ant build target uno-deploy
<target name="uno-deploy" description="Deploys UNO extension
package" depends="uno-package">
<echo message="deploying UNO extension package ..."/>
<echo message="${office.unopkg} gui -f ${uno.package.name}"/>
<exec executable="${office.unopkg}" dir="${office.program.dir}"
failonerror="true">
<arg value="gui"/>
<arg value="-f"/>
<arg file="${uno.package.name}"/>
</exec>
</target>
If you understand Ant build scripts, you'll realize that the build
target does nothing but invoke unopkg as you would do from the command
line [see the example above].
See the text generated in the output window, it may say something like
deploying UNO extension package ...
/opt/openoffice.org2.4/program/unopkg gui -f
/home/ariel/NetBeansProjects/ooo/addins/DocCellAccessAddIn/dist/DocCellAccessAddIn.oxt
If you cannot execute this command from the command line, then
something is wrong with your plug-in configuration or something is wrong
with Windows [also notice that there is a bug on Windows with long file
paths, I've seen that debugging may work but deploying fails because of
this issue].
Again, I discourage deploying the extension in your common OOo with your
common user installation, see above.
(I hate NETBeans!)
mmm... among friends this kind of topic starts the IDEs-war (NB vs.
Eclipse, etc.). Me, for Java, I like NB (even over Eclipse).
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]