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);
}
}
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();
});
}
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;
}
}
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);
});
}
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;
}
}
Aggregations