use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationDetailEditorPanel method loadFeatureEditorModelsCommon.
private void loadFeatureEditorModelsCommon(AjaxRequestTarget aTarget, JCas aJCas, AnnotationLayer aLayer, FeatureStructure aFS, Map<AnnotationFeature, Serializable> aRemembered) {
clearFeatureEditorModels(aTarget);
AnnotatorState state = AnnotationDetailEditorPanel.this.getModelObject();
// Populate from feature structure
for (AnnotationFeature feature : annotationService.listAnnotationFeature(aLayer)) {
if (!feature.isEnabled()) {
continue;
}
Serializable value = null;
if (aFS != null) {
value = annotationService.getAdapter(aLayer).getFeatureValue(feature, aFS);
} else if (aRemembered != null) {
value = aRemembered.get(feature);
}
FeatureState featureState = null;
if (WebAnnoConst.CHAIN_TYPE.equals(feature.getLayer().getType())) {
if (state.getSelection().isArc()) {
if (feature.getLayer().isLinkedListBehavior() && WebAnnoConst.COREFERENCE_RELATION_FEATURE.equals(feature.getName())) {
featureState = new FeatureState(feature, value);
}
} else {
if (WebAnnoConst.COREFERENCE_TYPE_FEATURE.equals(feature.getName())) {
featureState = new FeatureState(feature, value);
}
}
} else {
featureState = new FeatureState(feature, value);
}
if (featureState != null) {
state.getFeatureStates().add(featureState);
// verification to check whether constraints exist for this project or NOT
if (state.getConstraints() != null && state.getSelection().getAnnotation().isSet()) {
// indicator.setRulesExist(true);
populateTagsBasedOnRules(aJCas, featureState);
} else {
// indicator.setRulesExist(false);
featureState.tagset = annotationService.listTags(featureState.feature.getTagset());
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationDetailEditorPanel method reset.
public void reset(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
state.getSelection().clear();
clearFeatureEditorModels(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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.api.annotation.model.AnnotatorState in project webanno by webanno.
the class AnnotationFeatureForm method updateRememberLayer.
void updateRememberLayer() {
editorPanel.getLog().trace("updateRememberLayer()");
AnnotatorState state = getModelObject();
if (state.getPreferences().isRememberLayer()) {
if (state.getDefaultAnnotationLayer() == null) {
state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
}
} else if (!state.getSelection().isArc()) {
state.setDefaultAnnotationLayer(state.getSelectedAnnotationLayer());
}
// if no layer is selected in Settings
if (state.getSelectedAnnotationLayer() != null) {
selectedAnnotationLayer.setDefaultModelObject(state.getSelectedAnnotationLayer().getUiName());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState 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);
}
Aggregations