Search in sources :

Example 26 with TagDefinition

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

the class TaggerContextMenu method initListeners.

private void initListeners() {
    tagChangedListener = new PropertyChangeListener() {

        @SuppressWarnings("unchecked")
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            Object newValue = evt.getNewValue();
            Object oldValue = evt.getOldValue();
            if (oldValue == null) {
                // created
                Pair<TagsetDefinition, TagDefinition> value = (Pair<TagsetDefinition, TagDefinition>) newValue;
                TagsetDefinition tagset = value.getFirst();
                TagDefinition tag = value.getSecond();
                Object parent = tagset;
                if (!tag.getParentUuid().isEmpty()) {
                    parent = tagset.getTagDefinition(tag.getParentUuid());
                }
                MenuItem parentItem = entryToMenuItemMap.get(parent);
                if (parentItem != null) {
                    addToMenuItem(parentItem, tagset, tag);
                }
            } else if (newValue == null) {
                // removed
                Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
                TagDefinition deletedTag = deleted.getSecond();
                MenuItem menuItem = entryToMenuItemMap.get(deletedTag);
                if (menuItem != null) {
                    contextMenu.removeItem(menuItem);
                }
            } else {
                // update
                TagDefinition tag = (TagDefinition) newValue;
                TagsetDefinition tagset = (TagsetDefinition) oldValue;
                MenuItem menuItem = entryToMenuItemMap.get(tag);
                if (menuItem != null) {
                    menuItem.setText(createTagMenuItemCaption(tag));
                }
            }
        }
    };
    tagManager.addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) TagDefinition(de.catma.tag.TagDefinition) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) MenuItem(com.vaadin.ui.MenuBar.MenuItem) Pair(de.catma.util.Pair)

Example 27 with TagDefinition

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

the class TaggerContextMenu method addToMenuItem.

private void addToMenuItem(MenuItem parentMenuItem, TagsetDefinition tagset, TagDefinition tag) {
    MenuItem tagMenuItem = parentMenuItem.addItem(createTagMenuItemCaption(tag), new TagDefinitionCommand(tag, tagSelectionListener));
    tagMenuItem.setStyleName("tagger-contextmenu-menuitem");
    entryToMenuItemMap.put(tag, tagMenuItem);
    for (TagDefinition childTag : tagset.getDirectChildren(tag)) {
        addToMenuItem(tagMenuItem, tagset, childTag);
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) MenuItem(com.vaadin.ui.MenuBar.MenuItem)

Example 28 with TagDefinition

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

the class AnnotationDetailsPanel method addAnnotation.

public void addAnnotation(Annotation annotation) throws IOException {
    Optional<AnnotationDataItem> optionalItem = findAnnotationDataItem(annotation.getTagInstance().getUuid());
    if (optionalItem.isPresent() && isAttached()) {
        annotationDetailsTree.collapse(annotationDetailData.getRootItems());
        annotationDetailsTree.select(optionalItem.get());
        annotationDetailsTree.expand(optionalItem.get());
        int itemIdx = annotationDetailData.getRootItems().indexOf(optionalItem.get());
        if (itemIdx >= 0) {
            annotationDetailsTree.scrollTo(itemIdx, ScrollDestination.START);
        }
    } else {
        AnnotationDataItem annotationDataItem = new AnnotationDataItem(annotation, project.getTagManager().getTagLibrary().getTagsetDefinition(annotation.getTagInstance().getTagsetId()), kwicProvider, project.hasPermission(project.getRoleForCollection(annotation.getUserMarkupCollection().getId()), RBACPermission.COLLECTION_WRITE), () -> isCurrentEditedCollection.apply(annotation.getUserMarkupCollection().getUuid()));
        annotationDetailsTree.collapse(annotationDetailData.getRootItems());
        annotationDetailData.addItem(null, annotationDataItem);
        String tagId = annotation.getTagInstance().getTagDefinitionId();
        for (Property property : annotation.getTagInstance().getUserDefinedProperties()) {
            TagDefinition tag = project.getTagManager().getTagLibrary().getTagDefinition(tagId);
            if (tag != null) {
                // may be deleted already
                PropertyDefinition propertyDef = tag.getPropertyDefinitionByUuid(property.getPropertyDefinitionId());
                if (propertyDef != null) {
                    // may be deleted already
                    AnnotationPropertyDataItem propertyDataItem = new AnnotationPropertyDataItem(property, () -> propertyDef.getName());
                    annotationDetailData.addItem(annotationDataItem, propertyDataItem);
                    for (String value : property.getPropertyValueList()) {
                        AnnotationPropertyValueDataItem valueDataItem = new AnnotationPropertyValueDataItem(value);
                        annotationDetailData.addItem(propertyDataItem, valueDataItem);
                    }
                }
            }
        }
        annotationDetailsProvider.refreshAll();
        if (isAttached()) {
            List<AnnotationTreeItem> items = new ArrayList<>();
            items.add(annotationDataItem);
            items.addAll(annotationDetailData.getChildren(annotationDataItem));
            annotationDetailsTree.expand(items);
            annotationDetailsTree.select(annotationDataItem);
            int itemIdx = annotationDetailData.getRootItems().size() - 1;
            if (itemIdx >= 0) {
                annotationDetailsTree.scrollTo(itemIdx, ScrollDestination.START);
            }
        }
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) ArrayList(java.util.ArrayList) Property(de.catma.tag.Property) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 29 with TagDefinition

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

the class AnnotationPanel method addTags.

private void addTags(TagsetDataItem tagsetItem, TagsetDefinition tagset) {
    for (TagDefinition tag : tagset) {
        if (tag.getParentUuid().isEmpty()) {
            TagDataItem tagItem = new TagDataItem(tag);
            tagsetData.addItem(tagsetItem, tagItem);
            addTagSubTree(tagset, tag, tagItem);
        }
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition)

Example 30 with TagDefinition

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

the class GitTagsetHandlerTest method createTagDefinitionWithParent.

@Test
public void createTagDefinitionWithParent() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a TagDefinition object that has a (fake) parent
        String tagDefinitionId = this.idGenerator.generate();
        String parentTagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, parentTagDefinitionId);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, parentTagDefinitionId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Aggregations

TagDefinition (de.catma.tag.TagDefinition)72 ArrayList (java.util.ArrayList)31 PropertyDefinition (de.catma.tag.PropertyDefinition)28 TagsetDefinition (de.catma.tag.TagsetDefinition)28 List (java.util.List)23 IDGenerator (de.catma.util.IDGenerator)22 Pair (de.catma.util.Pair)22 UI (com.vaadin.ui.UI)19 Project (de.catma.project.Project)19 ErrorHandler (de.catma.ui.module.main.ErrorHandler)19 PropertyChangeEvent (java.beans.PropertyChangeEvent)19 PropertyChangeListener (java.beans.PropertyChangeListener)19 IOException (java.io.IOException)19 Collection (java.util.Collection)19 Collectors (java.util.stream.Collectors)19 Notification (com.vaadin.ui.Notification)17 Type (com.vaadin.ui.Notification.Type)17 Set (java.util.Set)17 TagManagerEvent (de.catma.tag.TagManager.TagManagerEvent)16 SaveCancelListener (de.catma.ui.dialog.SaveCancelListener)16