Search in sources :

Example 16 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class AnnotateResourcePanel method handleCollectionChanged.

@Subscribe
public void handleCollectionChanged(CollectionChangeEvent collectionChangeEvent) {
    if (collectionChangeEvent.getChangeType().equals(ChangeType.CREATED)) {
        SourceDocument document = collectionChangeEvent.getDocument();
        AnnotationCollectionReference collectionReference = collectionChangeEvent.getCollectionReference();
        CollectionDataItem collectionDataItem = new CollectionDataItem(collectionReference, project.hasPermission(project.getRoleForCollection(collectionReference.getId()), RBACPermission.COLLECTION_WRITE));
        documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(document)).findAny().ifPresent(documentDataItem -> {
            documentData.addItem(documentDataItem, collectionDataItem);
            documentTree.getDataProvider().refreshAll();
        });
        if (isAttached()) {
            Notification.show("Info", String.format("Collection %1$s has been created!", collectionReference.toString()), Type.TRAY_NOTIFICATION);
        }
        if (getSelectedDocument() != null && getSelectedDocument().equals(document)) {
            collectionDataItem.fireSelectedEvent(this.resourceSelectionListener);
        }
    } else if (collectionChangeEvent.getChangeType().equals(ChangeType.DELETED)) {
        Optional<DocumentTreeItem> optionalDocResource = documentData.getRootItems().stream().filter(item -> ((DocumentDataItem) item).getDocument().equals(collectionChangeEvent.getDocument())).findAny();
        if (optionalDocResource.isPresent()) {
            documentData.getChildren(optionalDocResource.get()).stream().filter(item -> ((CollectionDataItem) item).getCollectionRef().equals(collectionChangeEvent.getCollectionReference())).findAny().ifPresent(item -> documentData.removeItem(item));
        }
    } else {
        documentTree.getDataProvider().refreshAll();
    }
}
Also used : SelectionEvent(com.vaadin.event.selection.SelectionEvent) UI(com.vaadin.ui.UI) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) VaadinIcons(com.vaadin.icons.VaadinIcons) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) Version(de.catma.tag.Version) Collection(java.util.Collection) Set(java.util.Set) TreeGrid(com.vaadin.ui.TreeGrid) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) List(java.util.List) Type(com.vaadin.ui.Notification.Type) RendererClickEvent(com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent) PropertyChangeListener(java.beans.PropertyChangeListener) Optional(java.util.Optional) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) SelectionMode(com.vaadin.ui.Grid.SelectionMode) RBACPermission(de.catma.rbac.RBACPermission) Column(com.vaadin.ui.Grid.Column) VerticalLayout(com.vaadin.ui.VerticalLayout) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) TreeGridFactory(de.catma.ui.component.TreeGridFactory) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) ButtonRenderer(com.vaadin.ui.renderers.ButtonRenderer) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ListDataProvider(com.vaadin.data.provider.ListDataProvider) TreeData(com.vaadin.data.TreeData) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ChangeType(de.catma.project.event.ChangeType) SerializablePredicate(com.vaadin.server.SerializablePredicate) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Collections(java.util.Collections) Grid(com.vaadin.ui.Grid) Optional(java.util.Optional) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Subscribe(com.google.common.eventbus.Subscribe)

Example 17 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class CollectionXMLExportStreamSource method getStream.

@Override
public InputStream getStream() {
    final UI ui = UI.getCurrent();
    final Project project = projectSupplier.get();
    final Corpus corpus = new Corpus();
    final Collection<SourceDocument> documents = documentSupplier.get();
    final Collection<AnnotationCollectionReference> collectionReferences = collectionReferenceSupplier.get();
    try {
        Set<String> documentIds = documents.stream().map(doc -> doc.getUuid()).collect(Collectors.toSet());
        collectionReferences.stream().forEach(ref -> documentIds.add(ref.getSourceDocumentId()));
        for (String documentId : documentIds) {
            corpus.addSourceDocument(project.getSourceDocument(documentId));
        }
        if (corpus.getSourceDocuments().size() == 0) {
            return null;
        }
        collectionReferences.forEach(ref -> corpus.addUserMarkupCollectionReference(ref));
        File tempFile = File.createTempFile(new IDGenerator().generate() + "_AnnotationCollection_Export", "tgz");
        try (FileOutputStream fos = new FileOutputStream(tempFile)) {
            new CorpusExporter(project, true).export(project.getName(), corpus, fos);
        }
        return new FileInputStream(tempFile);
    } catch (Exception e) {
        ((ErrorHandler) ui).showAndLogError("Error exporting Documents and Collections!", e);
    }
    return null;
}
Also used : CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) Collection(java.util.Collection) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) File(java.io.File) Corpus(de.catma.document.corpus.Corpus) ErrorHandler(de.catma.ui.module.main.ErrorHandler) IDGenerator(de.catma.util.IDGenerator) InputStream(java.io.InputStream) StreamSource(com.vaadin.server.StreamResource.StreamSource) SourceDocument(de.catma.document.source.SourceDocument) CorpusExporter(de.catma.document.corpus.CorpusExporter) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Corpus(de.catma.document.corpus.Corpus) FileInputStream(java.io.FileInputStream) Project(de.catma.project.Project) UI(com.vaadin.ui.UI) FileOutputStream(java.io.FileOutputStream) File(java.io.File) IDGenerator(de.catma.util.IDGenerator)

