Project

General

Profile

« Previous | Next » 

Revision 0dcf41f3

Added by Patrick Plitzner about 3 years ago

ref #8263 Cache child terms in content provider

View differences:

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
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java
96 96

  
97 97
    private Set<TermBase> changedTerms = new HashSet<>();
98 98

  
99
    private TermDtoContentProvider contentProvider;
100

  
99 101
	@Inject
100 102
	public DefinedTermEditorE4() {
101 103
	    CdmStore.getContextManager().addContextListener(this);
......
120 122
	    parent.setLayout(layout);
121 123
	    viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
122 124
	    viewer.getControl().setLayoutData(LayoutConstants.FILL());
123
	    viewer.setContentProvider(new TermDtoContentProvider());
125
	    contentProvider = new TermDtoContentProvider();
126
        viewer.setContentProvider(contentProvider);
124 127
	    viewer.setLabelProvider(new TermDtoLabelProvider());
125 128
	    viewer.setComparator(new DefinedTermSorter());
126 129

  
......
148 151
	    if(objectAffectedByOperation instanceof Collection){
149 152
	        for (Object o : (Collection<?>)objectAffectedByOperation) {
150 153
                if(o instanceof TermVocabularyDto){
154
                    contentProvider.removeVocabularyFromCache((TermVocabularyDto) o);
151 155
                    viewer.refresh(o);
152 156
                }
153 157
                else if(o instanceof TermDto){
158
                    contentProvider.removeVocabularyFromCache(((TermDto) o).getVocabularyDto());
154 159
                    viewer.refresh(((TermDto) o).getVocabularyDto());
155 160
                    viewer.refresh(o);
156 161
                    itemsToSelect.add((TermDto) o);
......
158 163
            }
159 164
	    }
160 165
	    if(objectAffectedByOperation instanceof TermVocabularyDto){
166
	        contentProvider.removeVocabularyFromCache((TermVocabularyDto) objectAffectedByOperation);
161 167
	        viewer.refresh();
162 168
	        itemsToSelect.add((AbstractTermDto) objectAffectedByOperation);
163 169
	    }
164 170
	    else if(objectAffectedByOperation instanceof TermDto){
165 171
	        TermDto termDto = (TermDto) objectAffectedByOperation;
166 172
            itemsToSelect.add(termDto);
173
            contentProvider.removeVocabularyFromCache(termDto.getVocabularyDto());
167 174
	        viewer.refresh(termDto.getVocabularyDto());
168 175
	    }
169 176
	    else{

Also available in: Unified diff