Registering EventListeners on Add-on Menu item

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi,
I would like to know if a client application can add a listener to an add-on menu item. I am guessing that when the user clicks the add-on menu item, the client application gets a call on the listener. Likewise I would also like to get a callback in the client application when the user executes a macro. Is there any sample code to exhibit this behavior.  

thanks,
Mangesh.
Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi,
   I would like to know if an external application can listen to events in OpenOffice.org. Or rather, I would like to get a call from OpenOffice.org to my application whenever one of the custom Add-on or Macro gets executed. Please let me know if this is possible. I have posted this question on several forums and have not got any response yet.

Thanks,
Mangesh.


-----Original Message-----
From: Shukla, Mangesh [mailto:[hidden email]]
Sent: Monday, January 07, 2013 5:28 PM
To: [hidden email]
Subject: Registering EventListeners on Add-on Menu item

Hi,
I would like to know if a client application can add a listener to an add-on menu item. I am guessing that when the user clicks the add-on menu item, the client application gets a call on the listener. Likewise I would also like to get a callback in the client application when the user executes a macro. Is there any sample code to exhibit this behavior.  

thanks,
Mangesh.
Reply | Threaded
Open this post in threaded view
|

Re: Registering EventListeners on Add-on Menu item

Ariel Constenla-Haile-2
In reply to this post by Shukla, Mangesh
Hi Mangesh,

On Mon, Jan 07, 2013 at 11:57:47AM +0000, Shukla, Mangesh wrote:
> Hi, I would like to know if a client application can add a listener to
> an add-on menu item. I am guessing that when the user clicks the
> add-on menu item, the client application gets a call on the listener.

I don't get if you are talking about an extension (add-on) or a real
client application. Can you clarify this?


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi Ariel,
    Thanks for your response. I am talking about a real client application. When a Add-on button is clicked (or any other actions is performed), I need the external client application to get a notification ( or a callback) so that I can populate the spreadsheet with information from the external application. I have read the information about the Automation support (which is specific to Windows), but I intend to have this working on Mac as well as Linux OS. My preferred language is C++, as the client application uses C++. Please let me know if you need anything else.

Thanks,
Mangesh




-----Original Message-----
From: Ariel Constenla-Haile [mailto:[hidden email]]
Sent: Tuesday, January 08, 2013 3:54 PM
To: [hidden email]
Subject: Re: Registering EventListeners on Add-on Menu item

Hi Mangesh,

On Mon, Jan 07, 2013 at 11:57:47AM +0000, Shukla, Mangesh wrote:
> Hi, I would like to know if a client application can add a listener to
> an add-on menu item. I am guessing that when the user clicks the
> add-on menu item, the client application gets a call on the listener.

I don't get if you are talking about an extension (add-on) or a real client application. Can you clarify this?


Regards
--
Ariel Constenla-Haile
La Plata, Argentina
Reply | Threaded
Open this post in threaded view
|

Re: Registering EventListeners on Add-on Menu item

Ariel Constenla-Haile-2
Hi Mangesh,

On Tue, Jan 08, 2013 at 10:31:47AM +0000, Shukla, Mangesh wrote:
> Hi Ariel, Thanks for your response. I am talking about a real client
> application. When a Add-on button is clicked (or any other actions is
> performed), I need the external client application to get
> a notification ( or a callback) so that I can populate the spreadsheet
> with information from the external application. I have read the
> information about the Automation support (which is specific to
> Windows), but I intend to have this working on Mac as well as Linux
> OS. My preferred language is C++, as the client application uses C++.
> Please let me know if you need anything else.

The first thing that comes to my mind, is why aren't you implementing
all this with an extension, it would be much simpler:

- you define a menu/toolbar item on Addons.xcu with a custom URL

- you register a ProtocolHandler to handle this URL, the application
  framework will query your ProtocolHandler for an object that can
  dispatch this URL and provide feature updates: your Dispatch

- when the user executes the menu/toolbar item, your Dispatch will be
  invoked to dispatch the respective URL, that is, perform the action
  associated with the URL (here you will populate the spreadsheet)

Doing this with a client application is far more complex: you will have
to intercept when the application framework queries for a Dispatch
object, so that it is your client application the one that provides the
Dispatch object, instead of the original ProtocolHandler.

You can achieve this with a "dispatch interceptor":
http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Dispatch_Interception

