Search in sources :

Example 16 with PropertyDefinition

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

the class EditAnnotationPropertiesDialog method createComponents.

private void createComponents(Project project) {
    propertyTabSheet = new TabSheet();
    propertyTabSheet.setSizeFull();
    String tagId = annotation.getTagInstance().getTagDefinitionId();
    TagDefinition tag = project.getTagManager().getTagLibrary().getTagDefinition(tagId);
    for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
        Property property = annotation.getTagInstance().getUserDefinedPropetyByUuid(propertyDef.getUuid());
        if (property == null) {
            property = new Property(propertyDef.getUuid(), Collections.emptySet());
        }
        propertyTabSheet.addTab(new EditPropertyTab(property, propertyDef.getPossibleValueList()), propertyDef.getName());
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) TabSheet(com.vaadin.ui.TabSheet) PropertyDefinition(de.catma.tag.PropertyDefinition) Property(de.catma.tag.Property)

Example 17 with PropertyDefinition

use of de.catma.tag.PropertyDefinition 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 18 with PropertyDefinition

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

the class AnnotationPanel method handleSingleEditProperties.

private void handleSingleEditProperties(List<PropertyDefinition> editedPropertyDefs, TagDefinition tag) {
    TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tag);
    for (PropertyDefinition existingPropertyDef : new ArrayList<>(tag.getUserDefinedPropertyDefinitions())) {
        // handle deleted PropertyDefs
        if (!editedPropertyDefs.contains(existingPropertyDef)) {
            project.getTagManager().removeUserDefinedPropertyDefinition(existingPropertyDef, tag, tagset);
        } else // handle updated PropertyDefs
        {
            editedPropertyDefs.stream().filter(possiblyChangedPd -> possiblyChangedPd.getUuid().equals(existingPropertyDef.getUuid())).findFirst().ifPresent(editedPropertyDef -> {
                existingPropertyDef.setName(editedPropertyDef.getName());
                existingPropertyDef.setPossibleValueList(editedPropertyDef.getPossibleValueList());
            });
            project.getTagManager().updateUserDefinedPropertyDefinition(tag, existingPropertyDef);
        }
    }
    // handle created PropertyDefs
    for (PropertyDefinition pd : editedPropertyDefs) {
        if (tag.getPropertyDefinitionByUuid(pd.getUuid()) == null) {
            PropertyDefinition createdPropertyDefinition = new PropertyDefinition(pd);
            pd.setUuid(idGenerator.generate());
            project.getTagManager().addUserDefinedPropertyDefinition(tag, createdPropertyDefinition);
        }
    }
}
Also used : TagsetDefinition(de.catma.tag.TagsetDefinition) ArrayList(java.util.ArrayList) PropertyDefinition(de.catma.tag.PropertyDefinition)

Example 19 with PropertyDefinition

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

the class PropertySelectionStep method setTag.

public void setTag(TagDefinition tag) {
    propertyTabSheet.removeAllComponents();
    for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
        Property property = new Property(propertyDef.getUuid(), Collections.emptySet());
        EditPropertyTab editPropertyTab = new EditPropertyTab(property, propertyDef.getPossibleValueList());
        editPropertyTab.addSelectionListener(event -> handleSelection());
        propertyTabSheet.addTab(editPropertyTab, propertyDef.getName());
    }
}
Also used : EditPropertyTab(de.catma.ui.module.annotate.annotationpanel.EditPropertyTab) PropertyDefinition(de.catma.tag.PropertyDefinition) Property(de.catma.tag.Property)

Example 20 with PropertyDefinition

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

the class JsonLdWebAnnotationTest method toTagReferenceList.

