Search in sources :

Example 6 with CyNetworkNaming

use of org.cytoscape.session.CyNetworkNaming in project cytoscape-impl by cytoscape.

the class CyNetworkManagerImpl method addNetwork.

@Override
public void addNetwork(final CyNetwork network, final boolean setCurrent) {
    if (network == null)
        throw new NullPointerException("Network is null");
    synchronized (lock) {
        logger.debug("Adding new Network Model: Model ID = " + network.getSUID());
        // Make sure the network has a name
        final CyRow row = network.getRow(network);
        final String name = row.get(CyNetwork.NAME, String.class);
        final String sharedName = row.get(CyRootNetwork.SHARED_NAME, String.class);
        if (name != null && !name.trim().isEmpty() && (sharedName == null || sharedName.trim().isEmpty())) {
            row.set(CyRootNetwork.SHARED_NAME, name);
        } else if (sharedName != null && !sharedName.trim().isEmpty() && (name == null || name.trim().isEmpty())) {
            row.set(CyNetwork.NAME, sharedName);
        } else if ((sharedName == null || sharedName.trim().isEmpty()) && (name == null || name.trim().isEmpty())) {
            final CyNetworkNaming namingUtil = serviceRegistrar.getService(CyNetworkNaming.class);
            final String newName = namingUtil.getSuggestedNetworkTitle("Network");
            row.set(CyNetwork.NAME, newName);
            row.set(CyRootNetwork.SHARED_NAME, newName);
        }
        // Add the new network to the internal map
        networkMap.put(network.getSUID(), network);
    }
    final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
    cyEventHelper.fireEvent(new NetworkAddedEvent(CyNetworkManagerImpl.this, network));
    if (setCurrent) {
        final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
        if (// It may be null when running unit tests
        applicationManager != null)
            applicationManager.setCurrentNetwork(network);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkAddedEvent(org.cytoscape.model.events.NetworkAddedEvent) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyRow(org.cytoscape.model.CyRow)

Example 7 with CyNetworkNaming

use of org.cytoscape.session.CyNetworkNaming in project cytoscape-impl by cytoscape.

the class TestCyNetworkFactory method mockCyServiceRegistrar.

private static CyServiceRegistrar mockCyServiceRegistrar(CyEventHelper deh) {
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
    EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(deh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    return serviceRegistrar;
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar)

Example 8 with CyNetworkNaming

use of org.cytoscape.session.CyNetworkNaming in project cytoscape-impl by cytoscape.

the class GenerateNetworkViewsTask method run.

@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    final CyNetwork[] networks = viewReader.getNetworks();
    if (networks == null || networks.length == 0)
        return;
    taskMonitor.setProgress(0.0);
    final CyNetworkNaming networkNaming = serviceRegistrar.getService(CyNetworkNaming.class);
    double numNets = (double) networks.length;
    int i = 0;
    results = new ArrayList<>();
    largeNetworks = new ArrayList<>();
    for (CyNetwork net : networks) {
        // Use original name if exists
        String networkName = net.getRow(net).get(CyNetwork.NAME, String.class);
        if (networkName == null || networkName.trim().length() == 0)
            networkName = (name != null) ? name : "? (Name is missing)";
        net.getRow(net).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
        serviceRegistrar.getService(CyNetworkManager.class).addNetwork(net, false);
        final int numGraphObjects = net.getNodeCount() + net.getEdgeCount();
        if (numGraphObjects < viewThreshold)
            createNetworkView(net);
        else
            largeNetworks.add(net);
        taskMonitor.setProgress((double) (++i) / numNets);
    }
    // If there is no name yet for the root network, set it the same as its base subnetwork
    if (networks.length == 1) {
        if (networks[0] instanceof CySubNetwork) {
            CySubNetwork subnet = (CySubNetwork) networks[0];
            final CyRootNetwork rootNet = subnet.getRootNetwork();
            String rootNetName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
            if (rootNetName == null || rootNetName.trim().length() == 0) {
                // The root network does not have a name yet, set it the same as the base subnetwork
                rootNet.getRow(rootNet).set(CyNetwork.NAME, networks[0].getRow(networks[0]).get(CyNetwork.NAME, String.class));
            }
        }
    }
    // Make sure rootNetwork has a name
    for (CyNetwork net : networks) {
        if (net instanceof CySubNetwork) {
            CySubNetwork subNet = (CySubNetwork) net;
            CyRootNetwork rootNet = subNet.getRootNetwork();
            String networkName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
            if (networkName == null || networkName.trim().length() == 0) {
                networkName = name;
                if (networkName == null)
                    networkName = "? (Name is missing)";
                rootNet.getRow(rootNet).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
            }
        }
    }
    setCurrentNetworkAndViewTask(networks[0]);
    if (!largeNetworks.isEmpty())
        insertTasksAfterCurrentTask(new ConfirmCreateNetworkViewsTask(largeNetworks));
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 9 with CyNetworkNaming

use of org.cytoscape.session.CyNetworkNaming 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

CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)9 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)5 CyGroupManager (org.cytoscape.group.CyGroupManager)4 CyNetwork (org.cytoscape.model.CyNetwork)4 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)4 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)4 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)4 TaskMonitor (org.cytoscape.work.TaskMonitor)4 Test (org.junit.Test)4 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)3 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)3 CyRootNetworkManagerImpl (org.cytoscape.model.internal.CyRootNetworkManagerImpl)3 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)3 ObservableTask (org.cytoscape.work.ObservableTask)3