use of de.catma.util.Pair in project catma by forTEXT.
the class V3TeiDocumentConverter method getTarget.
private Pair<String, Range> getTarget(TeiElement pointer) {
String target = pointer.getAttributeValue(Attribute.ptr_target);
String[] uri_points = target.split("#");
String uri = uri_points[0].trim();
String[] points = uri_points[1].split("/.");
try {
uri = URLEncoder.encode(uri, "UTF8");
Range r = new Range(Integer.valueOf(points[1].substring(0, points[1].indexOf(',')).trim()), Integer.valueOf(points[2].substring(0, points[2].indexOf(')')).trim()));
return new Pair<String, Range>(uri, r);
} catch (UnsupportedEncodingException uee) {
throw new IllegalStateException("UTF8 characterset not supported!");
}
}
use of de.catma.util.Pair in project catma by forTEXT.
the class ProjectView method handleCorpusImport.
private void handleCorpusImport() {
try {
if (project.hasUncommittedChanges()) {
SingleTextInputDialog dlg = new SingleTextInputDialog("Commit all changes", "You have changes, that need to be committed first, please enter a short description for this commit:", commitMsg -> {
try {
project.commitChanges(commitMsg);
importCollection();
} catch (Exception e) {
setEnabled(true);
((ErrorHandler) UI.getCurrent()).showAndLogError("error committing changes", e);
}
});
dlg.show();
} else {
CorpusImportDialog corpusImportDialog = new CorpusImportDialog(new SaveCancelListener<Pair<File, List<CorpusImportDocumentMetadata>>>() {
@Override
public void savePressed(Pair<File, List<CorpusImportDocumentMetadata>> result) {
importCorpus(result.getFirst(), result.getSecond());
}
});
corpusImportDialog.show();
}
} catch (Exception e) {
errorHandler.showAndLogError("Error accessing Project!", e);
}
}
use of de.catma.util.Pair in project catma by forTEXT.
the class TagsView 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();
if (tag.getParentUuid().isEmpty()) {
tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
if (!tagsetData.contains(tagDataItem)) {
tagsetData.addItem(tagsetDataItem, tagDataItem);
tagsetDataProvider.refreshAll();
tagsetGrid.expand(tagsetDataItem);
}
});
} else {
tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
if (!tagsetData.contains(tagDataItem)) {
TagDefinition parentTag = project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid());
TagsetTreeItem parentTagItem = new TagDataItem(parentTag, tagsetDataItem.isEditable());
tagsetData.addItem(parentTagItem, tagDataItem);
tagsetDataProvider.refreshAll();
tagsetGrid.expand(parentTagItem);
}
});
}
} else if (newValue == null) {
// removed
Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
TagDefinition deletedTag = deleted.getSecond();
tagsetData.removeItem(new TagDataItem(deletedTag, true));
tagsetDataProvider.refreshAll();
tagsetGrid.deselectAll();
} else {
// update
TagDefinition tag = (TagDefinition) newValue;
TagsetDefinition tagset = (TagsetDefinition) oldValue;
tagsetData.getRootItems().stream().map(tagsetTreeItem -> (TagsetDataItem) tagsetTreeItem).filter(tagsetDataItem -> tagsetDataItem.getTagset().getUuid().equals(tagset.getUuid())).findFirst().ifPresent(tagsetDataItem -> {
TagDataItem oldItem = new TagDataItem(tag, tagsetDataItem.isEditable());
String parentTagId = tag.getParentUuid();
TagsetTreeItem parent = tagsetDataItem;
if (!parentTagId.isEmpty()) {
parent = new TagDataItem(tagset.getTagDefinition(parentTagId), tagsetDataItem.isEditable());
}
tagsetData.removeItem(oldItem);
TagDataItem tagDataItem = new TagDataItem(tag, tagsetDataItem.isEditable());
tagDataItem.setPropertiesExpanded(true);
tagsetData.addItem(parent, tagDataItem);
addTagSubTree(tagset, tag, tagDataItem);
// TODO: sort
tagsetDataProvider.refreshAll();
showExpandedProperties(tagDataItem);
});
}
}
};
project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
propertyDefinitionChangedListener = new PropertyChangeListener() {
@SuppressWarnings("unchecked")
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object newValue = evt.getNewValue();
Object oldValue = evt.getOldValue();
TagDefinition tag = null;
if (oldValue == null) {
// created
Pair<PropertyDefinition, TagDefinition> newData = (Pair<PropertyDefinition, TagDefinition>) newValue;
tag = newData.getSecond();
} else if (newValue == null) {
// removed
Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>> oldData = (Pair<PropertyDefinition, Pair<TagDefinition, TagsetDefinition>>) oldValue;
tag = oldData.getSecond().getFirst();
} else {
// update
tag = (TagDefinition) oldValue;
}
TagsetTreeItem parentItem = null;
if (tag.getParentUuid().isEmpty()) {
parentItem = new TagsetDataItem(project.getTagManager().getTagLibrary().getTagsetDefinition(tag.getTagsetDefinitionUuid()));
} else {
parentItem = new TagDataItem(project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid()));
}
final String tagId = tag.getUuid();
tagsetData.getChildren(parentItem).stream().map(tagsetTreeItem -> (TagDataItem) tagsetTreeItem).filter(tagDataItem -> tagDataItem.getTag().getUuid().equals(tagId)).findFirst().ifPresent(tagDataItem -> {
tagDataItem.setPropertiesExpanded(false);
hideExpandedProperties(tagDataItem);
tagDataItem.setPropertiesExpanded(true);
showExpandedProperties(tagDataItem);
});
tagsetDataProvider.refreshAll();
tagsetGrid.deselectAll();
}
};
project.getTagManager().addPropertyChangeListener(TagManagerEvent.userPropertyDefinitionChanged, propertyDefinitionChangedListener);
}
use of de.catma.util.Pair 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.util.Pair 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);
}
Aggregations