use of org.gephi.utils.longtask.spi.LongTask 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.utils.longtask.spi.LongTask in project gephi by gephi.
the class StatisticsControllerUIImpl method execute.
@Override
public void execute(final Statistics statistics) {
StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
final StatisticsUI[] uis = getUI(statistics);
for (StatisticsUI s : uis) {
s.setup(statistics);
}
model.setRunning(statistics, true);
controller.execute(statistics, new LongTaskListener() {
@Override
public void taskFinished(LongTask task) {
model.setRunning(statistics, false);
for (StatisticsUI s : uis) {
model.addResult(s);
s.unsetup();
}
}
});
}
use of org.gephi.utils.longtask.spi.LongTask in project gephi by gephi.
the class StatisticsControllerUIImpl method execute.
@Override
public void execute(final Statistics statistics, final LongTaskListener listener) {
StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
final StatisticsUI[] uis = getUI(statistics);
for (StatisticsUI s : uis) {
s.setup(statistics);
}
model.setRunning(statistics, true);
controller.execute(statistics, new LongTaskListener() {
@Override
public void taskFinished(LongTask task) {
model.setRunning(statistics, false);
for (StatisticsUI s : uis) {
model.addResult(s);
s.unsetup();
}
if (listener != null) {
listener.taskFinished(statistics instanceof LongTask ? (LongTask) statistics : null);
}
}
});
}
use of org.gephi.utils.longtask.spi.LongTask in project gephi by gephi.
the class StatisticsFrontEnd method run.
private void run() {
GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
GraphModel graphModel = graphController.getGraphModel();
//Create Statistics
StatisticsController controller = Lookup.getDefault().lookup(StatisticsController.class);
StatisticsControllerUI controllerUI = Lookup.getDefault().lookup(StatisticsControllerUI.class);
StatisticsBuilder builder = controller.getBuilder(statisticsUI.getStatisticsClass());
currentStatistics = builder.getStatistics();
if (currentStatistics != null) {
if (currentStatistics instanceof DynamicStatistics && !graphModel.isDynamic()) {
DialogDisplayer.getDefault().notifyLater(new NotifyDescriptor.Message(NbBundle.getMessage(StatisticsFrontEnd.class, "StatisticsFrontEnd.notDynamicGraph"), NotifyDescriptor.WARNING_MESSAGE));
return;
}
LongTaskListener listener = new LongTaskListener() {
@Override
public void taskFinished(LongTask task) {
showReport();
}
};
JPanel settingsPanel = statisticsUI.getSettingsPanel();
if (currentStatistics instanceof DynamicStatistics) {
DynamicSettingsPanel dynamicPanel = new DynamicSettingsPanel();
statisticsUI.setup(currentStatistics);
dynamicPanel.setup((DynamicStatistics) currentStatistics);
JPanel dynamicSettingsPanel = DynamicSettingsPanel.createCounpoundPanel(dynamicPanel, settingsPanel);
final DialogDescriptor dd = new DialogDescriptor(dynamicSettingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
if (dynamicSettingsPanel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) dynamicSettingsPanel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
dynamicPanel.unsetup((DynamicStatistics) currentStatistics);
statisticsUI.unsetup();
controllerUI.execute(currentStatistics, listener);
}
} else if (settingsPanel != null) {
statisticsUI.setup(currentStatistics);
final DialogDescriptor dd = new DialogDescriptor(settingsPanel, NbBundle.getMessage(StatisticsTopComponent.class, "StatisticsFrontEnd.settingsPanel.title", builder.getName()));
if (settingsPanel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) settingsPanel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
if (DialogDisplayer.getDefault().notify(dd).equals(NotifyDescriptor.OK_OPTION)) {
statisticsUI.unsetup();
controllerUI.execute(currentStatistics, listener);
}
} else {
statisticsUI.setup(currentStatistics);
controllerUI.execute(currentStatistics, listener);
}
}
}
use of org.gephi.utils.longtask.spi.LongTask in project gephi by gephi.
the class ProjectControllerUIImpl method loadProject.
private void loadProject(File file) {
lockProjectActions();
final Runnable loadTask = controller.openProject(file);
final String fileName = file.getName();
Runnable loadRunnable = new Runnable() {
@Override
public void run() {
loadTask.run();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
String title = frame.getTitle() + " - " + fileName;
frame.setTitle(title);
}
});
//Status line
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(ProjectControllerUIImpl.class, "ProjectControllerUI.status.opened", fileName));
}
};
if (loadTask instanceof LongTask) {
longTaskExecutor.execute((LongTask) loadTask, loadRunnable);
} else {
longTaskExecutor.execute(null, loadRunnable);
}
//Save MRU
MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
mostRecentFiles.addFile(file.getAbsolutePath());
}
Aggregations