private void actionDelete(AjaxRequestTarget aTarget)
        throws IOException, UIMAException, ClassNotFoundException
    {
        BratAnnotatorModel bratAnnotatorModel = getModelObject();
        JCas jCas = getCas(bratAnnotatorModel);
        AnnotationFS fs = selectByAddr(jCas, selectedAnnotationId);
        TypeAdapter adapter = getAdapter(selectedAnnotationLayer);
        String attachFeatureName = adapter.getAttachFeatureName();
        String attachTypeName = adapter.getAnnotationTypeName();
        Set<TypeAdapter> typeAdapters = new HashSet<TypeAdapter>();
        for (AnnotationLayer layer : annotationService.listAnnotationLayer(bratAnnotatorModel
                .getProject())) {
            typeAdapters.add(getAdapter(layer));
        }
        // delete associated relation annotation
        for (TypeAdapter ad : typeAdapters) {
            if (adapter.getAnnotationTypeName().equals(ad.getAnnotationTypeName())) {
                continue;
            }
            String tn = ad.getAttachTypeName();
            if (tn == null) {
                continue;
            }
            if (tn.equals(attachTypeName)) {
                Sentence thisSentence = BratAjaxCasUtil.getCurrentSentence(jCas, beginOffset,
                        endOffset);
                ad.deleteBySpan(jCas, fs, thisSentence.getBegin(), thisSentence.getEnd());
                break;
            }
            String fn = ad.getAttachFeatureName();
            if (fn == null) {
                continue;
            }
            if (fn.equals(attachFeatureName)) {
                Sentence thisSentence = BratAjaxCasUtil.getCurrentSentence(jCas, beginOffset,
                        endOffset);
                ad.deleteBySpan(jCas, fs, thisSentence.getBegin(), thisSentence.getEnd());
                break;
            }
        }
        // BEGIN HACK - Issue 933
        if (adapter instanceof ChainAdapter) {
            ((ChainAdapter) adapter).setArc(false);
        }
        // END HACK - Issue 933
        adapter.delete(jCas, selectedAnnotationId);
        repository.updateJCas(bratAnnotatorModel.getMode(), bratAnnotatorModel.getDocument(),
                bratAnnotatorModel.getUser(), jCas);
        // update timestamp now
        int sentenceNumber = BratAjaxCasUtil.getSentenceNumber(jCas, beginOffset);
        bratAnnotatorModel.getDocument().setSentenceAccessed(sentenceNumber);
        repository.updateTimeStamp(bratAnnotatorModel.getDocument(), bratAnnotatorModel.getUser(),
                bratAnnotatorModel.getMode());
        if (bratAnnotatorModel.isScrollPage()) {
            updateSentenceAddressAndOffsets(jCas, beginOffset);
        }
        bratAnnotatorModel.setRememberedSpanLayer(selectedAnnotationLayer);
        bratAnnotatorModel.setAnnotate(false);
        // store latest annotations
        for (IModel<String> model : featureValueModels) {
            AnnotationFeature feature = featuresModel.get(featureValueModels.indexOf(model))
                    .getObject().feature;
            selectedAnnotationLayer = feature.getLayer();
            selectedFeatureValues.put(feature, model.getObject());
        }
        info(generateMessage(selectedAnnotationLayer, null, true));
        // A hack to rememeber the Visural DropDown display
        // value
        bratAnnotatorModel.setRememberedSpanLayer(selectedAnnotationLayer);
        bratAnnotatorModel.setRememberedSpanFeatures(selectedFeatureValues);
        selectedSpanText = "";
        selectedAnnotationId = -1;
        aTarget.add(annotationFeatureForm);
       // setLayerAndFeatureModels(jCas);
        bratRender(aTarget, jCas);
        onChange(aTarget, getModelObject());
    }
