Search in sources :

Example 1 with AbstractCyNetworkReader

use of org.cytoscape.io.read.AbstractCyNetworkReader in project cytoscape-impl by cytoscape.

the class LoadMultipleNetworksTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    this.taskMonitor = taskMonitor;
    if (readers == null && readers.isEmpty())
        throw new IllegalArgumentException("No network reader specified.");
    taskMonitor.setTitle("Import Networks");
    taskMonitor.setProgress(0.0);
    final String rootNetName = rootNetwork != null ? rootNetwork.getRow(rootNetwork).get(CyRootNetwork.NAME, String.class) : null;
    final String targetColumn = targetColumnList != null ? targetColumnList.getSelectedValue() : null;
    final NetworkViewRenderer renderer = rendererList != null ? rendererList.getSelectedValue() : null;
    final float total = readers.size();
    int count = 1;
    for (Entry<String, CyNetworkReader> entry : readers.entrySet()) {
        if (cancelled)
            return;
        final CyNetworkReader r = entry.getValue();
        if (r instanceof AbstractCyNetworkReader) {
            AbstractCyNetworkReader ar = (AbstractCyNetworkReader) r;
            if (rootNetName != null) {
                ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(rootNetName));
                ls.setSelectedValue(rootNetName);
                ar.setRootNetworkList(ls);
            } else {
                // Force "create new collection"
                ar.setRootNetworkList(new ListSingleSelection<>(Collections.emptyList()));
                ar.setTargetColumnList(new ListSingleSelection<>(Collections.emptyList()));
            }
            if (targetColumn != null) {
                ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(targetColumn));
                ls.setSelectedValue(targetColumn);
                ar.setTargetColumnList(ls);
            }
            if (renderer != null) {
                ListSingleSelection<NetworkViewRenderer> ls = new ListSingleSelection<>(Collections.singletonList(renderer));
                ls.setSelectedValue(renderer);
                ar.setNetworkViewRendererList(ls);
            }
        }
        name = entry.getKey();
        loadNetwork(r);
        taskMonitor.setProgress(count / total);
        count++;
    }
}
Also used : AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Aggregations

NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)1 AbstractCyNetworkReader (org.cytoscape.io.read.AbstractCyNetworkReader)1 CyNetworkReader (org.cytoscape.io.read.CyNetworkReader)1 ListSingleSelection (org.cytoscape.work.util.ListSingleSelection)1