Merge branch 'hotfix/5.22.1'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / dna / SampleDesignationHistoryDetailSection.java
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.Comparator;
14 import java.util.LinkedList;
15
16 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
17 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
18 import eu.etaxonomy.cdm.model.common.Identifier;
19 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21 import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
22 import eu.etaxonomy.taxeditor.view.search.derivative.DerivateLabelProvider;
23
24 /**
25 * @author n.hoffmann
26 * @created May 11, 2011
27 * @version 1.0
28 */
29 public class SampleDesignationHistoryDetailSection extends AbstractSampleDesignationDetailSection {
30
31 /**
32 * @param formFactory
33 * @param conversation
34 * @param parentElement
35 * @param style
36 */
37 public SampleDesignationHistoryDetailSection(CdmFormFactory formFactory,
38 ConversationHolder conversation, ICdmFormElement parentElement,
39 int style) {
40 super(formFactory, conversation, parentElement, "Sample Designation History", style);
41 }
42
43 /* (non-Javadoc)
44 * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
45 */
46 @Override
47 public Collection<Identifier> getCollection(IdentifiableEntity<?> entity) {
48 LinkedList<Identifier> sampleDesignations = new LinkedList<>();
49 for (Identifier identifier : entity.getIdentifiers()) {
50 if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
51 sampleDesignations.add(identifier);
52 }
53 }
54 if(sampleDesignations.size()>0){
55 sampleDesignations.removeFirst();//first is the current sample designation
56 }
57 return sampleDesignations;
58 }
59
60 @Override
61 public Comparator<Identifier> getComparator() {
62 return new DefaultCdmBaseComparator<>();
63 }
64
65 @Override
66 public void refresh() {
67 internalUpdateSection(false);
68 }
69
70
71 /* (non-Javadoc)
72 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getTooltipString()
73 */
74 /** {@inheritDoc} */
75 @Override
76 protected String getTooltipString() {
77 return "Add a sample designation to the history";
78 }
79
80 /* (non-Javadoc)
81 * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
82 */
83 /** {@inheritDoc} */
84 @Override
85 public void addElement(Identifier sampleDesignation) {
86 //The current sample designation is always the first one found.
87 //The following are recent sample designations with the most recent being
88 //the second one found and so on
89 Identifier currentSampleDesignation = DerivateLabelProvider.getCurrentSampleDesignation(getEntity());
90 int indexOfCurrentSampleDesignation = getEntity().getIdentifiers().indexOf(currentSampleDesignation);
91 getEntity().addIdentifier(indexOfCurrentSampleDesignation+1, sampleDesignation);
92 }
93
94 /**
95 * {@inheritDoc}
96 */
97 @Override
98 public Identifier addExisting() {
99 return null;
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 @Override
106 public boolean allowAddExisting() {
107 return false;
108 }
109
110 }