Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Custom event listeners
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Omar Wagih  
View profile  
 More options Sep 11 2012, 12:40 am
From: Omar Wagih <omarwa...@gmail.com>
Date: Mon, 10 Sep 2012 21:40:43 -0700 (PDT)
Local: Tues, Sep 11 2012 12:40 am
Subject: Custom event listeners

From the 3.0 cookbook, its states that if you want to create a custom event
listener you do the following:

// Define a class, which implements a listener interfacepublic class MyListenerClass implements NetworkAddedListener {.... public void handleEvent(NetworkAddedEvent e){ // do something here }}and

// Register the listener in the CyActivator classregisterService(bc,myListenerClass, NetworkAddedListener.class, new Properties());

However, I have a custom object I would like to update when a network is added. How do I do that if my listener class has to be instantiated inside my CyActivator class..?

In other words, is there a way to register a listener class outside the CyActivator class?

Thanks,
Omar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Montojo  
View profile  
 More options Sep 11 2012, 10:24 am
From: Jason Montojo <jrr...@gmail.com>
Date: Tue, 11 Sep 2012 10:24:43 -0400
Local: Tues, Sep 11 2012 10:24 am
Subject: Re: [Cytoscape-discuss] Custom event listeners

Hi Omar,

You can (un)register OSGi services dynamically using a CyServiceRegistrar.
 It's available as an OSGi service so you can fetch it in CyActivator.
 Just hold on to a reference so you can use it later.

Hope this helps,
Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Scooter Morris  
View profile  
 More options Sep 11 2012, 10:57 am
From: Scooter Morris <scoo...@cgl.ucsf.edu>
Date: Tue, 11 Sep 2012 07:57:36 -0700
Local: Tues, Sep 11 2012 10:57 am
Subject: Re: [Cytoscape-discuss] Custom event listeners

Hi Omar,
     The other question is why don't you hand your custom object to the
listener in CyActivator?

    MyClass myObject = new MyClass();
    MyListenerClass listener = new MyListenerClass(myObject);
    registerService(bc, listener, NetworkAddedListener.class, new
    Properties());

That way, all of your services are in the CyActivator, which makes them
easier to find, and you can still pass around your status object.  In
your listener class, you could call methods to update your object.  
Another option is just to have MyClass implement NetworkAddedListener
and advertise that service...

Of course, you can, as Jason suggested also pass the CyServiceRegistrar
object down and register your services from there, but I don't really
see how that helps.  You still need to instantiate your object and the
CyActivator is the easiest place to do that...

-- scooter

On 09/11/2012 07:24 AM, Jason Montojo wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Omar Wagih  
View profile  
 More options Sep 12 2012, 1:26 am
From: Omar Wagih <omarwa...@gmail.com>
Date: Tue, 11 Sep 2012 22:26:03 -0700 (PDT)
Local: Wed, Sep 12 2012 1:26 am
Subject: Re: [Cytoscape-discuss] Custom event listeners

There are too many custom objects and I would rather not move things around.
In future apps, I will know to have a reference for everything in
CyActivator Thanks!

Now, I used CyServiceRegistrar to register my listener (which implements
several listeners) like this:

//Create listener object
 NetworkViewListeners networkViewListeners = new NetworkViewListeners();

        //Register them
        CyActivator.serviceRegistrar.registerService(networkViewListeners,
                NetworkViewAddedListener.class, new Properties());
        CyActivator.serviceRegistrar.registerService(networkViewListeners,
                NetworkViewAboutToBeDestroyedListener.class, new
Properties());
        CyActivator.serviceRegistrar.registerService(networkViewListeners,
                RowsSetListener.class, new Properties());

However, when for example a view is created, the handleEvent method for the
NetworkViewAddedListener is called* more than once*
I am positive I am adding the network view only once..

Is there something I am missing?

Omar


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Montojo  
View profile  
 More options Sep 12 2012, 11:09 am
From: Jason Montojo <jrr...@gmail.com>
Date: Wed, 12 Sep 2012 11:09:46 -0400
Local: Wed, Sep 12 2012 11:09 am
Subject: Re: [Cytoscape-discuss] Custom event listeners

Hi Omar,

> I tried Jason's suggestion

> 1) Set CyServiceRegistrar reference in CyActivator class

> //Service regisrar

>  public static CyServiceRegistrar serviceRegistrar;

Non-final public static variables are almost always a terrible idea.  They
invite weird code coupling and negatively impact modularity.  To clarify
what I suggested, I meant you should get a service reference in CyActivator
and pass that reference either via the constructor or some other method
call to the class that needs it.  In this case, passing via constructor is
probably the most elegant approach.  For example:

CyServiceRegistrar registrar = getService(bc, CyServiceRegistrar.class);
MyListener listener = new MyListener(registrar);

Hopes this helps,
Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Montojo  
View profile  
 More options Sep 12 2012, 11:14 am
From: Jason Montojo <jrr...@gmail.com>
Date: Wed, 12 Sep 2012 11:14:04 -0400
Local: Wed, Sep 12 2012 11:14 am
Subject: Re: [Cytoscape-discuss] Custom event listeners

Hi Omar,

However, when for example a view is created, the handleEvent method for the

> NetworkViewAddedListener is called* more than once*
> I am positive I am adding the network view only once..

> Is there something I am missing?

Are you sure handleEvent is being called multiple times for the exact same
network view?  Cytoscape creates multiple network views when the first view
is created.  One of them is the main network view that shows up in your
workspace.  The other is the birds eye view (which is the little network
overview in the Network tab).  Apart from that, Cytoscape creates a network
view to display the visual style preview in the VizMapper tab.  It's
possible your listener is being called for those network views too.  Can
you verify whether this is the case in the debugger?

Thanks,
Jason


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Omar Wagih  
View profile  
 More options Sep 14 2012, 9:50 pm
From: Omar Wagih <omarwa...@gmail.com>
Date: Fri, 14 Sep 2012 18:50:23 -0700 (PDT)
Local: Fri, Sep 14 2012 9:50 pm
Subject: Re: [Cytoscape-discuss] Custom event listeners

Hello!
Sorry for the late response!

Everything magically worked when I passed in CyServicerRegistrar as an
argument to my constructors rather than using a static non-final!
@scooter the main reason I am using CyServicerRegistrar is that I have too
many managers/factories which I would have to pass through my constructors
at least twice or 3 times so it gets messy

Thanks guys!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »