Search in sources :

Example 1 with CreateNetworkViewTask

use of org.cytoscape.task.internal.view.CreateNetworkViewTask in project cytoscape-impl by cytoscape.

the class AbstractNetworkFromSelectionTask method run.

@Override
public void run(TaskMonitor tm) {
    if (parentNetwork == null) {
        tm.showMessage(TaskMonitor.Level.ERROR, "Source network must be specified.");
        return;
    }
    tm.setProgress(0.0);
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(parentNetwork);
    CyNetworkView sourceView = null;
    if (views.size() != 0)
        sourceView = views.iterator().next();
    tm.setProgress(0.1);
    // Get the selected nodes
    final Set<CyNode> nodes = getNodes(parentNetwork);
    tm.setProgress(0.2);
    if (// return;
    nodes.size() <= 0)
        throw new IllegalArgumentException("No nodes are selected.");
    // create subnetwork and add selected nodes and appropriate edges
    newNet = rootNetMgr.getRootNetwork(parentNetwork).addSubNetwork();
    // We need to cpy the columns to local tables, since copying them to default table will duplicate the virtual columns.
    addColumns(parentNetwork.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS));
    addColumns(parentNetwork.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS));
    addColumns(parentNetwork.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS));
    tm.setProgress(0.3);
    for (final CyNode node : nodes) {
        newNet.addNode(node);
        cloneRow(parentNetwork.getRow(node), newNet.getRow(node));
        // Set rows and edges to not selected state to avoid conflicts with table browser
        newNet.getRow(node).set(CyNetwork.SELECTED, false);
        if (groupMgr.isGroup(node, parentNetwork)) {
            CyGroup group = groupMgr.getGroup(node, parentNetwork);
            GroupUtils.addGroupToNetwork(group, parentNetwork, newNet);
        }
    }
    tm.setProgress(0.4);
    for (final CyEdge edge : getEdges(parentNetwork)) {
        newNet.addEdge(edge);
        cloneRow(parentNetwork.getRow(edge), newNet.getRow(edge));
        // Set rows and edges to not selected state to avoid conflicts with table browser
        newNet.getRow(edge).set(CyNetwork.SELECTED, false);
    }
    tm.setProgress(0.5);
    newNet.getRow(newNet).set(CyNetwork.NAME, getNetworkName());
    DataUtils.saveParentNetworkSUID(newNet, parentNetwork.getSUID());
    networkManager.addNetwork(newNet, false);
    tm.setProgress(0.6);
    // create the view in a separate task
    final Set<CyNetwork> networks = new HashSet<CyNetwork>();
    networks.add(newNet);
    // Pick a CyNetworkViewFactory that is appropriate for the sourceView
    CyNetworkViewFactory sourceViewFactory = viewFactory;
    if (sourceView != null) {
        NetworkViewRenderer networkViewRenderer = appMgr.getNetworkViewRenderer(sourceView.getRendererId());
        if (networkViewRenderer != null) {
            sourceViewFactory = networkViewRenderer.getNetworkViewFactory();
        }
    }
    final CreateNetworkViewTask createViewTask = new CreateNetworkViewTask(undoSupport, networks, sourceViewFactory, networkViewManager, networkManager, null, eventHelper, vmMgr, renderingEngineMgr, appMgr, sourceView, serviceRegistrar);
    insertTasksAfterCurrentTask(createViewTask);
    /*
		insertTasksAfterCurrentTask(createViewTask, new AbstractTask() {
			@Override
			@SuppressWarnings("unchecked")
			public void run(final TaskMonitor tm) throws Exception {
				// Select the new view
				tm.setProgress(0.0);
				final List<CyNetworkView> createdViews = (List<CyNetworkView>) createViewTask.getResults(List.class);
				
				if (!createdViews.isEmpty()) {
					CyNetworkView nv = createdViews.get(createdViews.size() - 1);

					if (nv != null) {
						insertTasksAfterCurrentTask(new RegisterNetworkTask(nv, null, networkManager, vmMgr, appMgr, networkViewManager));
						return;
					}
				}
				insertTasksAfterCurrentTask(new RegisterNetworkTask(newNet, networkManager, vmMgr, appMgr, networkViewManager));
				
				tm.setProgress(1.0);
			}
		});
		*/
    tm.setProgress(1.0);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyGroup(org.cytoscape.group.CyGroup) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CreateNetworkViewTask(org.cytoscape.task.internal.view.CreateNetworkViewTask) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Aggregations

HashSet (java.util.HashSet)1 NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)1 CyGroup (org.cytoscape.group.CyGroup)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CreateNetworkViewTask (org.cytoscape.task.internal.view.CreateNetworkViewTask)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)1