Search in sources :

Example 1 with SessionState

use of org.cytoscape.internal.io.sessionstate.SessionState 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 SessionState

use of org.cytoscape.internal.io.sessionstate.SessionState in project cytoscape-impl by cytoscape.

the class SessionHandler method saveSessionState.

private File saveSessionState(final SessionAboutToBeSavedEvent e) {
    final SessionState sessState = new SessionState();
    // CytoPanels States
    final Cytopanels cytopanels = new Cytopanels();
    sessState.setCytopanels(cytopanels);
    for (Map.Entry<String, CytoPanelName> entry : CYTOPANEL_NAMES.entrySet()) {
        final CytoPanel p = desktop.getCytoPanel(entry.getValue());
        final Cytopanel cytopanel = new Cytopanel();
        cytopanel.setId(entry.getKey());
        cytopanel.setPanelState(p.getState().toString());
        cytopanel.setSelectedPanel(Integer.toString(p.getSelectedIndex()));
        cytopanels.getCytopanel().add(cytopanel);
    }
    // Create temp file
    File tmpFile = new File(System.getProperty("java.io.tmpdir"), SESSION_STATE_FILENAME);
    tmpFile.deleteOnExit();
    // Write to the file
    sessionIO.write(sessState, tmpFile);
    return tmpFile;
}
Also used : SessionState(org.cytoscape.internal.io.sessionstate.SessionState) CytoPanelName(org.cytoscape.application.swing.CytoPanelName) Cytopanels(org.cytoscape.internal.io.sessionstate.Cytopanels) CytoPanel(org.cytoscape.application.swing.CytoPanel) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) Cytopanel(org.cytoscape.internal.io.sessionstate.Cytopanel)

Aggregations

File (java.io.File)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 SessionState (org.cytoscape.internal.io.sessionstate.SessionState)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CytoPanel (org.cytoscape.application.swing.CytoPanel)1 CytoPanelName (org.cytoscape.application.swing.CytoPanelName)1 NetworkList (org.cytoscape.internal.io.networklist.NetworkList)1 Cytopanel (org.cytoscape.internal.io.sessionstate.Cytopanel)1 Cytopanels (org.cytoscape.internal.io.sessionstate.Cytopanels)1 CyNetwork (org.cytoscape.model.CyNetwork)1