Search in sources :

Example 1 with Database

use of org.gephi.io.importer.api.Database 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 2 with Database

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

the class EdgeListDatabaseImporterUI method unsetup.

@Override
public void unsetup(boolean update) {
    if (update) {
        Database database = panel.getSelectedDatabase();
        for (DatabaseImporter importer : importers) {
            importer.setDatabase(database);
        }
    }
    panel = null;
    importers = null;
}
Also used : DatabaseImporter(org.gephi.io.importer.spi.DatabaseImporter) Database(org.gephi.io.importer.api.Database)

Example 3 with Database

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

the class EdgeListDatabaseManager method load.

private void load() {
    if (databaseConfigurations == null) {
        databaseConfigurations = FileUtil.getConfigFile("EdgeListDatabase");
    }
    if (databaseConfigurations != null) {
        InputStream is = null;
        try {
            is = databaseConfigurations.getInputStream();
            ObjectInputStream ois = new ObjectInputStream(is);
            List<Database> unserialized = (List<Database>) ois.readObject();
            if (unserialized != null) {
                edgeListDatabases = unserialized;
            }
        } catch (java.io.InvalidClassException e) {
        } catch (EOFException eofe) {
        // Empty configuration: do nothing
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) Database(org.gephi.io.importer.api.Database) EOFException(java.io.EOFException) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Database (org.gephi.io.importer.api.Database)3 IOException (java.io.IOException)2 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ChangeListener (javax.swing.event.ChangeListener)1 Container (org.gephi.io.importer.api.Container)1 DatabaseImporter (org.gephi.io.importer.spi.DatabaseImporter)1 ImporterUI (org.gephi.io.importer.spi.ImporterUI)1 LongTask (org.gephi.utils.longtask.spi.LongTask)1 ValidationPanel (org.netbeans.validation.api.ui.ValidationPanel)1 DialogDescriptor (org.openide.DialogDescriptor)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 FileObject (org.openide.filesystems.FileObject)1