Search in sources :

Example 1 with SessionAboutToBeSavedEvent

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;
}
Also used : CySession(org.cytoscape.session.CySession) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) SessionAboutToBeSavedEvent(org.cytoscape.session.events.SessionAboutToBeSavedEvent) CyTableMetadata(org.cytoscape.model.CyTableMetadata) ArrayList(java.util.ArrayList) List(java.util.List) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTableMetadata (org.cytoscape.model.CyTableMetadata)1 CyProperty (org.cytoscape.property.CyProperty)1 SimpleCyProperty (org.cytoscape.property.SimpleCyProperty)1 CySession (org.cytoscape.session.CySession)1 SessionAboutToBeSavedEvent (org.cytoscape.session.events.SessionAboutToBeSavedEvent)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)1 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1