Search in sources :

Example 21 with TagReference

use of de.catma.document.annotation.TagReference in project catma by forTEXT.

the class ProjectView method handleSaveDocumentWizardContext.

private void handleSaveDocumentWizardContext(final WizardContext result) {
    setEnabled(false);
    setProgressBarVisible(true);
    final UI ui = UI.getCurrent();
    BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
    BackgroundService backgroundService = backgroundServiceProvider.accuireBackgroundService();
    backgroundService.submit(new DefaultProgressCallable<Void>() {

        @SuppressWarnings("unchecked")
        @Override
        public Void call() throws Exception {
            IDGenerator idGenerator = new IDGenerator();
            boolean useApostropheAsSeparator = (Boolean) result.get(DocumentWizard.WizardContextKey.APOSTROPHE_AS_SEPARATOR);
            String collectionNamePattern = (String) result.get(DocumentWizard.WizardContextKey.COLLECTION_NAME_PATTERN);
            Collection<TagsetImport> tagsetImports = (Collection<TagsetImport>) result.get(DocumentWizard.WizardContextKey.TAGSET_IMPORT_LIST);
            Collection<UploadFile> uploadFiles = (Collection<UploadFile>) result.get(DocumentWizard.WizardContextKey.UPLOAD_FILE_LIST);
            if (tagsetImports == null) {
                tagsetImports = Collections.emptyList();
            }
            // Ignoring Tagsets
            tagsetImports.stream().filter(ti -> ti.getImportState().equals(TagsetImportState.WILL_BE_IGNORED)).forEach(tagsetImport -> {
                for (TagDefinition tag : tagsetImport.getExtractedTagset()) {
                    for (UploadFile uploadFile : uploadFiles) {
                        if (uploadFile.getIntrinsicMarkupCollection() != null) {
                            AnnotationCollection intrinsicMarkupCollection = uploadFile.getIntrinsicMarkupCollection();
                            intrinsicMarkupCollection.removeTagReferences(intrinsicMarkupCollection.getTagReferences(tag));
                        }
                    }
                }
            });
            getProgressListener().setProgress("Creating imported Tagsets");
            // Creating Tagsets
            tagsetImports.stream().filter(ti -> ti.getImportState().equals(TagsetImportState.WILL_BE_CREATED)).forEach(tagsetImport -> {
                getProgressListener().setProgress("Creating Tagset %1$s", tagsetImport.getTargetTagset().getName());
                ui.accessSynchronously(() -> {
                    if (project.getTagManager().getTagLibrary().getTagsetDefinition(tagsetImport.getTargetTagset().getUuid()) != null) {
                        // already imported, so it will be a merge
                        tagsetImport.setImportState(TagsetImportState.WILL_BE_MERGED);
                    } else {
                        TagsetDefinition extractedTagset = tagsetImport.getExtractedTagset();
                        try {
                            project.importTagsets(Collections.singletonList(new TagsetDefinitionImportStatus(extractedTagset, project.inProjectHistory(extractedTagset.getUuid()), project.getTagManager().getTagLibrary().getTagsetDefinition(extractedTagset.getUuid()) != null)));
                        } catch (Exception e) {
                            Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, String.format("Error importing tagset %1$s with ID %2$s", extractedTagset.getName(), extractedTagset.getUuid()), e);
                            String errorMsg = e.getMessage();
                            if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
                                errorMsg = "";
                            }
                            Notification.show("Error", String.format("Error importing tagset %1$s! " + "This tagset will be skipped!\n The underlying error message was:\n%2$s", extractedTagset.getName(), errorMsg), Type.ERROR_MESSAGE);
                        }
                    }
                    ui.push();
                });
            });
            // Merging Tagsets
            tagsetImports.stream().filter(ti -> ti.getImportState().equals(TagsetImportState.WILL_BE_MERGED)).forEach(tagsetImport -> {
                getProgressListener().setProgress("Merging Tagset %1$s", tagsetImport.getTargetTagset().getName());
                ui.accessSynchronously(() -> {
                    TagsetDefinition targetTagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tagsetImport.getTargetTagset().getUuid());
                    for (TagDefinition tag : tagsetImport.getExtractedTagset()) {
                        Optional<TagDefinition> optionalTag = targetTagset.getTagDefinitionsByName(tag.getName()).findFirst();
                        if (optionalTag.isPresent()) {
                            TagDefinition existingTag = optionalTag.get();
                            tag.getUserDefinedPropertyDefinitions().forEach(pd -> {
                                if (existingTag.getPropertyDefinition(pd.getName()) == null) {
                                    project.getTagManager().addUserDefinedPropertyDefinition(existingTag, new PropertyDefinition(pd));
                                }
                            });
                            for (UploadFile uploadFile : uploadFiles) {
                                if (uploadFile.getIntrinsicMarkupCollection() != null) {
                                    AnnotationCollection intrinsicMarkupCollection = uploadFile.getIntrinsicMarkupCollection();
                                    List<TagReference> tagReferences = intrinsicMarkupCollection.getTagReferences(tag);
                                    intrinsicMarkupCollection.removeTagReferences(tagReferences);
                                    Multimap<TagInstance, TagReference> referencesByInstance = ArrayListMultimap.create();
                                    tagReferences.forEach(tr -> referencesByInstance.put(tr.getTagInstance(), tr));
                                    for (TagInstance incomingTagInstance : referencesByInstance.keySet()) {
                                        TagInstance newTagInstance = new TagInstance(idGenerator.generate(), existingTag.getUuid(), incomingTagInstance.getAuthor(), incomingTagInstance.getTimestamp(), existingTag.getUserDefinedPropertyDefinitions(), targetTagset.getUuid());
                                        for (Property oldProp : incomingTagInstance.getUserDefinedProperties()) {
                                            String oldPropDefId = oldProp.getPropertyDefinitionId();
                                            PropertyDefinition oldPropDef = tag.getPropertyDefinitionByUuid(oldPropDefId);
                                            PropertyDefinition existingPropDef = existingTag.getPropertyDefinition(oldPropDef.getName());
                                            newTagInstance.addUserDefinedProperty(new Property(existingPropDef.getUuid(), oldProp.getPropertyValueList()));
                                        }
                                        ArrayList<TagReference> newReferences = new ArrayList<>();
                                        referencesByInstance.get(incomingTagInstance).forEach(tr -> {
                                            try {
                                                newReferences.add(new TagReference(newTagInstance, tr.getTarget().toString(), tr.getRange(), tr.getUserMarkupCollectionUuid()));
                                            } catch (URISyntaxException e) {
                                                e.printStackTrace();
                                            }
                                        });
                                        intrinsicMarkupCollection.addTagReferences(newReferences);
                                    }
                                }
                            }
                        } else {
                            tag.setTagsetDefinitionUuid(targetTagset.getUuid());
                            project.getTagManager().addTagDefinition(targetTagset, tag);
                        }
                    }
                    ui.push();
                });
            });
            // Importing docs and collections
            for (UploadFile uploadFile : uploadFiles) {
                getProgressListener().setProgress("Importing Document %1$s", uploadFile.getTitle());
                ui.accessSynchronously(() -> {
                    addUploadFile(uploadFile, useApostropheAsSeparator, collectionNamePattern);
                    ui.push();
                });
            }
            return null;
        }
    }, new ExecutionListener<Void>() {

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

        @Override
        public void error(Throwable t) {
            setProgressBarVisible(false);
            setEnabled(true);
            errorHandler.showAndLogError("Error adding Documents", t);
        }
    }, progressListener);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) HTMLNotification(de.catma.ui.component.HTMLNotification) Alignment(com.vaadin.ui.Alignment) IndexedProject(de.catma.indexer.IndexedProject) MembersChangedEvent(de.catma.ui.events.MembersChangedEvent) HeaderContextChangeEvent(de.catma.ui.events.HeaderContextChangeEvent) RouteToTagsEvent(de.catma.ui.events.routing.RouteToTagsEvent) TreeDataProvider(com.vaadin.data.provider.TreeDataProvider) TagsetImport(de.catma.ui.module.project.documentwizard.TagsetImport) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) CorpusImporter(de.catma.ui.module.project.corpusimport.CorpusImporter) CommitInfo(de.catma.project.CommitInfo) ExecutionListener(de.catma.backgroundservice.ExecutionListener) MenuBar(com.vaadin.ui.MenuBar) VerticalFlexLayout(de.catma.ui.layout.VerticalFlexLayout) Set(java.util.Set) RBACConstraint(de.catma.rbac.RBACConstraint) TagInstance(de.catma.tag.TagInstance) CorpusImportDocumentMetadata(de.catma.ui.module.project.corpusimport.CorpusImportDocumentMetadata) ItemClick(com.vaadin.ui.Grid.ItemClick) Stream(java.util.stream.Stream) Type(com.vaadin.ui.Notification.Type) PropertyChangeListener(java.beans.PropertyChangeListener) SingleTextInputDialog(de.catma.ui.dialog.SingleTextInputDialog) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) CanReloadAll(de.catma.ui.module.main.CanReloadAll) SelectionMode(com.vaadin.ui.Grid.SelectionMode) DocumentWizard(de.catma.ui.module.project.documentwizard.DocumentWizard) HugeCard(de.catma.ui.component.hugecard.HugeCard) ProjectChangedEvent(de.catma.ui.events.ProjectChangedEvent) DefaultProgressCallable(de.catma.backgroundservice.DefaultProgressCallable) TagManager(de.catma.tag.TagManager) com.vaadin.server(com.vaadin.server) LocalDateTime(java.time.LocalDateTime) WizardContext(de.catma.ui.dialog.wizard.WizardContext) ActionGridComponent(de.catma.ui.component.actiongrid.ActionGridComponent) ArrayList(java.util.ArrayList) Member(de.catma.user.Member) Pair(de.catma.util.Pair) TreeGridFactory(de.catma.ui.component.TreeGridFactory) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) Collator(java.text.Collator) ProgressListener(de.catma.backgroundservice.ProgressListener) XML2ContentHandler(de.catma.document.source.contenthandler.XML2ContentHandler) Property(de.catma.tag.Property) TreeData(com.vaadin.data.TreeData) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) ProjectReadyEvent(de.catma.project.event.ProjectReadyEvent) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) File(java.io.File) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) Button(com.vaadin.ui.Button) ChangeType(de.catma.project.event.ChangeType) CRC32(java.util.zip.CRC32) HtmlRenderer(com.vaadin.ui.renderers.HtmlRenderer) Grid(com.vaadin.ui.Grid) MenuItem(com.vaadin.ui.MenuBar.MenuItem) GenericUploadDialog(de.catma.ui.dialog.GenericUploadDialog) URISyntaxException(java.net.URISyntaxException) UI(com.vaadin.ui.UI) FlexWrap(de.catma.ui.layout.FlexLayout.FlexWrap) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) SearchFilterProvider(de.catma.ui.component.actiongrid.SearchFilterProvider) RouteToAnalyzeEvent(de.catma.ui.events.routing.RouteToAnalyzeEvent) TikaContentHandler(de.catma.document.source.contenthandler.TikaContentHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) HorizontalFlexLayout(de.catma.ui.layout.HorizontalFlexLayout) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) CatmaApplication(de.catma.ui.CatmaApplication) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) RouteToConflictedProjectEvent(de.catma.ui.events.routing.RouteToConflictedProjectEvent) ProgressBar(com.vaadin.ui.ProgressBar) IconButton(de.catma.ui.component.IconButton) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) Collection(java.util.Collection) TreeGrid(com.vaadin.ui.TreeGrid) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SourceDocumentInfo(de.catma.document.source.SourceDocumentInfo) ProjectReference(de.catma.project.ProjectReference) TagReference(de.catma.document.annotation.TagReference) List(java.util.List) CloseSafe(de.catma.util.CloseSafe) Corpus(de.catma.document.corpus.Corpus) TagDefinition(de.catma.tag.TagDefinition) RBACConstraintEnforcer(de.catma.rbac.RBACConstraintEnforcer) RouteToAnnotateEvent(de.catma.ui.events.routing.RouteToAnnotateEvent) Optional(java.util.Optional) FileType(de.catma.document.source.FileType) RBACPermission(de.catma.rbac.RBACPermission) CorpusImportDialog(de.catma.ui.module.project.corpusimport.CorpusImportDialog) ProjectManager(de.catma.project.ProjectManager) PropertyDefinition(de.catma.tag.PropertyDefinition) UploadFile(de.catma.ui.module.project.documentwizard.UploadFile) RBACRole(de.catma.rbac.RBACRole) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) User(de.catma.user.User) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) Charset(java.nio.charset.Charset) Notification(com.vaadin.ui.Notification) Label(com.vaadin.ui.Label) TagsetDefinition(de.catma.tag.TagsetDefinition) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) OpenProjectListener(de.catma.project.OpenProjectListener) ListDataProvider(com.vaadin.data.provider.ListDataProvider) FileOSType(de.catma.document.source.FileOSType) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) ConflictedProject(de.catma.project.conflict.ConflictedProject) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) ContextMenu(com.vaadin.contextmenu.ContextMenu) SourceContentHandler(de.catma.document.source.contenthandler.SourceContentHandler) TagsetImportState(de.catma.ui.module.project.documentwizard.TagsetImportState) BOMFilterInputStream(de.catma.document.source.contenthandler.BOMFilterInputStream) DateTimeFormatter(java.time.format.DateTimeFormatter) HierarchicalQuery(com.vaadin.data.provider.HierarchicalQuery) Parameter(de.catma.ui.Parameter) Comparator(java.util.Comparator) Collections(java.util.Collections) BackgroundService(de.catma.backgroundservice.BackgroundService) InputStream(java.io.InputStream) Component(com.vaadin.ui.Component) TagsetImport(de.catma.ui.module.project.documentwizard.TagsetImport) TagDefinition(de.catma.tag.TagDefinition) BackgroundService(de.catma.backgroundservice.BackgroundService) BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) UI(com.vaadin.ui.UI) ArrayList(java.util.ArrayList) List(java.util.List) Property(de.catma.tag.Property) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Optional(java.util.Optional) PropertyDefinition(de.catma.tag.PropertyDefinition) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TagsetDefinition(de.catma.tag.TagsetDefinition) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Multimap(com.google.common.collect.Multimap) UploadFile(de.catma.ui.module.project.documentwizard.UploadFile) TagInstance(de.catma.tag.TagInstance) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Collection(java.util.Collection) TagReference(de.catma.document.annotation.TagReference) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) IDGenerator(de.catma.util.IDGenerator)