private void actionDelete(AjaxRequestTarget aTarget)
        throws IOException, UIMAException, ClassNotFoundException
    {
        BratAnnotatorModel bratAnnotatorModel = getModelObject();
        JCas jCas = getCas(bratAnnotatorModel);
        AnnotationFS fs = selectByAddr(jCas, selectedAnnotationId);
        TypeAdapter adapter = getAdapter(selectedAnnotationLayer);
        String attachFeatureName = adapter.getAttachFeatureName();
        String attachTypeName = adapter.getAnnotationTypeName();
        Set<TypeAdapter> typeAdapters = new HashSet<TypeAdapter>();
        for (AnnotationLayer layer : annotationService.listAnnotationLayer(bratAnnotatorModel
                .getProject())) {
            typeAdapters.add(getAdapter(layer));
        }
       
        for (TypeAdapter ad : typeAdapters) {
            if (adapter.getAnnotationTypeName().equals(ad.getAnnotationTypeName())) {
                continue;
            }
            String tn = ad.getAttachTypeName();
            if (tn == null) {
                continue;
            }
            if (tn.equals(attachTypeName)) {
                Sentence thisSentence = BratAjaxCasUtil.getCurrentSentence(jCas, beginOffset,
                        endOffset);
                ad.deleteBySpan(jCas, fs, thisSentence.getBegin(), thisSentence.getEnd());
                break;
            }
            String fn = ad.getAttachFeatureName();
            if (fn == null) {
                continue;
            }
            if (fn.equals(attachFeatureName)) {
                Sentence thisSentence = BratAjaxCasUtil.getCurrentSentence(jCas, beginOffset,
                        endOffset);
                ad.deleteBySpan(jCas, fs, thisSentence.getBegin(), thisSentence.getEnd());
                break;
            }
        }
       
        if (adapter instanceof ChainAdapter) {
            ((ChainAdapter) adapter).setArc(false);
        }
       
        adapter.delete(jCas, selectedAnnotationId);
        repository.updateJCas(bratAnnotatorModel.getMode(), bratAnnotatorModel.getDocument(),
                bratAnnotatorModel.getUser(), jCas);
       
        int sentenceNumber = BratAjaxCasUtil.getSentenceNumber(jCas, beginOffset);
        bratAnnotatorModel.getDocument().setSentenceAccessed(sentenceNumber);
        repository.updateTimeStamp(bratAnnotatorModel.getDocument(), bratAnnotatorModel.getUser(),
                bratAnnotatorModel.getMode());
        if (bratAnnotatorModel.isScrollPage()) {
            updateSentenceAddressAndOffsets(jCas, beginOffset);
        }
        bratAnnotatorModel.setRememberedSpanLayer(selectedAnnotationLayer);
        bratAnnotatorModel.setAnnotate(false);
       
        for (IModel<String> model : featureValueModels) {
            AnnotationFeature feature = featuresModel.get(featureValueModels.indexOf(model))
                    .getObject().feature;
            selectedAnnotationLayer = feature.getLayer();
            selectedFeatureValues.put(feature, model.getObject());
        }
        info(generateMessage(selectedAnnotationLayer, null, true));
       
       
        bratAnnotatorModel.setRememberedSpanLayer(selectedAnnotationLayer);
        bratAnnotatorModel.setRememberedSpanFeatures(selectedFeatureValues);
        selectedSpanText = "";
        selectedAnnotationId = -1;
        aTarget.add(annotationFeatureForm);
      
        bratRender(aTarget, jCas);
        onChange(aTarget, getModelObject());
    }
private void actiondelete(ajaxrequesttarget atarget) throws ioexception, uimaexception, classnotfoundexception { bratannotatormodel bratannotatormodel = getmodelobject(); jcas jcas = getcas(bratannotatormodel); annotationfs fs = selectbyaddr(jcas, selectedannotationid); typeadapter adapter = getadapter(selectedannotationlayer); string attachfeaturename = adapter.getattachfeaturename(); string attachtypename = adapter.getannotationtypename(); set<typeadapter> typeadapters = new hashset<typeadapter>(); for (annotationlayer layer : annotationservice.listannotationlayer(bratannotatormodel .getproject())) { typeadapters.add(getadapter(layer)); } for (typeadapter ad : typeadapters) { if (adapter.getannotationtypename().equals(ad.getannotationtypename())) { continue; } string tn = ad.getattachtypename(); if (tn == null) { continue; } if (tn.equals(attachtypename)) { sentence thissentence = bratajaxcasutil.getcurrentsentence(jcas, beginoffset, endoffset); ad.deletebyspan(jcas, fs, thissentence.getbegin(), thissentence.getend()); break; } string fn = ad.getattachfeaturename(); if (fn == null) { continue; } if (fn.equals(attachfeaturename)) { sentence thissentence = bratajaxcasutil.getcurrentsentence(jcas, beginoffset, endoffset); ad.deletebyspan(jcas, fs, thissentence.getbegin(), thissentence.getend()); break; } } if (adapter instanceof chainadapter) { ((chainadapter) adapter).setarc(false); } adapter.delete(jcas, selectedannotationid); repository.updatejcas(bratannotatormodel.getmode(), bratannotatormodel.getdocument(), bratannotatormodel.getuser(), jcas); int sentencenumber = bratajaxcasutil.getsentencenumber(jcas, beginoffset); bratannotatormodel.getdocument().setsentenceaccessed(sentencenumber); repository.updatetimestamp(bratannotatormodel.getdocument(), bratannotatormodel.getuser(), bratannotatormodel.getmode()); if (bratannotatormodel.isscrollpage()) { updatesentenceaddressandoffsets(jcas, beginoffset); } bratannotatormodel.setrememberedspanlayer(selectedannotationlayer); bratannotatormodel.setannotate(false); for (imodel<string> model : featurevaluemodels) { annotationfeature feature = featuresmodel.get(featurevaluemodels.indexof(model)) .getobject().feature; selectedannotationlayer = feature.getlayer(); selectedfeaturevalues.put(feature, model.getobject()); } info(generatemessage(selectedannotationlayer, null, true)); bratannotatormodel.setrememberedspanlayer(selectedannotationlayer); bratannotatormodel.setrememberedspanfeatures(selectedfeaturevalues); selectedspantext = ""; selectedannotationid = -1; atarget.add(annotationfeatureform); bratrender(atarget, jcas); onchange(atarget, getmodelobject()); }