Search in sources :

Example 1 with MindMapLink

use of com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink 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"));
    }
}
Also used : Lookup(org.openide.util.Lookup) Problem(org.netbeans.modules.refactoring.api.Problem) FileObject(org.openide.filesystems.FileObject) URISyntaxException(java.net.URISyntaxException) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) URI(java.net.URI) URL(java.net.URL) MindMapLink(com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink) URISyntaxException(java.net.URISyntaxException)

Example 2 with MindMapLink

use of com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink 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;
}
Also used : Problem(org.netbeans.modules.refactoring.api.Problem) URISyntaxException(java.net.URISyntaxException) FileObject(org.openide.filesystems.FileObject) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) MindMapLink(com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink) URISyntaxException(java.net.URISyntaxException)

Aggregations

MMapURI (com.igormaznitsa.mindmap.model.MMapURI)2 MindMapLink (com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink)2 URISyntaxException (java.net.URISyntaxException)2 Problem (org.netbeans.modules.refactoring.api.Problem)2 FileObject (org.openide.filesystems.FileObject)2 URI (java.net.URI)1 URL (java.net.URL)1 Lookup (org.openide.util.Lookup)1