Skip to content

Commit

Permalink
Merge pull request #4146 from inception-project/feature/4139-Reusable…
Browse files Browse the repository at this point in the history
…-popover-component-for-annotation-editors

#4139 - Reusable popover component for annotation editors
  • Loading branch information
reckart authored Aug 12, 2023
2 parents c2c0068 + 71a8a30 commit 37e55f0
Show file tree
Hide file tree
Showing 98 changed files with 7,703 additions and 7,118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.apache.uima.cas.CAS.TYPE_NAME_STRING_ARRAY;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -49,7 +48,8 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetail;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.adapter.IllegalFeatureValueException;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureEditor;
Expand Down Expand Up @@ -232,9 +232,9 @@ public String renderFeatureValue(AnnotationFeature aFeature, FeatureStructure aF
}

@Override
public List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
var results = new ArrayList<VLazyDetailResult>();
var results = new VLazyDetailGroup();
if (aValue instanceof Iterable) {
var values = (Iterable<?>) aValue;
for (var v : values) {
Expand All @@ -243,15 +243,15 @@ public List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Obj
var tag = schemaService.getTag(value, aFeature.getTagset());

if (tag.isEmpty()) {
results.add(new VLazyDetailResult(value, "Tag not in tagset"));
results.addDetail(new VLazyDetail(value, "Tag not in tagset"));
}

if (tag.map(t -> isNotBlank(t.getDescription())).orElse(false)) {
results.add(new VLazyDetailResult(value, tag.get().getDescription()));
results.addDetail(new VLazyDetail(value, tag.get().getDescription()));
}
}
}
}
return results;
return asList(results);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetail;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureEditor;
Expand Down Expand Up @@ -230,17 +231,18 @@ public boolean suppressAutoFocus(AnnotationFeature aFeature)
}

