2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
;
11 import java
.util
.Collection
;
12 import java
.util
.HashSet
;
14 import org
.eclipse
.jface
.viewers
.TreeNodeContentProvider
;
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
;
27 public class TermDtoContentProvider
extends TreeNodeContentProvider
{
30 public Object
[] getElements(Object inputElement
) {
31 Collection
<TermVocabularyDto
> inputElements
= (Collection
<TermVocabularyDto
>) inputElement
;
32 return inputElements
.toArray();
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
));
40 } else if(parentElement
instanceof TermDto
){
41 if(((TermDto
) parentElement
).getIncludes()!=null){
42 children
.addAll(((TermDto
) parentElement
).getIncludes());
44 if(((TermDto
) parentElement
).getGeneralizationOf()!=null){
45 children
.addAll(((TermDto
) parentElement
).getGeneralizationOf());
48 return children
.toArray();
52 public Object
getParent(Object element
) {
53 if(element
instanceof TermDto
){
54 TermDto termDto
= (TermDto
) element
;
55 TermDto partOfDto
= termDto
.getPartOfDto();
59 TermDto kindOfDto
= termDto
.getKindOfDto();
63 TermVocabularyDto vocabularyDto
= termDto
.getVocabularyDto();
64 if(vocabularyDto
!=null){
67 //parent is the vocabulary
68 return new TermVocabularyDto(termDto
.getVocabularyUuid(), null, termDto
.getTermType());
75 public boolean hasChildren(Object element
) {
76 if(element
instanceof TermVocabularyDto
){
77 return getChildren(element
).length
> 0;
79 if (getChildren(element
) != null){
80 return getChildren(element
).length
> 0;