Skip to content

Commit

Permalink
[25984] korrektur, wenn keine pref existiert, wird null als color (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksic28 authored and huthomas committed Dec 14, 2023
1 parent e367d7a commit 3021595
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ public LoadResourcesFunction(Browser browser, String name, IAgendaComposite agen

@Override
public Object function(Object[] arguments) {
Set<String> selectedResources = agendaComposite.getSelectedResources();
Set<String> selectedResources = agendaComposite.getSelectedResources();
String colorPrefs = ConfigServiceHolder.get().get(PreferenceConstants.AG_BEREICH_FARBEN, null);
Map<String, String> resourceColors = new HashMap<>();
String[] colorAssignments = colorPrefs.split(";");
for (String assignment : colorAssignments) {
String[] parts = assignment.split(":");
if (parts.length == 2) {
resourceColors.put(parts[0], parts[1]);
}
}
Set<Resource> _selectedResources = new LinkedHashSet<Resource>();
int order = 0;
for (String selectedResource : selectedResources) {
String color = resourceColors.getOrDefault(selectedResource, null);
_selectedResources.add(new Resource(selectedResource, selectedResource, order, color));
order++;
}
String json = gson.toJson(_selectedResources);
return json;
Map<String, String> resourceColors = parseColorPreferences(colorPrefs);
Set<Resource> _selectedResources = new LinkedHashSet<>();
int order = 0;
for (String selectedResource : selectedResources) {
String color = resourceColors.get(selectedResource);
_selectedResources.add(new Resource(selectedResource, selectedResource, order++, color));
}
return gson.toJson(_selectedResources);
}

private Map<String, String> parseColorPreferences(String colorPrefs) {
Map<String, String> resourceColors = new HashMap<>();
if (colorPrefs != null) {
for (String assignment : colorPrefs.split(";")) {
String[] parts = assignment.split(":");
if (parts.length == 2) {
resourceColors.put(parts[0], parts[1]);
}
}
}
return resourceColors;
}
private class Resource {

private class Resource {
private String id;
private String title;
@SuppressWarnings("unused")
Expand Down

0 comments on commit 3021595

Please sign in to comment.