Search in sources :

Example 1 with NetworkList

use of org.cytoscape.internal.io.networklist.NetworkList in project cytoscape-impl by cytoscape.

the class SessionHandler method postLoading.

private final void postLoading(final CySession sess) {
    NetworkList netList = null;
    final Map<String, List<File>> filesMap = sess.getAppFileListMap();
    if (filesMap != null) {
        final List<File> files = filesMap.get(APP_NAME);
        if (files != null) {
            SessionState sessState = null;
            for (File f : files) {
                if (f.getName().endsWith(SESSION_STATE_FILENAME))
                    sessState = sessionIO.read(f, SessionState.class);
                else if (f.getName().endsWith(NETWORK_LIST_FILENAME))
                    netList = sessionIO.read(f, NetworkList.class);
            }
            if (sessState != null)
                setCytoPanelStates(sessState.getCytopanels());
        }
    }
    if (netList == null) {
        // Probably a Cy2 session file, which does not provide a separate "network_list" file
        // so let's get the orders from the networks in the CySession file
        // (we just assume the Session Reader sent the networks in the correct order in a LinkedHashSet)
        final Set<CyNetwork> netSet = sess.getNetworks();
        final Map<Long, Integer> netOrder = new HashMap<>();
        int count = 0;
        for (CyNetwork n : netSet) netOrder.put(n.getSUID(), count++);
        setSessionNetworks(netOrder);
    } else {
        setSessionNetworks(netList.getNetwork(), sess);
    }
}
Also used : SessionState(org.cytoscape.internal.io.sessionstate.SessionState) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CyNetwork(org.cytoscape.model.CyNetwork) NetworkList(org.cytoscape.internal.io.networklist.NetworkList) ArrayList(java.util.ArrayList) List(java.util.List) NetworkList(org.cytoscape.internal.io.networklist.NetworkList) File(java.io.File)

Example 2 with NetworkList

use of org.cytoscape.internal.io.networklist.NetworkList in project cytoscape-impl by cytoscape.

the class SessionHandler method saveNetworkList.

private File saveNetworkList(final SessionAboutToBeSavedEvent e) {
    final Map<Long, Integer> netOrder = netPanel.getNetworkListOrder();
    // Create the JAXB objects
    final NetworkList netList = new NetworkList();
    for (final Entry<Long, Integer> entry : netOrder.entrySet()) {
        final Long suid = entry.getKey();
        final Integer order = entry.getValue();
        if (order != null) {
            final Network n = new Network();
            n.setId(suid);
            n.setOrder(order);
            netList.getNetwork().add(n);
        }
    }
    // Create temp file
    File tmpFile = new File(System.getProperty("java.io.tmpdir"), NETWORK_LIST_FILENAME);
    tmpFile.deleteOnExit();
    // Write to the file
    sessionIO.write(netList, tmpFile);
    return tmpFile;
}
Also used : NetworkList(org.cytoscape.internal.io.networklist.NetworkList) Network(org.cytoscape.internal.io.networklist.Network) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyNetwork(org.cytoscape.model.CyNetwork) File(java.io.File)

Aggregations

File (java.io.File)2 NetworkList (org.cytoscape.internal.io.networklist.NetworkList)2 CyNetwork (org.cytoscape.model.CyNetwork)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Network (org.cytoscape.internal.io.networklist.Network)1 SessionState (org.cytoscape.internal.io.sessionstate.SessionState)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1