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);
}
Aggregations