Search in sources :

Example 6 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesEdgesTaskFactoryTest 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);
    NewNetworkSelectedNodesEdgesTaskFactoryImpl factory = new NewNetworkSelectedNodesEdgesTaskFactoryImpl(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)

Example 7 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class CloneNetworkTaskTest method runTest.

@Test
public void runTest() {
    final CyNetworkManager netmgr = mock(CyNetworkManager.class);
    final CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    final CyNetworkViewFactory netViewFactory = mock(CyNetworkViewFactory.class);
    final RenderingEngineManager reManager = mock(RenderingEngineManager.class);
    final CyNetworkNaming naming = mock(CyNetworkNaming.class);
    final TaskMonitor tm = mock(TaskMonitor.class);
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) Test(org.junit.Test)

Example 8 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method restoreNetworks.

private void restoreNetworks(final CySession sess) {
    logger.debug("Restoring networks...");
    Set<CyNetwork> networks = sess.getNetworks();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    for (CyNetwork n : networks) {
        netMgr.addNetwork(n, false);
    }
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 9 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method disposeCurrentSession.

@Override
public void disposeCurrentSession() {
    logger.debug("Disposing current session...");
    // Destroy network views
    final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
    for (final CyNetworkView nv : netViews) nvMgr.destroyNetworkView(nv);
    nvMgr.reset();
    // Destroy networks
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final Set<CyNetwork> networks = netMgr.getNetworkSet();
    for (final CyNetwork n : networks) netMgr.destroyNetwork(n);
    netMgr.reset();
    // Destroy styles
    logger.debug("Removing current visual styles...");
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualStyle defaultStyle = vmMgr.getDefaultVisualStyle();
    final List<VisualStyle> allStyles = new ArrayList<>(vmMgr.getAllVisualStyles());
    for (final VisualStyle vs : allStyles) {
        if (!vs.equals(defaultStyle))
            vmMgr.removeVisualStyle(vs);
    }
    // Destroy tables
    final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
    tblMgr.reset();
    // Reset groups
    serviceRegistrar.getService(CyGroupManager.class).reset();
    // Unregister session properties
    final Set<CyProperty<?>> cyPropsClone = getAllProperties();
    for (CyProperty<?> cyProps : cyPropsClone) {
        if (cyProps.getSavePolicy().equals(CyProperty.SavePolicy.SESSION_FILE)) {
            serviceRegistrar.unregisterAllServices(cyProps);
            sessionProperties.remove(cyProps.getName());
        }
    }
    // Clear undo stack
    serviceRegistrar.getService(UndoSupport.class).reset();
    // Reset current table and rendering engine
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    appMgr.reset();
    currentFileName = null;
    disposed = true;
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 10 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.

the class CyNetworkNamingImpl method getSuggestedSubnetworkTitle.

@Override
public String getSuggestedSubnetworkTitle(final CyNetwork parentNetwork) {
    String parentName = parentNetwork.getRow(parentNetwork).get(CyNetwork.NAME, String.class);
    // capture just the digits
    Pattern p = Pattern.compile(".*\\((\\d*)\\)$");
    Matcher m = p.matcher(parentName);
    int start = 0;
    if (m.matches()) {
        parentName = parentName.substring(0, m.start(1) - 1);
        start = Integer.decode(m.group(1));
    }
    final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
    for (int i = start; true; i++) {
        final String nameCandidate = parentName + "(" + (i + 1) + ")";
        if (!isNetworkTitleTaken(nameCandidate, netManager))
            return nameCandidate;
    }
}
Also used : Pattern(java.util.regex.Pattern) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Matcher(java.util.regex.Matcher)

Aggregations

CyNetworkManager (org.cytoscape.model.CyNetworkManager)49 CyNetwork (org.cytoscape.model.CyNetwork)28 CyApplicationManager (org.cytoscape.application.CyApplicationManager)14 Test (org.junit.Test)14 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)12 CyNode (org.cytoscape.model.CyNode)9 ArrayList (java.util.ArrayList)8 CyGroupManager (org.cytoscape.group.CyGroupManager)8 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)7 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)7 CyTableManager (org.cytoscape.model.CyTableManager)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 CyNetworkView (org.cytoscape.view.model.CyNetworkView)6 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)6 TaskIterator (org.cytoscape.work.TaskIterator)6 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)5 UndoSupport (org.cytoscape.work.undo.UndoSupport)5