Search in sources :

Example 6 with CatmaApplication

use of de.catma.ui.CatmaApplication in project catma by forTEXT.

the class ProjectView method importCollection.

private void importCollection() {
    Set<SourceDocument> selectedDocuments = getSelectedDocuments();
    if (selectedDocuments.size() != 1) {
        Notification.show("Info", "Please select the corresponding Document first!", Type.HUMANIZED_MESSAGE);
    } else {
        final SourceDocument document = selectedDocuments.iterator().next();
        GenericUploadDialog uploadDialog = new GenericUploadDialog(String.format("Upload a Collection for %1$s:", document.toString()), new SaveCancelListener<byte[]>() {

            public void savePressed(byte[] result) {
                InputStream is = new ByteArrayInputStream(result);
                try {
                    if (BOMFilterInputStream.hasBOM(result)) {
                        is = new BOMFilterInputStream(is, // $NON-NLS-1$
                        Charset.forName("UTF-8"));
                    }
                    Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadResult = project.loadAnnotationCollection(is, document);
                    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = loadResult.getSecond();
                    final AnnotationCollection annotationCollection = loadResult.getFirst();
                    CollectionImportDialog tagsetImportDialog = new CollectionImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {

                        @Override
                        public void savePressed(List<TagsetDefinitionImportStatus> result) {
                            try {
                                project.importCollection(result, annotationCollection);
                            } catch (IOException e) {
                                ((CatmaApplication) UI.getCurrent()).showAndLogError("Error importing Tagsets", e);
                            }
                        }
                    });
                    tagsetImportDialog.show();
                } catch (IOException e) {
                    ((CatmaApplication) UI.getCurrent()).showAndLogError("Error loading external Tagsets", e);
                } finally {
                    CloseSafe.close(is);
                }
            }
        });
        uploadDialog.show();
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) GenericUploadDialog(de.catma.ui.dialog.GenericUploadDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) InputStream(java.io.InputStream) SourceDocument(de.catma.document.source.SourceDocument) IOException(java.io.IOException) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) CatmaApplication(de.catma.ui.CatmaApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ArrayList(java.util.ArrayList) List(java.util.List) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) Pair(de.catma.util.Pair)

Example 7 with CatmaApplication

use of de.catma.ui.CatmaApplication 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)

Example 8 with CatmaApplication

use of de.catma.ui.CatmaApplication in project catma by forTEXT.

the class UploadStep method initComponents.