Back to the original question: registering a menu/toolbar listener is
impossible, this is as designed, it will be a huge performance issue;
only the component in the application framework responsible for
controlling the menu/tool bar is a menu/toolbar listener (it gets
notified when the menu/toolbar item is selected/clicked, and dispatches
the respective URL using the dispatch framework).


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi Ariel,
    Thanks for the quick reply.  Actually I intend to implement this just as you describe. I intend to create an Extension to add my own Menu and toolbar items. Also I will be adding some Macros (functions which appear in the functions wizard), to the extension. The intention to add these UI items, is to transfer the call to the external application, so that the data from the external application can be populated in the spreadsheet. The actual functionality lies in the external application, and I need to get the calls redirected to the external application as and when the user invokes the menu items/toolbar items/macros in the extension.

I have checked the link about the dispatch framework. However it is not clear to me, how it could be made to work with a C++ client. Could you direct me to some samples to illustrate the behavior.

Regards,
Mangesh

-----Original Message-----
From: Ariel Constenla-Haile [mailto:[hidden email]]
Sent: Tuesday, January 08, 2013 4:33 PM
To: [hidden email]
Subject: Re: Registering EventListeners on Add-on Menu item

Hi Mangesh,

On Tue, Jan 08, 2013 at 10:31:47AM +0000, Shukla, Mangesh wrote:
> Hi Ariel, Thanks for your response. I am talking about a real client
> application. When a Add-on button is clicked (or any other actions is
> performed), I need the external client application to get a
> notification ( or a callback) so that I can populate the spreadsheet
> with information from the external application. I have read the
> information about the Automation support (which is specific to
> Windows), but I intend to have this working on Mac as well as Linux
> OS. My preferred language is C++, as the client application uses C++.
> Please let me know if you need anything else.

The first thing that comes to my mind, is why aren't you implementing all this with an extension, it would be much simpler:

- you define a menu/toolbar item on Addons.xcu with a custom URL

- you register a ProtocolHandler to handle this URL, the application
  framework will query your ProtocolHandler for an object that can
  dispatch this URL and provide feature updates: your Dispatch

- when the user executes the menu/toolbar item, your Dispatch will be
  invoked to dispatch the respective URL, that is, perform the action
  associated with the URL (here you will populate the spreadsheet)

Doing this with a client application is far more complex: you will have to intercept when the application framework queries for a Dispatch object, so that it is your client application the one that provides the Dispatch object, instead of the original ProtocolHandler.

You can achieve this with a "dispatch interceptor":
http://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Dispatch_Interception

Back to the original question: registering a menu/toolbar listener is impossible, this is as designed, it will be a huge performance issue; only the component in the application framework responsible for controlling the menu/tool bar is a menu/toolbar listener (it gets notified when the menu/toolbar item is selected/clicked, and dispatches the respective URL using the dispatch framework).


Regards
--
Ariel Constenla-Haile
La Plata, Argentina
Reply | Threaded
Open this post in threaded view
|

Re: Registering EventListeners on Add-on Menu item

Ariel Constenla-Haile-2
Hi Mangesh,

On Tue, Jan 08, 2013 at 11:18:17AM +0000, Shukla, Mangesh wrote:

> Hi Ariel, Thanks for the quick reply.  Actually I intend to implement
> this just as you describe. I intend to create an Extension to add my
> own Menu and toolbar items. Also I will be adding some Macros
> (functions which appear in the functions wizard), to the extension.
> The intention to add these UI items, is to transfer the call to the
> external application, so that the data from the external application
> can be populated in the spreadsheet. The actual functionality lies in
> the external application, and I need to get the calls redirected to
> the external application as and when the user invokes the menu
> items/toolbar items/macros in the extension.
Then the proper way to do this seems not to intercept the dispatch
framework; simply implement an extension that communicates to the
external application when it is asked to dispatch; the steps would be:

- the dispatch framework asks your extension to dispatch a certain URL
  when the user executes a menu/toolbar item

- when dispatching, your extension communicates to the external
  application an retrieves the information to populate the spreadsheet

The key point here is the communication between the extension and the
external application. The Zotero extension talks to Zotero,
a bibliographic program for Firexfox (or standalone), does this via
a socket (AFAIK).

Another thing to consider: is this external application already running
on the target system, or are you planning to install the application
together with the extension?


> I have checked the link about the dispatch framework. However it is
> not clear to me, how it could be made to work with a C++ client. Could
> you direct me to some samples to illustrate the behavior.

