ref #6333 Add generic support for entity collection sections to allow
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / description / DescribedSpecimenSection.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.description;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.List;
15
16 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
17 import eu.etaxonomy.cdm.model.description.TaxonDescription;
18 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
19 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
20 import eu.etaxonomy.taxeditor.ui.dialog.selection.DerivedUnitSelectionDialog;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
24
25 /**
26 * <p>DescribedSpecimenSection class.</p>
27 *
28 * @author n.hoffmann
29 * @created Sep 16, 2010
30 * @version 1.0
31 */
32 public class DescribedSpecimenSection extends AbstractEntityCollectionSection<TaxonDescription, SpecimenOrObservationBase> {
33
34 /**
35 * <p>Constructor for DescribedSpecimenSection.</p>
36 *
37 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
38 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
39 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
40 * @param style a int.
41 */
42 public DescribedSpecimenSection(CdmFormFactory formFactory,
43 ConversationHolder conversation, ICdmFormElement parentElement,
44 int style) {
45 super(formFactory, conversation, parentElement, "Described Specimen", style);
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public Collection<SpecimenOrObservationBase> getCollection(
51 TaxonDescription entity) {
52 //FIXME:This class is not really an entity collection section, and should be moved
53 // to a single entity section, but one with the possibility of launching a wizard
54 List<SpecimenOrObservationBase> collection = new ArrayList<SpecimenOrObservationBase>();
55 if(entity.getDescribedSpecimenOrObservation() != null) {
56 collection.add(entity.getDescribedSpecimenOrObservation());
57 }
58 return collection;
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public SpecimenOrObservationBase createNewElement() {
64 DerivedUnit selection = DerivedUnitSelectionDialog.select(getShell(), getConversationHolder(), null);
65 return selection;
66 }
67
68 /** {@inheritDoc} */
69 @Override
70 public void addElement(SpecimenOrObservationBase element) {
71 getEntity().setDescribedSpecimenOrObservation(element);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public void removeElement(SpecimenOrObservationBase element) {
77 getEntity().setDescribedSpecimenOrObservation(null);
78 }
79
80 /** {@inheritDoc} */
81 @Override
82 public String getEmptyString() {
83 return "No described specimen yet.";
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 protected String getTooltipString() {
89 return "Add a described specimen.";
90 }
91
92 /**
93 * {@inheritDoc}
94 */
95 @Override
96 public SpecimenOrObservationBase addExisting() {
97 return null;
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public boolean allowAddExisting() {
105 return false;
106 }
107 }