Project

General

Profile

Download (3.22 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

    
10
package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
11

    
12
import java.util.Collection;
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.view.derivateSearch.DerivateLabelProvider;
21

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

    
29
	/**
30
	 * @param formFactory
31
	 * @param conversation
32
	 * @param parentElement
33
	 * @param style
34
	 */
35
	public SampleDesignationHistoryDetailSection(CdmFormFactory formFactory,
36
			ConversationHolder conversation, ICdmFormElement parentElement,
37
			int style) {
38
		super(formFactory, conversation, parentElement, "Sample Designation History", style);
39
	}
40

    
41
	/* (non-Javadoc)
42
	 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
43
	 */
44
	@Override
45
	public Collection<Identifier> getCollection(IdentifiableEntity<?> entity) {
46
	    LinkedList<Identifier> sampleDesignations = new LinkedList<Identifier>();
47
	    for (Identifier identifier : entity.getIdentifiers()) {
48
	        if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
49
	            sampleDesignations.add(identifier);
50
	        }
51
	    }
52
	    if(sampleDesignations.size()>0){
53
	        sampleDesignations.removeFirst();//first is the current sample designation
54
	    }
55
	    return sampleDesignations;
56
	}
57

    
58
	@Override
59
	public void refresh() {
60
		internalUpdateSection(false);
61
	}
62

    
63

    
64
	/* (non-Javadoc)
65
	 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
66
	 */
67
	/** {@inheritDoc} */
68
	@Override
69
	protected String getTooltipString() {
70
		return "Add a sample designation to the history";
71
	}
72

    
73
	/* (non-Javadoc)
74
     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
75
     */
76
    /** {@inheritDoc} */
77
    @Override
78
    public void addElement(Identifier sampleDesignation) {
79
        //The current sample designation is always the first one found.
80
        //The following are recent sample designations with the most recent being
81
        //the second one found and so on
82
        Identifier currentSampleDesignation = DerivateLabelProvider.getCurrentSampleDesignation(getEntity());
83
        int indexOfCurrentSampleDesignation = getEntity().getIdentifiers().indexOf(currentSampleDesignation);
84
        getEntity().addIdentifier(indexOfCurrentSampleDesignation+1, sampleDesignation);
85
    }
86

    
87
    /**
88
     * {@inheritDoc}
89
     */
90
    @Override
91
    public Identifier addExisting() {
92
        return null;
93
    }
94

    
95
    /**
96
     * {@inheritDoc}
97
     */
98
    @Override
99
    public boolean allowAddExisting() {
100
        return false;
101
    }
102

    
103
}
(21-21/32)