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);
}
}
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;
}
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) {
}
}
}
}
}
Aggregations