Project

General

Profile

Download (3.1 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.input;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Set;
16

    
17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
18
import eu.etaxonomy.cdm.model.common.DefinedTerm;
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.cdm.model.common.TermType;
21
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22
import eu.etaxonomy.cdm.model.description.Feature;
23
import eu.etaxonomy.cdm.model.description.FeatureTree;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25
import eu.etaxonomy.taxeditor.store.TermStore;
26

    
27

    
28

    
29
/**
30
 * @author n.hoffmann
31
 * @date Jan 24, 2012
32
 *
33
 */
34
public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm> {
35

    
36
	private TermType termType;
37
	private Set<TermVocabulary<DefinedTermBase>> vocabularies;
38

    
39
	// FIXME: the default feature should be move to CdmApplicationState
40
	//        where it is a singleton instance variable
41
	private static FeatureTree defaultFeatureTree = null;
42

    
43
	private List<String> termClasses = Arrays.asList(new String[]{
44
			DefinedTerm.class.getName()
45
	});
46

    
47
	public TermEditorInput(TermType termType) {
48
		this.termType = termType;
49
		vocabularies = new HashSet<TermVocabulary<DefinedTermBase>>();
50
		initialiseVocabularies();
51
	}
52
	public String getName() {
53
		return termType.getMessage();
54
	}
55

    
56
	/* (non-Javadoc)
57
	 * @see eu.etaxonomy.taxeditor.editor.definedterm.input.AbstractDefinedTermEditorInput#getTermClasses()
58
	 */
59
	@Override
60
	public List<String> getTermClasses() {
61
		return termClasses;
62
	}
63

    
64
	public TermType getTermType() {
65
		return termType;
66
	}
67

    
68
	public void initialiseVocabularies() {
69
		if(vocabularies != null) {
70
			vocabularies.clear();
71
		}
72
		List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(termType,
73
		        Arrays.asList("terms"));
74
		vocabularies.addAll(vocs);
75
	}
76

    
77
	public Set<TermVocabulary<DefinedTermBase>> getVocabularies() {
78
		return vocabularies;
79
	}
80

    
81
	public void updateDefaultFeatureTree() {
82
	    for(TermVocabulary vocab : getVocabularies()) {
83
	        if(vocab != null && TermType.Feature.equals(vocab.getTermType())) {
84
	            defaultFeatureTree = null;
85
	            return;
86
	        }
87
	    }
88
	}
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public Set<TermVocabulary<DefinedTermBase>>  getRootEntities() {
94
        return getVocabularies();
95
    }
96
    /**
97
     * {@inheritDoc}
98
     */
99
    @Override
100
    public void merge() {
101
        CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);
102
        updateDefaultFeatureTree();
103
    }
104

    
105
    public static FeatureTree getDefaultFeatureTree() {
106
        if(defaultFeatureTree == null) {
107
            defaultFeatureTree = FeatureTree.NewInstance(TermStore.getTerms(Feature.class));
108
        }
109
        return defaultFeatureTree;
110
    }
111
}
(2-2/2)