Search in sources :

Example 16 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class ClojureActionProvider method invokeAction.

public void invokeAction(final String command, final Lookup context) throws IllegalArgumentException {
    // Runnable action = new Runnable() { public void run () {} };
    // *
    final Runnable action = new Runnable() {

        public void run() {
            try {
                FileObject fo = project.getProjectDirectory().getFileObject(getBuildXmlFileName(project));
                ActionUtils.runTarget(fo, commands.get(command), null);
            } catch (IOException e) {
                LOG.log(Level.FINEST, e.getMessage());
            }
        }
    };
    // */
    action.run();
}
Also used : FileObject(org.openide.filesystems.FileObject) IOException(java.io.IOException)

Example 17 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method setSourceRoots.

/**
 * Sets array of source roots.
 *
 * @param sourceRoots a new array of sourceRoots
 */
public void setSourceRoots(String[] sourceRoots) {
    LOG.log(Level.FINE, "SourcePathProviderImpl.setSourceRoots(" + java.util.Arrays.asList(sourceRoots) + ")");
    Set<String> newRoots = new HashSet<String>(Arrays.asList(sourceRoots));
    ClassPath oldCP = null;
    ClassPath newCP = null;
    synchronized (this) {
        List<FileObject> sourcePath = new ArrayList<FileObject>(Arrays.asList(smartSteppingSourcePath.getRoots()));
        List<FileObject> sourcePathOriginal = new ArrayList<FileObject>(Arrays.asList(originalSourcePath.getRoots()));
        // First check whether there are some new source roots
        Set<String> newOriginalRoots = new HashSet<String>(newRoots);
        for (FileObject fo : sourcePathOriginal) {
            newOriginalRoots.remove(getRoot(fo));
        }
        if (!newOriginalRoots.isEmpty()) {
            for (String root : newOriginalRoots) {
                FileObject fo = getFileObject(root);
                if (fo != null) {
                    sourcePathOriginal.add(fo);
                }
            }
            originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
            if (additionalSourceRoots == null) {
                additionalSourceRoots = new HashSet<String>();
            }
            additionalSourceRoots.addAll(newOriginalRoots);
        }
        // Then correct the smart-stepping path
        Set<String> newSteppingRoots = new HashSet<String>(newRoots);
        for (FileObject fo : sourcePath) {
            newSteppingRoots.remove(getRoot(fo));
        }
        Set<FileObject> removedSteppingRoots = new HashSet<FileObject>();
        Set<FileObject> removedOriginalRoots = new HashSet<FileObject>();
        for (FileObject fo : sourcePath) {
            String spr = getRoot(fo);
            if (!newRoots.contains(spr)) {
                removedSteppingRoots.add(fo);
                if (additionalSourceRoots != null && additionalSourceRoots.contains(spr)) {
                    removedOriginalRoots.add(fo);
                    additionalSourceRoots.remove(spr);
                    if (additionalSourceRoots.size() == 0) {
                        additionalSourceRoots = null;
                    }
                }
            }
        }
        if (removedOriginalRoots.size() > 0) {
            sourcePathOriginal.removeAll(removedOriginalRoots);
            originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
        }
        if (newSteppingRoots.size() > 0 || removedSteppingRoots.size() > 0) {
            for (String root : newSteppingRoots) {
                FileObject fo = getFileObject(root);
                if (fo != null) {
                    sourcePath.add(fo);
                }
            }
            sourcePath.removeAll(removedSteppingRoots);
            oldCP = smartSteppingSourcePath;
            smartSteppingSourcePath = ClassPathSupport.createClassPath(sourcePath.toArray(new FileObject[0]));
            newCP = smartSteppingSourcePath;
        }
    }
    if (oldCP != null) {
        pcs.firePropertyChange(PROP_SOURCE_ROOTS, oldCP, newCP);
    }
}
Also used : ClassPath(org.netbeans.api.java.classpath.ClassPath) FileObject(org.openide.filesystems.FileObject) HashSet(java.util.HashSet)

Example 18 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getAllURLs.

/**
 * Translates a relative path to all possible URLs.
 * Uses GlobalPathRegistry if global == true.
 *
 * @param relativePath a relative path (java/lang/Thread.java)
 * @param global true if global path should be used
 * @return url
 */
