use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class TagSelectionPanel method initData.
private void initData() {
try {
tagsetData = new TreeData<TagsetTreeItem>();
Collection<TagsetDefinition> tagsets = project.getTagManager().getTagLibrary().getTagsetDefinitions();
for (TagsetDefinition tagset : tagsets) {
TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
tagsetData.addItem(null, tagsetItem);
addTags(tagsetItem, tagset);
}
tagsetDataProvider = new TreeDataProvider<TagsetTreeItem>(tagsetData);
tagsetGrid.setDataProvider(tagsetDataProvider);
for (TagsetDefinition tagset : tagsets) {
expandTagsetDefinition(tagset);
}
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("Error loading data!", e);
}
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class GraphWorktreeProject method initTagManagerListeners.
private void initTagManagerListeners() {
tagsetDefinitionChangedListener = new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
if (!tagManagerListenersEnabled) {
return;
}
try {
if (evt.getOldValue() == null) {
// insert
final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
addTagsetDefinition(tagsetDefinition);
} else if (evt.getNewValue() == null) {
// delete
final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getOldValue();
removeTagsetDefinition(tagsetDefinition);
} else {
// update
final TagsetDefinition tagsetDefinition = (TagsetDefinition) evt.getNewValue();
updateTagsetDefinition(tagsetDefinition);
}
} catch (Exception e) {
propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
}
}
};
tagManager.addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetDefinitionChangedListener);
tagDefinitionChangedListener = new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent evt) {
if (!tagManagerListenersEnabled) {
return;
}
try {
if (evt.getOldValue() == null) {
@SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getNewValue();
TagsetDefinition tagsetDefinition = args.getFirst();
TagDefinition tagDefinition = args.getSecond();
addTagDefinition(tagDefinition, tagsetDefinition);
} else if (evt.getNewValue() == null) {
@SuppressWarnings("unchecked") final Pair<TagsetDefinition, TagDefinition> args = (Pair<TagsetDefinition, TagDefinition>) evt.getOldValue();
TagsetDefinition tagsetDefinition = args.getFirst();
TagDefinition tagDefinition = args.getSecond();
removeTagDefinition(tagDefinition, tagsetDefinition);
} else {
TagDefinition tag = (TagDefinition) evt.getNewValue();
TagsetDefinition tagset = (TagsetDefinition) evt.getOldValue();
updateTagDefinition(tag, tagset);
}
} catch (Exception e) {
propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
}
}
};
tagManager.addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagDefinitionChangedListener);
userDefinedPropertyChangedListener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
if (!tagManagerListenersEnabled) {
return;
}
Object oldValue = evt.getOldValue();
Object newValue = evt.getNewValue();
try {
if (oldValue == null) {
// insert
@SuppressWarnings("unchecked") Pair<PropertyDefinition, TagDefinition> newPair = (Pair<PropertyDefinition, TagDefinition>) newValue;
PropertyDefinition propertyDefinition = newPair.getFirst();
TagDefinition tagDefinition = newPair.getSecond();
addPropertyDefinition(propertyDefinition, tagDefinition);
} else if (newValue == null) {
// delete
@SuppressWarnings("unchecked") Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldPair = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
PropertyDefinition propertyDefinition = oldPair.getFirst();
TagDefinition tagDefinition = oldPair.getSecond().getFirst();
TagsetDefinition tagsetDefinition = oldPair.getSecond().getSecond();
removePropertyDefinition(propertyDefinition, tagDefinition, tagsetDefinition);
} else {
// update
PropertyDefinition propertyDefinition = (PropertyDefinition) evt.getNewValue();
TagDefinition tagDefinition = (TagDefinition) evt.getOldValue();
updatePropertyDefinition(propertyDefinition, tagDefinition);
}
} catch (Exception e) {
propertyChangeSupport.firePropertyChange(RepositoryChangeEvent.exceptionOccurred.name(), null, e);
}
}
};
tagManager.addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, userDefinedPropertyChangedListener);
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class GraphWorktreeProject method loadTagLibrary.
@Override
public List<TagsetDefinitionImportStatus> loadTagLibrary(InputStream inputStream) throws IOException {
TeiSerializationHandlerFactory factory = new TeiSerializationHandlerFactory();
factory.setTagManager(new TagManager(new TagLibrary()));
TagLibrarySerializationHandler tagLibrarySerializationHandler = factory.getTagLibrarySerializationHandler();
TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
List<String> resourceIds = gitProjectHandler.getResourceIds();
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
for (TagsetDefinition tagset : importedLibrary) {
boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
}
return tagsetDefinitionImportStatusList;
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class GraphWorktreeProject method loadAnnotationCollection.
public Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadAnnotationCollection(InputStream inputStream, SourceDocument document) throws IOException {
TagManager tagManager = new TagManager(new TagLibrary());
TeiTagLibrarySerializationHandler tagLibrarySerializationHandler = new TeiTagLibrarySerializationHandler(tagManager);
TagLibrary importedLibrary = tagLibrarySerializationHandler.deserialize(null, inputStream);
List<String> resourceIds = gitProjectHandler.getResourceIds();
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = new ArrayList<>();
for (TagsetDefinition tagset : importedLibrary) {
boolean inProjectHistory = resourceIds.contains(tagset.getUuid());
boolean current = inProjectHistory && (getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid()) != null);
tagsetDefinitionImportStatusList.add(new TagsetDefinitionImportStatus(tagset, inProjectHistory, current));
}
String collectionId = idGenerator.generate();
TeiUserMarkupCollectionDeserializer deserializer = new TeiUserMarkupCollectionDeserializer(tagLibrarySerializationHandler.getTeiDocument(), tagManager.getTagLibrary(), collectionId);
AnnotationCollection annotationCollection = new AnnotationCollection(collectionId, tagLibrarySerializationHandler.getTeiDocument().getContentInfoSet(), tagManager.getTagLibrary(), deserializer.getTagReferences(), document.getUuid(), document.getRevisionHash());
return new Pair<>(annotationCollection, tagsetDefinitionImportStatusList);
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class GraphWorktreeProject method synchronizeWithRemote.
@Override
public void synchronizeWithRemote(OpenProjectListener openProjectListener) throws Exception {
if (hasUncommittedChanges()) {
throw new IllegalStateException("There are uncommitted changes that need to be committed first!");
}
for (TagsetDefinition tagset : getTagsets()) {
gitProjectHandler.synchronizeTagsetWithRemote(tagset.getUuid());
}
for (SourceDocument document : getSourceDocuments()) {
gitProjectHandler.synchronizeSourceDocumentWithRemote(document.getUuid());
for (AnnotationCollectionReference collectionReference : document.getUserMarkupCollectionRefs()) {
gitProjectHandler.synchronizeCollectionWithRemote(collectionReference.getId());
}
}
gitProjectHandler.synchronizeWithRemote();
if (gitProjectHandler.hasConflicts()) {
gitProjectHandler.initAndUpdateSubmodules();
openProjectListener.conflictResolutionNeeded(new GitConflictedProject(projectReference, gitProjectHandler, documentId -> getSourceDocumentURI(documentId)));
} else {
boolean forceGraphReload = gitProjectHandler.loadRolesPerResource();
gitProjectHandler.initAndUpdateSubmodules();
gitProjectHandler.removeStaleSubmoduleDirectories();
gitProjectHandler.ensureDevBranches();
rootRevisionHash = gitProjectHandler.getRootRevisionHash();
ProgressListener progressListener = new ProgressListener() {
@Override
public void setProgress(String value, Object... args) {
openProjectListener.progress(value, args);
}
};
graphProjectHandler.ensureProjectRevisionIsLoaded(new ExecutionListener<TagManager>() {
@Override
public void error(Throwable t) {
openProjectListener.failure(t);
}
@Override
public void done(TagManager result) {
tagManager.load(result.getTagLibrary());
openProjectListener.ready(GraphWorktreeProject.this);
}
}, progressListener, rootRevisionHash, tagManager, () -> gitProjectHandler.getTagsets(), () -> gitProjectHandler.getDocuments(), (tagLibrary) -> gitProjectHandler.getCollections(tagLibrary, progressListener), forceGraphReload, backgroundService);
}
}
Aggregations