Example 22 with TagReference

use of de.catma.document.annotation.TagReference in project catma by forTEXT.

the class TeiUserMarkupCollectionDeserializer method deserialize.

private void deserialize(String collectionId) {
    Nodes segmentNodes = teiDocument.getNodes(TeiElementName.seg, AttributeValue.seg_ana_catma_tag_ref.getStartsWith());
    for (int i = 0; i < segmentNodes.size(); i++) {
        TeiElement curSegment = (TeiElement) segmentNodes.get(i);
        AnaValueHandler anaValueHandler = new AnaValueHandler();
        List<String> tagInstanceIDs = anaValueHandler.makeTagInstanceIDListFrom(curSegment.getAttributeValue(Attribute.ana));
        Elements pointerElements = curSegment.getChildElements(TeiElementName.ptr);
        for (String tagInstanceID : tagInstanceIDs) {
            TagInstance tagInstance = createTagInstance(tagInstanceID);
            for (int j = 0; j < pointerElements.size(); j++) {
                TeiElement curPointer = (TeiElement) pointerElements.get(j);
                PtrValueHandler ptrValueHandler = new PtrValueHandler();
                TargetValues targetValues = ptrValueHandler.getTargetValuesFrom(curPointer.getAttributeValue(Attribute.ptr_target));
                try {
                    TagReference tagReference = new TagReference(tagInstance, targetValues.getURI(), targetValues.getRange(), collectionId);
                    tagReferences.add(tagReference);
                } catch (URISyntaxException ue) {
                    logger.log(Level.SEVERE, "error during deserialization", ue);
                }
            }
        }
    }
}
Also used : TargetValues(de.catma.serialization.tei.PtrValueHandler.TargetValues) TagInstance(de.catma.tag.TagInstance) TagReference(de.catma.document.annotation.TagReference) URISyntaxException(java.net.URISyntaxException) Elements(nu.xom.Elements) Nodes(nu.xom.Nodes)

