use of de.janrufmonitor.repository.imexporter.OldDatFileCallImporter in project janrufmonitor by tbrandt77.
the class ImportAction method run.
public void run(String[] filenames) {
try {
String filename = filenames[0];
TableViewer viewer = (TableViewer) this.m_app.getApplication().getViewer();
Cursor c = new Cursor(viewer.getTable().getDisplay(), SWT.CURSOR_WAIT);
if (!filename.endsWith(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_JOURNAL, "ajournal.dat"))) {
File f = new File(filename);
String ext = f.getName();
IImExporter ie = ImExportFactory.getInstance().getImporterByExtension(ext);
if (ie == null && ext.lastIndexOf(".") >= 0) {
ext = "*" + ext.substring(ext.lastIndexOf("."));
ie = ImExportFactory.getInstance().getImporterByExtension(ext);
if (ie == null) {
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
new SWTExecuter() {
protected void execute() {
MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
m_logger.warning("Import of data failed.");
}
}.start();
}
}
if (ie != null && ie.getMode() != IImExporter.CALL_MODE)
return;
final IImExporter imp = ie;
imp.setFilename(filename);
viewer.getTable().getShell().setCursor(c);
ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayManager.getDefaultDisplay().getActiveShell());
try {
IRunnableWithProgress r = new IRunnableWithProgress() {
public void run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask(getI18nManager().getString(getNamespace(), "importprogress", "label", getLanguage()), IProgressMonitor.UNKNOWN);
progressMonitor.worked(1);
final ICallList importedCalls = getRuntime().getCallFactory().createCallList();
if (imp.getMode() == IImExporter.CALL_MODE) {
importedCalls.add(((ICallImporter) imp).doImport());
m_app.getController().addElements(importedCalls);
}
if (importedCalls.size() > 0) {
final String msg = StringUtils.replaceString(getI18nManager().getString(getNamespace(), "success", "description", getLanguage()), "{%1}", Integer.toString(importedCalls.size()));
PropagationFactory.getInstance().fire(new Message(Message.INFO, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(msg)), "Tray");
new SWTExecuter() {
protected void execute() {
m_app.updateViews(true);
}
}.start();
} else {
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getI18nManager().getString(Journal.NAMESPACE, "title", "label", getLanguage()), new Exception(getI18nManager().getString(getNamespace(), "error", "description", getLanguage()))), "Tray");
new SWTExecuter() {
protected void execute() {
MessageDialog.openError(DisplayManager.getDefaultDisplay().getActiveShell(), getI18nManager().getString(getNamespace(), "error", "label", getLanguage()), getI18nManager().getString(getNamespace(), "error", "description", getLanguage()));
m_logger.warning("Import of data failed.");
// m_app.getController().addElements(importedCalls);
m_app.updateViews(true);
}
}.start();
}
progressMonitor.done();
}
};
pmd.setBlockOnOpen(false);
pmd.run(true, false, r);
// ModalContext.run(r, true,
// pmd.getProgressMonitor(),
// DisplayManager.getDefaultDisplay());
} catch (InterruptedException e) {
throw e;
} catch (InvocationTargetException e) {
throw e;
}
viewer.getTable().getShell().setCursor(null);
c.dispose();
} else {
// do ajournal.dat migration
int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(this.getI18nManager().getString(this.getNamespace(), "migrationconfirm", "label", this.getLanguage()));
if (messageBox.open() == SWT.YES) {
viewer.getTable().getShell().setCursor(c);
IImExporter imp = ImExportFactory.getInstance().getImporter("OldDatFileCallImporter");
if (imp != null && (imp instanceof OldDatFileCallImporter)) {
((OldDatFileCallImporter) imp).setDatePattern(this.m_app.getApplication().getConfiguration().getProperty(CFG_OLD_DATE, "dd.MM.yyyy HH:mm:ss"));
((OldDatFileCallImporter) imp).setFilename(filename);
ICallList importedCalls = ((OldDatFileCallImporter) imp).doImport();
if (importedCalls != null) {
this.m_app.getController().addElements(importedCalls);
String msg = getI18nManager().getString(getNamespace(), "success", "description", getLanguage());
msg = StringUtils.replaceString(msg, "{%1}", Integer.toString(importedCalls.size()));
if (!suppressDialogs)
MessageDialog.openInformation(new Shell(DisplayManager.getDefaultDisplay()), getI18nManager().getString(getNamespace(), "success", "label", getLanguage()), msg);
m_app.updateViews(true);
}
}
viewer.getTable().getShell().setCursor(null);
c.dispose();
} else {
return;
}
}
} catch (Exception ex) {
this.m_logger.log(Level.SEVERE, ex.getMessage(), ex);
PropagationFactory.getInstance().fire(new Message(Message.ERROR, getNamespace(), "error", ex));
}
}
Aggregations