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