IIRC there is an example in the SDK, but it's written in Java, and is
rather complicated/obscure. Anyway, I wouldn't suggest to follow this
path of intercepting dispatches in the external application; better
implement an extension that "talks to" this external application.

There are several drawbacks for the other approach:

- the external application will have to be linked to the URE
- the external application will have to bootstrap OpenOffice, or connect
  to a running instance
- etc


Regards
--
Ariel Constenla-Haile
La Plata, Argentina

attachment0 (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi Ariel,
    The way I intend to use OpenOffice  Calc, is as follows:
1] OpenOffice.org Calc is started/launched from the external application. i.e external application exists along with OpenOffice on the same machine and is always available.
2] The external application connects on a socket type of connection, on a port to OpenOffice.org Calc.
3] An extension is implemented and deployed which adds the menu items to Calc. (it also adds macros to the extension). Ideally I would like to enable the extension only when Calc is started by the external application. And I am looking for ways to do this. But that is for later.
4] When the user invokes the menu on the extension, my extension communicates to the external  application an retrieves the information to populate the spreadsheet.

From your comments, I gather that you are advising me to  implement an extension that "talks to" this external application, and I thank you for your suggestions. It would be very helpful if you could give me more details on this or point me to some sample application. I have searched the web and have found very little information on this.

Thanks,
Mangesh.
 



-----Original Message-----
From: Ariel Constenla-Haile [mailto:[hidden email]]
Sent: Tuesday, January 08, 2013 5:15 PM
To: [hidden email]
Subject: Re: Registering EventListeners on Add-on Menu item

Hi Mangesh,

On Tue, Jan 08, 2013 at 11:18:17AM +0000, Shukla, Mangesh wrote:

> Hi Ariel, Thanks for the quick reply.  Actually I intend to implement
> this just as you describe. I intend to create an Extension to add my
> own Menu and toolbar items. Also I will be adding some Macros
> (functions which appear in the functions wizard), to the extension.
> The intention to add these UI items, is to transfer the call to the
> external application, so that the data from the external application
> can be populated in the spreadsheet. The actual functionality lies in
> the external application, and I need to get the calls redirected to
> the external application as and when the user invokes the menu
> items/toolbar items/macros in the extension.

Then the proper way to do this seems not to intercept the dispatch framework; simply implement an extension that communicates to the external application when it is asked to dispatch; the steps would be:

- the dispatch framework asks your extension to dispatch a certain URL
  when the user executes a menu/toolbar item

- when dispatching, your extension communicates to the external
  application an retrieves the information to populate the spreadsheet

The key point here is the communication between the extension and the external application. The Zotero extension talks to Zotero, a bibliographic program for Firexfox (or standalone), does this via a socket (AFAIK).

Another thing to consider: is this external application already running on the target system, or are you planning to install the application together with the extension?


> I have checked the link about the dispatch framework. However it is
> not clear to me, how it could be made to work with a C++ client. Could
> you direct me to some samples to illustrate the behavior.

IIRC there is an example in the SDK, but it's written in Java, and is rather complicated/obscure. Anyway, I wouldn't suggest to follow this path of intercepting dispatches in the external application; better implement an extension that "talks to" this external application.

There are several drawbacks for the other approach:

- the external application will have to be linked to the URE
- the external application will have to bootstrap OpenOffice, or connect
  to a running instance
- etc


Regards
--
Ariel Constenla-Haile
La Plata, Argentina
Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
In reply to this post by Ariel Constenla-Haile-2
Hi Ariel,
     Could you please give me more details on what exactly should be done to establish communication between OpenOffice.org and external application.

Thanks,
Mangesh

-----Original Message-----
From: Shukla, Mangesh
Sent: Tuesday, January 08, 2013 5:50 PM
To: [hidden email]
Subject: RE: Registering EventListeners on Add-on Menu item

Hi Ariel,
    The way I intend to use OpenOffice  Calc, is as follows:
1] OpenOffice.org Calc is started/launched from the external application. i.e external application exists along with OpenOffice on the same machine and is always available.
2] The external application connects on a socket type of connection, on a port to OpenOffice.org Calc.
3] An extension is implemented and deployed which adds the menu items to Calc. (it also adds macros to the extension). Ideally I would like to enable the extension only when Calc is started by the external application. And I am looking for ways to do this. But that is for later.
4] When the user invokes the menu on the extension, my extension communicates to the external  application an retrieves the information to populate the spreadsheet.

From your comments, I gather that you are advising me to  implement an extension that "talks to" this external application, and I thank you for your suggestions. It would be very helpful if you could give me more details on this or point me to some sample application. I have searched the web and have found very little information on this.

Thanks,
Mangesh.
 



-----Original Message-----
From: Ariel Constenla-Haile [mailto:[hidden email]]
Sent: Tuesday, January 08, 2013 5:15 PM
To: [hidden email]
Subject: Re: Registering EventListeners on Add-on Menu item

Hi Mangesh,

On Tue, Jan 08, 2013 at 11:18:17AM +0000, Shukla, Mangesh wrote:

> Hi Ariel, Thanks for the quick reply.  Actually I intend to implement
> this just as you describe. I intend to create an Extension to add my
> own Menu and toolbar items. Also I will be adding some Macros
> (functions which appear in the functions wizard), to the extension.
> The intention to add these UI items, is to transfer the call to the
> external application, so that the data from the external application
> can be populated in the spreadsheet. The actual functionality lies in
> the external application, and I need to get the calls redirected to
> the external application as and when the user invokes the menu
> items/toolbar items/macros in the extension.

Then the proper way to do this seems not to intercept the dispatch framework; simply implement an extension that communicates to the external application when it is asked to dispatch; the steps would be:

- the dispatch framework asks your extension to dispatch a certain URL
  when the user executes a menu/toolbar item

- when dispatching, your extension communicates to the external
  application an retrieves the information to populate the spreadsheet

The key point here is the communication between the extension and the external application. The Zotero extension talks to Zotero, a bibliographic program for Firexfox (or standalone), does this via a socket (AFAIK).

Another thing to consider: is this external application already running on the target system, or are you planning to install the application together with the extension?


> I have checked the link about the dispatch framework. However it is
> not clear to me, how it could be made to work with a C++ client. Could
> you direct me to some samples to illustrate the behavior.

IIRC there is an example in the SDK, but it's written in Java, and is rather complicated/obscure. Anyway, I wouldn't suggest to follow this path of intercepting dispatches in the external application; better implement an extension that "talks to" this external application.

There are several drawbacks for the other approach:

- the external application will have to be linked to the URE
- the external application will have to bootstrap OpenOffice, or connect
  to a running instance
- etc


Regards
--
Ariel Constenla-Haile
La Plata, Argentina
Reply | Threaded
Open this post in threaded view
|

Re: Registering EventListeners on Add-on Menu item

Marcin Gutman
 > Could you please give me more details on what exactly should be done
to establish communication between
 > OpenOffice.org and external application.
 >
Maybe this will be helpful...
You can check this extensions:
http://extensions.libreoffice.org/extension-center/improved-trend-lines
http://extensions.libreoffice.org/extension-center/digitizer-of-xy-chart

They are available in two versions each i.e. as an OXT extension or as a
"standalone" JAR version.

In both cases GUI are written in pure Java Swing.
In the first case GUI are started using L/OOo "Add-Ons" menu.
In the second case L/OOo is not running. For the first time when a GUI
is started from a JAR file (as any java program) a path to a directory
with "soffice" executable must be set. After that a GUI is able to
launch L/OOo and connect yourself to it using L/OOo Bootstrap method.

(Source code is available.)

Best Regards,
Marcin


Reply | Threaded
Open this post in threaded view
|

RE: Registering EventListeners on Add-on Menu item

Shukla, Mangesh
Hi Marcin,
    Thanks for your response. Hopefully this will get me started.

Warm regards,
Mangesh


-----Original Message-----
From: Marcin Gutman [mailto:[hidden email]]
Sent: Wednesday, January 09, 2013 5:04 PM
To: [hidden email]; Shukla, Mangesh
Subject: Re: Registering EventListeners on Add-on Menu item

 > Could you please give me more details on what exactly should be done to establish communication between  > OpenOffice.org and external application.
 >
Maybe this will be helpful...
You can check this extensions:
http://extensions.libreoffice.org/extension-center/improved-trend-lines
http://extensions.libreoffice.org/extension-center/digitizer-of-xy-chart

They are available in two versions each i.e. as an OXT extension or as a "standalone" JAR version.

In both cases GUI are written in pure Java Swing.
In the first case GUI are started using L/OOo "Add-Ons" menu.
In the second case L/OOo is not running. For the first time when a GUI is started from a JAR file (as any java program) a path to a directory with "soffice" executable must be set. After that a GUI is able to launch L/OOo and connect yourself to it using L/OOo Bootstrap method.

(Source code is available.)

Best Regards,
Marcin