use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationDetailEditorPanel method loadFeatureEditorModels.
public void loadFeatureEditorModels(JCas aJCas, AjaxRequestTarget aTarget) throws AnnotationException {
LOG.trace("loadFeatureEditorModels()");
AnnotatorState state = getModelObject();
Selection selection = state.getSelection();
List<FeatureState> featureStates = state.getFeatureStates();
for (FeatureState featureState : featureStates) {
if (StringUtils.isNotBlank(featureState.feature.getLinkTypeName())) {
featureState.value = new ArrayList<>();
}
}
try {
if (selection.isSpan()) {
annotationFeatureForm.updateLayersDropdown();
}
if (selection.getAnnotation().isSet()) {
// If an existing annotation was selected, take the feature editor model values from
// there
AnnotationFS annoFs = selectByAddr(aJCas, state.getSelection().getAnnotation().getId());
// Try obtaining the layer from the feature structure
AnnotationLayer layer;
try {
layer = annotationService.getLayer(state.getProject(), annoFs);
state.setSelectedAnnotationLayer(layer);
LOG.trace(String.format("loadFeatureEditorModels() selectedLayer set from selection: %s", state.getSelectedAnnotationLayer().getUiName()));
} catch (NoResultException e) {
clearFeatureEditorModels(aTarget);
throw new IllegalStateException("Unknown layer [" + annoFs.getType().getName() + "]", e);
}
// selected span annotation
if (!selection.isArc() && !state.getPreferences().isRememberLayer()) {
state.setSelectedAnnotationLayer(layer);
}
loadFeatureEditorModelsCommon(aTarget, aJCas, layer, annoFs, null);
} else {
if (selection.isArc()) {
// Avoid creation of arcs on locked layers
if (state.getSelectedAnnotationLayer() != null && state.getSelectedAnnotationLayer().isReadonly()) {
state.setSelectedAnnotationLayer(new AnnotationLayer());
} else {
loadFeatureEditorModelsCommon(aTarget, aJCas, state.getSelectedAnnotationLayer(), null, state.getRememberedArcFeatures());
}
} else {
loadFeatureEditorModelsCommon(aTarget, aJCas, state.getSelectedAnnotationLayer(), null, state.getRememberedSpanFeatures());
}
}
annotationFeatureForm.updateRememberLayer();
if (aTarget != null) {
aTarget.add(annotationFeatureForm);
}
} catch (Exception e) {
throw new AnnotationException(e);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationDetailEditorPanel method checkAttachStatus.
public AttachStatus checkAttachStatus(AjaxRequestTarget aTarget, Project aProject, AnnotationFS aFS) {
AnnotationLayer layer = annotationService.getLayer(aProject, aFS);
AttachStatus attachStatus = new AttachStatus();
Set<AnnotationFS> attachedRels = getAttachedRels(aFS, layer);
boolean attachedToReadOnlyRels = attachedRels.stream().anyMatch(relFS -> {
AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
return relLayer.isReadonly();
});
if (attachedToReadOnlyRels) {
attachStatus.readOnlyAttached |= true;
}
attachStatus.attachCount += attachedRels.size();
// We do not count these atm since they only exist for built-in layers and are not
// visible in the UI for the user.
/*
Set<AnnotationFS> attachedSpans = getAttachedSpans(aFS, layer);
boolean attachedToReadOnlySpans = attachedSpans.stream().anyMatch(relFS -> {
AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
return relLayer.isReadonly();
});
if (attachedToReadOnlySpans) {
attachStatus.readOnlyAttached |= true;
}
attachStatus.attachCount += attachedSpans.size();
*/
Set<AnnotationFS> attachedLinks = getAttachedLinks(aFS, layer);
boolean attachedToReadOnlyLinks = attachedLinks.stream().anyMatch(relFS -> {
AnnotationLayer relLayer = annotationService.getLayer(aProject, relFS);
return relLayer.isReadonly();
});
if (attachedToReadOnlyLinks) {
attachStatus.readOnlyAttached |= true;
}
attachStatus.attachCount += attachedLinks.size();
return attachStatus;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationFeatureForm method updateLayersDropdown.
public void updateLayersDropdown() {
editorPanel.getLog().trace("updateLayersDropdown()");
AnnotatorState state = getModelObject();
annotationLayers.clear();
AnnotationLayer l = null;
for (AnnotationLayer layer : state.getAnnotationLayers()) {
if (!layer.isEnabled() || layer.isReadonly() || layer.getName().equals(Token.class.getName())) {
continue;
}
if (layer.getType().equals(WebAnnoConst.SPAN_TYPE)) {
annotationLayers.add(layer);
l = layer;
} else // manage chain type
if (layer.getType().equals(WebAnnoConst.CHAIN_TYPE)) {
for (AnnotationFeature feature : annotationService.listAnnotationFeature(layer)) {
if (!feature.isEnabled()) {
continue;
}
if (feature.getName().equals(WebAnnoConst.COREFERENCE_TYPE_FEATURE)) {
annotationLayers.add(layer);
}
}
}
// chain
}
if (state.getDefaultAnnotationLayer() != null) {
state.setSelectedAnnotationLayer(state.getDefaultAnnotationLayer());
} else if (l != null) {
state.setSelectedAnnotationLayer(l);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationFeatureForm method actionReplace.
private void actionReplace(AjaxRequestTarget aTarget) throws IOException {
AnnotatorState state = AnnotationFeatureForm.this.getModelObject();
AnnotationLayer newLayer = layerSelector.getModelObject();
JCas jCas = editorPanel.getEditorCas();
AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
AnnotationLayer currentLayer = annotationService.getLayer(state.getProject(), fs);
if (currentLayer.isReadonly()) {
error("Cannot replace an annotation on a read-only layer.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
AttachStatus attachStatus = editorPanel.checkAttachStatus(aTarget, state.getProject(), fs);
if (attachStatus.readOnlyAttached) {
error("Cannot replace an annotation to which annotations on read-only layers attach.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
replaceAnnotationDialog.setContentModel(new StringResourceModel("ReplaceDialog.text", AnnotationFeatureForm.this).setParameters(currentLayer.getUiName(), newLayer.getUiName(), attachStatus.attachCount));
replaceAnnotationDialog.setConfirmAction((_target) -> {
// The delete action clears the selection, but we need it to create
// the new annotation - so we save it.
Selection savedSel = editorPanel.getModelObject().getSelection().copy();
// Delete current annotation
editorPanel.actionDelete(_target);
// Set up the action to create the replacement annotation
AnnotationLayer layer = layerSelector.getModelObject();
state.getSelection().set(savedSel);
state.getSelection().setAnnotation(VID.NONE_ID);
state.setSelectedAnnotationLayer(layer);
state.setDefaultAnnotationLayer(layer);
selectedAnnotationLayer.setDefaultModelObject(layer.getUiName());
editorPanel.loadFeatureEditorModels(_target);
// Create the replacement annotation
editorPanel.actionCreateOrUpdate(_target, editorPanel.getEditorCas());
layerSelector.modelChanged();
_target.add(AnnotationFeatureForm.this);
});
replaceAnnotationDialog.setCancelAction((_target) -> {
state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
_target.add(AnnotationFeatureForm.this);
});
replaceAnnotationDialog.show(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationFeatureForm method actionDelete.
private void actionDelete(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
AnnotatorState state = AnnotationFeatureForm.this.getModelObject();
AnnotationLayer layer = state.getSelectedAnnotationLayer();
TypeAdapter adapter = annotationService.getAdapter(layer);
JCas jCas = editorPanel.getEditorCas();
AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
if (layer.isReadonly()) {
error("Cannot replace an annotation on a read-only layer.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
AttachStatus attachStatus = editorPanel.checkAttachStatus(aTarget, state.getProject(), fs);
if (attachStatus.readOnlyAttached) {
error("Cannot delete an annotation to which annotations on read-only layers attach.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
if (adapter instanceof SpanAdapter && attachStatus.attachCount > 0) {
deleteAnnotationDialog.setContentModel(new StringResourceModel("DeleteDialog.text", this, Model.of(layer)).setParameters(attachStatus.attachCount));
deleteAnnotationDialog.setConfirmAction((aCallbackTarget) -> {
editorPanel.actionDelete(aCallbackTarget);
});
deleteAnnotationDialog.show(aTarget);
} else {
editorPanel.actionDelete(aTarget);
}
}
Aggregations