1
|
/**
|
2
|
* Copyright (C) 2021 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.ui.element;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
/**
|
15
|
* @author a.mueller
|
16
|
* @date 22.01.2021
|
17
|
*/
|
18
|
public class CacheRelevanceHelper {
|
19
|
|
20
|
protected Set<ToggleableTextElement> cacheDependencies = new HashSet<>();
|
21
|
|
22
|
public CacheRelevance cacheRelevance() {
|
23
|
CacheRelevance result = CacheRelevance.NONE;
|
24
|
for (ToggleableTextElement cache : this.cacheDependencies){
|
25
|
if (cache != null){ //null should not happen anymore but just in case
|
26
|
if (cache.getState()){
|
27
|
result = result.addCacheRelevance(cache.getRelevance());
|
28
|
}
|
29
|
//add recursion for light dependencies
|
30
|
result = result.addCacheRelevance(cache.cacheRelevance().getLight());
|
31
|
}
|
32
|
}
|
33
|
return result;
|
34
|
}
|
35
|
|
36
|
public void addDependsOnCache(ToggleableTextElement toggleElement) {
|
37
|
if (toggleElement != null){
|
38
|
cacheDependencies.add(toggleElement);
|
39
|
}
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* For hierarchical caching
|
44
|
*/
|
45
|
public ToggleableTextElement[] getDependenciesArray() {
|
46
|
return this.cacheDependencies.toArray(new ToggleableTextElement[0]);
|
47
|
}
|
48
|
|
49
|
public static void addDependsOnCacheForSubElements(AbstractFormSection<?> section,
|
50
|
ToggleableTextElement toggleElement) {
|
51
|
section.getElements().stream()
|
52
|
.filter(x -> x instanceof ICacheRelevantFormElement)
|
53
|
.forEach(
|
54
|
x->((ICacheRelevantFormElement)x).addDependsOnCache(toggleElement));
|
55
|
}
|
56
|
|
57
|
public static void updateCacheRelevanceForSubelements(AbstractFormSection<?> section) {
|
58
|
updateCacheRelevanceForSubelements(section.getElements());
|
59
|
}
|
60
|
|
61
|
public static void updateCacheRelevanceForSubelements(Set<ICdmFormElement> elements) {
|
62
|
// System.out.print("setIrrelevant: " + this.getClass().getName());
|
63
|
// System.out.println("");
|
64
|
elements.stream()
|
65
|
.filter(x -> x instanceof ICacheRelevantFormElement)
|
66
|
.forEach(
|
67
|
x->((ICacheRelevantFormElement)x).updateCacheRelevance());
|
68
|
|
69
|
}
|
70
|
|
71
|
|
72
|
}
|