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
|
import java.util.UUID;
|
14
|
|
15
|
import org.eclipse.jface.viewers.TreeNodeContentProvider;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
18
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
19
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
20
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
21
|
|
22
|
/**
|
23
|
*
|
24
|
* @author pplitzner
|
25
|
* @since Oct 29, 2018
|
26
|
*
|
27
|
*/
|
28
|
public class TermDtoContentProvider extends TreeNodeContentProvider {
|
29
|
|
30
|
@Override
|
31
|
public Object[] getElements(Object inputElement) {
|
32
|
Collection<TermVocabularyDto> inputElements = (Collection<TermVocabularyDto>) inputElement;
|
33
|
return inputElements.toArray();
|
34
|
}
|
35
|
|
36
|
@Override
|
37
|
public Object[] getChildren(Object parentElement) {
|
38
|
Collection<Object> children = new HashSet<>();
|
39
|
if(parentElement instanceof TermVocabularyDto){
|
40
|
children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(((TermVocabularyDto)parentElement).getUuid()));
|
41
|
} else if(parentElement instanceof TermDto){
|
42
|
if(((TermDto) parentElement).getIncludes()!=null){
|
43
|
children.addAll(((TermDto) parentElement).getIncludes());
|
44
|
}
|
45
|
if(((TermDto) parentElement).getGeneralizationOf()!=null){
|
46
|
children.addAll(((TermDto) parentElement).getGeneralizationOf());
|
47
|
}
|
48
|
}
|
49
|
return children.toArray();
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public Object getParent(Object element) {
|
54
|
if(element instanceof TermDto){
|
55
|
UUID partOfUuid = ((TermDto) element).getPartOfUuid();
|
56
|
if(partOfUuid==null){
|
57
|
return CdmStore.getService(IVocabularyService.class).load(((TermDto) element).getVocabularyUuid());
|
58
|
}
|
59
|
return new TermDto(partOfUuid, null, null);
|
60
|
}
|
61
|
return null;
|
62
|
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public boolean hasChildren(Object element) {
|
67
|
if(element instanceof TermVocabularyDto){
|
68
|
//performance optimization
|
69
|
return true;
|
70
|
}
|
71
|
if (getChildren(element) != null){
|
72
|
return getChildren(element).length > 0;
|
73
|
}
|
74
|
return false;
|
75
|
}
|
76
|
|
77
|
}
|