use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.
the class ImportWizard method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
WizardIterator wizardIterator = new WizardIterator();
WizardDescriptor wizardDescriptor = new WizardDescriptor(wizardIterator);
wizardDescriptor.setTitleFormat(new MessageFormat("{0} ({1})"));
wizardDescriptor.setTitle(NbBundle.getMessage(getClass(), "ImportWizard.wizard.title"));
Dialog dialog = DialogDisplayer.getDefault().createDialog(wizardDescriptor);
dialog.setVisible(true);
dialog.toFront();
boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
if (!cancelled) {
ImporterWizardUI wizardUI = wizardIterator.getCurrentWizardUI();
//Get Importer
WizardImporter importer = null;
for (WizardImporterBuilder wizardBuilder : Lookup.getDefault().lookupAll(WizardImporterBuilder.class)) {
WizardImporter im = wizardBuilder.buildImporter();
if (wizardUI.isUIForImporter(im)) {
importer = im;
}
}
if (importer == null) {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "ImportWizard.error_no_matching_importer"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
return;
}
//Unsetup
wizardIterator.unsetupPanels(importer);
ImportControllerUI importControllerUI = Lookup.getDefault().lookup(ImportControllerUI.class);
importControllerUI.importWizard(importer);
}
}
use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.
the class CommandLineProcessor method process.
@Override
public void process(Env env, Map values) throws CommandException {
List<String> filenameList = new ArrayList<>();
Object obj = values.get(openOption);
if (obj != null) {
filenameList.addAll(Arrays.asList((String[]) obj));
}
obj = values.get(openOption2);
if (obj != null) {
filenameList.addAll(Arrays.asList((String[]) obj));
}
try {
for (int i = 0; i < filenameList.size(); i++) {
File file = new File(filenameList.get(i));
if (!file.isAbsolute()) {
file = new File(env.getCurrentDirectory(), filenameList.get(i));
}
FileObject fileObject = FileUtil.toFileObject(file);
if (!file.exists()) {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
return;
}
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ew) {
ew.printStackTrace();
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
return;
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
importController.importFile(fileObject);
} else {
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
}
}
} catch (OutOfMemoryError ex) {
System.gc();
NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
} catch (Exception ex) {
ex.printStackTrace();
NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
DialogDisplayer.getDefault().notify(nd);
}
}
use of org.gephi.desktop.importer.api.ImportControllerUI in project gephi by gephi.
the class DragNDropFrameAdapter method register.
public static void register() {
JFrame frame = (JFrame) WindowManager.getDefault().getMainWindow();
frame.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferHandler.TransferSupport support) {
if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
return false;
}
//Impossible to get data here and look if compatible format
return true;
}
@Override
public boolean importData(TransferHandler.TransferSupport support) {
if (!canImport(support)) {
return false;
}
try {
List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
File file = (File) data.get(0);
FileObject fileObject = FileUtil.toFileObject(file);
if (!file.exists()) {
return false;
}
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ew) {
ew.printStackTrace();
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(DragNDropFrameAdapter.class, "DragNDropFrameAdapter.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
importController.importFile(fileObject);
} else {
return false;
}
}
return true;
} catch (UnsupportedFlavorException ex) {
Exceptions.printStackTrace(ex);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
return false;
}
});
}
Aggregations