diff --git a/inception/inception-ui-project/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/project/layers/FeatureDetailForm.java b/inception/inception-ui-project/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/project/layers/FeatureDetailForm.java index 45e1da37bf..e29cae6ba3 100644 --- a/inception/inception-ui-project/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/project/layers/FeatureDetailForm.java +++ b/inception/inception-ui-project/src/main/java/de/tudarmstadt/ukp/clarin/webanno/ui/project/layers/FeatureDetailForm.java @@ -19,20 +19,23 @@ import static de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.MID_FEATURE_DETAIL_FORM; import static de.tudarmstadt.ukp.clarin.webanno.ui.project.layers.ProjectLayersPanel.MID_FEATURE_SELECTION_FORM; -import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.CHAIN_TYPE; -import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.RELATION_TYPE; +import static de.tudarmstadt.ukp.inception.support.lambda.HtmlElementEvents.CHANGE_EVENT; import static de.tudarmstadt.ukp.inception.support.lambda.LambdaBehavior.enabledWhen; import static de.tudarmstadt.ukp.inception.support.lambda.LambdaBehavior.visibleWhen; import static java.util.Arrays.asList; import static java.util.Objects.isNull; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.apache.uima.cas.CAS.TYPE_NAME_BOOLEAN; +import static org.apache.uima.cas.CAS.TYPE_NAME_DOUBLE; +import static org.apache.uima.cas.CAS.TYPE_NAME_FLOAT; +import static org.apache.uima.cas.CAS.TYPE_NAME_INTEGER; +import static org.apache.uima.cas.CAS.TYPE_NAME_STRING; +import static org.apache.uima.cas.CAS.TYPE_NAME_STRING_ARRAY; import java.io.IOException; -import org.apache.uima.cas.CAS; import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; -import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.feedback.IFeedback; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; @@ -53,6 +56,8 @@ import de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasStorageService; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature; import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer; +import de.tudarmstadt.ukp.inception.annotation.layer.chain.ChainLayerSupport; +import de.tudarmstadt.ukp.inception.annotation.layer.relation.RelationLayerSupport; import de.tudarmstadt.ukp.inception.bootstrap.dialog.ChallengeResponseDialog; import de.tudarmstadt.ukp.inception.documents.api.DocumentService; import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService; @@ -62,6 +67,7 @@ import de.tudarmstadt.ukp.inception.schema.api.feature.FeatureType; import de.tudarmstadt.ukp.inception.schema.api.layer.LayerSupportRegistry; import de.tudarmstadt.ukp.inception.support.lambda.LambdaAjaxButton; +import de.tudarmstadt.ukp.inception.support.lambda.LambdaAjaxFormComponentUpdatingBehavior; import de.tudarmstadt.ukp.inception.support.lambda.LambdaBehavior; import de.tudarmstadt.ukp.inception.support.lambda.LambdaButton; import de.tudarmstadt.ukp.inception.support.lambda.LambdaModelAdapter; @@ -108,7 +114,7 @@ public FeatureDetailForm(String id, IModel aFeature) add(new TextArea("description")); defaultOptionsContainer = new WebMarkupContainer("defaultOptionsContainer"); - defaultOptionsContainer.add(LambdaBehavior.visibleWhen(this::isUsingDefaultOptions)); + defaultOptionsContainer.add(visibleWhen(this::isUsingDefaultOptions)); add(defaultOptionsContainer); defaultOptionsContainer.add(new CheckBox("enabled").setOutputMarkupPlaceholderTag(true)); defaultOptionsContainer.add(new CheckBox("curatable").setOutputMarkupPlaceholderTag(true)); @@ -116,9 +122,9 @@ public FeatureDetailForm(String id, IModel aFeature) required = new CheckBox("required"); required.setOutputMarkupPlaceholderTag(true); required.add(LambdaBehavior.onConfigure(_this -> { - boolean mandatory = asList(CAS.TYPE_NAME_INTEGER, CAS.TYPE_NAME_FLOAT, - CAS.TYPE_NAME_DOUBLE, CAS.TYPE_NAME_BOOLEAN) - .contains(FeatureDetailForm.this.getModelObject().getType()); + var type = FeatureDetailForm.this.getModelObject().getType(); + var mandatory = asList(TYPE_NAME_INTEGER, TYPE_NAME_FLOAT, TYPE_NAME_DOUBLE, + TYPE_NAME_BOOLEAN).contains(type); _this.setEnabled(!mandatory); if (mandatory) { required.setModel(Model.of(true)); @@ -130,15 +136,26 @@ public FeatureDetailForm(String id, IModel aFeature) defaultOptionsContainer.add(required); defaultOptionsContainer.add(new CheckBox("visible").setOutputMarkupPlaceholderTag(true)); + defaultOptionsContainer.add(new CheckBox("hideUnconstraintFeature") // + .setOutputMarkupPlaceholderTag(true) // + .add(visibleWhen(() -> { + var type = FeatureDetailForm.this.getModelObject().getType(); + var constaintsSupportType = asList(TYPE_NAME_STRING_ARRAY, TYPE_NAME_STRING) + .contains(type); + var hasTagset = FeatureDetailForm.this.getModelObject().getTagset() != null; + return constaintsSupportType && hasTagset; + })) // + .setOutputMarkupPlaceholderTag(true)); defaultOptionsContainer - .add(new CheckBox("hideUnconstraintFeature").setOutputMarkupPlaceholderTag(true)); - defaultOptionsContainer.add(new CheckBox("includeInHover") - .setOutputMarkupPlaceholderTag(true).add(LambdaBehavior.visibleWhen(() -> { - var layertype = FeatureDetailForm.this.getModelObject().getLayer().getType(); - // Currently not configurable for chains or relations - // TODO: technically it is possible - return !CHAIN_TYPE.equals(layertype) && !RELATION_TYPE.equals(layertype); - }))); + .add(new CheckBox("includeInHover").setOutputMarkupPlaceholderTag(true) // + .add(visibleWhen(() -> { + var layertype = FeatureDetailForm.this.getModelObject().getLayer() + .getType(); + // Currently not configurable for chains or relations + // TODO: technically it is possible + return !ChainLayerSupport.TYPE.equals(layertype) + && !RelationLayerSupport.TYPE.equals(layertype); + }))); add(featureType = new DropDownChoice("type") { @@ -180,24 +197,17 @@ protected void onModelChanged() asList(featureSupportRegistry.getFeatureType(getModelObject()))); } })); - featureType.add(new AjaxFormComponentUpdatingBehavior("change") - { - private static final long serialVersionUID = -2904306846882446294L; - - @Override - protected void onUpdate(AjaxRequestTarget aTarget) - { - aTarget.add(required); - aTarget.add(traitsContainer); - } - }); + featureType.add(new LambdaAjaxFormComponentUpdatingBehavior(CHANGE_EVENT, _target -> { + _target.add(required); + _target.add(traitsContainer); + })); // Processing the data in onAfterSubmit so the traits panel can use the // override onSubmit in its nested form and store the traits before // we clear the currently selected feature. add(new LambdaAjaxButton<>("save", this::actionSave).triggerAfterSubmit()); add(new LambdaAjaxButton<>("delete", this::actionDelete) - .add(enabledWhen(() -> isDeletable()))); + .add(enabledWhen(this::isDeletable))); // Set default form processing to false to avoid saving data add(new LambdaButton("cancel", this::actionCancel).setDefaultFormProcessing(false));