Search in sources :

Example 6 with Container

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

the class DesktopImportControllerUI method importDatabase.

@Override
public void importDatabase(Database database, final DatabaseImporter importer) {
    try {
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.error_no_matching_db_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.database.ui.dialog.title");
            JPanel panel = ui.getPanel();
            ui.setup(new DatabaseImporter[] { importer });
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (result.equals(NotifyDescriptor.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
            if (database == null) {
                database = importer.getDatabase();
            }
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        final String containerSource = database != null ? database.getName() : (ui != null ? ui.getDisplayName() : importer.getClass().getSimpleName());
        final Database db = database;
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importDatabase(db, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) JPanel(javax.swing.JPanel) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) Database(org.gephi.io.importer.api.Database) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Example 7 with Container

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

the class ImportControllerImpl method importFile.

@Override
public Container importFile(Reader reader, FileImporter importer) {
    //Create Container
    final Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
    //Report
    Report report = new Report();
    container.setReport(report);
    importer.setReader(reader);
    try {
        if (importer.execute(container.getLoader())) {
            if (importer.getReport() != null && importer.getReport() != report) {
                report.append(importer.getReport());
            }
            report.close();
            return container;
        }
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        try {
            reader.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
    return null;
}
Also used : Container(org.gephi.io.importer.api.Container) Report(org.gephi.io.importer.api.Report) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with Container

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

the class ImportControllerImpl method importWizard.

@Override
public Container importWizard(WizardImporter importer) {
    //Create Container
    final Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
    //Report
    Report report = new Report();
    container.setReport(report);
    try {
        if (importer.execute(container.getLoader())) {
            if (importer.getReport() != null) {
                report.append(importer.getReport());
            }
            report.close();
            return container;
        }
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return null;
}
Also used : Container(org.gephi.io.importer.api.Container) Report(org.gephi.io.importer.api.Report) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with Container

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

the class DesktopImportControllerUI method importStream.

@Override
public void importStream(final InputStream stream, String importerName) {
    try {
        final FileImporter importer = controller.getFileImporter(importerName);
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
            fi[0] = importer;
            ui.setup(fi);
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (!result.equals(NotifyDescriptor.OK_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        final String containerSource = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.streamSource", importerName);
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importFile(stream, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) JPanel(javax.swing.JPanel) FileImporter(org.gephi.io.importer.spi.FileImporter) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Example 10 with Container

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

the class DesktopImportControllerUI method importFile.

@Override
public void importFile(FileObject fileObject) {
    try {
        final FileImporter importer = controller.getFileImporter(FileUtil.toFile(fileObject));
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        //MRU
        MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
        mostRecentFiles.addFile(fileObject.getPath());
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
            fi[0] = importer;
            ui.setup(fi);
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (!result.equals(NotifyDescriptor.OK_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        fileObject = getArchivedFile(fileObject);
        final String containerSource = fileObject.getNameExt();
        final InputStream stream = fileObject.getInputStream();
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importFile(stream, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) JPanel(javax.swing.JPanel) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileImporter(org.gephi.io.importer.spi.FileImporter) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Aggregations

Container (org.gephi.io.importer.api.Container)14 IOException (java.io.IOException)9 JPanel (javax.swing.JPanel)8 ChangeEvent (javax.swing.event.ChangeEvent)8 ChangeListener (javax.swing.event.ChangeListener)8 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)8 DialogDescriptor (org.openide.DialogDescriptor)8 FileObject (org.openide.filesystems.FileObject)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 ImporterUI (org.gephi.io.importer.spi.ImporterUI)6 LongTask (org.gephi.utils.longtask.spi.LongTask)6 NotifyDescriptor (org.openide.NotifyDescriptor)6 Report (org.gephi.io.importer.api.Report)5 FileImporter (org.gephi.io.importer.spi.FileImporter)4 FileNotFoundException (java.io.FileNotFoundException)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 BZip2CompressorInputStream (org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream)2 MostRecentFiles (org.gephi.desktop.mrufiles.api.MostRecentFiles)2