This example plugin uses the Cytoscape network and attributes data structures to perform a simple node selection operation. When the user selects one or more nodes in the graph and then activates the plugin, it will iterate over each selected node and additionally select all neighbors of that node. To run the plugin, save the jar file below to your local disk in the Cytoscape plugins directory. Then run Cytoscape and load in a sample yeast network (for example, galFiltered.sif in the sampleData directory of the public Cytoscape distribution). Select one or more nodes, then activate the plugin via the {{{Plugins->NeighborNodeSelection}}} menu option. [[attachment:NeighborNodeSelection.java]] <
> [[attachment:NeighborNodeSelection.jar]] === Looking at the Plugin === {{{#!java public NeighborNodeSelection() { NeighborNodeSelectionAction action = new NeighborNodeSelectionAction(); action.setPreferredMenu("Plugins"); Cytoscape.getDesktop().getCyMenus().addAction(action); } }}} The plugin constructor adds an entry to the menus of the window. This is a very common operation, giving the user the ability to execute the plugin on command. A plugin could add more than one menu entry, if it provided more than one possible operation. What actually happens is that the plugin defines an extension of the {{{CytoscapeAction}}} class, which is an extension of the Swing {{{AbstractAction}}} class. The code in this extension class gets called whenever the user selects the item that appears in the menu. (See the [[http://java.sun.com/docs/books/tutorial/uiswing/index.html|Swing section]] of the Java tutorial and the [[http://java.sun.com/j2se/1.4.2/docs/api/index.html|Java API]] for more information). The plugin works with several core objects. The {{{CyNetwork}}} object is a graph and also contains the associated data. The plugin uses the network to find the neighbors of the currently selected nodes. The {{{CyNetworkView}}} contains information on what node views are currently selected. At the end of the algorithm, the plugin calls the redrawGraph method on the window. This is required to let Cytoscape know that it should redraw the graph (for example, to update the appearance of newly selected nodes).