Search in sources :

Example 1 with CorpusImporter

use of de.catma.ui.module.project.corpusimport.CorpusImporter in project catma by forTEXT.

the class ProjectView method importCorpus.

private void importCorpus(final File corpusFile, final List<CorpusImportDocumentMetadata> documentMetadataList) {
    setEnabled(false);
    setProgressBarVisible(true);
    try {
        final String tempDir = ((CatmaApplication) UI.getCurrent()).accquirePersonalTempFolder();
        final UI ui = UI.getCurrent();
        BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
        BackgroundService backgroundService = backgroundServiceProvider.accuireBackgroundService();
        backgroundService.submit(new DefaultProgressCallable<Void>() {

            @Override
            public Void call() throws Exception {
                return new CorpusImporter().importCorpus(getProgressListener(), corpusFile, documentMetadataList, tempDir, ui, project);
            }
        }, new ExecutionListener<Void>() {

            @Override
            public void done(Void result) {
                setProgressBarVisible(false);
                setEnabled(true);
            }

            @Override
            public void error(Throwable t) {
                setProgressBarVisible(false);
                setEnabled(true);
                Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, "Error importing the CATMA 5 Corpus!", t);
                String errorMsg = t.getMessage();
                if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                    errorMsg = "";
                }
                Notification.show("Error", String.format("Error importing the CATMA 5 Corpus! " + "This import will be aborted!\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
            }
        }, progressListener);
    } catch (Exception e) {
        setProgressBarVisible(false);
        setEnabled(true);
        Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, "Error importing the CATMA 5 Corpus!", e);
        String errorMsg = e.getMessage();
        if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
            errorMsg = "";
        }
        Notification.show("Error", String.format("Error importing the CATMA 5 Corpus! " + "This import will be aborted!\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
    }
}
Also used : BackgroundService(de.catma.backgroundservice.BackgroundService) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CatmaApplication(de.catma.ui.CatmaApplication) UI(com.vaadin.ui.UI) CorpusImporter(de.catma.ui.module.project.corpusimport.CorpusImporter)

Aggregations

UI (com.vaadin.ui.UI)1 BackgroundService (de.catma.backgroundservice.BackgroundService)1 BackgroundServiceProvider (de.catma.backgroundservice.BackgroundServiceProvider)1 CatmaApplication (de.catma.ui.CatmaApplication)1 CorpusImporter (de.catma.ui.module.project.corpusimport.CorpusImporter)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1