Tutorial:Create a Bundle App Using IDE

From OpenTutorials
Jump to: navigation, search

Slideshow Create a Bundle App Using IDE (about 30 minutes)

Cytoscape 3 is architecturally re-designed new version of Cytoscape. This tutorial will cover:

  1. Generate a Cytoscape 3 app project
  2. Writing the code for a functionalapp for Cytoscape 3
  3. Deploying of the final app into Cytoscape 3


In this tutorial, you are going to create an OSGi Bundle style Cytoscape 3 App. To create native Cytoscape 3 app, you need to understand basics of OSGi. However, there are several tools to automate this process.

What is a Native Cytoscape 3 App?

  • Really just an OSGi bundle
    • In Cytoscape 3, there is no clear difference between core and apps. Everything is an OSGi bundle.
  • Classpath advantages
    • Minimize library version conflicts
  • Publish your own API and hide implementations
    • You have package-level access control of your classes.

Tools You Need

  • Java Development Kit (JDK) 6 or 7
  • Maven 3.x
  • Git
  • Eclipse

Create App from Maven Archetype in Eclipse

To create an OSGi bundle app, we can use the Cytoscape Maven archetypes. This will quickly create a Maven-based project that will build an OSGi bundle-based Cytoscape app and is easily extensible to fit your needs.

Create project from archetype

  • Select File → New → Other...
  • Select Maven → Maven Project and click Next
  • Click Next again
  • Make sure you have the Cytoscape archetype catalog in your setting file. If not, press "Configure..." and add the following remote catalog (and press "Ok" and "Apply" at the end):


Eclipse newMavenProject0.png

  • Select the Cytoscape archetype catalog and uncheck Show the last version of Archetype only to show all versions of the archetype. Use the version of the archetype corresponding with the version of the Cytoscape API you need - usually, this is version 3.0.0 unless you need to use features from a newer version. Here, we select the 3.0.0 version of cyaction-app and click Next.

Eclipse newMavenProject1.png

  • Enter the required information including artifact and package name.

Eclipse newMavenProject2.png

  • Click Finish. After 10-20 seconds, Eclipse creates a new Maven project with the artifact name you specified in the last step.
  • Your project directory should be like the following screenshot:

Eclipse newMavenProject3.png

  • Run Maven clean install to make sure you can build the generated project in Eclipse. Select pom.xml, right click to get the pop-up menu

Eclipse newMavenProject4.png

  • Try the app. Copy the app jar file (in the target directory) to the ~/CytoscapeConfiguration/3/apps/installed/ directory (under your home directory) and run Cytoscape.

Run Generated App

  • Copy the app JAR file (in the target directory) to the ~/CytoscapeConfiguration/3/apps/installed/ directory (under your home directory).
    • Note: If you are developing an app and will be making regular changes, it may be easier to create a symbolic link to the JAR file in ~/CytoscapeConfiguration/3/apps/installed/ instead of copying it. The advantage of this is that you won't have to copy the JAR every time you rebuild - the downside being that deleting the target directory uninstalls the JAR as well. This can be done using the mklink command (Windows) or the ln command using the -s option (Mac/Linux). Note that you may need administrative privileges to do this on Windows.
  • Run Cytoscape 3 by executing the cytoscape.sh/bat file.
  • From the command line, type 'list'. This command displays bundles running on the current OSGi runtime. Make sure your bundle is running.


  • Type 'ls -a YOUR_BUNDLE_ID'. This indicates that your new app bundle is running and exporting an OSGi service! The template generates a very simple app template to create an instance of a class and export it as an OSGi service.
  • Click the Apps menu - note that there is a new menu item, "Hello World App".

Add Your Function

  • In this example, you are going to add the same function as in the simple Cytoscape app tutorial, i.e., to hide all unconnected (singleton) nodes in the current network view.
  • To start, you will need to add dependencies to the pom.xml file as necessary. In this example, you will need to add one new dependency - presentation-api.

  • Next, edit the MenuAction class such that it looks like the following. This is the only class you need for this app.
package org.cytoscape.myapp.internal;
import java.awt.event.ActionEvent;
import org.cytoscape.application.swing.AbstractCyAction;
import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.presentation.property.BasicVisualLexicon;

 * Creates a new menu item under Apps menu section.
public class MenuAction extends AbstractCyAction {

	private final CyApplicationManager applicationManager;
	public MenuAction(final CyApplicationManager applicationManager, final String menuTitle) {
		super(menuTitle, applicationManager, null, null);
		this.applicationManager = applicationManager;
	public void actionPerformed(ActionEvent e) {

	    final CyNetworkView currentNetworkView = applicationManager.getCurrentNetworkView();
	    if (currentNetworkView == null)
	    // View is always associated with its model.
	    final CyNetwork network = currentNetworkView.getModel();
	    for (CyNode node : network.getNodeList()) {

	        if (network.getNeighborList(node,CyEdge.Type.ANY).isEmpty()) {
	        	currentNetworkView.getNodeView(node).setVisualProperty(BasicVisualLexicon.NODE_VISIBLE, false);	        	
  • Finally, edit the CyActivator class: replace the string "Hello World App" with "Hide unconnected nodes (OSGi bundle version)".

Try the App

  • Build again. Recopy the JAR file to ~/CytoscapeConfiguration/3/apps/installed/ directory (under your home directory) if necessary.
  • Run Cytoscape. You will see a new menu item 'Hide unconnected nodes (OSGi bundle version)' under Apps. Try to load a network and make sure this works as expected.