Search in sources :

Example 36 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 37 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)

Example 38 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 39 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 40 with FileObject

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

the class SourcePathProviderImpl method getSourceRoots.

private String[] getSourceRoots(ClassPath classPath) {
    FileObject[] sourceRoots = classPath.getRoots();
    List<String> roots = new ArrayList<String>(sourceRoots.length);
    for (FileObject fo : sourceRoots) {
        String root = getRoot(fo);
        if (root != null) {
            roots.add(root);
        }
    }
    return roots.toArray(new String[0]);
}
Also used : FileObject(org.openide.filesystems.FileObject)

Aggregations

FileObject (org.openide.filesystems.FileObject)86 File (java.io.File)28 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)11 DataObject (org.openide.loaders.DataObject)8 NotifyDescriptor (org.openide.NotifyDescriptor)7 Project (org.netbeans.api.project.Project)6 ActionEvent (java.awt.event.ActionEvent)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 InputStream (java.io.InputStream)5 JFileChooser (javax.swing.JFileChooser)5 JPanel (javax.swing.JPanel)5 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)5 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)5 DialogDescriptor (org.openide.DialogDescriptor)5 ActionListener (java.awt.event.ActionListener)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 OpenCookie (org.openide.cookies.OpenCookie)4