Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5098 - Conditional feature option for integer features should not be offered #5103

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -108,17 +114,17 @@ public FeatureDetailForm(String id, IModel<AnnotationFeature> aFeature)
add(new TextArea<String>("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));
defaultOptionsContainer.add(new CheckBox("remember").setOutputMarkupPlaceholderTag(true));
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));
Expand All @@ -130,15 +136,26 @@ public FeatureDetailForm(String id, IModel<AnnotationFeature> 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<FeatureType>("type")
{
Expand Down Expand Up @@ -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));

Expand Down