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()));
}
Aggregations