I have my custom event class which implements several listeners The handleEvent methods of the class depends on a JTree which is created after files are loaded through a custom JFrame. Thus, I can't register the listeners in CyActivator. I instantiated the class, and passed references of the class + a reference of CyServiceRegistrar through to where my JFrame is being created. After my files are loaded and my JTree is created, I set the JTree in my custom event listener class like this: myListeners.setTree(myJTree) and register the listeners.
However, I run into this issue: In the case that someone loads JFrame file loader from the app menu to load the the files a *second* time, the listeners are registered again and thus my handleEvent methods are called more than once.
I tried unregistering all services when my custom file loader JFrame is opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but it fails
I usually get around that issue by reusing the JFrame instance. For
example, your menu item could be a CyAction that lazily instantiates the
JFrame. If the JFrame already exists, it just re-displays it. That way,
your JFrame is created exactly once and the services are registered only
once.
On Sat, Sep 15, 2012 at 7:28 PM, Omar Wagih <omarwa...@gmail.com> wrote:
> I have my custom event class which implements several listeners
> The handleEvent methods of the class depends on a JTree which is created
> after files are loaded through a custom JFrame. Thus, I can't register the
> listeners in CyActivator.
> I instantiated the class, and passed references of the class + a reference
> of CyServiceRegistrar through to where my JFrame is being created.
> After my files are loaded and my JTree is created, I set the JTree in my
> custom event listener class like this: myListeners.setTree(myJTree) and
> register the listeners.
> However, I run into this issue:
> In the case that someone loads JFrame file loader from the app menu to
> load the the files a *second* time, the listeners are registered again
> and thus my handleEvent methods are called more than once.
> I tried unregistering all services when my custom file loader JFrame is
> opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but
> it fails
> Any idea what's going on?
> Thanks
> --
> You received this message because you are subscribed to the Google Groups
> "cytoscape-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cytoscape-discuss/-/JrM2K7WTPQYJ.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cytoscape-discuss?hl=en.
I dont think this will work in terms of debugging/developing my app.
Every time I rebuild my project and update my bundle in the cytoscape terminal, I want the old listeners to be removed/unregistered and the new one registered. Does this make sense?
I am constantly updating my listeners throughout the development of my app and would hate having to restart Cytoscape in order to see the effect of my new listeners without the redundancy of the old ones
Any alternatives?
Omar
On 2012-09-17, at 11:09 AM, Jason Montojo wrote:
> I usually get around that issue by reusing the JFrame instance. For example, your menu item could be a CyAction that lazily instantiates the JFrame. If the JFrame already exists, it just re-displays it. That way, your JFrame is created exactly once and the services are registered only once.
> Hope this helps,
> Jason
> On Sat, Sep 15, 2012 at 7:28 PM, Omar Wagih <omarwa...@gmail.com> wrote:
> I have my custom event class which implements several listeners
> The handleEvent methods of the class depends on a JTree which is created after files are loaded through a custom JFrame. Thus, I can't register the listeners in CyActivator.
> I instantiated the class, and passed references of the class + a reference of CyServiceRegistrar through to where my JFrame is being created. > After my files are loaded and my JTree is created, I set the JTree in my custom event listener class like this: myListeners.setTree(myJTree) and register the listeners.
> However, I run into this issue: > In the case that someone loads JFrame file loader from the app menu to load the the files a second time, the listeners are registered again and thus my handleEvent methods are called more than once.
> I tried unregistering all services when my custom file loader JFrame is opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but it fails
> Any idea what's going on?
> Thanks
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/cytoscape-discuss/-/JrM2K7WTPQYJ.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
When you update your bundle, OSGi unloads the old one and loads the new one
(i.e. you end up with a new JFrame). That causes all of the OSGi services
registered by your bundle to be forcefully unregistered. You shouldn't
need to restart Cytoscape for your changes to take effect. If Cytoscape is
holding onto references to your old class, then this will definitely not
work; for example, if you grab Cytoscape's JMenuBar and add things to that
directly. However, if you're extending Cytoscape strictly using OSGi
services (e.g. CyAction, *TaskFactory), you won't run into this problem.
I use the approach I described in the GeneMANIA app and I haven't run into
instances where I've had to restart Cytoscape when updating my app.
On Mon, Sep 17, 2012 at 2:15 PM, Omar Wagih <omarwa...@gmail.com> wrote:
> Hi Jason,
> I dont think this will work in terms of debugging/developing my app.
> Every time I rebuild my project and update my bundle in the cytoscape
> terminal, I want the old listeners to be removed/unregistered and the new
> one registered. Does this make sense?
> I am constantly updating my listeners throughout the development of my app
> and would hate having to restart Cytoscape in order to see the effect of my
> new listeners without the redundancy of the old ones
> Any alternatives?
> Omar
> On 2012-09-17, at 11:09 AM, Jason Montojo wrote:
> Hi Omar,
> I usually get around that issue by reusing the JFrame instance. For
> example, your menu item could be a CyAction that lazily instantiates the
> JFrame. If the JFrame already exists, it just re-displays it. That way,
> your JFrame is created exactly once and the services are registered only
> once.
> Hope this helps,
> Jason
> On Sat, Sep 15, 2012 at 7:28 PM, Omar Wagih <omarwa...@gmail.com> wrote:
>> I have my custom event class which implements several listeners
>> The handleEvent methods of the class depends on a JTree which is created
>> after files are loaded through a custom JFrame. Thus, I can't register the
>> listeners in CyActivator.
>> I instantiated the class, and passed references of the class + a
>> reference of CyServiceRegistrar through to where my JFrame is being
>> created.
>> After my files are loaded and my JTree is created, I set the JTree in my
>> custom event listener class like this: myListeners.setTree(myJTree) and
>> register the listeners.
>> However, I run into this issue:
>> In the case that someone loads JFrame file loader from the app menu to
>> load the the files a *second* time, the listeners are registered again
>> and thus my handleEvent methods are called more than once.
>> I tried unregistering all services when my custom file loader JFrame is
>> opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but
>> it fails
>> Any idea what's going on?
>> Thanks
>> --
>> You received this message because you are subscribed to the Google Groups
>> "cytoscape-discuss" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/cytoscape-discuss/-/JrM2K7WTPQYJ.
>> To post to this group, send email to cytoscape-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to
>> cytoscape-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/cytoscape-discuss?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cytoscape-discuss?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/cytoscape-discuss?hl=en.
I took your exact same approach. My JFrame class is instantiated in CyActivator and I have a class which extends AbstractCyAction and on actionPerformed it calls frame.setVisible(true)
This works fine.
Now, In my CyActivator class, I instantiate my listeners class and register my listeners:
myListeners = new AppListeners();
//Register listeners
registerService(bc, myListeners, NetworkViewAddedListener.class, new Properties());
My listeners class prints the following:
public void handleEvent(NetworkViewAddedEvent nvae) {
System.out.println("Network view add: registering->"+nvae.getNetworkView().getModel().getSUID());
}
If I build my app, launch cytoscape, update and start, when my network is generated I see the output:
Network view add: registering->71
Which is great. Now, If I rebuild changing the print statement to include more arrows, update my bundle and launch my app again, on a network view added event I see
> When you update your bundle, OSGi unloads the old one and loads the new one (i.e. you end up with a new JFrame). That causes all of the OSGi services registered by your bundle to be forcefully unregistered. You shouldn't need to restart Cytoscape for your changes to take effect. If Cytoscape is holding onto references to your old class, then this will definitely not work; for example, if you grab Cytoscape's JMenuBar and add things to that directly. However, if you're extending Cytoscape strictly using OSGi services (e.g. CyAction, *TaskFactory), you won't run into this problem.
> I use the approach I described in the GeneMANIA app and I haven't run into instances where I've had to restart Cytoscape when updating my app.
> Hope this helps,
> Jason
> On Mon, Sep 17, 2012 at 2:15 PM, Omar Wagih <omarwa...@gmail.com> wrote:
> Hi Jason,
> I dont think this will work in terms of debugging/developing my app.
> Every time I rebuild my project and update my bundle in the cytoscape terminal, I want the old listeners to be removed/unregistered and the new one registered. Does this make sense?
> I am constantly updating my listeners throughout the development of my app and would hate having to restart Cytoscape in order to see the effect of my new listeners without the redundancy of the old ones
> Any alternatives?
> Omar
> On 2012-09-17, at 11:09 AM, Jason Montojo wrote:
>> Hi Omar,
>> I usually get around that issue by reusing the JFrame instance. For example, your menu item could be a CyAction that lazily instantiates the JFrame. If the JFrame already exists, it just re-displays it. That way, your JFrame is created exactly once and the services are registered only once.
>> Hope this helps,
>> Jason
>> On Sat, Sep 15, 2012 at 7:28 PM, Omar Wagih <omarwa...@gmail.com> wrote:
>> I have my custom event class which implements several listeners
>> The handleEvent methods of the class depends on a JTree which is created after files are loaded through a custom JFrame. Thus, I can't register the listeners in CyActivator.
>> I instantiated the class, and passed references of the class + a reference of CyServiceRegistrar through to where my JFrame is being created. >> After my files are loaded and my JTree is created, I set the JTree in my custom event listener class like this: myListeners.setTree(myJTree) and register the listeners.
>> However, I run into this issue: >> In the case that someone loads JFrame file loader from the app menu to load the the files a second time, the listeners are registered again and thus my handleEvent methods are called more than once.
>> I tried unregistering all services when my custom file loader JFrame is opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but it fails
>> Any idea what's going on?
>> Thanks
>> -- >> You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
>> To view this discussion on the web visit https://groups.google.com/d/msg/cytoscape-discuss/-/JrM2K7WTPQYJ.
>> To post to this group, send email to cytoscape-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
>> -- >> You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
>> To post to this group, send email to cytoscape-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> When you update your bundle, OSGi unloads the old one and loads the new one (i.e. you end up with a new JFrame). That causes all of the OSGi services registered by your bundle to be forcefully unregistered. You shouldn't need to restart Cytoscape for your changes to take effect. If Cytoscape is holding onto references to your old class, then this will definitely not work; for example, if you grab Cytoscape's JMenuBar and add things to that directly. However, if you're extending Cytoscape strictly using OSGi services (e.g. CyAction, *TaskFactory), you won't run into this problem.
> I use the approach I described in the GeneMANIA app and I haven't run into instances where I've had to restart Cytoscape when updating my app.
> Hope this helps,
> Jason
> On Mon, Sep 17, 2012 at 2:15 PM, Omar Wagih <omarwa...@gmail.com> wrote:
> Hi Jason,
> I dont think this will work in terms of debugging/developing my app.
> Every time I rebuild my project and update my bundle in the cytoscape terminal, I want the old listeners to be removed/unregistered and the new one registered. Does this make sense?
> I am constantly updating my listeners throughout the development of my app and would hate having to restart Cytoscape in order to see the effect of my new listeners without the redundancy of the old ones
> Any alternatives?
> Omar
> On 2012-09-17, at 11:09 AM, Jason Montojo wrote:
>> Hi Omar,
>> I usually get around that issue by reusing the JFrame instance. For example, your menu item could be a CyAction that lazily instantiates the JFrame. If the JFrame already exists, it just re-displays it. That way, your JFrame is created exactly once and the services are registered only once.
>> Hope this helps,
>> Jason
>> On Sat, Sep 15, 2012 at 7:28 PM, Omar Wagih <omarwa...@gmail.com> wrote:
>> I have my custom event class which implements several listeners
>> The handleEvent methods of the class depends on a JTree which is created after files are loaded through a custom JFrame. Thus, I can't register the listeners in CyActivator.
>> I instantiated the class, and passed references of the class + a reference of CyServiceRegistrar through to where my JFrame is being created. >> After my files are loaded and my JTree is created, I set the JTree in my custom event listener class like this: myListeners.setTree(myJTree) and register the listeners.
>> However, I run into this issue: >> In the case that someone loads JFrame file loader from the app menu to load the the files a second time, the listeners are registered again and thus my handleEvent methods are called more than once.
>> I tried unregistering all services when my custom file loader JFrame is opened like this: serviceRegistrar.unregisterAllServices(myListeners);, but it fails
>> Any idea what's going on?
>> Thanks
>> -- >> You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
>> To view this discussion on the web visit https://groups.google.com/d/msg/cytoscape-discuss/-/JrM2K7WTPQYJ.
>> To post to this group, send email to cytoscape-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
>> -- >> You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
>> To post to this group, send email to cytoscape-discuss@googlegroups.com.
>> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.
> -- > You received this message because you are subscribed to the Google Groups "cytoscape-discuss" group.
> To post to this group, send email to cytoscape-discuss@googlegroups.com.
> To unsubscribe from this group, send email to cytoscape-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/cytoscape-discuss?hl=en.