package org.cytoscape.io.internal.read;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.cytoscape.io.internal.util.ReadUtils;
import org.cytoscape.io.read.CyNetworkReader;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNetworkFactory;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.model.subnetwork.CyRootNetwork;
import org.cytoscape.model.subnetwork.CyRootNetworkManager;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.util.ListSingleSelection;

public abstract class AbstractNetworkReader extends AbstractTask implements CyNetworkReader {

	protected CyNetwork[] cyNetworks;

	protected VisualStyle[] visualstyles;
	protected InputStream inputStream;

	protected final CyNetworkViewFactory cyNetworkViewFactory;
	protected final CyNetworkFactory cyNetworkFactory;

	protected final CyNetworkManager cyNetworkManager;;
	protected final CyRootNetworkManager cyRootNetworkManager;

	@Tunable(description = "Please choose a network collection:")
	public ListSingleSelection<Object> networkCollection;

	protected HashMap<String, CyRootNetwork> name2RootMap;

	public AbstractNetworkReader(InputStream inputStream, final CyNetworkViewFactory cyNetworkViewFactory,
			final CyNetworkFactory cyNetworkFactory, final CyNetworkManager cyNetworkManager, final CyRootNetworkManager cyRootNetworkManager) {
		if (inputStream == null)
			throw new NullPointerException("Input stream is null");
		if (cyNetworkViewFactory == null)
			throw new NullPointerException("CyNetworkViewFactory is null");
		if (cyNetworkFactory == null)
			throw new NullPointerException("CyNetworkFactory is null");

		this.inputStream = inputStream;
		this.cyNetworkViewFactory = cyNetworkViewFactory;
		this.cyNetworkFactory = cyNetworkFactory;
		this.cyNetworkManager = cyNetworkManager;
		this.cyRootNetworkManager = cyRootNetworkManager;

		this.name2RootMap = ReadUtils.getRootNetworkMap(this.cyNetworkManager, this.cyRootNetworkManager);
		
		Iterator<String> it = name2RootMap.keySet().iterator();
		
		final List<Object> networkList = new ArrayList<Object>();
		networkList.add("new Collection");
		
		while (it.hasNext()){
			networkList.add(it.next());			
		}
		networkCollection = new ListSingleSelection<Object>(networkList);
	}

	@Override
	public CyNetwork[] getNetworks() {
		return cyNetworks;
	}
}

@@ -172,16 +172,39 @@
 l.List;%0D
+%0Aimport java.util.Map;%0D
 %0A%0D%0Aimpor
@@ -418,32 +418,68 @@
 etworkManager;%0D%0A
+import org.cytoscape.model.CyNode;%0D%0A
 import org.cytos
@@ -808,16 +808,69 @@
 ection;%0D
+%0Aimport org.cytoscape.model.subnetwork.CySubNetwork;%0D
 %0A%0D%0Apubli
@@ -1489,16 +1489,91 @@
 ootMap;%0D
+%0A%09protected Map%3CString, CyNode%3E nMap = new HashMap%3CString, CyNode%3E(10000);%0D
 %0A%0D%0A%09publ
@@ -2795,16 +2795,16 @@
 ks() %7B%0D%0A
-
 %09%09return
@@ -2821,11 +2821,566 @@
 s;%0D%0A%09%7D%0D%0A
+%09%0D%0A%09protected void initNodeMap(CyNetwork rootNetwork)%7B%09%09%0D%0A%09%09Iterator%3CCySubNetwork%3E subnetworkIt = cyRootNetworkManager.getRootNetwork(rootNetwork).getSubNetworkList().iterator();%0D%0A%09%09%0D%0A%09%09while(subnetworkIt.hasNext())%7B%0D%0A%09%09%09CySubNetwork subnetwork = subnetworkIt.next();%0D%0A%09%09%09%0D%0A%09%09%09Iterator%3CCyNode%3E nodeIt = subnetwork.getNodeList().iterator();%0D%0A%09%09%09while(nodeIt.hasNext())%7B%0D%0A%09%09%09%09CyNode node = nodeIt.next();%0D%0A%09%09%09%09String name = subnetwork.getDefaultNodeTable().getRow(node).get(CyNetwork.NAME, String.class);%0D%0A%09%09%09%09this.nMap.put(name, node);%09%09%09%09%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Add a new method