Search in sources :

Example 1 with ColoringStrategyType

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType in project webanno by webanno.

the class UserPreferencesServiceImpl method loadLegacyPreferences.

private AnnotationPreference loadLegacyPreferences(Project aProject, String aUsername, Mode aMode) {
    AnnotationPreference preference = new AnnotationPreference();
    BeanWrapper wrapper = new BeanWrapperImpl(preference);
    // get annotation preference from file system
    try {
        Properties props = loadLegacyPreferencesFile(aUsername, aProject);
        for (Entry<Object, Object> entry : props.entrySet()) {
            String property = entry.getKey().toString();
            int index = property.indexOf(".");
            String propertyName = property.substring(index + 1);
            String mode = property.substring(0, index);
            if (wrapper.isWritableProperty(propertyName) && mode.equals(aMode.getName())) {
                if (AnnotationPreference.class.getDeclaredField(propertyName).getGenericType() instanceof ParameterizedType) {
                    if (entry.getValue().toString().startsWith("[")) {
                        // its a list
                        List<String> value = Arrays.asList(StringUtils.replaceChars(entry.getValue().toString(), "[]", "").split(","));
                        if (!value.get(0).equals("")) {
                            wrapper.setPropertyValue(propertyName, value);
                        }
                    } else if (entry.getValue().toString().startsWith("{")) {
                        // its a map
                        String s = StringUtils.replaceChars(entry.getValue().toString(), "{}", "");
                        Map<String, String> value = Arrays.stream(s.split(",")).map(x -> x.split("=")).collect(Collectors.toMap(x -> x[0], x -> x[1]));
                        wrapper.setPropertyValue(propertyName, value);
                    }
                } else {
                    wrapper.setPropertyValue(propertyName, entry.getValue());
                }
            }
        }
    }// no preference found
     catch (Exception e) {
        preference.setHiddenAnnotationLayerIds(new HashSet<>());
        preference.setWindowSize(defaultPreferences.getPageSize());
        preference.setScrollPage(defaultPreferences.isAutoScroll());
        preference.setRememberLayer(defaultPreferences.isRememberLayer());
    }
    // Get color preferences for each layer, init with default if not found
    Map<Long, ColoringStrategyType> colorPerLayer = preference.getColorPerLayer();
    if (colorPerLayer == null) {
        colorPerLayer = new HashMap<>();
        preference.setColorPerLayer(colorPerLayer);
    }
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!colorPerLayer.containsKey(layer.getId())) {
            colorPerLayer.put(layer.getId(), coloringService.getBestInitialStrategy(layer, preference));
        }
    }
    return preference;
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) RepositoryProperties(de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties) Properties(java.util.Properties) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) IOException(java.io.IOException) ParameterizedType(java.lang.reflect.ParameterizedType) BeanWrapper(org.springframework.beans.BeanWrapper) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType)

Example 2 with ColoringStrategyType

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType in project webanno by webanno.

the class AnnotationPreferencesDialogContent method createLayerContainer.

