Creating a node/edge dependent submenus within the context menu -- App development

176 views
Skip to first unread message

Corinna Vehlow

unread,
Aug 13, 2013, 3:02:34 PM8/13/13
to cytoscape...@googlegroups.com
Hi,

I'm currently working on an App for Cytopscape 3 that can be called over the context menu. So far, I have created a menu-option under Apps that shows up (lets name it "MyEdgeAction"), if the right-click was performed on an edge.
Therefore I used the sample app CreateNetworkViewContextMenu.
Instead of having one single menu option (Apps/MyEdgeAction), my app should have several submenu-options that depend on the clicked edge, similar to the ExternalLinks context-menu-option of Cytoscape (see attached screenshot). So I want to create I context-menu structure, such as:
Apps/MyEdgeAction/action1
Apps/MyEdgeAction/action2
Apps/MyEdgeAction/action3
Where the number and type of available actions depends on the edge the user clicked on.
These could be even split into further submenu, e.g.,
Apps/MyEdgeAction/action1/action1.1
Apps/MyEdgeAction/action1/action1.2

Does anyone know, how to set up a context menu like this?

Corinna
SubmenuInContextMenu.png

Tim Hull

unread,
Aug 13, 2013, 5:14:58 PM8/13/13
to cytoscape...@googlegroups.com
When implementing CyEdgeViewContextMenuFactory, create a JMenu in the createMenuItem function instead of a JMenuItem. You can then add both JMenuItems and JMenus (to which you can add JMenuItems to create submenus) to this menu as desired. 

After you have finished constructing your menu as desired, you would create the CyMenuItem to be returned by passing the parent JMenu into CyMenuItem's constructor (JMenu is accepted as a child class of JMenuItem).

Hope this helps...

Tim


--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.
To post to this group, send email to cytoscape...@googlegroups.com.
Visit this group at http://groups.google.com/group/cytoscape-helpdesk.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Corinna Vehlow

unread,
Aug 13, 2013, 6:08:30 PM8/13/13
to cytoscape...@googlegroups.com
Thanks for your response.

Can you tell me more about how to use the CyEdgeViewContextMenuFactory for this purpose?
Similar to the sample app CreateNetworkViewContextMenu, I have created a class that extends the abstract class AbstractEdgeViewTaskFactory. An instance of that class is than registered in the start method of CyActivator.
Would that be similar for the CyEdgeViewContextMenuFactory? Can you refer to or do you have some code snippets maybe?

Corinna


Am Dienstag, 13. August 2013 15:14:58 UTC-6 schrieb Tim Hull:
When implementing CyEdgeViewContextMenuFactory, create a JMenu in the createMenuItem function instead of a JMenuItem. You can then add both JMenuItems and JMenus (to which you can add JMenuItems to create submenus) to this menu as desired. 

After you have finished constructing your menu as desired, you would create the CyMenuItem to be returned by passing the parent JMenu into CyMenuItem's constructor (JMenu is accepted as a child class of JMenuItem).

Hope this helps...

Tim
On Tue, Aug 13, 2013 at 12:02 PM, Corinna Vehlow <corinna...@gmail.com> wrote:
Hi,

I'm currently working on an App for Cytopscape 3 that can be called over the context menu. So far, I have created a menu-option under Apps that shows up (lets name it "MyEdgeAction"), if the right-click was performed on an edge.
Therefore I used the sample app CreateNetworkViewContextMenu.
Instead of having one single menu option (Apps/MyEdgeAction), my app should have several submenu-options that depend on the clicked edge, similar to the ExternalLinks context-menu-option of Cytoscape (see attached screenshot). So I want to create I context-menu structure, such as:
Apps/MyEdgeAction/action1
Apps/MyEdgeAction/action2
Apps/MyEdgeAction/action3
Where the number and type of available actions depends on the edge the user clicked on.
These could be even split into further submenu, e.g.,
Apps/MyEdgeAction/action1/action1.1
Apps/MyEdgeAction/action1/action1.2

Does anyone know, how to set up a context menu like this?

Corinna

--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpdesk+unsub...@googlegroups.com.

Tim Hull

unread,
Aug 13, 2013, 8:00:44 PM8/13/13
to cytoscape...@googlegroups.com
You can create edge context menus in two ways - using the CyEdgeViewContextMenuFactory or the AbstractEdgeViewTaskFactory. The former will create menus and menu items directly - the latter will generate a single menu item using the Task framework.

You can set individual EdgeViewTaskFactory objects to put themselves on a specific submenu by setting the preferredMenu property in their properties object as in the following code, which generates an "Edge View Task" menu item under the Apps-Samples submenu:

// Add right click menu item to the edge view
Properties myEdgeViewTaskFactoryProps = new Properties();
myEdgeViewTaskFactoryProps.setProperty("preferredAction","NEW");
myEdgeViewTaskFactoryProps.setProperty("preferredMenu","Apps.Samples");
myEdgeViewTaskFactoryProps.setProperty("title","Edge View Task");

registerService(bc,myEdgeViewTaskFactory,EdgeViewTaskFactory.class, myEdgeViewTaskFactoryProps);

However, each TaskFactory corresponds to a single menu item, and will always appear in the menu if registered (though it can be disabled when unavailable by implementing the isReady function). 

To generate a fully dynamic menu, you must instead implement the CyEdgeViewContextMenuFactory that I described in my previous e-mail. Sample project sample26 (under our samples directory) has an example of this...

Hope this helps...

Tim


To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.

Corinna Vehlow

