Multiple Plugins - "Invoke first plugin(already running instance) methods from second plugin"

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple Plugins - "Invoke first plugin(already running instance) methods from second plugin"

sharanbabuk
This post was updated on .
Hello Everyone,

I'm working on an application where we need to invoke variables or methods of a plugin that is already running under imageJ. Here invocation(or pulling values from 1st plugin) should happen from 2nd plugin. I hope, I'm not confusing. To be clear, my intention is to get variable values of plugin-1 by executing plugin-2.
I went through the threads and found only 1 relevant thread(http://imagej.1557.x6.nabble.com/call-to-my-plugin-from-other-one-td3684404.html). It says that we can re-execute plugin-1 from plugin-2 by using IJ.run(plugin-1) command. But this doesn't solve my purpose as it is creating a new instance of plugin-1. Rather, in my case, I need to get variables from already running instance of plugin-1

Let me know if you need any other information.

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Plugins - "Invoke first plugin(already running instance) methods from second plugin"

Peterbauer Thomas
Hi,

you could implement a static method in plugin1 which returns a reference
to itself. Something like:

public class Plugin1 implements PlugIn {

     //Reference to Plugin1
     private static Plugin1 thisIsPlugin1;
     //Reference to some value in plugin1
     private int someValueInPlugin1 = 1;

     //Constructor creating a reference to itself
     public Plugin1() {
         thisIsPlugin1 = this;
     }

     //Returns a reference to plugin1
     public static Plugin1 getInstance() {
         return thisIsPlugin1;
     }

     //Returns some value from plugin1
     public int getSomeValueFromPlugin1() {
         return someValueInPlugin1;
     }

     //Startup of plugin1
     public void run(String arg) {
         //Create some object
         new Plugin1();
     }
}

In plugin2, you can then use:

    ...
   Plugin1 p1 = Plugin1.getInstance();
   if (p1 != null) {
     int someValueInPlugin1 = p1.getSomeValueFromPlugin1();
    }

If you cannot make use of this (perhaps because you cannot change the
code of plugin1), other ways involving ImageJ's WindowManager class
might be possible.

Best,
Thomas


On 2014-04-19 00:24, sharanbabuk wrote:

> Hello Everyone,
>
> I'm working on an application where we need to invoke variables or methods
> of a plugin that is already running under imageJ. Here invocation(or pulling
> values from 1st plugin) should happen from 2nd plugin when I execute it. I
> hope I'm not confusing. To be clear, my intention is to get variable values
> from plugin-1 by executing plugin-2.
> I went through the threads and found only 1 relevant thread. It says that we
> can re-execute plugin-1 from plugin-2 by using IJ.run(plugin-1) command. But
> this doesn't solve my purpose as it is creating a new instance of plugin-1.
> Rather, in my case, I need to get variables from already running instance of
> plugin-1
>
> Let me know if you need any other information.
>
> Thanks
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Multiple-Plugins-Invoke-first-plugin-already-running-instance-methods-from-second-plugin-tp5007363.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Plugins - "Invoke first plugin(already running instance) methods from second plugin"

sharanbabuk
@Thomas Peterbauer-2

Thanks for the quick reply.
I tried those suggestions and it is working perfectly fine!