Skip to content

Commit

Permalink
#4583 - Ability to configure layer visibility via a sidebar
Browse files Browse the repository at this point in the history
- Added the sidebar
- Started also saving some legacy preferences in the new preferences system so that eventually we may get away from the old preferences file
- Bit of cleaning up here and there
  • Loading branch information
reckart committed Mar 3, 2024
1 parent b9c65a6 commit 1449fe1
Show file tree
Hide file tree
Showing 34 changed files with 677 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.wicket.Component;
import org.apache.wicket.model.IModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;

import de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasProvider;
import de.tudarmstadt.ukp.clarin.webanno.model.Project;
Expand All @@ -37,6 +38,7 @@
* {@link ActiveLearningAutoConfiguration#activeLearningSidebarFactory}.
* </p>
*/
@Order(4000)
public class ActiveLearningSidebarFactory
extends AnnotationSidebarFactory_ImplBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import static de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategyType.GRAY;
import static de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategyType.LEGACY;
import static de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategyType.STATIC_PASTELLE;
import static de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringBehaviour.NORMAL;
import static de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringStrategy.NORMAL;
import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.SPAN_TYPE;
import static java.lang.Integer.MAX_VALUE;
import static java.util.Arrays.asList;
Expand All @@ -50,7 +50,7 @@
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringService;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategy;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategyType;
import de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringBehaviour;
import de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringStrategy;
import de.tudarmstadt.ukp.inception.rendering.editorstate.ColoringPreferences;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.api.event.LayerConfigurationChangedEvent;
Expand Down Expand Up @@ -85,7 +85,7 @@ public ColoringStrategy getStrategy(AnnotationLayer aLayer, ColoringPreferences
Map<String[], Queue<String>> aColorQueues)
{
ColoringStrategyType t = aPreferences.getColorPerLayer().get(aLayer.getId());
ReadonlyColoringBehaviour rt = aPreferences.getReadonlyLayerColoringBehaviour();
ReadonlyColoringStrategy rt = aPreferences.getReadonlyLayerColoringBehaviour();

if (aLayer.isReadonly() && rt != NORMAL) {
t = rt.getColoringStrategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.PreRenderer;
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.PreRendererImpl;
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.RenderNotificationRenderStep;
import de.tudarmstadt.ukp.clarin.webanno.security.UserDao;
import de.tudarmstadt.ukp.inception.documents.api.RepositoryProperties;
import de.tudarmstadt.ukp.inception.preferences.PreferencesService;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringService;
Expand Down Expand Up @@ -89,10 +90,10 @@ public UserPreferencesService userPreferencesService(
AnnotationSchemaService aAnnotationService, RepositoryProperties aRepositoryProperties,
ColoringService aColoringService,
AnnotationSchemaProperties aAnnotationEditorProperties,
PreferencesService aPreferencesService)
PreferencesService aPreferencesService, UserDao aUserService)
{
return new UserPreferencesServiceImpl(aDefaultPreferences, aAnnotationService,
aRepositoryProperties, aColoringService, aAnnotationEditorProperties,
aPreferencesService);
aPreferencesService, aUserService);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.AnnotationEditorState.KEY_EDITOR_STATE;
import static de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION;
import static de.tudarmstadt.ukp.clarin.webanno.model.Mode.CURATION;
import static de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference.FONT_ZOOM_MAX;
import static de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference.FONT_ZOOM_MIN;
import static de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference.SIDEBAR_SIZE_MAX;
import static de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference.SIDEBAR_SIZE_MIN;
import static de.tudarmstadt.ukp.inception.support.WebAnnoConst.CHAIN_TYPE;
Expand All @@ -30,10 +32,10 @@

import java.io.IOException;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Pair;
Expand All @@ -54,16 +56,14 @@
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;

import de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.AnnotationEditorState;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.security.UserDao;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorFactory;
import de.tudarmstadt.ukp.inception.editor.AnnotationEditorRegistry;
import de.tudarmstadt.ukp.inception.preferences.PreferencesService;
import de.tudarmstadt.ukp.inception.project.api.ProjectService;
import de.tudarmstadt.ukp.inception.rendering.coloring.ColoringStrategyType;
import de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringBehaviour;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotationPreference;
import de.tudarmstadt.ukp.inception.rendering.coloring.ReadonlyColoringStrategy;
import de.tudarmstadt.ukp.inception.rendering.editorstate.AnnotatorState;
import de.tudarmstadt.ukp.inception.schema.api.AnnotationSchemaService;
import de.tudarmstadt.ukp.inception.schema.api.config.AnnotationSchemaProperties;
Expand All @@ -80,7 +80,7 @@ public class AnnotationPreferencesDialogContent
{
private static final long serialVersionUID = -2102136855109258306L;

private static final Logger LOG = getLogger(AnnotationPreferencesDialogContent.class);
private static final Logger LOG = getLogger(MethodHandles.lookup().lookupClass());

private @SpringBean AnnotationSchemaService annotationService;
private @SpringBean ProjectService projectService;
Expand All @@ -105,35 +105,35 @@ public AnnotationPreferencesDialogContent(String aId, IModel<AnnotatorState> aMo
editorChoices = getEditorChoices();
onChangeAction = aOnChangeAction;

form = new Form<>("form", new CompoundPropertyModel<>(loadModel(stateModel.getObject())));
form = new Form<>("form", new CompoundPropertyModel<>(loadPreferences(stateModel.getObject())));

NumberTextField<Integer> windowSizeField = new NumberTextField<>("windowSize");
var windowSizeField = new NumberTextField<Integer>("windowSize");
windowSizeField.setType(Integer.class);
windowSizeField.setMinimum(1);
form.add(windowSizeField);

NumberTextField<Integer> sidebarSizeLeftField = new NumberTextField<>("sidebarSizeLeft");
var sidebarSizeLeftField = new NumberTextField<Integer>("sidebarSizeLeft");
sidebarSizeLeftField.setType(Integer.class);
sidebarSizeLeftField.setMinimum(SIDEBAR_SIZE_MIN);
sidebarSizeLeftField.setMaximum(SIDEBAR_SIZE_MAX);
form.add(sidebarSizeLeftField);

NumberTextField<Integer> sidebarSizeRightField = new NumberTextField<>("sidebarSizeRight");
var sidebarSizeRightField = new NumberTextField<Integer>("sidebarSizeRight");
sidebarSizeRightField.setType(Integer.class);
sidebarSizeRightField.setMinimum(SIDEBAR_SIZE_MIN);
sidebarSizeRightField.setMaximum(SIDEBAR_SIZE_MAX);
form.add(sidebarSizeRightField);

NumberTextField<Integer> fontZoomField = new NumberTextField<>("fontZoom");
var fontZoomField = new NumberTextField<Integer>("fontZoom");
fontZoomField.setType(Integer.class);
fontZoomField.setMinimum(AnnotationPreference.FONT_ZOOM_MIN);
fontZoomField.setMaximum(AnnotationPreference.FONT_ZOOM_MAX);
fontZoomField.setMinimum(FONT_ZOOM_MIN);
fontZoomField.setMaximum(FONT_ZOOM_MAX);
form.add(fontZoomField);

AnnotationEditorState state = preferencesService
.loadDefaultTraitsForProject(KEY_EDITOR_STATE, stateModel.getObject().getProject());
var state = preferencesService.loadDefaultTraitsForProject(KEY_EDITOR_STATE,
stateModel.getObject().getProject());

DropDownChoice<Pair<String, String>> editor = new DropDownChoice<>("editor");
var editor = new DropDownChoice<Pair<String, String>>("editor");
editor.setChoiceRenderer(new ChoiceRenderer<>("value"));
editor.setChoices(editorChoices);
editor.add(
Expand All @@ -145,19 +145,19 @@ public AnnotationPreferencesDialogContent(String aId, IModel<AnnotatorState> aMo
form.add(createLayerContainer());

// Add a check box to enable/disable automatic page navigations while annotating
CheckBox scrollCheckBox = new CheckBox("scrollPage");
var scrollCheckBox = new CheckBox("scrollPage");
scrollCheckBox.setOutputMarkupId(true);
form.add(scrollCheckBox);

// Add a check box to enable/disable arc collapsing
CheckBox collapseCheckBox = new CheckBox("collapseArcs");
var collapseCheckBox = new CheckBox("collapseArcs");
collapseCheckBox.setOutputMarkupId(true);
form.add(collapseCheckBox);

// Add global read-only coloring strategy combo box
DropDownChoice<ReadonlyColoringBehaviour> readOnlyColor = new DropDownChoice<>(
var readOnlyColor = new DropDownChoice<ReadonlyColoringStrategy>(
"readonlyLayerColoringBehaviour");
readOnlyColor.setChoices(asList(ReadonlyColoringBehaviour.values()));
readOnlyColor.setChoices(asList(ReadonlyColoringStrategy.values()));
readOnlyColor.setChoiceRenderer(new ChoiceRenderer<>("descriptiveName"));
form.add(readOnlyColor);

Expand All @@ -180,10 +180,10 @@ private List<Pair<String, String>> getEditorChoices()
private void actionSave(AjaxRequestTarget aTarget, Form<Preferences> aForm)
{
try {
AnnotatorState state = stateModel.getObject();
Preferences model = form.getModelObject();
var state = stateModel.getObject();
var model = form.getModelObject();

AnnotationPreference prefs = state.getPreferences();
var prefs = state.getPreferences();
prefs.setScrollPage(model.scrollPage);
prefs.setWindowSize(model.windowSize);
prefs.setSidebarSizeLeft(model.sidebarSizeLeft);
Expand All @@ -203,7 +203,7 @@ private void actionSave(AjaxRequestTarget aTarget, Form<Preferences> aForm)
// layers
state.refreshSelectableLayers(annotationEditorProperties::isLayerBlocked);

userPreferencesService.savePreference(state, userDao.getCurrentUsername());
userPreferencesService.savePreferences(state, userDao.getCurrentUsername());
}
catch (IOException e) {
error("Preference file not found");
Expand All @@ -219,12 +219,12 @@ private void actionCancel(AjaxRequestTarget aTarget)
findParent(ModalDialog.class).close(aTarget);
}

private Preferences loadModel(AnnotatorState state)
private Preferences loadPreferences(AnnotatorState aState)
{
AnnotationPreference prefs = state.getPreferences();
var prefs = aState.getPreferences();

// Import current settings from the annotator
Preferences model = new Preferences();
var model = new Preferences();
model.windowSize = Math.max(prefs.getWindowSize(), 1);
model.sidebarSizeLeft = prefs.getSidebarSizeLeft();
model.sidebarSizeRight = prefs.getSidebarSizeRight();
Expand All @@ -235,20 +235,20 @@ private Preferences loadModel(AnnotatorState state)
model.collapseArcs = prefs.isCollapseArcs();

model.editor = editorChoices.stream().filter(
editor -> Objects.equals(editor.getKey(), state.getPreferences().getEditor()))
editor -> Objects.equals(editor.getKey(), aState.getPreferences().getEditor()))
.findFirst().orElseGet(() -> {
AnnotationEditorFactory editorFactory = annotationEditorRegistry
.getDefaultEditorFactory();
return Pair.of(editorFactory.getBeanName(), editorFactory.getDisplayName());
});

model.annotationLayers = annotationService.listAnnotationLayer(state.getProject()).stream()
model.annotationLayers = annotationService.listAnnotationLayer(aState.getProject()).stream()
// hide disabled Layers
.filter(layer -> layer.isEnabled())
// hide blocked layers
.filter(layer -> !annotationEditorProperties.isLayerBlocked(layer))
.filter(layer -> !(layer.getType().equals(CHAIN_TYPE)
&& CURATION == state.getMode()))
&& CURATION == aState.getMode()))
.collect(Collectors.toList());

return model;
Expand All @@ -263,13 +263,13 @@ private ListView<AnnotationLayer> createLayerContainer()
@Override
protected void populateItem(ListItem<AnnotationLayer> aItem)
{
Preferences prefs = form.getModelObject();
AnnotationLayer layer = aItem.getModelObject();
Set<Long> hiddenLayerIds = stateModel.getObject().getPreferences()
var prefs = form.getModelObject();
var layer = aItem.getModelObject();
var hiddenLayerIds = stateModel.getObject().getPreferences()
.getHiddenAnnotationLayerIds();

// add visibility checkbox
CheckBox layerVisible = new CheckBox("annotationLayerActive",
var layerVisible = new CheckBox("annotationLayerActive",
Model.of(!hiddenLayerIds.contains(layer.getId())));

layerVisible.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target -> {
Expand All @@ -283,8 +283,7 @@ protected void populateItem(ListItem<AnnotationLayer> aItem)
aItem.add(layerVisible);

// add coloring strategy choice
DropDownChoice<ColoringStrategyType> layerColor = new DropDownChoice<>(
"layercoloring");
var layerColor = new DropDownChoice<ColoringStrategyType>("layercoloring");
layerColor.setModel(Model.of(prefs.colorPerLayer.get(layer.getId())));
layerColor.setChoiceRenderer(new ChoiceRenderer<>("descriptiveName"));
layerColor.setChoices(asList(ColoringStrategyType.values()));
Expand Down Expand Up @@ -338,7 +337,7 @@ private static class Preferences
private int fontZoom;
private boolean scrollPage;
private List<AnnotationLayer> annotationLayers;
private ReadonlyColoringBehaviour readonlyLayerColoringBehaviour;
private ReadonlyColoringStrategy readonlyLayerColoringBehaviour;
private Map<Long, ColoringStrategyType> colorPerLayer;
private boolean collapseArcs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface UserPreferencesService
AnnotationPreference loadPreferences(Project aProject, String aUsername, Mode aMode)
throws IOException;

void savePreference(AnnotatorState aState, String aUsername) throws IOException;
void savePreferences(AnnotatorState aState, String aUsername) throws IOException;

void savePreferences(Project aProject, String aUsername, Mode aMode, AnnotationPreference aPref)
throws IOException;
Expand Down
Loading

0 comments on commit 1449fe1

Please sign in to comment.