Revision 0dcf41f3
Added by Patrick Plitzner almost 5 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.definedterm; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.Collection; |
13 |
import java.util.HashMap; |
|
12 | 14 |
import java.util.HashSet; |
15 |
import java.util.Map; |
|
13 | 16 |
|
14 | 17 |
import org.eclipse.jface.viewers.TreeNodeContentProvider; |
15 | 18 |
|
... | ... | |
26 | 29 |
*/ |
27 | 30 |
public class TermDtoContentProvider extends TreeNodeContentProvider { |
28 | 31 |
|
29 |
@Override |
|
32 |
private Map<TermVocabularyDto, Collection<TermDto>> vocabularyToChildTermMap = new HashMap<>(); |
|
33 |
|
|
34 |
@Override |
|
30 | 35 |
public Object[] getElements(Object inputElement) { |
31 | 36 |
Collection<TermVocabularyDto> inputElements = (Collection<TermVocabularyDto>) inputElement; |
32 | 37 |
return inputElements.toArray(); |
... | ... | |
36 | 41 |
public Object[] getChildren(Object parentElement) { |
37 | 42 |
Collection<TermDto> children = new HashSet<>(); |
38 | 43 |
if(parentElement instanceof TermVocabularyDto){ |
39 |
children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy((TermVocabularyDto)parentElement));
|
|
44 |
children.addAll(getChildTerms((TermVocabularyDto)parentElement));
|
|
40 | 45 |
} else if(parentElement instanceof TermDto){ |
41 | 46 |
if(((TermDto) parentElement).getIncludes()!=null){ |
42 | 47 |
children.addAll(((TermDto) parentElement).getIncludes()); |
... | ... | |
82 | 87 |
return false; |
83 | 88 |
} |
84 | 89 |
|
90 |
public Collection<? extends TermDto> getChildTerms(TermVocabularyDto voc) { |
|
91 |
Collection<TermDto> children = vocabularyToChildTermMap.get(voc); |
|
92 |
if(children==null){ |
|
93 |
children = new ArrayList<>(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(voc)); |
|
94 |
vocabularyToChildTermMap.put(voc, children); |
|
95 |
} |
|
96 |
return children; |
|
97 |
} |
|
98 |
|
|
99 |
public void removeVocabularyFromCache(TermVocabularyDto voc){ |
|
100 |
vocabularyToChildTermMap.remove(voc); |
|
101 |
} |
|
102 |
|
|
85 | 103 |
} |
Also available in: Unified diff
ref #8263 Cache child terms in content provider