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
).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());
47 if(((TermDto
) parentElement
).getGeneralizationOf()!=null){
48 children
.addAll(((TermDto
) parentElement
).getGeneralizationOf());
51 return children
.toArray();
55 public Object
getParent(Object element
) {
56 if(element
instanceof TermDto
){
57 TermDto termDto
= (TermDto
) element
;
58 TermDto partOfDto
= termDto
.getPartOfDto();
62 TermDto kindOfDto
= termDto
.getKindOfDto();
66 TermVocabularyDto vocabularyDto
= termDto
.getVocabularyDto();
67 if(vocabularyDto
!=null){
70 //parent is the vocabulary
71 return new TermVocabularyDto(termDto
.getVocabularyUuid(), null, termDto
.getTermType());
78 public boolean hasChildren(Object element
) {
79 if(element
instanceof TermVocabularyDto
){
80 return getChildren(element
).length
> 0;
82 if (getChildren(element
) != null){
83 return getChildren(element
).length
> 0;