Project

General

Profile

Download (2.93 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.ui.section.supplemental;
5

    
6
import java.util.ArrayList;
7
import java.util.Collection;
8
import java.util.Collections;
9
import java.util.List;
10

    
11
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
12
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
13
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
14
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
15
import eu.etaxonomy.cdm.model.media.Media;
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
18
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
19
import eu.etaxonomy.taxeditor.ui.section.description.SourceComparator;
20

    
21
/**
22
 * <p>SourceSection class.</p>
23
 *
24
 * @author n.hoffmann
25
 * @created Nov 17, 2009
26
 * @version 1.0
27
 */
28
public class SourceSection extends AbstractEntityCollectionSection<IIdentifiableEntity, IdentifiableSource> {
29

    
30
	/**
31
	 * <p>Constructor for SourceSection.</p>
32
	 *
33
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
34
	 * @param style a int.
35
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
36
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
37
	 */
38
	public SourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) {
39
		super(cdmFormFactory, conversation, parentElement, "Sources", style);
40
	}
41

    
42
	/** {@inheritDoc} */
43
	@Override
44
	public IdentifiableSource createNewElement() {
45
	    IIdentifiableEntity entity = getEntity();
46
	    OriginalSourceType type;
47
	    if(entity instanceof Media) {
48
	        type = OriginalSourceType.PrimaryMediaSource;
49
        }
50
	    else{
51
	        //default
52
	        type = OriginalSourceType.PrimaryTaxonomicSource;
53
	    }
54
	    return IdentifiableSource.NewInstance(type);
55
	}
56

    
57
	/** {@inheritDoc} */
58
	@Override
59
	public Collection<IdentifiableSource> getCollection(
60
			IIdentifiableEntity entity) {
61
		List<IdentifiableSource> sources = new ArrayList<IdentifiableSource>(entity.getSources());
62
		Collections.sort(sources, new SourceComparator());
63
        return sources;
64
	}
65

    
66
	/** {@inheritDoc} */
67
	@Override
68
	public String getEmptyString() {
69
		return "No references yet.";
70
	}
71

    
72
	/** {@inheritDoc} */
73
	@Override
74
	protected String getTooltipString() {
75
		return "Create a new reference.";
76
	}
77

    
78
	/** {@inheritDoc} */
79
	@Override
80
	public void addElement(IdentifiableSource element) {
81
		getEntity().addSource(element);
82
	}
83

    
84
	/** {@inheritDoc} */
85
	@Override
86
	public void removeElement(IdentifiableSource element) {
87
		getEntity().removeSource(element);
88
	}
89

    
90
    /**
91
     * {@inheritDoc}
92
     */
93
    @Override
94
    public IdentifiableSource addExisting() {
95
        // TODO Auto-generated method stub
96
        return null;
97
    }
98

    
99
    /**
100
     * {@inheritDoc}
101
     */
102
    @Override
103
    public boolean allowAddExisting() {
104
        // TODO Auto-generated method stub
105
        return false;
106
    }
107

    
108
}
(17-17/19)