use of org.netbeans.modules.refactoring.api.Problem in project netbeans-mmd-plugin by raydac.
the class AbstractPlugin method _processFileObject.
private Problem _processFileObject(final Project project, int level, final FileObject fileObject) {
final Project theProject;
if (project == null) {
theProject = FileOwnerQuery.getOwner(fileObject);
} else {
theProject = project;
}
if (theProject == null) {
LOGGER.warn("Request process file object without a project as the owner : " + fileObject);
return null;
}
final FileObject projectDirectory = theProject.getProjectDirectory();
if (projectDirectory == null) {
LOGGER.warn("Request process file object in a project which doesn't have folder : " + fileObject + ", project : " + project);
return null;
}
final File projectFolder = FileUtil.toFile(projectDirectory);
Problem result = processFile(theProject, level, projectFolder, fileObject);
level++;
if (fileObject.isFolder()) {
for (final FileObject fo : fileObject.getChildren()) {
if (result != null) {
break;
}
if (fo.isFolder()) {
result = _processFileObject(theProject, level, fo);
} else {
result = processFile(theProject, level, projectFolder, fo);
}
}
}
return result;
}
use of org.netbeans.modules.refactoring.api.Problem in project netbeans-mmd-plugin by raydac.
the class MoveFileActionPlugin method checkParameters.
@Override
public Problem checkParameters() {
if (this.refactoring.getRefactoringSource().lookup(AbstractMMDRefactoringUI.class) != null) {
final Lookup targetLookup = this.refactoring.getTarget();
if (targetLookup == null) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindLookup"));
}
final URL url = targetLookup.lookup(URL.class);
if (url == null) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindURL"));
}
final FileObject obj = URLMapper.findFileObject(url);
if (obj == null) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindTargetFolder"));
}
if (!obj.isFolder()) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.targetIsNotFolder"));
}
}
return null;
}
use of org.netbeans.modules.refactoring.api.Problem 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.netbeans.modules.refactoring.api.Problem 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.netbeans.modules.refactoring.api.Problem 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;
}
Aggregations