use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.
the class MoveFileActionPlugin method processFile.
@Override
protected Problem processFile(final Project project, final int level, final File projectFolder, final FileObject fileObject) {
final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);
final Lookup targetLookup = this.refactoring.getTarget();
if (targetLookup == null) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindLookup"));
}
final URL targetURL = targetLookup.lookup(URL.class);
if (targetURL != null) {
try {
URI baseURI = targetURL.toURI();
if (baseURI.isAbsolute()) {
final URI projectURI = Utilities.toURI(projectFolder);
baseURI = projectURI.relativize(baseURI);
}
final MMapURI newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null).replaceBaseInPath(true, baseURI, level);
for (final FileObject mmap : allMapsInProject(project)) {
try {
if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
final MoveElement element = new MoveElement(new MindMapLink(mmap), projectFolder, MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
element.setTarget(newFileAsURI);
addElement(element);
}
} catch (Exception ex) {
ErrorManager.getDefault().notify(ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
}
}
} catch (URISyntaxException ex) {
// NOI18N
LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex);
// NOI18N
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantMakeURIForFile"));
}
return null;
} else {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindURL"));
}
}
use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.
the class RenameFileActionPlugin method processFile.
@Override
protected Problem processFile(final Project project, final int level, final File projectFolder, final FileObject fileObject) {
final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);
String newFileName = this.refactoring.getNewName();
if (newFileName == null) {
return new Problem(false, "Detected null as new file name for rename refactoring action");
}
if (level == 0 && !fileObject.isFolder()) {
final String ext = FilenameUtils.getExtension(fileObject.getNameExt());
if (!ext.isEmpty()) {
if (!newFileName.toLowerCase(Locale.ENGLISH).endsWith('.' + ext)) {
newFileName += '.' + ext;
}
}
} else {
newFileName = newFileName.replace('.', '/');
}
final MMapURI newFileAsURI;
try {
if (level == 0) {
newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null).replaceName(newFileName);
} else {
newFileAsURI = MMapURI.makeFromFilePath(projectFolder, replaceNameInPath(level, fileObject.getPath(), newFileName), null);
}
} catch (URISyntaxException ex) {
// NOI18N
LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantMakeURI"));
}
for (final FileObject mmap : allMapsInProject(project)) {
if (isCanceled()) {
break;
}
try {
if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
final RenameElement element = new RenameElement(new MindMapLink(mmap), projectFolder, MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
element.setNewFile(newFileAsURI);
addElement(element);
}
} catch (Exception ex) {
ErrorManager.getDefault().notify(ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
}
}
return null;
}
use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.
the class MovePanel method getFolders.
private void getFolders(final FileObject root, final FileObject folder, final List<String> result) {
for (final FileObject c : folder.getChildren()) {
if (c.isFolder()) {
result.add(FileUtil.getRelativePath(root, c));
getFolders(root, c, result);
}
}
}
use of org.openide.filesystems.FileObject in project netbeans-mmd-plugin by raydac.
the class RefactoringActionsProvider method doFindUsages.
@Override
public void doFindUsages(final Lookup lookup) {
final FileObject fileObject = RefactoringUtils.getMMD(lookup);
UI.openRefactoringUI(new WhereUsedRefactoringUI(lookup, fileObject));
}
Aggregations