Example 18 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class ConflictedProjectView method showNextAnnotationConflict.

private void showNextAnnotationConflict() throws IOException {
    if (annotationConflictIterator.hasNext()) {
        SourceDocument document = documents.stream().filter(doc -> doc.getUuid().equals(currentCollectionConflict.getDocumentId())).findFirst().get();
        KwicProvider kwicProvider = new KwicProvider(document);
        AnnotationConflict annotationConflict = annotationConflictIterator.next();
        AnnotationConflictView annotationConflictView = new AnnotationConflictView(annotationConflict, currentCollectionConflict, tagManager, kwicProvider, () -> showNextConflict());
        mainPanel.removeAllComponents();
        mainPanel.addComponent(annotationConflictView);
    } else {
        showNextConflict();
    }
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) KwicProvider(de.catma.indexer.KwicProvider)

Example 19 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class AnnotationPanel method handelAddCollectionRequest.

private void handelAddCollectionRequest() {
    final SourceDocument document = currentDocumentProvider.get();
    if (document != null) {
        SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Add Annotation Collection", "Please enter the Collection name:", new SaveCancelListener<String>() {

            @Override
            public void savePressed(String result) {
                project.createUserMarkupCollection(result, document);
            }
        });
        collectionNameDlg.show();
    } else {
        Notification.show("Info", "Please select a Document first!", Type.HUMANIZED_MESSAGE);
    }
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog)

Example 20 with SourceDocument

use of de.catma.document.source.SourceDocument in project catma by forTEXT.

the class AnnotateResourcePanel method handleAddCollectionRequest.

private void handleAddCollectionRequest() {
    Set<DocumentTreeItem> selectedItems = documentTree.getSelectedItems();
    Set<SourceDocument> selectedDocuments = new HashSet<>();
    for (DocumentTreeItem resource : selectedItems) {
        DocumentTreeItem root = documentData.getParent(resource);
        if (root == null) {
            root = resource;
        }
        DocumentDataItem documentDataItem = (DocumentDataItem) root;
        selectedDocuments.add(documentDataItem.getDocument());
    }
    if (selectedDocuments.isEmpty()) {
        SourceDocument document = getSelectedDocument();
        if (document != null) {
            selectedDocuments.add(document);
        }
    }
    if (selectedDocuments.isEmpty()) {
        Notification.show("Info", "Please select at least one Document first!", Type.HUMANIZED_MESSAGE);
    } else {
        SingleTextInputDialog collectionNameDlg = new SingleTextInputDialog("Add Annotation Collection", "Please enter the Collection name:", new SaveCancelListener<String>() {

            @Override
            public void savePressed(String result) {
                for (SourceDocument document : selectedDocuments) {
                    project.createUserMarkupCollection(result, document);
                }
            }
        });
        collectionNameDlg.show();
    }
}
Also used : SourceDocument(de.catma.document.source.SourceDocument) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) HashSet(java.util.HashSet)

Aggregations

SourceDocument (de.catma.document.source.SourceDocument)48 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)23 Project (de.catma.project.Project)17 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)15 List (java.util.List)15 TagsetDefinition (de.catma.tag.TagsetDefinition)13 IOException (java.io.IOException)13 Collectors (java.util.stream.Collectors)13 UI (com.vaadin.ui.UI)12 IDGenerator (de.catma.util.IDGenerator)12 HashSet (java.util.HashSet)12 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 EventBus (com.google.common.eventbus.EventBus)10 Subscribe (com.google.common.eventbus.Subscribe)10 CollectionChangeEvent (de.catma.project.event.CollectionChangeEvent)10 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)9 ChangeType (de.catma.project.event.ChangeType)9 RBACPermission (de.catma.rbac.RBACPermission)9 Pair (de.catma.util.Pair)9 Indexer (de.catma.indexer.Indexer)8