Search in sources :

Example 1 with SubNetworkPanel

use of org.cytoscape.internal.view.SubNetworkPanel in project cytoscape-impl by cytoscape.

the class SessionHandler method setSessionNetworks.

/**
 * @param netOrder Maps CyNetwork SUID to the network position
 */
private void setSessionNetworks(final Map<Long, Integer> netOrder) {
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final List<CySubNetwork> sortedNetworks = new ArrayList<>();
    for (CyNetwork n : netMgr.getNetworkSet()) {
        if (n instanceof CySubNetwork && netMgr.networkExists(n.getSUID()))
            sortedNetworks.add((CySubNetwork) n);
    }
    Collections.sort(sortedNetworks, new Comparator<CySubNetwork>() {

        @Override
        public int compare(final CySubNetwork n1, final CySubNetwork n2) {
            try {
                Integer o1 = netOrder.get(n1.getSUID());
                Integer o2 = netOrder.get(n2.getSUID());
                if (o1 == null)
                    o1 = -1;
                if (o2 == null)
                    o2 = -1;
                return o1.compareTo(o2);
            } catch (final Exception e) {
                logger.error("Cannot sort networks", e);
            }
            return 0;
        }
    });
    final CyApplicationManager applicationMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final List<CyNetwork> selectedNetworks = applicationMgr.getSelectedNetworks();
    final List<CyNetworkView> selectedViews = applicationMgr.getSelectedNetworkViews();
    invokeOnEDT(() -> {
        netPanel.setNetworks(sortedNetworks);
        for (SubNetworkPanel snp : netPanel.getAllSubNetworkItems()) {
            final int count = netViewMgr.getNetworkViews(snp.getModel().getNetwork()).size();
            snp.getModel().setViewCount(count);
        }
        netPanel.setSelectedNetworks(selectedNetworks);
        netViewMediator.getNetworkViewMainPanel().setSelectedNetworkViews(selectedViews);
    });
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkManager(org.cytoscape.model.CyNetworkManager) SubNetworkPanel(org.cytoscape.internal.view.SubNetworkPanel) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

ArrayList (java.util.ArrayList)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 SubNetworkPanel (org.cytoscape.internal.view.SubNetworkPanel)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNetworkManager (org.cytoscape.model.CyNetworkManager)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)1