Search in sources :

Example 66 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class GenerateNetworkViewsTask method setCurrentNetworkAndViewTask.

public void setCurrentNetworkAndViewTask(final CyNetwork network) {
    final CyNetworkViewManager netViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final List<CyNetworkView> views = new ArrayList<>(netViewManager.getNetworkViews(network));
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    boolean currentViewSet = false;
    for (CyNetworkView v : views) {
        if (v.getModel().equals(network)) {
            applicationManager.setCurrentNetworkView(v);
            currentViewSet = true;
            break;
        }
    }
    if (!currentViewSet)
        applicationManager.setCurrentNetwork(network);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 67 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class LoadMultipleNetworksTask method init.

private void init() {
    // otherwise let the reader's tunables handle it.
    if (readers != null && readers.size() > 1) {
        // Initialize column list
        if (rootNetwork != null)
            setTargetColumnList(getTargetColumns(rootNetwork));
        else
            setTargetColumnList(new ListSingleSelection<>());
        // Initialize renderer list
        final List<NetworkViewRenderer> renderers = new ArrayList<>();
        NetworkViewRenderer defViewRenderer = null;
        final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
        final Set<NetworkViewRenderer> rendererSet = applicationManager.getNetworkViewRendererSet();
        // so the combo-box does not appear to the user, since there is nothing to select anyway.
        if (rendererSet.size() > 1) {
            renderers.addAll(rendererSet);
            Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {

                @Override
                public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
                    return r1.toString().compareToIgnoreCase(r2.toString());
                }
            });
        }
        defViewRenderer = applicationManager.getDefaultNetworkViewRenderer();
        rendererList = new ListSingleSelection<>(renderers);
        if (defViewRenderer != null && renderers.contains(defViewRenderer))
            rendererList.setSelectedValue(defViewRenderer);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) ArrayList(java.util.ArrayList) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 68 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class ExportSelectedNetworkTaskFactoryImpl method createTaskIterator.

@Override
public TaskIterator createTaskIterator(File file) {
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    CyNetworkView view = applicationManager.getCurrentNetworkView();
    if (view != null)
        return getExportNetworkViewTaskFactory().createTaskIterator(view, file);
    CyNetwork network = applicationManager.getCurrentNetwork();
    if (network != null)
        return getExportNetworkTaskFactory().createTaskIterator(network, file);
    return null;
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 69 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class OpenSessionCommandTask method changeCurrentSession.

private void changeCurrentSession(CySessionManager sessionManager, TaskMonitor tm) throws Exception {
    final CySession newSession = reader.getSession();
    if (newSession == null)
        throw new NullPointerException("Session could not be read for file: " + file);
    String fileName = file != null ? file.getAbsolutePath() : new URI(url).getPath().replace("/", "");
    sessionManager.setCurrentSession(newSession, fileName);
    // Set Current network: this is necessary to update GUI
    final CyApplicationManager appManager = serviceRegistrar.getService(CyApplicationManager.class);
    final RenderingEngine<CyNetwork> currentEngine = appManager.getCurrentRenderingEngine();
    if (currentEngine != null)
        appManager.setCurrentRenderingEngine(currentEngine);
    tm.setProgress(1.0);
    tm.setStatusMessage("Session file " + fileName + " successfully loaded.");
    // Add this session file URL as the most recent file
    if (file != null)
        serviceRegistrar.getService(RecentlyOpenedTracker.class).add(file.toURI().toURL());
}
Also used : CySession(org.cytoscape.session.CySession) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetwork(org.cytoscape.model.CyNetwork) URI(java.net.URI)

Example 70 with CyApplicationManager

use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7