Example 23 with TagReference

use of de.catma.document.annotation.TagReference in project catma by forTEXT.

the class GraphWorktreeProject method removePropertyDefinition.

private void removePropertyDefinition(PropertyDefinition propertyDefinition, TagDefinition tagDefinition, TagsetDefinition tagsetDefinition) throws Exception {
    // remove AnnotationProperties
    Multimap<String, TagReference> annotationIdsByCollectionId = graphProjectHandler.getTagReferencesByCollectionId(this.rootRevisionHash, propertyDefinition, tagDefinition);
    for (String collectionId : annotationIdsByCollectionId.keySet()) {
        // TODO: check permissions if commit is allowed, if that is not the case skip git update
        gitProjectHandler.addCollectionToStagedAndCommit(collectionId, String.format("Autocommitting changes before performing an update of Annotations " + "as part of a Property Definition deletion operation", propertyDefinition.getName()), false);
        Collection<TagReference> tagReferences = annotationIdsByCollectionId.get(collectionId);
        Set<TagInstance> tagInstances = tagReferences.stream().map(tagReference -> tagReference.getTagInstance()).collect(Collectors.toSet());
        tagInstances.forEach(tagInstance -> tagInstance.removeUserDefinedProperty(propertyDefinition.getUuid()));
        for (TagInstance tagInstance : tagInstances) {
            gitProjectHandler.addOrUpdate(collectionId, tagReferences.stream().filter(tagRef -> tagRef.getTagInstanceId().equals(tagInstance.getUuid())).collect(Collectors.toList()), tagManager.getTagLibrary());
        }
        String collectionRevisionHash = gitProjectHandler.addCollectionToStagedAndCommit(collectionId, String.format("Annotation Properties removed, caused by the removal of Tag Property %1$s ", propertyDefinition.getName()), false);
        graphProjectHandler.removeProperties(this.rootRevisionHash, collectionId, collectionRevisionHash, propertyDefinition.getUuid());
    }
    String tagsetRevision = gitProjectHandler.removePropertyDefinition(propertyDefinition, tagDefinition, tagsetDefinition);
    tagsetDefinition.setRevisionHash(tagsetRevision);
    String oldRootRevisionHash = this.rootRevisionHash;
    this.rootRevisionHash = gitProjectHandler.commitProject(String.format("Removed Property Definition %1$s with ID %2$s " + "from Tag %3$s with ID %4$s in Tagset %5$s with ID %6$s", propertyDefinition.getName(), propertyDefinition.getUuid(), tagDefinition.getName(), tagDefinition.getUuid(), tagsetDefinition.getName(), tagsetDefinition.getUuid()));
    graphProjectHandler.removePropertyDefinition(rootRevisionHash, propertyDefinition, tagDefinition, tagsetDefinition, oldRootRevisionHash);
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Reply(de.catma.document.comment.Reply) LoadingCache(com.google.common.cache.LoadingCache) Status(org.eclipse.jgit.api.Status) UI(com.vaadin.ui.UI) IndexedProject(de.catma.indexer.IndexedProject) TermExtractor(de.catma.indexer.TermExtractor) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInfoProvider(de.catma.repository.git.graph.FileInfoProvider) ErrorHandler(de.catma.ui.module.main.ErrorHandler) Locale(java.util.Locale) Map(java.util.Map) DocumentChangeEvent(de.catma.project.event.DocumentChangeEvent) URI(java.net.URI) Path(java.nio.file.Path) CommitInfo(de.catma.project.CommitInfo) CATMAPropertyKey(de.catma.properties.CATMAPropertyKey) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Collection(java.util.Collection) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ProjectReference(de.catma.project.ProjectReference) TagReference(de.catma.document.annotation.TagReference) CacheLoader(com.google.common.cache.CacheLoader) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) TPGraphProjectHandler(de.catma.repository.git.graph.tp.TPGraphProjectHandler) TagDefinition(de.catma.tag.TagDefinition) CacheBuilder(com.google.common.cache.CacheBuilder) ContentInfoSet(de.catma.document.source.ContentInfoSet) CollectionChangeEvent(de.catma.project.event.CollectionChangeEvent) RBACPermission(de.catma.rbac.RBACPermission) StatusPrinter(de.catma.repository.git.managers.StatusPrinter) PropertyDefinition(de.catma.tag.PropertyDefinition) TagManager(de.catma.tag.TagManager) CommentProvider(de.catma.repository.git.graph.CommentProvider) RBACRole(de.catma.rbac.RBACRole) MediaType(org.apache.tika.mime.MediaType) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) User(de.catma.user.User) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) CommentChangeEvent(de.catma.project.event.CommentChangeEvent) Comment(de.catma.document.comment.Comment) Charset(java.nio.charset.Charset) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) Member(de.catma.user.Member) StandardContentHandler(de.catma.document.source.contenthandler.StandardContentHandler) TagsetDefinition(de.catma.tag.TagsetDefinition) Pair(de.catma.util.Pair) IDGenerator(de.catma.util.IDGenerator) RBACSubject(de.catma.rbac.RBACSubject) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) OpenProjectListener(de.catma.project.OpenProjectListener) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) RemovalNotification(com.google.common.cache.RemovalNotification) ProgressListener(de.catma.backgroundservice.ProgressListener) Property(de.catma.tag.Property) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TermInfo(de.catma.indexer.TermInfo) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) File(java.io.File) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) Indexer(de.catma.indexer.Indexer) ChangeType(de.catma.project.event.ChangeType) GraphProjectHandler(de.catma.repository.git.graph.GraphProjectHandler) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) Paths(java.nio.file.Paths) PropertyChangeSupport(java.beans.PropertyChangeSupport) RemovalListener(com.google.common.cache.RemovalListener) BackgroundService(de.catma.backgroundservice.BackgroundService) InputStream(java.io.InputStream) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) TagInstance(de.catma.tag.TagInstance) TagReference(de.catma.document.annotation.TagReference)

