Project

General

Profile

Download (2.78 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 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.ui.section.occurrence.dna;
10

    
11
import java.util.Collection;
12
import java.util.Comparator;
13
import java.util.LinkedList;
14

    
15
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
17
import eu.etaxonomy.cdm.model.common.Identifier;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
21
import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
22

    
23
/**
24
 * @author n.hoffmann
25
 * @created May 11, 2011
26
 */
27
public class SampleDesignationHistoryDetailSection extends AbstractSampleDesignationDetailSection {
28

    
29
	public SampleDesignationHistoryDetailSection(CdmFormFactory formFactory,
30
			ConversationHolder conversation, ICdmFormElement parentElement,
31
			int style) {
32
		super(formFactory, conversation, parentElement, "Sample Designation History", style);
33
	}
34

    
35
	@Override
36
	public Collection<Identifier> getCollection(IdentifiableEntity<?> entity) {
37
	    LinkedList<Identifier> sampleDesignations = new LinkedList<>();
38
	    for (Identifier identifier : entity.getIdentifiers()) {
39
	        if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
40
	            sampleDesignations.add(identifier);
41
	        }
42
	    }
43
	    if(sampleDesignations.size()>0){
44
	        sampleDesignations.removeFirst();//first is the current sample designation
45
	    }
46
	    return sampleDesignations;
47
	}
48

    
49
	@Override
50
	public Comparator<Identifier> getComparator() {
51
        return new DefaultCdmBaseComparator<>();
52
	}
53

    
54
	@Override
55
	public void refresh() {
56
		internalUpdateSection(false);
57
	}
58

    
59
	@Override
60
	protected String getTooltipString() {
61
		return "Add a sample designation to the history";
62
	}
63

    
64
    @Override
65
    public void addElement(Identifier sampleDesignation) {
66
        //The current sample designation is always the first one found.
67
        //The following are recent sample designations with the most recent being
68
        //the second one found and so on
69
        Identifier currentSampleDesignation = DerivateLabelProvider.getCurrentSampleDesignation(getEntity());
70
        int indexOfCurrentSampleDesignation = getEntity().getIdentifiers().indexOf(currentSampleDesignation);
71
        getEntity().addIdentifier(indexOfCurrentSampleDesignation+1, sampleDesignation);
72
    }
73

    
74
    @Override
75
    public Identifier addExisting() {
76
        return null;
77
    }
78

    
79
    @Override
80
    public boolean allowAddExisting() {
81
        return false;
82
    }
83
}
(21-21/32)