Skip to content

Commit

Permalink
Merge pull request #3764 from inception-project/feature/3728-Allow-op…
Browse files Browse the repository at this point in the history
…ening-URL-feature-values-in-new-browser-window

#3728 - Allow opening URL feature values in new browser window
  • Loading branch information
reckart authored Jan 29, 2023
2 parents 8950631 + a7e64c9 commit 530811d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
<label wicket:for="value" wicket:enclosure="feature" class="feature-editor-label col-form-label">
<span wicket:id="feature"/>
<span class="float-end">
<span wicket:id="textIndicator"></span>
<span wicket:id="textIndicator"/>
</span>
<a wicket:id="openIri" class="float-end" target="_blank">
<i class="fas fa-external-link-alt"/>
</a>
</label>
<div class="feature-editor-value">
<input wicket:id="value" class="form-control col-sm-12"></input>
<input class="flex-content" wicket:id="value" type="text"/>
<div wicket:id="keyBindings" class="col-sm-12"/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,44 @@

import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.form.AbstractTextComponent;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.model.IModel;
import org.apache.wicket.validation.validator.UrlValidator;

import com.googlecode.wicket.kendo.ui.form.TextField;

import de.tudarmstadt.ukp.clarin.webanno.api.annotation.keybindings.KeyBindingsPanel;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormComponentUpdatingBehavior;
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;

public class InputFieldTextFeatureEditor
public class InputFieldStringFeatureEditor
extends TextFeatureEditorBase
{
private static final long serialVersionUID = 8686646370500180943L;

public InputFieldTextFeatureEditor(String aId, MarkupContainer aItem,
private ExternalLink openIri;
private UrlValidator urlValidator = new UrlValidator(new String[] { "http", "https" });

public InputFieldStringFeatureEditor(String aId, MarkupContainer aItem,
IModel<FeatureState> aModel, AnnotationActionHandler aHandler)
{
super(aId, aItem, aModel);

AnnotationFeature feat = getModelObject().feature;
StringFeatureTraits traits = readFeatureTraits(feat);

var featureValueAsString = aModel.map(FeatureState::getValue).map(Object::toString);

openIri = new ExternalLink("openIri", featureValueAsString);
openIri.add(visibleWhen(featureValueAsString.map(urlValidator::isValid)));
openIri.setOutputMarkupPlaceholderTag(true);
queue(openIri);

add(new KeyBindingsPanel("keyBindings", () -> traits.getKeyBindings(), aModel, aHandler)
// The key bindings are only visible when the label is also enabled, i.e. when the
// editor is used in a "normal" context and not e.g. in the keybindings
// editor is used in a "normal" context and not e.g. in the key bindings
// configuration panel
.add(visibleWhen(() -> getLabelComponent().isVisible())));
}
Expand All @@ -54,6 +67,11 @@ public InputFieldTextFeatureEditor(String aId, MarkupContainer aItem,
@Override
protected AbstractTextComponent createInputField()
{
return new TextField<>("value");

var textField = new TextField<>("value");
textField.add(new LambdaAjaxFormComponentUpdatingBehavior("change", t -> {
t.add(openIri);
}));
return textField;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public FeatureEditor createEditor(String aId, MarkupContainer aOwner,
}
else {
// Otherwise use a simple input field
return new InputFieldTextFeatureEditor(aId, aOwner, aFeatureStateModel, aHandler);
return new InputFieldStringFeatureEditor(aId, aOwner, aFeatureStateModel, aHandler);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<span wicket:id="iri" class="fas fa-info-circle"></span>
<button wicket:id="iri" class="btn btn-link p-0 text-reset"><i class="fas fa-info-circle"/></button>
</wicket:panel>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@ public String getModelObject()
{
return (String) getDefaultModelObject();
}

public IModel<String> getModel()
{
return (IModel<String>) getDefaultModel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
<span class="float-end">
<span wicket:id="disabledKBWarning"/>
</span>
<a wicket:id="openIri" class="float-end" target="_blank">
<i class="fas fa-external-link-alt"/>
</a>
</label>
<div class="feature-editor-value">
<div class="input-group">
<div class="input-group-text">
<span wicket:id="iriInfoBadge" class="me-2"/>
<a wicket:id="openIri" target="_blank">
<i class="fas fa-external-link-alt"></i>
</a>
<span wicket:id="iriInfoBadge"/>
</div>
<input class="flex-content" wicket:id="value" type="text"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.convert.IConverter;
import org.apache.wicket.util.string.StringValue;
import org.apache.wicket.validation.validator.UrlValidator;
import org.danekja.java.util.function.serializable.SerializableFunction;
import org.wicketstuff.event.annotation.OnEvent;

Expand Down Expand Up @@ -76,6 +77,7 @@ public class ConceptFeatureEditor
private Label description;
private IriInfoBadge iriBadge;
private ExternalLink openIriLink;
private UrlValidator urlValidator = new UrlValidator(new String[] { "http", "https" });

public ConceptFeatureEditor(String aId, MarkupContainer aItem, IModel<FeatureState> aModel,
IModel<AnnotatorState> aStateModel, AnnotationActionHandler aHandler)
Expand All @@ -89,7 +91,7 @@ public ConceptFeatureEditor(String aId, MarkupContainer aItem, IModel<FeatureSta

iriBadge = new IriInfoBadge("iriInfoBadge", iriModel);
iriBadge.setOutputMarkupPlaceholderTag(true);
iriBadge.add(visibleWhen(() -> isNotBlank(iriBadge.getModelObject())));
iriBadge.add(visibleWhen(iriBadge.getModel().map(urlValidator::isValid)));
add(iriBadge);

openIriLink = new ExternalLink("openIri", iriModel);
Expand Down

0 comments on commit 530811d

Please sign in to comment.