Example 24 with TagReference

use of de.catma.document.annotation.TagReference in project catma by forTEXT.

the class TaggerView method initListeners.

private void initListeners() {
    this.tagReferencesChangedListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue() != null) {
                @SuppressWarnings("unchecked") Pair<AnnotationCollection, List<TagReference>> changeValue = (Pair<AnnotationCollection, List<TagReference>>) evt.getNewValue();
                List<TagReference> tagReferences = changeValue.getSecond();
                List<TagReference> relevantTagReferences = new ArrayList<TagReference>();
                for (TagReference tr : tagReferences) {
                    if (isRelevantTagReference(tr, userMarkupCollectionManager.getUserMarkupCollections())) {
                        relevantTagReferences.add(tr);
                    }
                }
                tagger.setVisible(relevantTagReferences, true);
                Set<String> tagInstanceUuids = new HashSet<String>();
                for (TagReference tr : relevantTagReferences) {
                    tagInstanceUuids.add(tr.getTagInstance().getUuid());
                }
                tagInstanceUuids.forEach(annotationId -> tagger.updateAnnotation(annotationId));
            } else if (evt.getOldValue() != null) {
                @SuppressWarnings("unchecked") Pair<String, Collection<String>> changeValue = (Pair<String, Collection<String>>) evt.getOldValue();
                String collectionId = changeValue.getFirst();
                Collection<String> annotationIds = changeValue.getSecond();
                if (userMarkupCollectionManager.contains(collectionId)) {
                    userMarkupCollectionManager.removeTagInstance(annotationIds, false);
                }
                tagger.removeTagInstances(annotationIds);
                annotationPanel.removeAnnotations(annotationIds);
            }
        }
    };
    project.addPropertyChangeListener(RepositoryChangeEvent.tagReferencesChanged, tagReferencesChangedListener);
    annotationPropertiesChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            TagInstance tagInstance = (TagInstance) evt.getOldValue();
            tagger.updateAnnotation(tagInstance.getUuid());
        }
    };
    project.addPropertyChangeListener(RepositoryChangeEvent.propertyValueChanged, annotationPropertiesChangedListener);
    tagChangedListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
            // created
            // noop
            } else if (newValue == null) {
                // removed
                @SuppressWarnings("unchecked") Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                for (AnnotationCollectionReference ref : userMarkupCollectionManager.getCollections(deleted.getSecond())) {
                    setAnnotationCollectionSelected(ref, false);
                    setAnnotationCollectionSelected(ref, true);
                }
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
                    List<TagReference> relevantTagReferences = collection.getTagReferences(tag);
                    tagger.setVisible(relevantTagReferences, false);
                    tagger.setVisible(relevantTagReferences, true);
                }
            }
        }
    };
    project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
