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();
}
}
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;
}
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();
}
}
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);
}
}
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();
}
}
Aggregations