use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.Renderer in project webanno by webanno.
the class AttachedAnnotationListPanel method getRelationInfo.
private List<AttachedAnnotationInfo> getRelationInfo() {
Selection selection = getModelObject().getSelection();
if (!selection.isSet() || selection.getAnnotation().getId() == NONE) {
return Collections.emptyList();
}
CAS cas;
try {
cas = page.getEditorCas();
} catch (IOException e) {
// If we have trouble accessing the CAS, we probably never get here anyway...
// the AnnotationPageBase should already have found the issue and displayed some
// error to the user.
LOG.error("Unable to access editor CAS", e);
return Collections.emptyList();
}
AnnotationFS annoFs = selectAnnotationByAddr(cas, selection.getAnnotation().getId());
VID localVid = new VID(annoFs);
List<AttachedAnnotation> attachedAnnotations = new ArrayList<>();
attachedAnnotations.addAll(schemaService.getAttachedRels(getModelObject().getSelectedAnnotationLayer(), annoFs));
attachedAnnotations.addAll(schemaService.getAttachedLinks(getModelObject().getSelectedAnnotationLayer(), annoFs));
Map<AnnotationLayer, List<AnnotationFeature>> featureCache = new HashMap<>();
Map<AnnotationLayer, Renderer> rendererCache = new HashMap<>();
Map<AnnotationLayer, TypeAdapter> adapterCache = new HashMap<>();
List<AttachedAnnotationInfo> result = new ArrayList<>();
for (AttachedAnnotation rel : attachedAnnotations) {
AnnotationLayer layer = rel.getLayer();
List<AnnotationFeature> features = featureCache.get(layer);
TypeAdapter adapter;
Renderer renderer;
if (features == null) {
features = schemaService.listSupportedFeatures(layer);
featureCache.put(layer, features);
adapter = schemaService.getAdapter(layer);
adapterCache.put(layer, adapter);
renderer = layerRegistry.getLayerSupport(layer).createRenderer(layer, () -> featureCache.get(layer));
rendererCache.put(layer, renderer);
} else {
adapter = adapterCache.get(layer);
renderer = rendererCache.get(layer);
}
Map<String, String> renderedFeatures;
if (rel.getRelation() != null) {
renderedFeatures = renderer.renderLabelFeatureValues(adapter, rel.getRelation(), features);
} else {
renderedFeatures = renderer.renderLabelFeatureValues(adapter, rel.getEndpoint(), features);
}
String labelText = TypeUtil.getUiLabelText(adapter, renderedFeatures);
if (isEmpty(labelText)) {
labelText = rel.getLayer().getUiName();
} else {
labelText = rel.getLayer().getUiName() + ": " + labelText;
}
AttachedAnnotationInfo i = new AttachedAnnotationInfo(layer, localVid, rel.getRelation() != null ? new VID(rel.getRelation()) : null, new VID(rel.getEndpoint()), labelText, rel.getEndpoint().getCoveredText(), rel.getDirection());
result.add(i);
}
return result;
}
Aggregations