Also used : BackgroundServiceProvider(de.catma.backgroundservice.BackgroundServiceProvider) ZonedDateTime(java.time.ZonedDateTime) VerticalSplitPanel(com.vaadin.ui.VerticalSplitPanel) EditAnnotationPropertiesDialog(de.catma.ui.module.annotate.annotationpanel.EditAnnotationPropertiesDialog) IndexedProject(de.catma.indexer.IndexedProject) ClientCommentReply(de.catma.ui.client.ui.tagger.shared.ClientCommentReply) KwicProvider(de.catma.indexer.KwicProvider) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) ExpansionListener(de.catma.ui.module.analyze.visualization.ExpansionListener) ExecutionListener(de.catma.backgroundservice.ExecutionListener) Slider(com.vaadin.ui.Slider) Set(java.util.Set) TagInstance(de.catma.tag.TagInstance) ClosableTab(de.catma.ui.component.tabbedview.ClosableTab) Pager(de.catma.ui.module.annotate.pager.Pager) Type(com.vaadin.ui.Notification.Type) PropertyChangeListener(java.beans.PropertyChangeListener) SliderMode(org.vaadin.sliderpanel.client.SliderMode) DefaultProgressCallable(de.catma.backgroundservice.DefaultProgressCallable) Range(de.catma.document.Range) TagManager(de.catma.tag.TagManager) VerticalLayout(com.vaadin.ui.VerticalLayout) SplitterPositionChangedListener(de.catma.ui.module.annotate.TaggerSplitPanel.SplitterPositionChangedListener) CommentMessage(de.catma.ui.events.CommentMessage) ArrayList(java.util.ArrayList) Pair(de.catma.util.Pair) SaveCancelListener(de.catma.ui.dialog.SaveCancelListener) ResourceSelectionListener(de.catma.ui.module.annotate.resourcepanel.ResourceSelectionListener) Property(de.catma.tag.Property) QueryResultRow(de.catma.queryengine.result.QueryResultRow) IOException(java.io.IOException) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) ValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener) Annotation(de.catma.document.annotation.Annotation) TagManagerEvent(de.catma.tag.TagManager.TagManagerEvent) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) Button(com.vaadin.ui.Button) ChangeType(de.catma.project.event.ChangeType) TextRange(de.catma.ui.client.ui.tagger.shared.TextRange) HorizontalLayout(com.vaadin.ui.HorizontalLayout) AnnotateResourcePanel(de.catma.ui.module.annotate.resourcepanel.AnnotateResourcePanel) SplitterPositionChangedEvent(de.catma.ui.module.annotate.TaggerSplitPanel.SplitterPositionChangedEvent) Reply(de.catma.document.comment.Reply) ClientComment(de.catma.ui.client.ui.tagger.shared.ClientComment) URISyntaxException(java.net.URISyntaxException) UI(com.vaadin.ui.UI) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog) RouteToAnalyzeEvent(de.catma.ui.events.routing.RouteToAnalyzeEvent) TaggerContextMenu(de.catma.ui.module.annotate.contextmenu.TaggerContextMenu) ErrorHandler(de.catma.ui.module.main.ErrorHandler) CatmaApplication(de.catma.ui.CatmaApplication) SliderPanel(org.vaadin.sliderpanel.SliderPanel) VaadinIcons(com.vaadin.icons.VaadinIcons) Version(de.catma.tag.Version) IconButton(de.catma.ui.component.IconButton) Collection(java.util.Collection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) MarginInfo(com.vaadin.shared.ui.MarginInfo) TagReference(de.catma.document.annotation.TagReference) List(java.util.List) TaggerListener(de.catma.ui.module.annotate.Tagger.TaggerListener) Corpus(de.catma.document.corpus.Corpus) TagDefinition(de.catma.tag.TagDefinition) Optional(java.util.Optional) HazelCastService(de.catma.hazelcast.HazelCastService) SliderPanelBuilder(org.vaadin.sliderpanel.SliderPanelBuilder) ValueChangeEvent(com.vaadin.data.HasValue.ValueChangeEvent) KwicPanel(de.catma.ui.module.analyze.visualization.kwic.KwicPanel) ClickListener(com.vaadin.ui.Button.ClickListener) PagerComponent(de.catma.ui.module.annotate.pager.PagerComponent) AnnotationPanel(de.catma.ui.module.annotate.annotationpanel.AnnotationPanel) AnnotationCollectionManager(de.catma.document.annotation.AnnotationCollectionManager) PageChangeListener(de.catma.ui.module.annotate.pager.PagerComponent.PageChangeListener) UIMessageListener(de.catma.ui.UIMessageListener) User(de.catma.user.User) Level(java.util.logging.Level) HashSet(java.util.HashSet) EventBus(com.google.common.eventbus.EventBus) CommentChangeEvent(de.catma.project.event.CommentChangeEvent) Comment(de.catma.document.comment.Comment) Notification(com.vaadin.ui.Notification) Page(de.catma.ui.module.annotate.pager.Page) HazelcastConfiguration(de.catma.hazelcast.HazelcastConfiguration) TagsetDefinition(de.catma.tag.TagsetDefinition) IDGenerator(de.catma.util.IDGenerator) Subscribe(com.google.common.eventbus.Subscribe) TagLibrary(de.catma.tag.TagLibrary) PropertyChangeEvent(java.beans.PropertyChangeEvent) ClickEvent(com.vaadin.ui.Button.ClickEvent) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) Project(de.catma.project.Project) RepositoryChangeEvent(de.catma.project.Project.RepositoryChangeEvent) ReplyChangeEvent(de.catma.project.event.ReplyChangeEvent) TabCaptionChangeListener(de.catma.ui.component.tabbedview.TabCaptionChangeListener) DateTimeFormatter(java.time.format.DateTimeFormatter) ITopic(com.hazelcast.core.ITopic) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Set(java.util.Set) HashSet(java.util.HashSet) PropertyChangeListener(java.beans.PropertyChangeListener) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition) TagInstance(de.catma.tag.TagInstance) ClientTagInstance(de.catma.ui.client.ui.tagger.shared.ClientTagInstance) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) Collection(java.util.Collection) TagReference(de.catma.document.annotation.TagReference) ArrayList(java.util.ArrayList) List(java.util.List) Pair(de.catma.util.Pair)

