Search in sources :

Example 1 with GenericUploadDialog

use of de.catma.ui.dialog.GenericUploadDialog in project catma by forTEXT.

the class ProjectView method handleImportTagsetsRequest.

private void handleImportTagsetsRequest() {
    GenericUploadDialog uploadDialog = new GenericUploadDialog("Upload a Tag Library with one or more Tagsets:", 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"));
                }
                List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = project.loadTagLibrary(is);
                TagsetImportDialog tagsetImportDialog = new TagsetImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {

                    @Override
                    public void savePressed(List<TagsetDefinitionImportStatus> result) {
                        try {
                            project.importTagsets(result);
                        } 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 : CatmaApplication(de.catma.ui.CatmaApplication) GenericUploadDialog(de.catma.ui.dialog.GenericUploadDialog) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) InputStream(java.io.InputStream) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream)

Example 2 with GenericUploadDialog

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

Aggregations

BOMFilterInputStream (de.catma.document.source.contenthandler.BOMFilterInputStream)2 TagsetDefinitionImportStatus (de.catma.serialization.TagsetDefinitionImportStatus)2 CatmaApplication (de.catma.ui.CatmaApplication)2 GenericUploadDialog (de.catma.ui.dialog.GenericUploadDialog)2 SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)1 SourceDocument (de.catma.document.source.SourceDocument)1 Pair (de.catma.util.Pair)1