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;
}
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()));
}
};
}
Aggregations