private ListView<AnnotationLayer> createLayerContainer() {
    return new ListView<AnnotationLayer>("annotationLayers") {

        private static final long serialVersionUID = -4040731191748923013L;

        @Override
        protected void populateItem(ListItem<AnnotationLayer> aItem) {
            Preferences prefs = form.getModelObject();
            AnnotationLayer layer = aItem.getModelObject();
            Set<Long> hiddenLayerIds = stateModel.getObject().getPreferences().getHiddenAnnotationLayerIds();
            // add visibility checkbox
            CheckBox layerVisible = new CheckBox("annotationLayerActive", Model.of(!hiddenLayerIds.contains(layer.getId())));
            layerVisible.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target -> {
                if (!layerVisible.getModelObject()) {
                    hiddenLayerIds.add(layer.getId());
                } else {
                    hiddenLayerIds.remove(layer.getId());
                }
            }));
            aItem.add(layerVisible);
            // add coloring strategy choice
            DropDownChoice<ColoringStrategyType> layerColor = new BootstrapSelect<>("layercoloring");
            layerColor.setModel(Model.of(prefs.colorPerLayer.get(layer.getId())));
            layerColor.setChoiceRenderer(new ChoiceRenderer<>("descriptiveName"));
            layerColor.setChoices(asList(ColoringStrategyType.values()));
            layerColor.add(new LambdaAjaxFormComponentUpdatingBehavior("change", _target -> prefs.colorPerLayer.put(layer.getId(), layerColor.getModelObject())));
            aItem.add(layerColor);
            // add label
            aItem.add(new Label("annotationLayerDesc", layer.getUiName()));
        }
    };
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) ProjectService(de.tudarmstadt.ukp.clarin.webanno.api.ProjectService) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType) LoggerFactory(org.slf4j.LoggerFactory) CheckBox(org.apache.wicket.markup.html.form.CheckBox) CompoundPropertyModel(org.apache.wicket.model.CompoundPropertyModel) ANNOTATION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION) AnnotationSchemaService(de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) LambdaBehavior.visibleWhen(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaBehavior.visibleWhen) Pair(org.apache.commons.lang3.tuple.Pair) AnnotationPreference(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) Label(org.apache.wicket.markup.html.basic.Label) NumberTextField(org.apache.wicket.markup.html.form.NumberTextField) CURATION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.CURATION) Logger(org.slf4j.Logger) ListItem(org.apache.wicket.markup.html.list.ListItem) LambdaAjaxFormComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormComponentUpdatingBehavior) Model(org.apache.wicket.model.Model) UserDao(de.tudarmstadt.ukp.clarin.webanno.security.UserDao) Set(java.util.Set) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) ReadonlyColoringBehaviour(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ReadonlyColoringBehaviour) IOException(java.io.IOException) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) Serializable(java.io.Serializable) CORRECTION(de.tudarmstadt.ukp.clarin.webanno.model.Mode.CORRECTION) Panel(org.apache.wicket.markup.html.panel.Panel) List(java.util.List) AnnotationEditorFactory(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory) PreferencesUtil(de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.PreferencesUtil) LambdaAjaxLink(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxLink) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) CHAIN_TYPE(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE) AnnotationEditorRegistry(de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorRegistry) Label(org.apache.wicket.markup.html.basic.Label) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) LambdaAjaxFormComponentUpdatingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxFormComponentUpdatingBehavior) ListView(org.apache.wicket.markup.html.list.ListView) CheckBox(org.apache.wicket.markup.html.form.CheckBox) ListItem(org.apache.wicket.markup.html.list.ListItem) BootstrapSelect(de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect) ColoringStrategyType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType)

Aggregations

ColoringStrategyType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ColoringStrategyType)2 AnnotationPreference (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotationPreference)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 IOException (java.io.IOException)2 Map (java.util.Map)2 BootstrapSelect (de.agilecoders.wicket.extensions.markup.html.bootstrap.form.select.BootstrapSelect)1 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)1 ProjectService (de.tudarmstadt.ukp.clarin.webanno.api.ProjectService)1 RepositoryProperties (de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties)1 CHAIN_TYPE (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CHAIN_TYPE)1 AnnotationEditorFactory (de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorFactory)1 AnnotationEditorRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.AnnotationEditorRegistry)1 ReadonlyColoringBehaviour (de.tudarmstadt.ukp.clarin.webanno.api.annotation.coloring.ReadonlyColoringBehaviour)1 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 PreferencesUtil (de.tudarmstadt.ukp.clarin.webanno.api.annotation.page.PreferencesUtil)1 ANNOTATION (de.tudarmstadt.ukp.clarin.webanno.model.Mode.ANNOTATION)1 CORRECTION (de.tudarmstadt.ukp.clarin.webanno.model.Mode.CORRECTION)1 CURATION (de.tudarmstadt.ukp.clarin.webanno.model.Mode.CURATION)1 UserDao (de.tudarmstadt.ukp.clarin.webanno.security.UserDao)1 LambdaAjaxButton (de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton)1