Search in sources :

Example 1 with SessionLoadedEvent

use of org.cytoscape.session.events.SessionLoadedEvent in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method setCurrentSession.

@Override
public void setCurrentSession(CySession sess, final String fileName) {
    // Always remove the current session first
    if (!disposed)
        disposeCurrentSession();
    if (sess == null) {
        logger.debug("Creating empty session...");
        final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
        final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
        final Set<CyProperty<?>> props = getAllProperties();
        sess = new CySession.Builder().properties(props).visualStyles(styles).build();
    } else {
        logger.debug("Restoring the session...");
        // Save the selected networks first, so the selection state can be restored later.
        final List<CyNetwork> selectedNetworks = new ArrayList<>();
        final Set<CyNetwork> networks = sess.getNetworks();
        for (CyNetwork n : networks) {
            final Boolean selected = n.getDefaultNetworkTable().getRow(n.getSUID()).get(CyNetwork.SELECTED, Boolean.class);
            if (Boolean.TRUE.equals(selected))
                selectedNetworks.add(n);
        }
        restoreProperties(sess);
        restoreNetworks(sess);
        restoreTables(sess);
        restoreNetworkViews(sess, selectedNetworks);
        restoreNetworkSelection(sess, selectedNetworks);
        restoreVisualStyles(sess);
        restoreCurrentVisualStyle();
    }
    currentFileName = fileName;
    disposed = false;
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(new SessionLoadedEvent(this, sess, getCurrentSessionFileName()));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) SessionLoadedEvent(org.cytoscape.session.events.SessionLoadedEvent)

Aggregations

ArrayList (java.util.ArrayList)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyProperty (org.cytoscape.property.CyProperty)1 SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)1 SessionLoadedEvent (org.cytoscape.session.events.SessionLoadedEvent)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1