use of de.catma.tag.Property in project catma by forTEXT.
the class EditAnnotationPropertiesDialog method getResult.
@Override
protected List<Property> getResult() {
List<Property> result = new ArrayList<>();
Iterator<Component> componentIterator = propertyTabSheet.iterator();
while (componentIterator.hasNext()) {
EditPropertyTab tab = (EditPropertyTab) componentIterator.next();
if (tab.isChanged()) {
Property property = tab.getProperty();
property.setPropertyValueList(tab.getPropertyValues());
result.add(property);
}
}
return result;
}
use of de.catma.tag.Property 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.Property in project catma by forTEXT.
the class GitMarkupCollectionHandler method getCollection.
public AnnotationCollection getCollection(String projectId, String collectionId, TagLibrary tagLibrary, ProgressListener progressListener, boolean hasWritePermission, Function<String, Boolean> hasTagsetIdReadPermissionGetter) throws Exception {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
localGitRepoManager.open(projectId, projectRootRepositoryName);
String markupCollectionSubmoduleRelDir = GitProjectHandler.ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME + "/" + collectionId;
File markupCollectionSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), markupCollectionSubmoduleRelDir);
String markupCollectionRevisionHash = localGitRepoManager.getSubmoduleHeadRevisionHash(markupCollectionSubmoduleRelDir);
// can't call open on an attached instance
localGitRepoManager.detach();
File markupCollectionHeaderFile = new File(markupCollectionSubmoduleAbsPath, HEADER_FILE_NAME);
String serializedMarkupCollectionHeaderFile = FileUtils.readFileToString(markupCollectionHeaderFile, StandardCharsets.UTF_8);
GitMarkupCollectionHeader markupCollectionHeader = new SerializationHelper<GitMarkupCollectionHeader>().deserialize(serializedMarkupCollectionHeaderFile, GitMarkupCollectionHeader.class);
ContentInfoSet contentInfoSet = new ContentInfoSet(markupCollectionHeader.getAuthor(), markupCollectionHeader.getDescription(), markupCollectionHeader.getPublisher(), markupCollectionHeader.getName());
AtomicInteger counter = new AtomicInteger();
ArrayList<TagReference> tagReferences = this.openTagReferences(projectId, collectionId, contentInfoSet.getTitle(), markupCollectionSubmoduleAbsPath, progressListener, counter);
// handle orphan Annotations
ArrayListMultimap<TagInstance, TagReference> tagInstances = ArrayListMultimap.create();
Set<String> orphanAnnotationIds = new HashSet<>();
Iterator<TagReference> tagReferenceIterator = tagReferences.iterator();
while (tagReferenceIterator.hasNext()) {
TagReference tagReference = tagReferenceIterator.next();
if (!orphanAnnotationIds.contains(tagReference.getTagInstanceId())) {
String tagsetId = tagReference.getTagInstance().getTagsetId();
boolean readPermission = hasTagsetIdReadPermissionGetter.apply(tagsetId);
TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagsetId);
String tagId = tagReference.getTagDefinitionId();
if (readPermission && (tagset == null || tagset.isDeleted(tagId))) {
// Tag/Tagset has been deleted, we remove the stale Annotation as well
orphanAnnotationIds.add(tagReference.getTagInstanceId());
tagReferenceIterator.remove();
} else {
// other orphan Annotations get ignored upon indexing
// until the corresponding Tag or its "deletion" info come along
tagInstances.put(tagReference.getTagInstance(), tagReference);
}
}
}
if (hasWritePermission) {
removeTagInstances(projectId, collectionId, orphanAnnotationIds);
}
// handle orphan Properties
if (hasWritePermission) {
for (TagInstance tagInstance : tagInstances.keySet()) {
TagsetDefinition tagset = tagLibrary.getTagsetDefinition(tagInstance.getTagsetId());
if (tagset != null) {
Collection<Property> properties = tagInstance.getUserDefinedProperties();
for (Property property : new HashSet<>(properties)) {
// deleted property?
if (tagset.isDeleted(property.getPropertyDefinitionId())) {
// yes, we remove the stale property
tagInstance.removeUserDefinedProperty(property.getPropertyDefinitionId());
// and save the change
JsonLdWebAnnotation annotation = new JsonLdWebAnnotation(CATMAPropertyKey.GitLabServerUrl.getValue(), projectId, tagInstances.get(tagInstance), tagLibrary);
createTagInstance(projectId, collectionId, annotation);
}
}
}
}
}
AnnotationCollection userMarkupCollection = new AnnotationCollection(collectionId, contentInfoSet, tagLibrary, tagReferences, markupCollectionHeader.getSourceDocumentId(), markupCollectionHeader.getSourceDocumentVersion());
userMarkupCollection.setRevisionHash(markupCollectionRevisionHash);
return userMarkupCollection;
}
}
use of de.catma.tag.Property in project catma by forTEXT.
the class TaggerView method tagInstanceAdded.
public void tagInstanceAdded(ClientTagInstance clientTagInstance) {
AnnotationCollection collection = annotationPanel.getSelectedEditableCollection();
if (collection == null) {
// shouldn't happen, but just in case
Notification.show("Info", "Please make sure you have an editable Collection available " + "and select this Collection as 'currently being edited'! " + "Your Annotation hasn't been saved!", Type.ERROR_MESSAGE);
} else {
TagLibrary tagLibrary = collection.getTagLibrary();
TagDefinition tagDef = tagLibrary.getTagDefinition(clientTagInstance.getTagDefinitionID());
TagInstance ti = new TagInstance(clientTagInstance.getInstanceID(), tagDef.getUuid(), project.getUser().getIdentifier(), ZonedDateTime.now().format(DateTimeFormatter.ofPattern(Version.DATETIMEPATTERN)), tagDef.getUserDefinedPropertyDefinitions(), tagDef.getTagsetDefinitionUuid());
List<TagReference> tagReferences = new ArrayList<TagReference>();
try {
String userMarkupCollectionUuid = collection.getId();
for (TextRange tr : clientTagInstance.getRanges()) {
Range r = new Range(tr.getStartPos(), tr.getEndPos());
TagReference ref = new TagReference(ti, sourceDocument.getUuid(), r, userMarkupCollectionUuid);
tagReferences.add(ref);
}
final Annotation annotation = new Annotation(ti, tagReferences, collection, tagLibrary.getTagPath(tagDef));
if (!tagDef.getUserDefinedPropertyDefinitions().isEmpty()) {
EditAnnotationPropertiesDialog editAnnotationPropertiesDialog = new EditAnnotationPropertiesDialog(project, annotation, new SaveCancelListener<List<Property>>() {
@Override
public void savePressed(List<Property> notOfInterest) {
userMarkupCollectionManager.addTagReferences(tagReferences, collection);
}
});
editAnnotationPropertiesDialog.show();
} else {
userMarkupCollectionManager.addTagReferences(tagReferences, collection);
}
} catch (URISyntaxException e) {
errorHandler.showAndLogError("Error adding Annotations!", e);
}
}
}
use of de.catma.tag.Property in project catma by forTEXT.
the class KwicPanel method initComponents.
private void initComponents() {
setSizeFull();
setMargin(false);
setSpacing(false);
btExpandCompress = new IconButton(expandResource);
btExpandCompress.setVisible(false);
kwicDataProvider = new ListDataProvider<>(new HashSet<>());
kwicGrid = new Grid<QueryResultRow>(kwicDataProvider);
kwicGrid.setSizeFull();
kwicGrid.addColumn(row -> kwicItemHandler.getDocumentName(row)).setCaption("Document").setWidth(200).setHidable(true);
kwicGrid.addColumn(row -> kwicItemHandler.getCollectionName(row)).setCaption("Collection").setWidth(200).setId(ColumnId.COLLECION_NAME.name()).setHidable(true).setHidden(true);
Column<QueryResultRow, ?> backwardCtxColumn = kwicGrid.addColumn(row -> kwicItemHandler.getBackwardContext(row)).setCaption("Left Context").setStyleGenerator(row -> kwicItemHandler.getBackwardContextStyle(row)).setWidth(200);
Column<QueryResultRow, ?> keywordColumn = kwicGrid.addColumn(row -> kwicItemHandler.getKeyword(row)).setCaption("Keyword").setWidth(200).setRenderer(new HtmlRenderer()).setStyleGenerator(row -> kwicItemHandler.getKeywordStyle(row)).setDescriptionGenerator(row -> kwicItemHandler.getKeywordDescription(row), ContentMode.HTML);
kwicGrid.addColumn(row -> kwicItemHandler.getForwardContext(row)).setCaption("Right Context").setStyleGenerator(row -> kwicItemHandler.getForwardContextStyle(row)).setWidth(200);
kwicGrid.addColumn(row -> row.getRange().getStartPoint()).setCaption("Start Point").setWidth(100).setId(ColumnId.START_POS.name()).setHidable(true);
kwicGrid.addColumn(row -> row.getRange().getEndPoint()).setCaption("End Point").setWidth(100).setHidable(true);
kwicGrid.addColumn(row -> kwicItemHandler.getTagPath(row)).setCaption("Tag").setHidable(true).setHidden(true).setId(ColumnId.TAG.name()).setWidth(200);
kwicGrid.addColumn(row -> kwicItemHandler.getPropertyName(row)).setCaption("Property").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_NAME.name()).setWidth(200);
kwicGrid.addColumn(row -> kwicItemHandler.getPropertyValue(row)).setCaption("Value").setHidable(true).setHidden(true).setId(ColumnId.PROPERTY_VALUE.name()).setWidth(200);
kwicGrid.sort(keywordColumn);
kwicGrid.getDefaultHeaderRow().getCell(keywordColumn).setStyleName("kwic-panel-keyword-header");
kwicGrid.getDefaultHeaderRow().getCell(backwardCtxColumn).setStyleName("kwic-panel-backwardctx-header");
kwicGridComponent = new ActionGridComponent<>(new Label("Keyword in context"), kwicGrid);
kwicGridComponent.getActionGridBar().setAddBtnVisible(false);
kwicGridComponent.getActionGridBar().addButtonRight(btExpandCompress);
kwicGridComponent.setMargin(new MarginInfo(false, false, false, true));
addComponent(kwicGridComponent);
setExpandRatio(kwicGridComponent, 1f);
btnClearSelectedRows = new IconButton(VaadinIcons.ERASER);
btnClearSelectedRows.setVisible(false);
btnClearSelectedRows.setDescription("Remove the selected rows from this list");
}
Aggregations