@Override
public List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
public List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
if (aValue instanceof String) {
var value = (String) aValue;
var tag = schemaService.getTag(value, aFeature.getTagset());
if (tag.isEmpty()) {
return asList(new VLazyDetailResult(value, "Tag not in tagset"));
return asList(new VLazyDetailGroup(new VLazyDetail(value, "Tag not in tagset")));
}

if (tag.map(t -> isNotBlank(t.getDescription())).orElse(false)) {
return asList(new VLazyDetailResult(value, tag.get().getDescription()));
return asList(
new VLazyDetailGroup(new VLazyDetail(value, tag.get().getDescription())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
import de.tudarmstadt.ukp.inception.rendering.vmodel.VCommentType;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VDocument;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetail;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureSupportRegistry;
import de.tudarmstadt.ukp.inception.schema.layer.LayerSupportRegistry;
Expand Down Expand Up @@ -251,7 +252,7 @@ public List<VObject> render(VDocument aVDocument, AnnotationFS aFS,
}

@Override
public List<VLazyDetailResult> lookupLazyDetails(CAS aCas, VID aVid, int aWindowBeginOffset,
public List<VLazyDetailGroup> lookupLazyDetails(CAS aCas, VID aVid, int aWindowBeginOffset,
int aWindowEndOffset)
{
if (!checkTypeSystem(aCas)) {
Expand All @@ -260,21 +261,19 @@ public List<VLazyDetailResult> lookupLazyDetails(CAS aCas, VID aVid, int aWindow

// FIXME Should also handle relations that are only partially visible using
// selectAnnotationsInWindow()
Map<Integer, Set<Integer>> relationLinks = getRelationLinks(aCas, aWindowBeginOffset,
aWindowEndOffset);
var relationLinks = getRelationLinks(aCas, aWindowBeginOffset, aWindowEndOffset);

// if this is a governor for more than one dependent, avoid duplicate yield
List<Integer> yieldDeps = new ArrayList<>();
var yieldDeps = new ArrayList<Integer>();

AnnotationFS fs = ICasUtil.selectByAddr(aCas, AnnotationFS.class, aVid.getId());
var fs = ICasUtil.selectByAddr(aCas, AnnotationFS.class, aVid.getId());

Optional<String> yield = renderYield(fs, relationLinks, yieldDeps);
var yield = renderYield(fs, relationLinks, yieldDeps);

List<VLazyDetailResult> details = super.lookupLazyDetails(aCas, aVid, aWindowBeginOffset,
aWindowEndOffset);
var details = super.lookupLazyDetails(aCas, aVid, aWindowBeginOffset, aWindowEndOffset);

if (yield.isPresent()) {
details.add(new VLazyDetailResult("Yield", yield.get()));
details.add(new VLazyDetailGroup(new VLazyDetail("Yield", yield.get())));
}

return details;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;

public interface AnnotationEditorExtension
Expand Down Expand Up @@ -79,8 +79,8 @@ default void generateContextMenuItems(List<IMenuItem> aItems)
// Do nothing by default
}

default List<VLazyDetailResult> lookupLazyDetails(SourceDocument aDocument, User aUser,
VID aVid, AnnotationFeature aFeature)
default List<VLazyDetailGroup> lookupLazyDetails(SourceDocument aDocument, User aUser, VID aVid,
AnnotationFeature aFeature)
{
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
* action, e.g. hovering the mouse over an annotation.
* </p>
*/
public class VLazyDetailResult
public class VLazyDetail
implements Serializable
{
private static final long serialVersionUID = -2371700263138292842L;

private final String label;
private final String value;

public VLazyDetailResult(String aLabel, String aValue)
public VLazyDetail(String aLabel, String aValue)
{
label = aLabel;
value = aValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Technische Universität Darmstadt under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Technische Universität Darmstadt
* licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.tudarmstadt.ukp.inception.rendering.vmodel;

import static java.util.Arrays.asList;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class VLazyDetailGroup
implements Serializable

{
private static final long serialVersionUID = -1750783154850087688L;

private final String title;

private List<VLazyDetail> details = new ArrayList<>();

public VLazyDetailGroup()
{
title = null;
}

public VLazyDetailGroup(VLazyDetail... aDetails)
{
title = null;
if (aDetails != null) {
details.addAll(asList(aDetails));
}
}

public VLazyDetailGroup(String aTitle)
{
title = aTitle;
}

public String getTitle()
{
return title;
}

public List<VLazyDetail> getDetails()
{
return details;
}

public void setDetails(List<VLazyDetail> aDetails)
{
details = aDetails;
}

public void addDetail(VLazyDetail aDetail)
{
details.add(aDetail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package de.tudarmstadt.ukp.inception.rendering;

import static de.tudarmstadt.ukp.clarin.webanno.support.uima.ICasUtil.getAddr;
import static de.tudarmstadt.ukp.clarin.webanno.support.uima.ICasUtil.selectByAddr;
import static de.tudarmstadt.ukp.inception.schema.validation.ValidationUtils.isRequiredFeatureMissing;
import static org.apache.commons.lang3.StringUtils.defaultString;
Expand All @@ -38,7 +37,8 @@
import de.tudarmstadt.ukp.inception.rendering.vmodel.VCommentType;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VDocument;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VID;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetail;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VObject;
import de.tudarmstadt.ukp.inception.schema.adapter.TypeAdapter;
import de.tudarmstadt.ukp.inception.schema.feature.FeatureSupportRegistry;
Expand Down Expand Up @@ -103,26 +103,26 @@ default void renderRequiredFeatureErrors(List<AnnotationFeature> aFeatures,
}

if (isRequiredFeatureMissing(f, aFS)) {
aResponse.add(new VComment(new VID(getAddr(aFS)), VCommentType.ERROR,
aResponse.add(new VComment(VID.of(aFS), VCommentType.ERROR,
"Required feature [" + f.getName() + "] not set."));
}
}
}

default List<VLazyDetailResult> lookupLazyDetails(CAS aCas, VID aVid, int windowBeginOffset,
default List<VLazyDetailGroup> lookupLazyDetails(CAS aCas, VID aVid, int windowBeginOffset,
int windowEndOffset)
{
var fsr = getFeatureSupportRegistry();

var aFs = selectByAddr(aCas, AnnotationFS.class, aVid.getId());

var details = new ArrayList<VLazyDetailResult>();
var details = new ArrayList<VLazyDetailGroup>();
generateLazyDetailsForFeaturesIncludedInHover(fsr, details, aFs);
return details;
}

default void generateLazyDetailsForFeaturesIncludedInHover(FeatureSupportRegistry fsr,
List<VLazyDetailResult> details, AnnotationFS aFs)
List<VLazyDetailGroup> details, AnnotationFS aFs)
{
for (var feature : getTypeAdapter().listFeatures()) {
if (!feature.isEnabled() || !feature.isIncludeInHover()
Expand All @@ -133,7 +133,9 @@ default void generateLazyDetailsForFeaturesIncludedInHover(FeatureSupportRegistr
String text = defaultString(
fsr.findExtension(feature).orElseThrow().renderFeatureValue(feature, aFs));

details.add(new VLazyDetailResult(feature.getName(), text));
var group = new VLazyDetailGroup();
group.addDetail(new VLazyDetail(feature.getName(), text));
details.add(group);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import de.tudarmstadt.ukp.inception.editor.action.AnnotationActionHandler;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.rendering.editorstate.FeatureState;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailResult;
import de.tudarmstadt.ukp.inception.rendering.vmodel.VLazyDetailGroup;
import de.tudarmstadt.ukp.inception.schema.adapter.AnnotationException;
import de.tudarmstadt.ukp.inception.schema.adapter.TypeAdapter;

Expand Down Expand Up @@ -234,7 +234,7 @@ default String renderFeatureValue(AnnotationFeature aFeature, String aLabel)
return aLabel;
}

default List<VLazyDetailResult> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
default List<VLazyDetailGroup> lookupLazyDetails(AnnotationFeature aFeature, Object aValue)
{
return Collections.emptyList();
}
Expand Down
Loading

0 comments on commit 37e55f0

Please sign in to comment.