use of de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus 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.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus 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