Project

General

Profile

Download (2.84 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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.editor.definedterm;
10

    
11
import java.util.Collection;
12
import java.util.HashSet;
13

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

    
16
import eu.etaxonomy.cdm.api.service.IVocabularyService;
17
import eu.etaxonomy.cdm.persistence.dto.TermDto;
18
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
19
import eu.etaxonomy.taxeditor.store.CdmStore;
20

    
21
/**
22
 *
23
 * @author pplitzner
24
 * @since Oct 29, 2018
25
 *
26
 */
27
public class TermDtoContentProvider extends TreeNodeContentProvider {
28

    
29
	@Override
30
	public Object[] getElements(Object inputElement) {
31
		Collection<TermVocabularyDto> inputElements = (Collection<TermVocabularyDto>) inputElement;
32
		return inputElements.toArray();
33
	}
34

    
35
	@Override
36
	public Object[] getChildren(Object parentElement) {
37
	    Collection<TermDto> children = new HashSet<>();
38
	    if(parentElement instanceof TermVocabularyDto){
39
	        children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(((TermVocabularyDto)parentElement).getUuid()));
40
	        // FIXME this is only temporarily done on the taxeditor side for the hotfix
41
	        // the cdmlib service method already sets the vocabulary DTO but cdmlib is not released with this hotfix
42
	        children.forEach(child->child.setVocabularyDto((TermVocabularyDto) parentElement));
43
	    } else if(parentElement instanceof TermDto){
44
	            if(((TermDto) parentElement).getIncludes()!=null){
45
	                children.addAll(((TermDto) parentElement).getIncludes());
46
	            }
47
                if(((TermDto) parentElement).getGeneralizationOf()!=null){
48
                    children.addAll(((TermDto) parentElement).getGeneralizationOf());
49
                }
50
	    }
51
	    return children.toArray();
52
	}
53

    
54
	@Override
55
	public Object getParent(Object element) {
56
		if(element instanceof TermDto){
57
		    TermDto termDto = (TermDto) element;
58
		    TermDto partOfDto = termDto.getPartOfDto();
59
		    if(partOfDto!=null){
60
		        return partOfDto;
61
		    }
62
		    TermDto kindOfDto = termDto.getKindOfDto();
63
		    if(kindOfDto!=null){
64
		        return kindOfDto;
65
		    }
66
		    TermVocabularyDto vocabularyDto = termDto.getVocabularyDto();
67
		    if(vocabularyDto!=null){
68
		        return vocabularyDto;
69
		    }
70
		    //parent is the vocabulary
71
		    return new TermVocabularyDto(termDto.getVocabularyUuid(), null, termDto.getTermType());
72
		}
73
		return null;
74

    
75
	}
76

    
77
	@Override
78
	public boolean hasChildren(Object element) {
79
	    if(element instanceof TermVocabularyDto){
80
	        return getChildren(element).length > 0;
81
	    }
82
		if (getChildren(element) != null){
83
			return getChildren(element).length > 0;
84
		}
85
		return false;
86
	}
87

    
88
}
(4-4/6)