@Override
  public CyNetworkView buildCyNetworkView(final CyNetwork network) {
    final CyNetworkView view = networkViewFactory.createNetworkView(network);
    final CyLayoutAlgorithm layout = layouts.getDefaultLayout();
    TaskIterator itr =
        layout.createTaskIterator(
            view, layout.getDefaultLayoutContext(), CyLayoutAlgorithm.ALL_NODE_VIEWS, "");
    Task nextTask = itr.next();
    try {
      nextTask.run(parentTaskMonitor);
    } catch (Exception e) {
      throw new RuntimeException("Could not finish layout", e);
    }

    parentTaskMonitor.setProgress(1.0d);
    return view;
  }
예제 #2
0
  private final Map<String, String> writeNetworkFile(String file, CyNetworkView view) {
    File networkFile = null;
    try {
      networkFile = new File(file);
      TaskIterator itr = exportNetworkViewTaskFactory.createTaskIterator(view, networkFile);
      while (itr.hasNext()) {
        final Task task = itr.next();
        task.run(new HeadlessTaskMonitor());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw getError("Could not save network file.", e, Response.Status.INTERNAL_SERVER_ERROR);
    }

    final Map<String, String> message = new HashMap<>();
    message.put("file", networkFile.getAbsolutePath());
    return message;
  }
  @Test
  public void testRun() throws Exception {
    final CyTable edgeTable = mock(CyTable.class);
    when(net.getDefaultEdgeTable()).thenReturn(edgeTable);
    UndoSupport undoSupport = mock(UndoSupport.class);

    Set<CyRow> deselectedEdges = new HashSet<CyRow>();
    deselectedEdges.add(r1);
    deselectedEdges.add(r2);
    when(edgeTable.getMatchingRows(CyNetwork.SELECTED, false)).thenReturn(deselectedEdges);

    when(r1.get(CyNetwork.SUID, Long.class)).thenReturn(1L);
    when(net.getEdge(1L)).thenReturn(e1);
    when(r2.get(CyNetwork.SUID, Long.class)).thenReturn(2L);
    when(net.getEdge(2L)).thenReturn(e2);

    // run the task
    Task t = new SelectAllEdgesTask(undoSupport, net, networkViewManager, eventHelper);
    t.run(tm);

    // check that the expected rows were set
    verify(r1, times(1)).set("selected", true);
    verify(r2, times(1)).set("selected", true);
  }