Project

General

Profile

Download (2.53 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<Object> children = new HashSet<>();
38
	    if(parentElement instanceof TermVocabularyDto){
39
	        children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(((TermVocabularyDto)parentElement).getUuid()));
40
	    } else if(parentElement instanceof TermDto){
41
	            if(((TermDto) parentElement).getIncludes()!=null){
42
	                children.addAll(((TermDto) parentElement).getIncludes());
43
	            }
44
                if(((TermDto) parentElement).getGeneralizationOf()!=null){
45
                    children.addAll(((TermDto) parentElement).getGeneralizationOf());
46
                }
47
	    }
48
	    return children.toArray();
49
	}
50

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

    
72
	}
73

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

    
85
}
(4-4/6)