Search in sources :

Example 1 with RecentlyOpenedTracker

use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.

the class RecentSessionManager method updateMenuItems.

private void updateMenuItems() {
    // Unregister services
    for (final OpenRecentSessionAction currentItem : currentMenuItems) serviceRegistrar.unregisterAllServices(currentItem);
    currentMenuItems.clear();
    final RecentlyOpenedTracker tracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
    final List<URL> urls = tracker.getRecentlyOpenedURLs();
    float gravity = 0.0f;
    for (final URL url : urls) {
        File file = null;
        try {
            URI uri = url.toURI();
            file = new File(uri);
        } catch (Exception e) {
            logger.error("Invalid recent file URL.", e);
            continue;
        }
        final OpenRecentSessionAction action = new OpenRecentSessionAction(gravity++, file);
        serviceRegistrar.registerService(action, CyAction.class, new Properties());
        currentMenuItems.add(action);
    }
    clearMenuAction.updateEnableState();
}
Also used : RecentlyOpenedTracker(org.cytoscape.io.util.RecentlyOpenedTracker) Properties(java.util.Properties) File(java.io.File) URI(java.net.URI) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with RecentlyOpenedTracker

use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.

the class StarterPanel method maybeOpenSession.

private void maybeOpenSession(final File file) {
    if (file.exists()) {
        Util.maybeOpenSession(file, StarterPanel.this.getTopLevelAncestor(), serviceRegistrar);
    } else {
        JOptionPane.showMessageDialog(StarterPanel.this.getTopLevelAncestor(), "Session file not found:\n" + file.getAbsolutePath(), "File not Found", JOptionPane.WARNING_MESSAGE);
        final RecentlyOpenedTracker fileTracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
        try {
            fileTracker.remove(file.toURI().toURL());
        } catch (Exception e) {
            logger.error("Error removing session file from RecentlyOpenedTracker.", e);
        }
    }
}
Also used : RecentlyOpenedTracker(org.cytoscape.io.util.RecentlyOpenedTracker)

Example 3 with RecentlyOpenedTracker

use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.

the class StarterPanel method getRecentFiles.

/**
 * Returns a list of the most recently opened session files.
 */
private List<FileInfo> getRecentFiles() {
    final List<FileInfo> files = new ArrayList<>();
    final RecentlyOpenedTracker fileTracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
    final List<URL> recentFiles = fileTracker.getRecentlyOpenedURLs();
    int fileCount = Math.min(recentFiles.size(), MAX_FILES);
    for (int i = 0; i < fileCount; i++) {
        final URL url = recentFiles.get(i);
        File file = null;
        try {
            URI uri = url.toURI();
            file = new File(uri);
        } catch (Exception e) {
            logger.error("Invalid file URL.", e);
            continue;
        }
        if (file.exists() && file.canRead()) {
            FileInfo fi = new FileInfo(file, file.getName(), file.getAbsolutePath());
            files.add(fi);
        } else {
            fileCount = Math.min(recentFiles.size(), fileCount + 1);
        }
    }
    return files;
}
Also used : RecentlyOpenedTracker(org.cytoscape.io.util.RecentlyOpenedTracker) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) File(java.io.File) URI(java.net.URI) URL(java.net.URL)

Aggregations

RecentlyOpenedTracker (org.cytoscape.io.util.RecentlyOpenedTracker)3 File (java.io.File)2 URI (java.net.URI)2 URL (java.net.URL)2 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ZipFile (java.util.zip.ZipFile)1