Search in sources :

Example 26 with CyNetworkManager

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

the class CyRootNetworkImpl method handleEvent.

@Override
public void handleEvent(NetworkAddedEvent e) {
    if (e.getNetwork() == this || subNetworks.contains(e.getNetwork())) {
        // Check if another network from this root was already registered - return if so
        CyNetworkManager netManager = e.getSource();
        List<CyNetwork> networks = new ArrayList<CyNetwork>();
        networks.add(this);
        networks.addAll(subNetworks);
        networks.remove(e.getNetwork());
        for (CyNetwork network : networks) {
            if (netManager.networkExists(network.getSUID()))
                return;
        }
        registerAllTables(networkTableMgr.getTables(this, CyNetwork.class).values());
        registerAllTables(networkTableMgr.getTables(this, CyNode.class).values());
        registerAllTables(networkTableMgr.getTables(this, CyEdge.class).values());
    }
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork)

Example 27 with CyNetworkManager

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

the class CyNetworkViewManagerImpl method addNetworkView.

@Override
public void addNetworkView(final CyNetworkView view, final boolean setCurrent) {
    if (view == null) {
        // Do nothing if view is null.
        logger.warn("Network view is null.");
        return;
    }
    final CyNetwork network = view.getModel();
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    synchronized (lock) {
        if (!netMgr.networkExists(network.getSUID()))
            throw new IllegalArgumentException("Network view cannot be added, because its network (" + network + ") is not registered");
        Collection<CyNetworkView> existingSet = networkViewMap.get(network);
        if (existingSet == null)
            existingSet = new LinkedHashSet<>();
        existingSet.add(view);
        networkViewMap.put(network, existingSet);
    }
    fireEvent(new NetworkViewAddedEvent(this, view));
    if (setCurrent) {
        final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
        if (// It may be null when running unit tests
        applicationManager != null)
            applicationManager.setCurrentNetworkView(view);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) NetworkViewAddedEvent(org.cytoscape.view.model.events.NetworkViewAddedEvent)

Example 28 with CyNetworkManager

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

the class NetworkViewMediator method updateNetworkViewTitle.

private final void updateNetworkViewTitle(final Collection<RowSetRecord> records, final CyTable source) {
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    for (final RowSetRecord record : records) {
        if (CyNetwork.NAME.equals(record.getColumn())) {
            // Assume payload collection is for same column
            for (CyNetwork net : netMgr.getNetworkSet()) {
                if (net.getDefaultNetworkTable() == source) {
                    final String name = record.getRow().get(CyNetwork.NAME, String.class);
                    if (name == null || name.trim().isEmpty())
                        continue;
                    final Collection<CyNetworkView> netViews = netViewMgr.getNetworkViews(net);
                    int count = 0;
                    for (CyNetworkView view : netViews) {
                        // TODO: Only update the view's title if the current title and the network name are in sync,
                        // because users can change the Network View title at any time
                        String title = name.trim();
                        title += (netViews.size() > 1 ? " (" + ++count + ")" : "");
                        view.setVisualProperty(BasicVisualLexicon.NETWORK_TITLE, title);
                        // if this visual property is locked
                        if (!view.isValueLocked(BasicVisualLexicon.NETWORK_TITLE)) {
                            invokeOnEDT(() -> {
                                getNetworkViewMainPanel().update(view);
                            });
                        }
                    }
                    break;
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 29 with CyNetworkManager

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

the class RootNetworkPanelModel method getSubNetworkCount.

@Override
public int getSubNetworkCount() {
    int count = 0;
    final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
    // Count number of public subnetworks
    for (CySubNetwork net : getNetwork().getSubNetworkList()) {
        if (netManager.networkExists(net.getSUID()))
            count++;
    }
    return count;
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 30 with CyNetworkManager

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

the class CyApplicationManagerImpl method getSelectedNetworks.

@Override
public List<CyNetwork> getSelectedNetworks() {
    final CyNetworkManager networkManager = serviceRegistrar.getService(CyNetworkManager.class);
    final Set<CyNetwork> allNetworks = networkManager.getNetworkSet();
    final List<CyNetwork> selectedNetworks = new ArrayList<>();
    for (final CyNetwork n : allNetworks) {
        final CyRow row = n.getRow(n);
        if (row.get(CyNetwork.SELECTED, Boolean.class, false))
            selectedNetworks.add(n);
    }
    return selectedNetworks;
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow)

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