Search in sources :

Example 1 with AttachStatus

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);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Selection(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection) AttachStatus(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) JCas(org.apache.uima.jcas.JCas) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Example 2 with AttachStatus

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);
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) AttachStatus(de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) JCas(org.apache.uima.jcas.JCas) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) StringResourceModel(org.apache.wicket.model.StringResourceModel)

Aggregations

AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 AttachStatus (de.tudarmstadt.ukp.clarin.webanno.ui.annotation.detail.AnnotationDetailEditorPanel.AttachStatus)2 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)2 JCas (org.apache.uima.jcas.JCas)2 StringResourceModel (org.apache.wicket.model.StringResourceModel)2 SpanAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter)1 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)1 Selection (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection)1