use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GitProjectHandler method getCollectionReferences.
public List<AnnotationCollectionReference> getCollectionReferences() {
ArrayList<AnnotationCollectionReference> collectionReferences = new ArrayList<>();
try (ILocalGitRepositoryManager localRepoManager = this.localGitRepositoryManager) {
try {
localRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
List<Path> paths = localRepoManager.getSubmodulePaths().stream().filter(path -> path != null && path.startsWith(ANNOTATION_COLLECTION_SUBMODULES_DIRECTORY_NAME)).map(path -> Paths.get(localRepoManager.getRepositoryWorkTree().toURI()).resolve(path)).collect(Collectors.toList());
localRepoManager.detach();
GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(localRepoManager, this.remoteGitServerManager, this.credentialsProvider);
for (Path collectionPath : paths) {
String collectionId = collectionPath.getFileName().toString();
RBACRole resourceRole = rolesPerResource.get(collectionId);
if ((resourceRole != null) && hasPermission(resourceRole, RBACPermission.COLLECTION_READ)) {
try {
collectionReferences.add(gitMarkupCollectionHandler.getCollectionReference(projectId, collectionId));
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("error loading Collection reference %1$s for project %2$s", collectionPath, projectId), e);
}
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("error loading Collection references for project %1$s", projectId), e);
}
}
return collectionReferences;
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class GitProjectHandler method hasUncommittedChanges.
public boolean hasUncommittedChanges() throws Exception {
try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
GitMarkupCollectionHandler collectionHandler = new GitMarkupCollectionHandler(localGitRepoManager, this.remoteGitServerManager, this.credentialsProvider);
// TODO: better get collectionRefs from graph
for (AnnotationCollectionReference collectionRef : getCollectionReferences()) {
if (collectionHandler.hasUncommittedChanges(projectId, collectionRef.getId())) {
return true;
}
}
// open the project root repo
localGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
return localGitRepoManager.hasUncommitedChangesWithSubmodules(getReadableSubmodules(localGitRepoManager));
}
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class TaggerView method initListeners.
private void initListeners() {
this.tagReferencesChangedListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue() != null) {
@SuppressWarnings("unchecked") Pair<AnnotationCollection, List<TagReference>> changeValue = (Pair<AnnotationCollection, List<TagReference>>) evt.getNewValue();
List<TagReference> tagReferences = changeValue.getSecond();
List<TagReference> relevantTagReferences = new ArrayList<TagReference>();
for (TagReference tr : tagReferences) {
if (isRelevantTagReference(tr, userMarkupCollectionManager.getUserMarkupCollections())) {
relevantTagReferences.add(tr);
}
}
tagger.setVisible(relevantTagReferences, true);
Set<String> tagInstanceUuids = new HashSet<String>();
for (TagReference tr : relevantTagReferences) {
tagInstanceUuids.add(tr.getTagInstance().getUuid());
}
tagInstanceUuids.forEach(annotationId -> tagger.updateAnnotation(annotationId));
} else if (evt.getOldValue() != null) {
@SuppressWarnings("unchecked") Pair<String, Collection<String>> changeValue = (Pair<String, Collection<String>>) evt.getOldValue();
String collectionId = changeValue.getFirst();
Collection<String> annotationIds = changeValue.getSecond();
if (userMarkupCollectionManager.contains(collectionId)) {
userMarkupCollectionManager.removeTagInstance(annotationIds, false);
}
tagger.removeTagInstances(annotationIds);
annotationPanel.removeAnnotations(annotationIds);
}
}
};
project.addPropertyChangeListener(RepositoryChangeEvent.tagReferencesChanged, tagReferencesChangedListener);
annotationPropertiesChangedListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
TagInstance tagInstance = (TagInstance) evt.getOldValue();
tagger.updateAnnotation(tagInstance.getUuid());
}
};
project.addPropertyChangeListener(RepositoryChangeEvent.propertyValueChanged, annotationPropertiesChangedListener);
tagChangedListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object newValue = evt.getNewValue();
Object oldValue = evt.getOldValue();
if (oldValue == null) {
// created
// noop
} else if (newValue == null) {
// removed
@SuppressWarnings("unchecked") Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
for (AnnotationCollectionReference ref : userMarkupCollectionManager.getCollections(deleted.getSecond())) {
setAnnotationCollectionSelected(ref, false);
setAnnotationCollectionSelected(ref, true);
}
} else {
// update
TagDefinition tag = (TagDefinition) newValue;
for (AnnotationCollection collection : userMarkupCollectionManager.getUserMarkupCollections()) {
List<TagReference> relevantTagReferences = collection.getTagReferences(tag);
tagger.setVisible(relevantTagReferences, false);
tagger.setVisible(relevantTagReferences, true);
}
}
}
};
project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
}
use of de.catma.document.annotation.AnnotationCollectionReference in project catma by forTEXT.
the class AnnotateResourcePanel method initData.
private void initData(SourceDocument currentlySelectedSourceDocument, Set<String> currentlysSelectedColletionIds) {
try {
documentData = new TreeData<>();
Collection<SourceDocument> documents = project.getSourceDocuments();
final SourceDocument preselection = currentlySelectedSourceDocument;
documentData.addRootItems(documents.stream().map(document -> new DocumentDataItem(document, preselection != null && document.equals(preselection))));
DocumentTreeItem preselectedItem = null;
for (DocumentTreeItem documentDataItem : documentData.getRootItems()) {
if (documentDataItem.isSelected()) {
preselectedItem = documentDataItem;
}
for (AnnotationCollectionReference umcRef : ((DocumentDataItem) documentDataItem).getDocument().getUserMarkupCollectionRefs()) {
documentData.addItem(documentDataItem, new CollectionDataItem(umcRef, project.hasPermission(project.getRoleForCollection(umcRef.getId()), RBACPermission.COLLECTION_WRITE), (currentlysSelectedColletionIds.isEmpty() || currentlysSelectedColletionIds.contains(umcRef.getId()))));
}
}
documentTree.setDataProvider(new TreeDataProvider<>(documentData));
if (preselectedItem != null) {
documentTree.expand(preselectedItem);
}
tagsetData = new ListDataProvider<TagsetDefinition>(project.getTagsets());
tagsetGrid.setDataProvider(tagsetData);
tagsetData.getItems().forEach(tagsetGrid::select);
documentData.getRootItems().stream().filter(documentItem -> documentItem.isSelected()).findAny().ifPresent(documentItem -> documentTree.expand(documentItem));
} catch (Exception e) {
errorHandler.showAndLogError("Error loading data!", e);
}
}
Aggregations