Search in sources :

Example 11 with CyEventHelper

use of org.cytoscape.event.CyEventHelper 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)

Example 12 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method restoreCurrentVisualStyle.

private void restoreCurrentVisualStyle() {
    // Make sure the current visual style is the one applied to the current network view
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.flushPayloadEvents();
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView cv = appMgr.getCurrentNetworkView();
    if (cv != null) {
        final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
        final VisualStyle style = vmMgr.getVisualStyle(cv);
        if (style != null && !style.equals(vmMgr.getCurrentVisualStyle()))
            vmMgr.setCurrentVisualStyle(style);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyEventHelper(org.cytoscape.event.CyEventHelper) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 13 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class CySubNetworkCyTableManagerTest method setUp.

@Before
public void setUp() {
    final CyEventHelper eh = new DummyCyEventHelper();
    final CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    final EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    networkTableMgr = new CyNetworkTableManagerImpl();
    networkManager = new CyNetworkManagerImpl(serviceRegistrar);
    mgr = new CyTableManagerImpl(networkTableMgr, networkManager, serviceRegistrar);
    CyTableFactoryImpl tableFactory = new CyTableFactoryImpl(eh, serviceRegistrar);
    CyRootNetworkImpl baseNet = new CyRootNetworkImpl(eh, (CyTableManagerImpl) mgr, networkTableMgr, tableFactory, serviceRegistrar, true, SavePolicy.DO_NOT_SAVE);
    // This is a different subnetwork and not "baseNetwork" in ArrayGraph.
    goodNetwork = baseNet.addSubNetwork();
    globalTable = tableFactory.createTable("test table", CyIdentifiable.SUID, Long.class, true, true);
    networkManager.addNetwork(goodNetwork);
    assertNotNull(globalTable);
    assertNotNull(goodNetwork);
    assertEquals(1, networkManager.getNetworkSet().size());
}
Also used : DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyEventHelper(org.cytoscape.event.CyEventHelper) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) CyTableFactoryImpl(org.cytoscape.model.internal.CyTableFactoryImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) CyRootNetworkImpl(org.cytoscape.model.internal.CyRootNetworkImpl) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) EquationCompiler(org.cytoscape.equations.EquationCompiler) Before(org.junit.Before)

Example 14 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class NewSessionTask method run.

@Override
public void run(TaskMonitor tm) throws Exception {
    if (confirm && destroyCurrentSession) {
        // Also checks destroyCurrentSession for backwards compatibility
        tm.setTitle("Create New Session");
        tm.setProgress(0.0);
        final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
        final CySessionManager sessionManager = serviceRegistrar.getService(CySessionManager.class);
        // Let everybody know the current session will be destroyed
        eventHelper.fireEvent(new SessionAboutToBeLoadedEvent(this));
        tm.setProgress(0.1);
        // Dispose the current session before loading the new one
        sessionManager.disposeCurrentSession();
        tm.setProgress(0.2);
        sessionManager.setCurrentSession(null, null);
        tm.setProgress(1.0);
    }
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) CySessionManager(org.cytoscape.session.CySessionManager) SessionAboutToBeLoadedEvent(org.cytoscape.session.events.SessionAboutToBeLoadedEvent)

Example 15 with CyEventHelper

use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.

the class ApplyFilterTask method applyFilter.

public static void applyFilter(CyServiceRegistrar serviceRegistrar, CyNetwork network, NamedTransformer<CyNetwork, CyIdentifiable> transformer) {
    CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    TransformerManager transformerManager = serviceRegistrar.getService(TransformerManager.class);
    SelectUtils selectUtils = new SelectUtils(eventHelper);
    // De-select all nodes and edges.
    // Do this before running the filter because selection handlers can run in parallel with the filter.
    selectUtils.setSelectedNodes(network, network.getNodeList(), false);
    selectUtils.setSelectedEdges(network, network.getEdgeList(), false);
    Sink sink = new Sink();
    transformerManager.execute(network, transformer.getTransformers(), sink);
    selectUtils.setSelectedNodes(network, sink.getNodes(), true);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) SelectUtils(org.cytoscape.task.internal.select.SelectUtils) TransformerManager(org.cytoscape.filter.TransformerManager)

Aggregations

CyEventHelper (org.cytoscape.event.CyEventHelper)63 CyNetworkView (org.cytoscape.view.model.CyNetworkView)19 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)19 CyNode (org.cytoscape.model.CyNode)15 UndoSupport (org.cytoscape.work.undo.UndoSupport)14 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)13 ArrayList (java.util.ArrayList)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetwork (org.cytoscape.model.CyNetwork)10 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)10 Test (org.junit.Test)10 Task (org.cytoscape.work.Task)9 CyTable (org.cytoscape.model.CyTable)8 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 CyEdge (org.cytoscape.model.CyEdge)7 CyRow (org.cytoscape.model.CyRow)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)5 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)5