NetworkView after destroying network

9 views
Skip to first unread message

gregor...@uni-greifswald.de

unread,
Nov 15, 2009, 8:15:39 AM11/15/09
to cytoscape-helpdesk
Hi,

I have a PropertyChangeListener listening for
Cytoscape.NETWORK_DESTROYED events. When I destroy an empty network
directly after creating it in a new session,
Cytoscape.getCurrentNetworkView() returns a FingCyNetwork (not the one
returned by Cytoscape.getNullNetworkView() ).

Hence, MyCytoscapeAction.enableForNetworkAndView() enabled the
menuItem of my plugin, when I close the empty network. However, it
should be disabled.
Whenever I destroy the last network, the plugin menuItem remains
enabled.

On the other hand, when creating an empty network, the networkView is
the one returned by Cytoscape.getNullNetworkView() and the plugins
remains disabled.

Are the events fired too early or why does this happen? Is there a way
to bypass this issue?


Cheers, Gregor

allan_k...@agilent.com

unread,
Nov 15, 2009, 10:38:04 AM11/15/09
to cytoscape...@googlegroups.com
When the NETWORK_DESTROYED event is fired, it is fired before the actual destruction of the network. This is to give listeners a chance to do any cleanup related to the destruction of the network that requires any references held by the network. Once the network is actually destroyed the references are lost.

Are you calling enableForNetworkAndView() directly when you receive the NETWORK_DESTROYED event? That may cause the behavior you see, because the network is still around. It is better to place the call inside the menuSelected() method, that way the code to enable/disable the network item will be done at a time when the menu is selected and the network will have already been destroyed.

This is done in many of the CytoscapeActions, see DestroyNetworkViewAction for details. If you are already embedding the call to enableForNetworkAndView in the menuSelected(), then something else must be going wrong. If that's the case, let me know and I'll see if I can help you track down the problem.

AllanK


Allan Kuchinsky
Principal Project Scientist
Molecular Tools  
Agilent Laboratories

Agilent Technologies, Inc.
Santa Clara, CA, USA
408.553.2423
allan_k...@agilent.com
--

You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To post to this group, send email to cytoscape...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cytoscape-helpdesk?hl=.




gregor...@uni-greifswald.de

unread,
Nov 15, 2009, 12:26:36 PM11/15/09
to cytoscape-helpdesk
Thank you for this hint, Allan! It works well now for the plugin menu.

As I also want to allow the plugin to be started with a button from
the TOOLBAR (I override isInToolBar() ), the corresponding button
should also be inactive when no network/networkView is present. Is
there also an easy way to get this done?

allan_k...@agilent.com

unread,
Nov 15, 2009, 1:56:12 PM11/15/09
to cytoscape...@googlegroups.com
Unfortunately, I don't know of an equivalent way of enabling/disabling the toolbar buttons. You could, I guess keep a handle to the toolbar button and listen for a NETWORK_VIEW_FOCUS event before enabling it. Disabling it might be a little trickier. You'd have to somehow know that you are destroying the last remaining network. Unfortunately, I don't know of a public method for getting all Cytoscape networks.

Does anyone else have any suggestions?


Allan Kuchinsky
Principal Project Scientist
Molecular Tools  
Agilent Laboratories

Agilent Technologies, Inc.
Santa Clara, CA, USA
408.553.2423
allan_k...@agilent.com



-----Original Message-----
From: gregor...@uni-greifswald.de [mailto:gregor...@uni-greifswald.de]
Sent: Sunday, November 15, 2009 9:27 AM
To: cytoscape-helpdesk

gregor...@uni-greifswald.de

unread,
Nov 16, 2009, 3:53:40 AM11/16/09
to cytoscape-helpdesk
I solved this by using a PCL listening on
CytoscapeDesktop.NETWORK_VIEW_* events in my plugin.
When a network view NV gets destroyed and there are not at least 2
network views before destroying NV, no network view will be available
after destorying NV. In this case, the toolbar buttons and menu items
shall be disabled.
As soon as a new network view gets created, the plugin shall be
available again:


PropertyChangeListener networkViewNumberListener = new
PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ( evt.getPropertyName().equals
(CytoscapeDesktop.NETWORK_VIEW_DESTROYED)) {
if ( Cytoscape.getNetworkSet().size() < 2) {
MyCytoscapeAction.setEnabled(false);
}
} else if ( evt.getPropertyName().equals
(CytoscapeDesktop.NETWORK_VIEW_CREATED)) {
MyCytoscapeAction.setEnabled(true);
}
}
};
Cytoscape.getDesktop().getSwingPropertyChangeSupport
().addPropertyChangeListener(networkViewNumberListener);


Thanks for the help again!


Gregor

gregor...@uni-greifswald.de

unread,
Nov 16, 2009, 4:00:35 AM11/16/09
to cytoscape-helpdesk
Sorry, the code should be

PropertyChangeListener networkViewNumberListener = new
PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ( evt.getPropertyName().equals
(CytoscapeDesktop.NETWORK_VIEW_DESTROYED)) {
if ( Cytoscape.getNetworkViewMap().keySet().size() < 2) {

gregor...@uni-greifswald.de

unread,
Nov 16, 2009, 4:02:29 AM11/16/09
to cytoscape-helpdesk
Sorry, the code should be


PropertyChangeListener networkViewNumberListener = new
PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if ( evt.getPropertyName().equals
(CytoscapeDesktop.NETWORK_VIEW_DESTROYED)) {
if ( Cytoscape.getNetworkViewMap().keySet().size() < 2) {
Reply all
Reply to author
Forward
0 new messages