@Test
public void toTagReferenceList() throws Exception {
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // TODO: test with a hierarchy of tag definitions
        HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
        JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
        this.projectsToDeleteOnTearDown.add((String) getJsonLdWebAnnotationResult.get("projectUuid"));
        assertNotNull(jsonLdWebAnnotation);
        List<TagReference> tagReferences = jsonLdWebAnnotation.toTagReferenceList((String) getJsonLdWebAnnotationResult.get("projectUuid"), (String) getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid"), jGitRepoManager, this.gitLabServerManager);
        assertEquals(2, tagReferences.size());
        for (TagReference tagReference : tagReferences) {
            TagDefinition tagDefinition = tagReference.getTagDefinition();
            TagInstance tagInstance = tagReference.getTagInstance();
            assertEquals(getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid"), tagDefinition.getTagsetDefinitionUuid());
            assertEquals(getJsonLdWebAnnotationResult.get("tagDefinitionUuid"), tagDefinition.getUuid());
            assertEquals("TAG_DEF", tagDefinition.getName());
            assertEquals("", tagDefinition.getParentUuid());
            PropertyDefinition[] systemPropertyDefinitions = tagDefinition.getSystemPropertyDefinitions().toArray(new PropertyDefinition[0]);
            assertEquals(1, systemPropertyDefinitions.length);
            assertEquals(getJsonLdWebAnnotationResult.get("systemPropertyDefinitionUuid"), systemPropertyDefinitions[0].getName());
            assertEquals("catma_displaycolor", systemPropertyDefinitions[0].getName());
            List<String> possibleSystemPropertyValues = systemPropertyDefinitions[0].getPossibleValueList();
            assertEquals(2, possibleSystemPropertyValues.size());
            assertArrayEquals(new String[] { "SYSPROP_VAL_1", "SYSPROP_VAL_2" }, possibleSystemPropertyValues.toArray(new String[0]));
            PropertyDefinition[] userPropertyDefinitions = tagDefinition.getUserDefinedPropertyDefinitions().toArray(new PropertyDefinition[0]);
            assertEquals(1, userPropertyDefinitions.length);
            assertEquals(getJsonLdWebAnnotationResult.get("userPropertyDefinitionUuid"), userPropertyDefinitions[0].getName());
            assertEquals("UPROP_DEF", userPropertyDefinitions[0].getName());
            List<String> possibleUserPropertyValues = userPropertyDefinitions[0].getPossibleValueList();
            assertEquals(2, possibleUserPropertyValues.size());
            assertArrayEquals(new String[] { "UPROP_VAL_1", "UPROP_VAL_2" }, possibleUserPropertyValues.toArray(new String[0]));
            assertEquals(getJsonLdWebAnnotationResult.get("tagInstanceUuid"), tagInstance.getUuid());
            Property[] systemProperties = tagInstance.getSystemProperties().toArray(new Property[0]);
            assertEquals(1, systemProperties.length);
            assertEquals(systemPropertyDefinitions[0], systemProperties[0].getPropertyDefinition());
            List<String> systemPropertyValues = systemProperties[0].getPropertyValueList();
            assertEquals(1, systemPropertyValues.size());
            assertEquals("SYSPROP_VAL_1", systemPropertyValues.get(0));
            Property[] userProperties = tagInstance.getUserDefinedProperties().toArray(new Property[0]);
            assertEquals(1, userProperties.length);
            assertEquals(userPropertyDefinitions[0], userProperties[0].getPropertyDefinition());
            List<String> userPropertyValues = userProperties[0].getPropertyValueList();
            assertEquals(1, userPropertyValues.size());
            assertEquals("UPROP_VAL_2", userPropertyValues.get(0));
        }
        assertEquals(new URI(String.format("http://catma.de/gitlab/%s/%s/%s", getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), GitProjectHandler.SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, getJsonLdWebAnnotationResult.get("sourceDocumentUuid"))), tagReferences.get(0).getTarget());
        assertEquals(new Range(12, 18), tagReferences.get(0).getRange());
        assertEquals(new URI(String.format("http://catma.de/gitlab/%s/%s/%s", getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), GitProjectHandler.SOURCE_DOCUMENT_SUBMODULES_DIRECTORY_NAME, getJsonLdWebAnnotationResult.get("sourceDocumentUuid"))), tagReferences.get(1).getTarget());
        assertEquals(new Range(41, 47), tagReferences.get(1).getRange());
    }
}
Also used : TagDefinition(de.catma.tag.TagDefinition) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) Range(de.catma.document.Range) PropertyDefinition(de.catma.tag.PropertyDefinition) URI(java.net.URI) TagInstance(de.catma.tag.TagInstance) TagReference(de.catma.document.standoffmarkup.usermarkup.TagReference) Property(de.catma.tag.Property) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test)

Aggregations

PropertyDefinition (de.catma.tag.PropertyDefinition)40 TagDefinition (de.catma.tag.TagDefinition)24 ArrayList (java.util.ArrayList)20 TagsetDefinition (de.catma.tag.TagsetDefinition)18 Pair (de.catma.util.Pair)14 IDGenerator (de.catma.util.IDGenerator)13 UI (com.vaadin.ui.UI)12 Property (de.catma.tag.Property)12 IOException (java.io.IOException)12 Collection (java.util.Collection)12 List (java.util.List)12 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)11 Multimap (com.google.common.collect.Multimap)11 TreeData (com.vaadin.data.TreeData)11 TreeDataProvider (com.vaadin.data.provider.TreeDataProvider)11 Project (de.catma.project.Project)11 ErrorHandler (de.catma.ui.module.main.ErrorHandler)11 PropertyChangeEvent (java.beans.PropertyChangeEvent)11 PropertyChangeListener (java.beans.PropertyChangeListener)11 Set (java.util.Set)11