Project

General

Profile

Revision 7832ef53

ID7832ef53ffdcaf4c8df8cc70b7ffdea0c347fb1b
Parent 4db1bbe6
Child 8e85af8b

Added by Patrick Plitzner over 1 year ago

ref #7875 Performance optimization for term content provider

  • Load complete term hierarchy
  • always return true for vocabulary hasChildren()

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java
14 14

  
15 15
import org.eclipse.jface.viewers.TreeNodeContentProvider;
16 16

  
17
import eu.etaxonomy.cdm.api.service.ITermService;
18 17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20 18
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21 19
import eu.etaxonomy.cdm.persistence.dto.TermDto;
22 20
import eu.etaxonomy.taxeditor.store.CdmStore;
......
39 37
	public Object[] getChildren(Object parentElement) {
40 38
	    Collection<Object> children = new HashSet<>();
41 39
	    if(parentElement instanceof TermVocabulary){
42
	        children.addAll(CdmStore.getService(IVocabularyService.class).getTopLevelTerms(((TermVocabulary)parentElement).getId()));
43
	    } else {
44
	        Collection<Object> includes = new HashSet<>();
45
	        Collection<Object> generalizationOfs = new HashSet<>();
46
	        if (parentElement instanceof DefinedTermBase) {
47
	            includes = ((DefinedTermBase) parentElement).getIncludes();
48
	            generalizationOfs = ((DefinedTermBase) parentElement).getGeneralizationOf();
49
	        }
50
	        else if(parentElement instanceof TermDto){
51
	            includes.addAll(CdmStore.getService(ITermService.class).getIncludesAsUuidAndTitleCache((TermDto) parentElement));
52
	            generalizationOfs.addAll(CdmStore.getService(ITermService.class).getKindOfsAsUuidAndTitleCache((TermDto) parentElement));
53
	        }
54
	        children.addAll(includes);
55
	        children.addAll(generalizationOfs);
40
	        children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(((TermVocabulary)parentElement).getId()));
41
	    } else if(parentElement instanceof TermDto){
42
	            children.addAll(((TermDto) parentElement).getIncludes());
56 43
	    }
57 44
	    return children.toArray();
58 45
	}
59 46

  
60 47
	@Override
61 48
	public Object getParent(Object element) {
62
		if(element instanceof DefinedTermBase){
63
			DefinedTermBase definedTermBase = (DefinedTermBase)element;
64
			if (definedTermBase.getPartOf() != null) {
65
			    return definedTermBase.getPartOf();
66
			}else if (definedTermBase.getKindOf() != null) {
67
                return definedTermBase.getKindOf();
68
            } else {
69
			    return definedTermBase.getVocabulary();
70
			}
71
		}
72
		else if(element instanceof TermDto){
49
		if(element instanceof TermDto){
73 50
		    UUID partOfUuid = ((TermDto) element).getPartOfUuid();
74 51
		    if(partOfUuid==null){
75 52
		        return CdmStore.getService(IVocabularyService.class).load(((TermDto) element).getVocabularyUuid());
......
82 59

  
83 60
	@Override
84 61
	public boolean hasChildren(Object element) {
62
	    if(element instanceof TermVocabulary){
63
	        //performance optimization
64
	        return true;
65
	    }
85 66
		if (getChildren(element) != null){
86 67
			return getChildren(element).length > 0;
87 68
		}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)