use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.Selection 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.api.annotation.model.Selection 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.api.annotation.model.Selection in project webanno by webanno.
the class BratAnnotationEditor method actionArc.
private ArcAnnotationResponse actionArc(AjaxRequestTarget aTarget, IRequestParameters request, JCas jCas, VID paramId) throws IOException, AnnotationException {
AnnotationFS originFs = selectByAddr(jCas, request.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt());
AnnotationFS targetFs = selectByAddr(jCas, request.getParameterValue(PARAM_TARGET_SPAN_ID).toInt());
AnnotatorState state = getModelObject();
Selection selection = state.getSelection();
selection.selectArc(paramId, originFs, targetFs);
if (selection.getAnnotation().isNotSet()) {
// Create new annotation
getActionHandler().actionCreateOrUpdate(aTarget, jCas);
} else {
getActionHandler().actionSelect(aTarget, jCas);
}
return new ArcAnnotationResponse();
}
Aggregations