Search in sources :

Example 11 with FileObject

use of org.openide.filesystems.FileObject in project gephi by gephi.

the class ProjectControllerUIImpl method openFile.

@Override
public void openFile() {
    final String LAST_PATH = "OpenFile_Last_Path";
    final String LAST_PATH_DEFAULT = "OpenFile_Last_Path_Default";
    //Get last directory
    String lastPathDefault = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH_DEFAULT, null);
    String lastPath = NbPreferences.forModule(ProjectControllerUIImpl.class).get(LAST_PATH, lastPathDefault);
    //Init dialog
    final JFileChooser chooser = new JFileChooser(lastPath);
    chooser.setMultiSelectionEnabled(true);
    DialogFileFilter gephiFilter = new DialogFileFilter(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject_filechooser_filter"));
    gephiFilter.addExtension(".gephi");
    DialogFileFilter graphFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_graphfilter"));
    graphFilter.addExtension(".gephi");
    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
    for (FileType fileType : importController.getImportController().getFileTypes()) {
        DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
        dialogFileFilter.addExtensions(fileType.getExtensions());
        chooser.addChoosableFileFilter(dialogFileFilter);
        graphFilter.addExtensions(fileType.getExtensions());
    }
    DialogFileFilter zipFileFilter = new DialogFileFilter(NbBundle.getMessage(getClass(), "OpenFile_filechooser_zipfilter"));
    zipFileFilter.addExtensions(new String[] { ".zip", ".gz", ".bz2" });
    chooser.addChoosableFileFilter(zipFileFilter);
    chooser.addChoosableFileFilter(gephiFilter);
    chooser.addChoosableFileFilter(graphFilter);
    //Open dialog
    int returnFile = chooser.showOpenDialog(null);
    if (returnFile == JFileChooser.APPROVE_OPTION) {
        File[] files = chooser.getSelectedFiles();
        FileObject[] fileObjects = new FileObject[files.length];
        int i = 0;
        File gephiFile = null;
        for (File file : files) {
            file = FileUtil.normalizeFile(file);
            FileObject fileObject = FileUtil.toFileObject(file);
            fileObjects[i++] = fileObject;
            if (fileObject.getExt().equalsIgnoreCase("gephi")) {
                if (gephiFile != null) {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectControllerUI.error.multipleGephi"), NotifyDescriptor.ERROR_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                    return;
                } else {
                    gephiFile = file;
                }
            }
            //Save last path
            NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath());
        }
        if (gephiFile != null) {
            //Project
            if (controller.getCurrentProject() != null) {
                if (!closeCurrentProject()) {
                    return;
                }
            }
            try {
                loadProject(gephiFile);
            } catch (Exception ew) {
                ew.printStackTrace();
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(ProjectControllerUIImpl.class, "OpenProject.defaulterror"), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
            }
        } else {
            //Import
            importController.importFiles(fileObjects);
        }
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) JFileChooser(javax.swing.JFileChooser) FileType(org.gephi.io.importer.api.FileType) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File)

Example 12 with FileObject

use of org.openide.filesystems.FileObject in project gephi by gephi.

the class RecentFiles method getMenuPresenter.

@Override
public JMenuItem getMenuPresenter() {
    JMenu menu = new JMenu(NbBundle.getMessage(RecentFiles.class, "CTL_OpenRecentFiles"));
    MostRecentFiles mru = Lookup.getDefault().lookup(MostRecentFiles.class);
    for (String filePath : mru.getMRUFileList()) {
        final File file = new File(filePath);
        if (file.exists()) {
            final String fileName = file.getName();
            JMenuItem menuItem = new JMenuItem(new AbstractAction(fileName) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    FileObject fileObject = FileUtil.toFileObject(file);
                    if (fileObject.hasExt(GEPHI_EXTENSION)) {
                        ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                        try {
                            pc.openProject(file);
                        } catch (Exception ex) {
                            Exceptions.printStackTrace(ex);
                        }
                    } else {
                        ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                        if (importController.getImportController().isFileSupported(file)) {
                            importController.importFile(fileObject);
                        }
                    }
                }
            });
            menu.add(menuItem);
        }
    }
    return menu;
}
Also used : MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) ActionEvent(java.awt.event.ActionEvent) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) JMenuItem(javax.swing.JMenuItem) File(java.io.File) AbstractAction(javax.swing.AbstractAction) JMenu(javax.swing.JMenu) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 13 with FileObject

use of org.openide.filesystems.FileObject in project gephi by gephi.

the class DirectoryNode method convertToValidDir.

/*public static boolean isNetBeansProject (File directory) {
    boolean retVal = false;
    if (directory != null) {
    FileObject fo = convertToValidDir(directory);
    if (fo != null) {
    if (Utilities.isUnix() && fo.getParent() != null
    && fo.getParent().getParent() == null) {
    retVal = false; // Ignore all subfolders of / on unixes
    // (e.g. /net, /proc)
    } else {
    retVal = ProjectManager.getDefault().isProject(fo);
    }
    }
    }
    return retVal;
    }*/
private static FileObject convertToValidDir(File f) {
    FileObject fo;
    File testFile = new File(f.getPath());
    if (testFile == null || testFile.getParent() == null) {
        // directories.
        return null;
    }
    /**
         *
         * ATTENTION: on Windows may occure dir.isDirectory () == dir.isFile () ==
         *
         * true then its used testFile instead of dir.
         *
         */
    if (!testFile.isDirectory()) {
        return null;
    }
    fo = FileUtil.toFileObject(FileUtil.normalizeFile(testFile));
    return fo;
}
Also used : FileObject(org.openide.filesystems.FileObject) File(java.io.File)

Example 14 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method getSourceRoots.

private String[] getSourceRoots(ClassPath classPath) {
    FileObject[] sourceRoots = classPath.getRoots();
    List<String> roots = new ArrayList<String>(sourceRoots.length);
    for (FileObject fo : sourceRoots) {
        String root = getRoot(fo);
        if (root != null) {
            roots.add(root);
        }
    }
    return roots.toArray(new String[0]);
}
Also used : FileObject(org.openide.filesystems.FileObject)

Example 15 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class ClojureSourcesHelper method getClojureSources.

public static List<FileObject> getClojureSources(Project project) {
    List<FileObject> result = new ArrayList<FileObject>();
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);
        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();
            if (fobj.getExt().equals(CLOJURE_EXT)) {
                result.add(fobj);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) FileObject(org.openide.filesystems.FileObject) Sources(org.netbeans.api.project.Sources) SourceGroup(org.netbeans.api.project.SourceGroup)

Aggregations

FileObject (org.openide.filesystems.FileObject)34 File (java.io.File)15 IOException (java.io.IOException)9 NotifyDescriptor (org.openide.NotifyDescriptor)6 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)5 ActionEvent (java.awt.event.ActionEvent)4 InputStream (java.io.InputStream)4 JPanel (javax.swing.JPanel)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 ProjectControllerUI (org.gephi.desktop.project.api.ProjectControllerUI)4 Document (org.w3c.dom.Document)4 ActionListener (java.awt.event.ActionListener)3 ArrayList (java.util.ArrayList)3 JFileChooser (javax.swing.JFileChooser)3 MostRecentFiles (org.gephi.desktop.mrufiles.api.MostRecentFiles)3 FileImporter (org.gephi.io.importer.spi.FileImporter)3 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)3 ClassPath (org.netbeans.api.java.classpath.ClassPath)3 DialogDescriptor (org.openide.DialogDescriptor)3