Search in sources :

Example 71 with FileObject

use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.

the class RefactoringUtils method getMMDs.

public static FileObject[] getMMDs(final Lookup lookup) {
    final Collection<? extends Node> nodes = lookup.lookupAll(Node.class);
    final List<FileObject> result = new ArrayList<FileObject>();
    for (final Node n : nodes) {
        final FileObject fo = n.getLookup().lookup(FileObject.class);
        if (fo != null) {
            if (isMMD(fo)) {
                result.add(fo);
            }
        }
    }
    return result.toArray(new FileObject[result.size()]);
}
Also used : Node(org.openide.nodes.Node) ArrayList(java.util.ArrayList) FileObject(org.openide.filesystems.FileObject)

Example 72 with FileObject

use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.

the class AbstractElement method writeMindMap.

protected static void writeMindMap(final File file, final MindMap map) throws IOException {
    final FileObject fileObject = FileUtil.toFileObject(file);
    FileLock lock = null;
    while (true) {
        try {
            lock = fileObject.lock();
            break;
        } catch (FileAlreadyLockedException ex) {
            delay(500L);
        }
    }
    try {
        final OutputStream out = fileObject.getOutputStream(lock);
        try {
            // NOI18N
            IOUtils.write(map.packToString(), out, "UTF-8");
        } finally {
            IOUtils.closeQuietly(out);
        }
    } finally {
        if (lock != null) {
            lock.releaseLock();
        }
    }
}
Also used : OutputStream(java.io.OutputStream) FileLock(org.openide.filesystems.FileLock) FileObject(org.openide.filesystems.FileObject) FileAlreadyLockedException(org.openide.filesystems.FileAlreadyLockedException)

Example 73 with FileObject

use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.

the class AbstractPlugin method findFileObjectInLookup.

private Collection<? extends FileObject> findFileObjectInLookup(final Lookup lookup) {
    final Collection<? extends FileObject> files = lookup.lookupAll(FileObject.class);
    final Collection<? extends NonRecursiveFolder> folders = lookup.lookupAll(NonRecursiveFolder.class);
    final Set<FileObject> result = new HashSet<FileObject>();
    for (final NonRecursiveFolder f : folders) {
        result.add(f.getFolder());
    }
    result.addAll(files);
    final Collection<? extends TreePathHandle> treePaths = lookup.lookupAll(TreePathHandle.class);
    for (final TreePathHandle h : treePaths) {
        result.add(h.getFileObject());
    }
    return result;
}
Also used : TreePathHandle(org.netbeans.api.java.source.TreePathHandle) NonRecursiveFolder(org.netbeans.api.fileinfo.NonRecursiveFolder) FileObject(org.openide.filesystems.FileObject)

Example 74 with FileObject

use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.

the class AbstractPlugin method prepare.

@Override
public final Problem prepare(final RefactoringElementsBag session) {
    if (isCanceled()) {
        return null;
    }
    final Collection<? extends FileObject> files = findFileObjectInLookup(this.refactoring.getRefactoringSource());
    fireProgressListenerStart(RenameRefactoring.PREPARE, files.size());
    Problem result = null;
    try {
        for (final FileObject fileObject : findFileObjectInLookup(this.refactoring.getRefactoringSource())) {
            if (isCanceled()) {
                return null;
            }
            if (result != null) {
                break;
            }
            final Project project = FileOwnerQuery.getOwner(fileObject);
            result = processFileObject(project, fileObject);
            fireProgressListenerStep(1);
        }
    } finally {
        synchronized (this.elements) {
            LOGGER.info("Detected " + this.elements.size() + " elements for refactoring");
            if (!isCanceled()) {
                session.addAll(refactoring, this.elements);
            }
        }
        fireProgressListenerStop();
    }
    return result;
}
Also used : Project(org.netbeans.api.project.Project) Problem(org.netbeans.modules.refactoring.api.Problem) FileObject(org.openide.filesystems.FileObject)

Example 75 with FileObject

use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.

the class AbstractPlugin method allMapsInProject.

protected Collection<FileObject> allMapsInProject(final Project project) {
    final Collection<? extends Scope> scopes = this.refactoring.getRefactoringSource().lookupAll(Scope.class);
    if (!scopes.isEmpty()) {
        final Collection<FileObject> mindMaps = new HashSet<FileObject>();
        for (final Scope s : scopes) {
            for (final NonRecursiveFolder f : s.getFolders()) {
                synchronized (this.cache) {
                    Collection<FileObject> found = this.cache.get(f.getFolder());
                    if (found == null) {
                        found = RefactoringUtils.findAllMindMapsInFolder(f, this);
                        this.cache.put(f.getFolder(), found);
                    }
                    mindMaps.addAll(found);
                }
            }
        }
        return mindMaps;
    } else {
        if (project == null) {
            return Collections.<FileObject>emptyList();
        }
        final FileObject projectFolder = project.getProjectDirectory();
        synchronized (this.cache) {
            Collection<FileObject> result = this.cache.get(projectFolder);
            if (result == null) {
                result = RefactoringUtils.findAllMindMapsInProject(project, this);
                this.cache.put(projectFolder, result);
            }
            return result;
        }
    }
}
Also used : Scope(org.netbeans.modules.refactoring.api.Scope) NonRecursiveFolder(org.netbeans.api.fileinfo.NonRecursiveFolder) FileObject(org.openide.filesystems.FileObject)

Aggregations

FileObject (org.openide.filesystems.FileObject)79 File (java.io.File)27 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)9 NotifyDescriptor (org.openide.NotifyDescriptor)7 Project (org.netbeans.api.project.Project)6 DataObject (org.openide.loaders.DataObject)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 BorderLayout (java.awt.BorderLayout)3