unread,
Aug 14, 2013, 12:39:56 PM8/14/13
to cytoscape...@googlegroups.com
I looked at sample 26 and compiled it and installed it in Cytoscape. However, the two menu-options "sample CyNodeVCMF" and "sample CyEdgeVCMF" do not appear in the context menu.
Is the method createMenuItem() called internally and automatically by Cytoscape or do I need to trigger the right click event somehow and do it manually?

Sample 26:
public class CyActivator extends AbstractCyActivator {
    @Override
    public void start(BundleContext context) throws Exception {
        CyNodeViewContextMenuFactory cyNodeVCMF  = new CyNodeVCMFSample();
        CyEdgeViewContextMenuFactory cyEdgeVCMF = new CyEdgeVCNMFSample();
       
        Properties properties = new Properties();
        registerAllServices(context, cyNodeVCMF, properties);
        registerAllServices(context, cyEdgeVCMF, properties);       
    }
}

public class CyNodeVCMFSample implements CyNodeViewContextMenuFactory, ActionListener{
    @Override
    public CyMenuItem createMenuItem(CyNetworkView netView,
            View<CyNode> nodeView) {       
        JMenuItem jMenu = new JMenuItem("sample CyNodeVCMF");
        jMenu.addActionListener(this);
        CyMenuItem newMenu = new CyMenuItem(jMenu, 1);
        return newMenu;       
    }

    public void actionPerformed(ActionEvent e) {
        // Write your own function here.
        JOptionPane.showMessageDialog(null, "CyNodeViewContextMenuFactory worked.");       
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpdesk+unsubscribe@googlegroups.com.
To post to this group, send email to cytoscape...@googlegroups.com.

Tim Hull

unread,
Aug 14, 2013, 2:52:57 PM8/14/13
to cytoscape...@googlegroups.com
There seems to be an issue with that sample - if you replace the dependency versions [3.0.0-alpha7,4.0) in the pom.xml with 3.0.0 (without brackets or parentheses), it should work fine. We will be releasing an updated version of the samples soon that will fix this and other issues...

Tim


To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.

Corinna Vehlow

unread,
Aug 14, 2013, 5:52:31 PM8/14/13
to cytoscape...@googlegroups.com
I changed and run mvn clean install again. The app seems to be loaded:

[ 167] [Active     ] [            ] [  190] Cytoscape Welcome Screen Impl (welcome-impl) (3.0.1)
[ 168] [Active     ] [            ] [  200] org.cytoscape.sample.sample26 (0.0.1.SNAPSHOT)
Cytoscape 3.0.1> start 168

But nevertheless, the menu-options do not appear anywhere.


--
You received this message because you are subscribed to a topic in the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-helpdesk/gjlTvJlibwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-helpd...@googlegroups.com.

IgorRodchenkov

unread,
Aug 14, 2013, 5:54:59 PM8/14/13
to cytoscape...@googlegroups.com
Did you check for what'sgoing on (if any exceptions are there) in your ~/CytoscapeConfiguration/3/framework-cytoscape.log right after installing the app?

IR.

--
You received this message because you are subscribed to a topic in the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-helpdesk/gjlTvJlibwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-helpdesk+unsub...@googlegroups.com.

Tim Hull

unread,
Aug 14, 2013, 7:54:55 PM8/14/13
to cytoscape...@googlegroups.com
It seems there are a few other things that need to be done to the pom.xml. First, replace the "bundle.namespace" line towards the beginning of the file with the following:

<bundle.namespace>org.cytoscape.sample.sample26.internal</bundle.namespace>

After that, replace the maven-bundle-plugin section with the following:

<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.4</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>!${bundle.namespace}.*</Export-Package>
<Private-Package>${bundle.namespace}.*</Private-Package>
<Bundle-Activator>${bundle.namespace}.CyActivator</Bundle-Activator>
</instructions>
</configuration>
</plugin>

This will all be fixed in the next update to our samples...

Tim

Corinna Vehlow

unread,
Aug 15, 2013, 12:20:13 PM8/15/13
to cytoscape...@googlegroups.com
Ok, thanks! With these changes in the pom.xml, the app works fine!

Corinna

--
You received this message because you are subscribed to a topic in the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-helpdesk/gjlTvJlibwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-helpdesk+unsub...@googlegroups.com.

To post to this group, send email to cytoscape...@googlegroups.com.
Visit this group at http://groups.google.com/group/cytoscape-helpdesk.
For more options, visit https://groups.google.com/groups/opt_out.

Noga

unread,
Mar 16, 2014, 2:26:13 PM3/16/14
to cytoscape...@googlegroups.com
Hi, 
I'm using the same sample, but I wish to know which node was clicked on - the node the context menu was opened for ?
Can I get this information from the ActionEvent ?

Thanks
Noga 
 

Tim Hull

unread,
Mar 17, 2014, 7:32:44 PM3/17/14
to cytoscape...@googlegroups.com
If you use the CyNodeViewContextMenuFactory, the createMenuItem method is called when the context menu is accessed. Here you have access to the node's view, from which you can get the actual CyNode using the getModel() method...

If you are doing something else, what exactly are you using to create the context menu?

Hope this helps...

Tim


--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.
To post to this group, send email to cytoscape...@googlegroups.com.
Visit this group at http://groups.google.com/group/cytoscape-helpdesk.
For more options, visit https://groups.google.com/d/optout.

נגה ברכה

unread,
Mar 18, 2014, 2:36:46 AM3/18/14
to cytoscape...@googlegroups.com
Yes this helps , thank you !

--
You received this message because you are subscribed to a topic in the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-helpdesk/gjlTvJlibwE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-helpd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages