Search in sources :

Example 76 with FileObject

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"));
    }
}
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 77 with FileObject

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;
}
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)

Example 78 with FileObject

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);
        }
    }
}
Also used : FileObject(org.openide.filesystems.FileObject)

Example 79 with FileObject

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));
}
Also used : 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