Search in sources :

Example 26 with FileObject

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

the class CommandLineProcessor method process.

@Override
public void process(Env env, Map values) throws CommandException {
    List<String> filenameList = new ArrayList<>();
    Object obj = values.get(openOption);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    obj = values.get(openOption2);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    try {
        for (int i = 0; i < filenameList.size(); i++) {
            File file = new File(filenameList.get(i));
            if (!file.isAbsolute()) {
                file = new File(env.getCurrentDirectory(), filenameList.get(i));
            }
            FileObject fileObject = FileUtil.toFileObject(file);
            if (!file.exists()) {
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
                return;
            }
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ew) {
                    ew.printStackTrace();
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
                return;
            } else {
                ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                    importController.importFile(fileObject);
                } else {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            }
        }
    } catch (OutOfMemoryError ex) {
        System.gc();
        NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    } catch (Exception ex) {
        ex.printStackTrace();
        NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : ArrayList(java.util.ArrayList) CommandException(org.netbeans.api.sendopts.CommandException) NotifyDescriptor(org.openide.NotifyDescriptor) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 27 with FileObject

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

the class DragNDropFrameAdapter method register.

public static void register() {
    JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
    frame.setTransferHandler(new TransferHandler() {

        @Override
        public boolean canImport(TransferHandler.TransferSupport support) {
            if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                return false;
            }
            //Impossible to get data here and look if compatible format
            return true;
        }

        @Override
        public boolean importData(TransferHandler.TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            try {
                List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
                File file = (File) data.get(0);
                FileObject fileObject = FileUtil.toFileObject(file);
                if (!file.exists()) {
                    return false;
                }
                if (fileObject.hasExt(GEPHI_EXTENSION)) {
                    ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                    try {
                        pc.openProject(file);
                    } catch (Exception ew) {
                        ew.printStackTrace();
                        NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                        DialogDisplayer.getDefault().notify(msg);
                    }
                } else {
                    ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                    if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                        importController.importFile(fileObject);
                    } else {
                        return false;
                    }
                }
                return true;
            } catch (UnsupportedFlavorException ex) {
                Exceptions.printStackTrace(ex);
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
            return false;
        }
    });
}
Also used : IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) JFrame(javax.swing.JFrame) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) TransferHandler(javax.swing.TransferHandler) List(java.util.List) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 28 with FileObject

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

the class ImportControllerImpl method importFile.

@Override
public Container importFile(File file) throws FileNotFoundException {
    FileObject fileObject = FileUtil.toFileObject(file);
    if (fileObject != null) {
        //Unzip and return content file
        fileObject = getArchivedFile(fileObject);
        FileImporterBuilder builder = getMatchingImporter(fileObject);
        if (fileObject != null && builder != null) {
            Container c = importFile(fileObject.getInputStream(), builder.buildImporter());
            return c;
        }
    }
    return null;
}
Also used : FileImporterBuilder(org.gephi.io.importer.spi.FileImporterBuilder) Container(org.gephi.io.importer.api.Container) FileObject(org.openide.filesystems.FileObject)

Example 29 with FileObject

use of org.openide.filesystems.FileObject in project cakephp-netbeans by cakephp.

the class CakePhpFrameworkProvider method getConfigurationFiles.

@Override
public File[] getConfigurationFiles(PhpModule phpModule) {
    // return all php files from app/config
    List<File> configFiles = new LinkedList<File>();
    // NOI18N
    FileObject config = phpModule.getSourceDirectory().getFileObject("app/config");
    assert config != null : "app/config not found for CakePHP project " + phpModule.getDisplayName();
    if (config != null && config.isFolder()) {
        Enumeration<? extends FileObject> children = config.getChildren(true);
        while (children.hasMoreElements()) {
            FileObject child = children.nextElement();
            if (child.isData() && FileUtils.isPhpFile(child)) {
                configFiles.add(FileUtil.toFile(child));
            }
        }
    }
    if (!configFiles.isEmpty()) {
        Collections.sort(configFiles, FILE_COMPARATOR);
    }
    return configFiles.toArray(new File[configFiles.size()]);
}
Also used : FileObject(org.openide.filesystems.FileObject) File(java.io.File) LinkedList(java.util.LinkedList)

Example 30 with FileObject

use of org.openide.filesystems.FileObject in project cakephp-netbeans by cakephp.

the class CakeScript method forPhpModule.

/**
     * Get the project specific, <b>valid only</b> Cake script. If not found, the {@link InvalidPhpProgramException} is thrown.
     * @param phpModule PHP module for which Cake script is taken
     * @return the project specific, <b>valid only</b> Cake script
     * @throws InvalidPhpProgramException if Zend script is not valid or missing completely
     */
public static CakeScript forPhpModule(PhpModule phpModule) throws InvalidPhpProgramException {
    FileObject sourceDirectory = phpModule.getSourceDirectory();
    // locate
    FileObject cake = sourceDirectory.getFileObject(SCRIPT_DIRECTORY + SCRIPT_NAME);
    if (cake == null) {
        cake = sourceDirectory.getFileObject(SCRIPT_DIRECTORY + SCRIPT_NAME_LONG);
    }
    if (cake == null) {
        throw new InvalidPhpProgramException(NbBundle.getMessage(CakeScript.class, "MSG_CakeNotFound"));
    }
    // validate
    String cakePath = FileUtil.toFile(cake).getAbsolutePath();
    String error = validate(cakePath);
    if (error != null) {
        throw new InvalidPhpProgramException(error);
    }
    return new CakeScript(cakePath, phpModule);
}
Also used : FileObject(org.openide.filesystems.FileObject)

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