Search in sources :

Example 1 with FileType

use of org.gephi.io.importer.api.FileType in project gephi by gephi.

the class ImporterBuilderCSV method getFileTypes.

@Override
public FileType[] getFileTypes() {
    FileType ft = new FileType(".csv", NbBundle.getMessage(getClass(), "fileType_CSV_Name"));
    FileType ft2 = new FileType(".edges", NbBundle.getMessage(getClass(), "fileType_Edges_Name"));
    return new FileType[] { ft, ft2 };
}
Also used : FileType(org.gephi.io.importer.api.FileType)

Example 2 with FileType

use of org.gephi.io.importer.api.FileType 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)

Aggregations

FileType (org.gephi.io.importer.api.FileType)2 File (java.io.File)1 JFileChooser (javax.swing.JFileChooser)1 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)1 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 FileObject (org.openide.filesystems.FileObject)1