use of org.gephi.io.importer.api.Container in project gephi by gephi.
the class DesktopImportControllerUI method importFile.
@Override
public void importFile(final Reader reader, 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) {
FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
fi[0] = importer;
ui.setup(fi);
String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
JPanel panel = ui.getPanel();
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(reader, 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.Container in project gephi by gephi.
the class DesktopImportControllerUI method importFiles.
@Override
public void importFiles(FileObject[] fileObjects) {
try {
Map<ImporterUI, List<FileImporter>> importerUIs = new HashMap<>();
List<FileImporter> importers = new ArrayList<>();
for (FileObject fileObject : fileObjects) {
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;
}
importers.add(importer);
ImporterUI ui = controller.getUI(importer);
if (ui != null) {
List<FileImporter> l = importerUIs.get(ui);
if (l == null) {
l = new ArrayList<>();
importerUIs.put(ui, l);
}
l.add(importer);
}
//MRU
MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
mostRecentFiles.addFile(fileObject.getPath());
}
for (Map.Entry<ImporterUI, List<FileImporter>> entry : importerUIs.entrySet()) {
ImporterUI ui = entry.getKey();
String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
JPanel panel = ui.getPanel();
FileImporter[] fi = (FileImporter[]) entry.getValue().toArray((FileImporter[]) Array.newInstance(entry.getValue().get(0).getClass(), 0));
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);
}
final List<Container> result = new ArrayList<>();
for (int i = 0; i < importers.size(); i++) {
final FileImporter importer = importers.get(i);
FileObject fileObject = fileObjects[i];
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);
result.add(container);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}, taskName, errorHandler);
}
executor.execute(null, new Runnable() {
@Override
public void run() {
if (!result.isEmpty()) {
finishImport(result.toArray(new Container[0]));
}
}
});
} catch (Exception ex) {
Logger.getLogger("").log(Level.WARNING, "", ex);
}
}
use of org.gephi.io.importer.api.Container in project gephi by gephi.
the class DesktopImportControllerUI method finishImport.
private void finishImport(Container[] containers) {
Report finalReport = new Report();
for (Container container : containers) {
if (container.verify()) {
Report report = container.getReport();
report.close();
finalReport.append(report);
} else {
//TODO
}
}
finalReport.close();
//Report panel
ReportPanel reportPanel = new ReportPanel();
reportPanel.setData(finalReport, containers);
DialogDescriptor dd = new DialogDescriptor(reportPanel, NbBundle.getMessage(DesktopImportControllerUI.class, "ReportPanel.title"));
Object response = DialogDisplayer.getDefault().notify(dd);
reportPanel.destroy();
finalReport.clean();
for (Container c : containers) {
c.getReport().clean();
}
if (!response.equals(NotifyDescriptor.OK_OPTION)) {
return;
}
final Processor processor = reportPanel.getProcessor();
//Project
Workspace workspace = null;
ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
ProjectControllerUI pcui = Lookup.getDefault().lookup(ProjectControllerUI.class);
if (pc.getCurrentProject() == null) {
pcui.newProject();
workspace = pc.getCurrentWorkspace();
}
//Process
final ProcessorUI pui = getProcessorUI(processor);
final ValidResult validResult = new ValidResult();
if (pui != null) {
try {
final JPanel panel = pui.getPanel();
if (panel != null) {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.processor.ui.dialog.title");
pui.setup(processor);
final DialogDescriptor dd2 = new DialogDescriptor(panel, title);
if (panel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) panel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd2.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
dd2.setValid(!vp.isProblem());
}
Object result = DialogDisplayer.getDefault().notify(dd2);
if (result.equals(NotifyDescriptor.CANCEL_OPTION) || result.equals(NotifyDescriptor.CLOSED_OPTION)) {
validResult.setResult(false);
} else {
//true
pui.unsetup();
validResult.setResult(true);
}
}
});
}
} catch (InterruptedException ex) {
Exceptions.printStackTrace(ex);
} catch (InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
}
}
if (validResult.isResult()) {
controller.process(containers, processor, workspace);
//StatusLine notify
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.status.multiImportSuccess", containers.length));
}
}
use of org.gephi.io.importer.api.Container in project gephi by gephi.
the class ReportPanel method initGraphTypeCombo.
private void initGraphTypeCombo(final Container[] containers) {
final String directedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.directed");
final String undirectedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.undirected");
final String mixedStr = NbBundle.getMessage(ReportPanel.class, "ReportPanel.graphType.mixed");
EdgeDirectionDefault edd = null;
for (Container container : containers) {
EdgeDirectionDefault d = container.getUnloader().getEdgeDefault();
if (edd == null) {
edd = d;
} else if (d.equals(EdgeDirectionDefault.UNDIRECTED) && !edd.equals(EdgeDirectionDefault.UNDIRECTED)) {
edd = EdgeDirectionDefault.MIXED;
} else if (d.equals(EdgeDirectionDefault.DIRECTED) && !edd.equals(EdgeDirectionDefault.DIRECTED)) {
edd = EdgeDirectionDefault.MIXED;
}
}
final EdgeDirectionDefault dir = edd;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DefaultComboBoxModel comboModel = new DefaultComboBoxModel();
switch(dir) {
case DIRECTED:
comboModel.addElement(directedStr);
comboModel.addElement(undirectedStr);
comboModel.addElement(mixedStr);
comboModel.setSelectedItem(directedStr);
break;
case UNDIRECTED:
comboModel.addElement(undirectedStr);
comboModel.addElement(mixedStr);
comboModel.setSelectedItem(undirectedStr);
break;
case MIXED:
comboModel.addElement(directedStr);
comboModel.addElement(undirectedStr);
comboModel.addElement(mixedStr);
comboModel.setSelectedItem(mixedStr);
break;
}
graphTypeCombo.setModel(comboModel);
}
});
graphTypeCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Object g = e.getItem();
if (g.equals(directedStr)) {
for (Container container : containers) {
container.getLoader().setEdgeDefault(EdgeDirectionDefault.DIRECTED);
}
} else if (g.equals(undirectedStr)) {
for (Container container : containers) {
container.getLoader().setEdgeDefault(EdgeDirectionDefault.UNDIRECTED);
}
} else if (g.equals(mixedStr)) {
for (Container container : containers) {
container.getLoader().setEdgeDefault(EdgeDirectionDefault.MIXED);
}
}
}
}
});
}
use of org.gephi.io.importer.api.Container in project gephi by gephi.
the class DesktopGeneratorController method generate.
@Override
public void generate(final Generator generator) {
String title = generator.getName();
GeneratorUI ui = generator.getUI();
if (ui != null) {
ui.setup(generator);
JPanel panel = ui.getPanel();
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 != NotifyDescriptor.OK_OPTION) {
return;
}
ui.unsetup();
}
final Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
container.setSource("" + generator.getName());
container.setReport(new Report());
String taskname = NbBundle.getMessage(DesktopGeneratorController.class, "DesktopGeneratorController.taskname", generator.getName());
//Error handler
LongTaskErrorHandler errorHandler = new LongTaskErrorHandler() {
@Override
public void fatalError(Throwable t) {
Logger.getLogger("").log(Level.SEVERE, "", t.getCause() != null ? t.getCause() : t);
}
};
//Execute
executor.execute(generator, new Runnable() {
@Override
public void run() {
generator.generate(container.getLoader());
finishGenerate(container);
}
}, taskname, errorHandler);
}
Aggregations