Search in sources :

Example 21 with CyNetworkManager

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

the class Util method maybeOpenSession.

public static void maybeOpenSession(File file, Component owner, CyServiceRegistrar serviceRegistrar, TaskObserver observer) {
    if (file.exists() && file.canRead()) {
        final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
        final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
        if (netManager.getNetworkSet().isEmpty() && tableManager.getAllTables(false).isEmpty())
            openSession(file, serviceRegistrar, observer);
        else
            openSessionWithWarning(file, owner, serviceRegistrar, observer);
    }
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager)

Example 22 with CyNetworkManager

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

the class CytoscapeDesktop method handleEvent.

@Override
public void handleEvent(AppsFinishedStartingEvent e) {
    invokeOnEDT(() -> {
        // Only show Starter Panel the first time if the initial session is empty
        // (for instance, Cystoscape can start up with a session file specified through the terminal)
        final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
        final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
        if (netManager.getNetworkSet().isEmpty() && tableManager.getAllTables(false).isEmpty())
            showStarterPanel();
    });
}
Also used : CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager)

Example 23 with CyNetworkManager

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

the class CyNetworkNamingImpl method getSuggestedNetworkTitle.

@Override
public String getSuggestedNetworkTitle(String desiredTitle) {
    if (desiredTitle == null || "".equals(desiredTitle.trim())) {
        desiredTitle = DEF_NETWORK_NAME_PREFIX;
        logger.warn("getSuggestedNetworkTitle: desiredTitle " + "was '" + desiredTitle + "'");
    }
    // capture just the digits
    Pattern p = Pattern.compile(".*_(\\d*)$");
    Matcher m = p.matcher(desiredTitle);
    int start = 0;
    if (m.matches()) {
        desiredTitle = desiredTitle.substring(0, m.start(1) - 1);
        // happens to be "" (empty str.) because of \\d*
        String gr = m.group(1);
        start = (gr.isEmpty()) ? 1 : Integer.decode(gr) + 1;
    }
    final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
    for (int i = start; true; i++) {
        final String titleCandidate = desiredTitle + ((i == 0) ? "" : ("_" + i));
        if (!isNetworkTitleTaken(titleCandidate, netManager))
            return titleCandidate;
    }
}
Also used : Pattern(java.util.regex.Pattern) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Matcher(java.util.regex.Matcher)

Example 24 with CyNetworkManager

use of org.cytoscape.model.CyNetworkManager 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)

Example 25 with CyNetworkManager

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

the class SessionHandler method handleEvent.

@Override
public void handleEvent(final CyShutdownEvent e) {
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    // If there are no networks, just quit.
    if (netMgr.getNetworkSet().isEmpty() || e.forceShutdown())
        return;
    // Ask user whether to save current session or not.
    final String msg = "Do you want to save your session?";
    final String header = "Save Networks Before Quitting?";
    final Object[] options = { "Yes, save and quit", "No, just quit", "Cancel" };
    final int n = JOptionPane.showOptionDialog(desktop.getJFrame(), msg, header, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
    if (n == JOptionPane.NO_OPTION) {
        return;
    } else if (n == JOptionPane.YES_OPTION) {
        final CySessionManager sessionMgr = serviceRegistrar.getService(CySessionManager.class);
        final String sessionFileName = sessionMgr.getCurrentSessionFileName();
        final File file;
        if (sessionFileName == null || sessionFileName.isEmpty()) {
            FileChooserFilter filter = new FileChooserFilter("Session File", "cys");
            List<FileChooserFilter> filterCollection = new ArrayList<FileChooserFilter>(1);
            filterCollection.add(filter);
            final FileUtil fileUtil = serviceRegistrar.getService(FileUtil.class);
            file = fileUtil.getFile(desktop, "Save Session File", FileUtil.SAVE, filterCollection);
        } else {
            file = new File(sessionFileName);
        }
        if (file == null) {
            // just check the file again in case the file chooser dialoge task is canceled.
            e.abortShutdown("User canceled the shutdown request.");
            return;
        }
        final SynchronousTaskManager<?> syncTaskMgr = serviceRegistrar.getService(SynchronousTaskManager.class);
        final SaveSessionAsTaskFactory saveTaskFactory = serviceRegistrar.getService(SaveSessionAsTaskFactory.class);
        syncTaskMgr.execute(saveTaskFactory.createTaskIterator(file));
        return;
    } else {
        e.abortShutdown("User canceled the shutdown request.");
        return;
    }
}
Also used : SynchronousTaskManager(org.cytoscape.work.SynchronousTaskManager) FileChooserFilter(org.cytoscape.util.swing.FileChooserFilter) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CySessionManager(org.cytoscape.session.CySessionManager) ArrayList(java.util.ArrayList) List(java.util.List) NetworkList(org.cytoscape.internal.io.networklist.NetworkList) File(java.io.File) FileUtil(org.cytoscape.util.swing.FileUtil) SaveSessionAsTaskFactory(org.cytoscape.task.write.SaveSessionAsTaskFactory)

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