private void initComponents() {
    HorizontalLayout uploadPanel = new HorizontalLayout();
    uploadPanel.setWidth("100%");
    uploadPanel.setSpacing(true);
    uploadPanel.setMargin(false);
    addComponent(uploadPanel);
    UploadStateWindow uploadStateWindow = new UploadStateWindow();
    uploadStateWindow.setModal(true);
    uploadStateWindow.setWindowPosition(WindowPosition.CENTER);
    upload = new MultiFileUpload(new UploadFinishedHandler() {

        @Override
        public void handleFile(InputStream stream, String fileName, String mimeType, long length, int filesLeftInQueue) {
            try {
                String tempDir = ((CatmaApplication) UI.getCurrent()).accquirePersonalTempFolder();
                final String fileId = idGenerator.generateDocumentId();
                File tempFile = new File(new File(tempDir), fileId);
                if (tempFile.exists()) {
                    tempFile.delete();
                }
                try (FileOutputStream fos = new FileOutputStream(tempFile)) {
                    IOUtils.copy(stream, fos);
                }
                try (FileInputStream fis = new FileInputStream(tempFile)) {
                    String type = tika.detect(fis, fileName);
                    UploadFile uploadFile = new UploadFile(fileId, tempFile.toURI(), fileName, type, length);
                    if (type.toLowerCase().trim().equals(FileType.ZIP.getMimeType())) {
                        handleZipFile(uploadFile);
                    } else {
                        fileList.add(uploadFile);
                        fileDataProvider.refreshAll();
                        stepChangeListener.stepChanged(UploadStep.this);
                    }
                }
            } catch (Exception e) {
                String errorMsg = e.getMessage();
                if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                    errorMsg = "";
                }
                Notification.show("Error", String.format("Error uploading %1$s, file will be skipped!\n%2$s", fileName, errorMsg), Type.ERROR_MESSAGE);
            }
        }
    }, uploadStateWindow) {

        @Override
        protected UploadStatePanel createStatePanel(UploadStateWindow uploadStateWindow) {
            return new MyUploadStatePanel(uploadStateWindow);
        }
    };
    uploadPanel.addComponent(upload);
    // 100 MB
    int maxFileSize = 104857600;
    upload.setMaxFileSize(maxFileSize);
    String errorMsgPattern = "File is too big (max = {0}): {2} ({1})";
    upload.setSizeErrorMsgPattern(errorMsgPattern);
    upload.setCaption("Upload files from your local computer");
    upload.setPanelCaption("Uploading file");
    upload.setMaxFileCount(300);
    upload.getSmartUpload().setUploadButtonCaptions("", "");
    upload.getSmartUpload().setUploadButtonIcon(VaadinIcons.UPLOAD);
    urlInputField = new TextField("or add a URL");
    urlInputField.setValueChangeMode(ValueChangeMode.BLUR);
    urlInputField.setWidth("100%");
    uploadPanel.addComponent(urlInputField);
    btFetch = new Button(VaadinIcons.CLOUD_DOWNLOAD);
    uploadPanel.addComponent(btFetch);
    uploadPanel.setComponentAlignment(btFetch, Alignment.BOTTOM_LEFT);
    progressBar = new ProgressBar();
    progressBar.setVisible(false);
    uploadPanel.addComponent(progressBar);
    fileGrid = new Grid<UploadFile>("or drag and drop some files to the list", fileDataProvider);
    fileGrid.setSizeFull();
    fileGrid.addColumn(UploadFile::getOriginalFilename).setCaption("File");
    fileGrid.addColumn(UploadFile::getMimetype).setCaption("Type");
    addComponent(fileGrid);
    setExpandRatio(fileGrid, 1.0f);
}
Also used : MultiFileUpload(com.wcs.wcslib.vaadin.widget.multifileupload.ui.MultiFileUpload) UploadStateWindow(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStateWindow) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UploadFinishedHandler(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadFinishedHandler) UploadStatePanel(com.wcs.wcslib.vaadin.widget.multifileupload.ui.UploadStatePanel) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) HorizontalLayout(com.vaadin.ui.HorizontalLayout) CatmaApplication(de.catma.ui.CatmaApplication) Button(com.vaadin.ui.Button) FileOutputStream(java.io.FileOutputStream) TextField(com.vaadin.ui.TextField) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) Html5File(com.vaadin.ui.Html5File) File(java.io.File) ProgressBar(com.vaadin.ui.ProgressBar)

Example 9 with CatmaApplication

use of de.catma.ui.CatmaApplication in project catma by forTEXT.

the class TaggerView method addCommentMessageListener.

private void addCommentMessageListener() {
    try {
        removeCommentMessageListener();
        if (this.sourceDocument != null) {
            HazelCastService hazelcastService = ((CatmaApplication) UI.getCurrent()).getHazelCastService();
            this.commentTopic = hazelcastService.getHazelcastClient().getTopic(HazelcastConfiguration.TopicName.COMMENT + "_" + this.sourceDocument.getUuid());
            this.commentMessageListenerRegId = this.commentTopic.addMessageListener(this.commentMessageListener);
        }
    } catch (Exception e) {
        logger.log(Level.WARNING, "error registering for comment messages", e);
    }
}
Also used : CatmaApplication(de.catma.ui.CatmaApplication) HazelCastService(de.catma.hazelcast.HazelCastService) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Aggregations

CatmaApplication (de.catma.ui.CatmaApplication)9 IOException (java.io.IOException)8 File (java.io.File)4 InputStream (java.io.InputStream)4 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Html5File (com.vaadin.ui.Html5File)3 UI (com.vaadin.ui.UI)3 BackgroundServiceProvider (de.catma.backgroundservice.BackgroundServiceProvider)3 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)3 BOMFilterInputStream (de.catma.document.source.contenthandler.BOMFilterInputStream)3 TagsetDefinitionImportStatus (de.catma.serialization.TagsetDefinitionImportStatus)3 GenericUploadDialog (de.catma.ui.dialog.GenericUploadDialog)3 SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)3 Button (com.vaadin.ui.Button)2