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