public String[] getAllURLs(String relativePath, boolean global) {
    if (verbose) {
        System.out.println("SPPI: getURL " + relativePath + " global " + global);
    }
    List<FileObject> fos;
    relativePath = normalize(relativePath);
    if (originalSourcePath == null) {
        fos = new ArrayList<FileObject>();
        for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
            fos.addAll(cp.findAllResources(relativePath));
        }
    } else {
        synchronized (this) {
            if (!global) {
                fos = smartSteppingSourcePath.findAllResources(relativePath);
                if (verbose) {
                    System.out.println("SPPI:   fos " + fos);
                }
            } else {
                fos = originalSourcePath.findAllResources(relativePath);
                if (verbose) {
                    System.out.println("SPPI:   fos " + fos);
                }
            }
        }
    }
    List<String> urls = new ArrayList<String>(fos.size());
    for (FileObject fo : fos) {
        try {
            urls.add(fo.getURL().toString());
        } catch (FileStateInvalidException e) {
            if (verbose) {
                System.out.println("SPPI:   FileStateInvalidException for " + fo);
            // skip it
            }
        }
    }
    return urls.toArray(new String[0]);
}
Also used : ClassPath(org.netbeans.api.java.classpath.ClassPath) FileStateInvalidException(org.openide.filesystems.FileStateInvalidException) FileObject(org.openide.filesystems.FileObject)

Example 19 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getFileObject.

/**
 * Returns FileObject for given String.
 */
private FileObject getFileObject(String file) {
    File f = new File(file);
    FileObject fo = FileUtil.toFileObject(f);
    String path = null;
    if (fo == null && file.contains("!/")) {
        int index = file.indexOf("!/");
        f = new File(file.substring(0, index));
        fo = FileUtil.toFileObject(f);
        path = file.substring(index + "!/".length());
    }
    if (fo != null && FileUtil.isArchiveFile(fo)) {
        fo = FileUtil.getArchiveRoot(fo);
        if (path != null) {
            fo = fo.getFileObject(path);
        }
    }
    return fo;
}
Also used : FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 20 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getRelativePath.

/**
 * Returns relative path for given url.
 *
 * @param url a url of resource file
 * @param directorySeparator a directory separator character
 * @param includeExtension whether the file extension should be included
 *        in the result
 *
 * @return relative path
 */
public String getRelativePath(String url, char directorySeparator, boolean includeExtension) {
    // 1) url -> FileObject
    FileObject fo = null;
    URL theUrl = null;
    if (verbose) {
        System.out.println("SPPI: getRelativePath " + url);
    }
    try {
        LOG.log(Level.ALL, " SourcePathProviderImpl::getRelativePath - " + url);
        fo = URLMapper.findFileObject(theUrl = new URL(url));
        if (verbose) {
            System.out.println("SPPI:   fo " + fo);
        }
    } catch (MalformedURLException e) {
        // e.printStackTrace ();
        return null;
    }
    String relativePath = smartSteppingSourcePath.getResourceName(fo, directorySeparator, includeExtension);
    if (relativePath == null) {
        // fallback to FileObject's class path
        ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);
        if (cp == null) {
            cp = ClassPath.getClassPath(fo, ClassPath.COMPILE);
        }
        if (cp == null) {
            // ET - If the url of the full path exists, return that...
            if (fo != null && theUrl != null) {
                File f = new File(theUrl.getPath());
                if (f.exists())
                    return f.getAbsolutePath();
            }
            return null;
        }
        relativePath = cp.getResourceName(fo, directorySeparator, includeExtension);
    }
    if (relativePath == null) {
        LOG.log(Level.ALL, " SourcePathProviderImpl::getRelativePath - NO GO! " + url);
    }
    return relativePath;
}
Also used : ClassPath(org.netbeans.api.java.classpath.ClassPath) MalformedURLException(java.net.MalformedURLException) FileObject(org.openide.filesystems.FileObject) File(java.io.File) URL(java.net.URL)

Aggregations

FileObject (org.openide.filesystems.FileObject)34 File (java.io.File)15 IOException (java.io.IOException)9 NotifyDescriptor (org.openide.NotifyDescriptor)6 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)5 ActionEvent (java.awt.event.ActionEvent)4 InputStream (java.io.InputStream)4 JPanel (javax.swing.JPanel)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)4 Document (org.w3c.dom.Document)4 ActionListener (java.awt.event.ActionListener)3 ArrayList (java.util.ArrayList)3 JFileChooser (javax.swing.JFileChooser)3 MostRecentFiles (org.gephi.desktop.mrufiles.api.MostRecentFiles)3 FileImporter (org.gephi.io.importer.spi.FileImporter)3 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)3 ClassPath (org.netbeans.api.java.classpath.ClassPath)3 DialogDescriptor (org.openide.DialogDescriptor)3