Example 25 with TagReference

use of de.catma.document.annotation.TagReference in project catma by forTEXT.

the class TaggerView method setAnnotationCollectionSelected.

private void setAnnotationCollectionSelected(AnnotationCollectionReference collectionReference, boolean selected) {
    try {
        AnnotationCollection collection = project.getUserMarkupCollection(collectionReference);
        if (selected) {
            userMarkupCollectionManager.add(collection);
            annotationPanel.addCollection(collection);
            List<TagReference> visibleRefs = annotationPanel.getVisibleTagReferences(collection.getTagReferences());
            if (!visibleRefs.isEmpty()) {
                tagger.setVisible(visibleRefs, true);
            }
        } else {
            userMarkupCollectionManager.remove(collectionReference.getId());
            annotationPanel.removeCollection(collectionReference.getId());
            tagger.setVisible(collection.getTagReferences(), false);
        }
    } catch (Exception e) {
        errorHandler.showAndLogError("Error handling Annotation Collection!", e);
    }
}
Also used : AnnotationCollection(de.catma.document.annotation.AnnotationCollection) TagReference(de.catma.document.annotation.TagReference) ValueOutOfBoundsException(com.vaadin.ui.Slider.ValueOutOfBoundsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Aggregations

TagReference (de.catma.document.annotation.TagReference)25 ArrayList (java.util.ArrayList)16 TagInstance (de.catma.tag.TagInstance)15 Property (de.catma.tag.Property)12 TagDefinition (de.catma.tag.TagDefinition)12 List (java.util.List)12 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)11 TagsetDefinition (de.catma.tag.TagsetDefinition)10 AnnotationCollectionReference (de.catma.document.annotation.AnnotationCollectionReference)8 SourceDocument (de.catma.document.source.SourceDocument)8 Logger (java.util.logging.Logger)8 PropertyDefinition (de.catma.tag.PropertyDefinition)7 TagLibrary (de.catma.tag.TagLibrary)7 IOException (java.io.IOException)7 Level (java.util.logging.Level)7 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6 Range (de.catma.document.Range)6 User (de.catma.user.User)6 File (java.io.File)6 Multimap (com.google.common.collect.Multimap)5