2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.element
;
11 import java
.util
.HashSet
;
18 public class CacheRelevanceHelper
{
20 protected Set
<ToggleableTextElement
> cacheDependencies
= new HashSet
<>();
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());
29 //add recursion for light dependencies
30 result
= result
.addCacheRelevance(cache
.cacheRelevance().getLight());
36 public void addDependsOnCache(ToggleableTextElement toggleElement
) {
37 if (toggleElement
!= null){
38 cacheDependencies
.add(toggleElement
);
43 * For hierarchical caching
45 public ToggleableTextElement
[] getDependenciesArray() {
46 return this.cacheDependencies
.toArray(new ToggleableTextElement
[0]);
49 public static void addDependsOnCacheForSubElements(AbstractFormSection
<?
> section
,
50 ToggleableTextElement toggleElement
) {
51 section
.getElements().stream()
52 .filter(x
-> x
instanceof ICacheRelevantFormElement
)
54 x
->((ICacheRelevantFormElement
)x
).addDependsOnCache(toggleElement
));
57 public static void updateCacheRelevanceForSubelements(AbstractFormSection
<?
> section
) {
58 updateCacheRelevanceForSubelements(section
.getElements());
61 public static void updateCacheRelevanceForSubelements(Set
<ICdmFormElement
> elements
) {
62 // System.out.print("setIrrelevant: " + this.getClass().getName());
63 // System.out.println("");
65 .filter(x
-> x
instanceof ICacheRelevantFormElement
)
67 x
->((ICacheRelevantFormElement
)x
).updateCacheRelevance());