imp = (Imp) getImporterList().getValue();
}
catch (Exception e)
{
Logger.error("error while saving import file",e);
throw new ApplicationException(i18n.tr("Fehler beim Starten des Imports"),e);
}
if (imp == null || imp.importer == null)
throw new ApplicationException(i18n.tr("Bitte w�hlen Sie ein Import-Format aus"));
settings.setAttribute("lastformat",imp.format.getName());
FileDialog fd = new FileDialog(GUI.getShell(),SWT.OPEN);
fd.setText(i18n.tr("Bitte w�hlen Sie die Datei aus, welche f�r den Import verwendet werden soll."));
fd.setFilterNames(imp.format.getFileExtensions());
String path = settings.getString("lastdir",System.getProperty("user.home"));
if (path != null && path.length() > 0)
fd.setFilterPath(path);
final String s = fd.open();
if (s == null || s.length() == 0)
{
close();
return;
}
final File file = new File(s);
if (!file.exists() || !file.isFile())
throw new ApplicationException(i18n.tr("Datei existiert nicht oder ist nicht lesbar"));
// Wir merken uns noch das Verzeichnis vom letzten mal
settings.setAttribute("lastdir",file.getParent());
// Dialog schliessen
close();
final Importer importer = imp.importer;
final IOFormat format = imp.format;
BackgroundTask t = new BackgroundTask() {
public void run(ProgressMonitor monitor) throws ApplicationException
{
try
{
InputStream is = new BufferedInputStream(new FileInputStream(file));
importer.doImport(context,format,is,monitor);
monitor.setPercentComplete(100);
monitor.setStatus(ProgressMonitor.STATUS_DONE);
GUI.getStatusBar().setSuccessText(i18n.tr("Daten importiert aus {0}",s));
GUI.getCurrentView().reload();
}
catch (ApplicationException ae)
{
monitor.setStatus(ProgressMonitor.STATUS_ERROR);
monitor.setStatusText(ae.getMessage());
GUI.getStatusBar().setErrorText(ae.getMessage());
throw ae;
}
catch (Exception e)
{
monitor.setStatus(ProgressMonitor.STATUS_ERROR);
Logger.error("error while reading objects from " + s,e);
ApplicationException ae = new ApplicationException(i18n.tr("Fehler beim Importieren der Daten aus {0}",s),e);
monitor.setStatusText(ae.getMessage());
GUI.getStatusBar().setErrorText(ae.getMessage());
throw ae;
}
}
public void interrupt() {}