use of org.cytoscape.session.events.SessionAboutToBeSavedEvent in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method getCurrentSession.
@Override
public CySession getCurrentSession() {
// Apps who want to save anything to a session will have to listen for this event
// and will then be responsible for adding files through SessionAboutToBeSavedEvent.addAppFiles(..)
final SessionAboutToBeSavedEvent savingEvent = new SessionAboutToBeSavedEvent(this);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(savingEvent);
final Set<CyNetwork> networks = getSerializableNetworks();
final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
// Visual Styles Map
final Map<CyNetworkView, String> stylesMap = new HashMap<>();
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
if (netViews != null) {
for (final CyNetworkView nv : netViews) {
final VisualStyle style = vmMgr.getVisualStyle(nv);
if (style != null)
stylesMap.put(nv, style.getTitle());
}
}
final Map<String, List<File>> appMap = savingEvent.getAppFileListMap();
final Set<CyTableMetadata> metadata = createTablesMetadata(networks);
final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
final Set<CyProperty<?>> props = getAllProperties();
// Build the session
final CySession sess = new CySession.Builder().properties(props).appFileListMap(appMap).tables(metadata).networks(networks).networkViews(netViews).visualStyles(styles).viewVisualStyleMap(stylesMap).build();
return sess;
}
Aggregations