Search in sources :

Example 21 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class TagSelectionPanel method initData.

private void initData() {
    try {
        tagsetData = new TreeData<TagsetTreeItem>();
        Collection<TagsetDefinition> tagsets = project.getTagManager().getTagLibrary().getTagsetDefinitions();
        for (TagsetDefinition tagset : tagsets) {
            TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
            tagsetData.addItem(null, tagsetItem);
            addTags(tagsetItem, tagset);
        }
        tagsetDataProvider = new TreeDataProvider<TagsetTreeItem>(tagsetData);
        tagsetGrid.setDataProvider(tagsetDataProvider);
        for (TagsetDefinition tagset : tagsets) {
            expandTagsetDefinition(tagset);
        }
    } catch (Exception e) {
        ((ErrorHandler) UI.getCurrent()).showAndLogError("Error loading data!", e);
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition)

Example 22 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class GraphWorktreeProject method initTagManagerListeners.

private void initTagManagerListeners() {
    tagsetDefinitionChangedListener = new PropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            try {
                if (evt.getOldValue() == null) {
                    // insert
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
                    addTagsetDefinition(tagsetDefinition);
                } else if (evt.getNewValue() == null) {
                    // delete
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getOldValue();
                    removeTagsetDefinition(tagsetDefinition);
                } else {
                    // update
                    final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
                    updateTagsetDefinition(tagsetDefinition);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetDefinitionChangedListener);
    tagDefinitionChangedListener = new PropertyChangeListener() {

        public void propertyChange(final PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            try {
                if (evt.getOldValue() == null) {
                    @SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getNewValue();
                    TagsetDefinition tagsetDefinition = args.getFirst();
                    TagDefinition tagDefinition = args.getSecond();
                    addTagDefinition(tagDefinition, tagsetDefinition);
                } else if (evt.getNewValue() == null) {
                    @SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getOldValue();
                    TagsetDefinition tagsetDefinition = args.getFirst();
                    TagDefinition tagDefinition = args.getSecond();
                    removeTagDefinition(tagDefinition, tagsetDefinition);
                } else {
                    TagDefinition tag = (TagDefinition) evt.getNewValue();
                    TagsetDefinition tagset = (TagsetDefinition) evt.getOldValue();
                    updateTagDefinition(tag, tagset);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagDefinitionChangedListener);
    userDefinedPropertyChangedListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (!tagManagerListenersEnabled) {
                return;
            }
            Object oldValue = evt.getOldValue();
            Object newValue = evt.getNewValue();
            try {
                if (oldValue == null) {
                    // insert
                    @SuppressWarnings("unchecked") Pair<PropertyDefinition, TagDefinition> newPair = (Pair<PropertyDefinition, TagDefinition>) newValue;
                    PropertyDefinition propertyDefinition = newPair.getFirst();
                    TagDefinition tagDefinition = newPair.getSecond();
                    addPropertyDefinition(propertyDefinition, tagDefinition);
                } else if (newValue == null) {
                    // delete
                    @SuppressWarnings("unchecked") Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldPair = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
                    PropertyDefinition propertyDefinition = oldPair.getFirst();
                    TagDefinition tagDefinition = oldPair.getSecond().getFirst();
                    TagsetDefinition tagsetDefinition = oldPair.getSecond().getSecond();
                    removePropertyDefinition(propertyDefinition, tagDefinition, tagsetDefinition);
                } else {
                    // update
                    PropertyDefinition propertyDefinition = (PropertyDefinition) evt.getNewValue();
                    TagDefinition tagDefinition = (TagDefinition) evt.getOldValue();
                    updatePropertyDefinition(propertyDefinition, tagDefinition);
                }
            } catch (Exception e) {
                propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, userDefinedPropertyChangedListener);
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) PropertyDefinition(de.catma.tag.PropertyDefinition) IOException(java.io.IOException) Pair(de.catma.util.Pair)

Example 23 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class GraphWorktreeProject method loadTagLibrary.

@Override
public List<TagsetDefinitionImportStatus> loadTagLibrary(InputStream inputStream) throws IOException {
    TeiSerializationHandlerFactory factory = new TeiSerializationHandlerFactory();
    factory.setTagManager(new TagManager(new TagLibrary()));
    TagLibrarySerializationHandler tagLibrarySerializationHandler = factory.getTagLibrarySerializationHandler();
    TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
    List<String> resourceIds = gitProjectHandler.getResourceIds();
    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
    for (TagsetDefinition tagset : importedLibrary) {
        boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
        boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
        tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
    }
    return tagsetDefinitionImportStatusList;
}
Also used : TagLibrary(de.catma.tag.TagLibrary) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) TeiSerializationHandlerFactory(de.catma.serialization.tei.TeiSerializationHandlerFactory) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) TagLibrarySerializationHandler(de.catma.serialization.TagLibrarySerializationHandler) ArrayList(java.util.ArrayList) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus)

Example 24 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class GraphWorktreeProject method loadAnnotationCollection.

public Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadAnnotationCollection(InputStream inputStream, SourceDocument document) throws IOException {
    TagManager tagManager = new TagManager(new TagLibrary());
    TeiTagLibrarySerializationHandler tagLibrarySerializationHandler = new TeiTagLibrarySerializationHandler(tagManager);
    TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
    List<String> resourceIds = gitProjectHandler.getResourceIds();
    List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
    for (TagsetDefinition tagset : importedLibrary) {
        boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
        boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
        tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
    }
    String collectionId = idGenerator.generate();
    TeiUserMarkupCollectionDeserializer deserializer = new TeiUserMarkupCollectionDeserializer(tagLibrarySerializationHandler.getTeiDocument(), tagManager.getTagLibrary(), collectionId);
    AnnotationCollection annotationCollection = new AnnotationCollection(collectionId, tagLibrarySerializationHandler.getTeiDocument().getContentInfoSet(), tagManager.getTagLibrary(), deserializer.getTagReferences(), document.getUuid(), document.getRevisionHash());
    return new Pair<>(annotationCollection, tagsetDefinitionImportStatusList);
}
Also used : TagLibrary(de.catma.tag.TagLibrary) AnnotationCollection(de.catma.document.annotation.AnnotationCollection) TeiTagLibrarySerializationHandler(de.catma.serialization.tei.TeiTagLibrarySerializationHandler) ArrayList(java.util.ArrayList) TeiUserMarkupCollectionDeserializer(de.catma.serialization.tei.TeiUserMarkupCollectionDeserializer) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) TagsetDefinitionImportStatus(de.catma.serialization.TagsetDefinitionImportStatus) Pair(de.catma.util.Pair)

Example 25 with TagsetDefinition

use of de.catma.tag.TagsetDefinition in project catma by forTEXT.

the class GraphWorktreeProject method synchronizeWithRemote.

@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
    if (hasUncommittedChanges()) {
        throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
    }
    for (TagsetDefinition tagset : getTagsets()) {
        gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
    }
    for (SourceDocument document : getSourceDocuments()) {
        gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
        for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
            gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
        }
    }
    gitProjectHandler.synchronizeWithRemote();
    if (gitProjectHandler.hasConflicts()) {
        gitProjectHandler.initAndUpdateSubmodules();
        openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
    } else {
        boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
        gitProjectHandler.initAndUpdateSubmodules();
        gitProjectHandler.removeStaleSubmoduleDirectories();
        gitProjectHandler.ensureDevBranches();
        rootRevisionHash = gitProjectHandler.getRootRevisionHash();
        ProgressListener progressListener = new ProgressListener() {

            @Override
            public void setProgress(String value, Object... args) {
                openProjectListener.progress(value, args);
            }
        };
        graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {

            @Override
            public void error(Throwable t) {
                openProjectListener.failure(t);
            }

            @Override
            public void done(TagManager result) {
                tagManager.load(result.getTagLibrary());
                openProjectListener.ready(GraphWorktreeProject.this);
            }
        }, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
    }
}
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) SourceDocument(de.catma.document.source.SourceDocument) AnnotationCollectionReference(de.catma.document.annotation.AnnotationCollectionReference) TagsetDefinition(de.catma.tag.TagsetDefinition) TagManager(de.catma.tag.TagManager) ProgressListener(de.catma.backgroundservice.ProgressListener)

Aggregations

TagsetDefinition (de.catma.tag.TagsetDefinition)61 IDGenerator (de.catma.util.IDGenerator)31 TagDefinition (de.catma.tag.TagDefinition)27 ArrayList (java.util.ArrayList)27 List (java.util.List)24 UI (com.vaadin.ui.UI)23 ErrorHandler (de.catma.ui.module.main.ErrorHandler)23 Pair (de.catma.util.Pair)23 IOException (java.io.IOException)23 Collection (java.util.Collection)23 Project (de.catma.project.Project)22 PropertyDefinition (de.catma.tag.PropertyDefinition)22 PropertyChangeEvent (java.beans.PropertyChangeEvent)22 PropertyChangeListener (java.beans.PropertyChangeListener)22 Version (de.catma.tag.Version)21 SingleTextInputDialog (de.catma.ui.dialog.SingleTextInputDialog)21 AnnotationCollection (de.catma.document.annotation.AnnotationCollection)20 Collectors (java.util.stream.Collectors)20 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)19 Set (java.util.Set)19